100 likes | 242 Views
제 25 강 : Context Switching in pdp / unix , savu () retu (). Context Switching in pdp/unix savu() retu(). savu( ) SP,EP. sh vi sim. CPU R0 R1 | S P E P. PAR PDR. a.out j u-stack. a.out k u-stack. a.out i u-stack. user
E N D
제25강 : Context Switching in pdp/unix, savu() retu() Context Switching in pdp/unixsavu() retu()
savu( ) SP,EP sh vi sim CPU R0 R1 | S P E P PAR PDR a.out j u-stack a.out k u-stack a.out i u-stack user k-stack user k-stack user k-stack KERNEL proc[i] proc[j] proc[k] … • Process-k was running so far • We will run process-j next • 3. Save current EP & SP in struct user • savu(u.u_rsav) • ** no need to save ppda address • ** Pk’s struct user saved EP & SP Kernel a.out
CPU R0 R1 | S P E P sh vi sim PAR PDR a.out k u-stack a.out j u-stack a.out i u-stack user k-stack user k-stack user k-stack KERNEL 1. Process-k was running so far 2. We will run process-j next 3. Save current EP & SP in struct user savu(u.u_rsav) 4. Choose next proc[j] to run 5.retu(proc[j] . p_addr) loads Kernel 7th PAR p_addr CPU(SP, EP) u.u_rsav proc[i] proc[j] proc[k] … Kernel a.out
retu( ) EP SP ppda sh vi sim CPU R0 R1 | S P E P PAR PDR a.out k u-stack a.out j u-stack a.out i u-stack user k-stack user k-stack user k-stack ppda KERNEL p_addr 1. Process-k was running so far 2. We will run process-j next 3. Save current EP & SP in struct user savu(u.u_rsav) 4. Choose next proc[j] to run 5. retu(proc[j] . p_addr) loads Kernel 7th PAR p_addr CPU(SP, EP) u.u_rsav proc[i] proc[j] proc[k] … Kernel a.out Now kernel is ready to work for new proc[j] now kernel is pointing to new image (vi’s a.out) to new struct user (vi’s environment) (just say “u” and it’s new user struct now) to new kernel stack (vi’s kernel history)
summaryretu() assembler procedure (8-2-1) a.out EP PAR PDR proc[i].p_addr load new ppda from proc[ ] user kernel stack k-stack structuseru.u_rsav[] load SP & EP bottom = ppda SP
user kernel stack summarysavu() assembler procedure (8-2-1) a.out EP PAR PDR X proc[i].p_addr don’t need this proc[ ] already has it k-stack structuseru.u_rsav[] save SP & EP bottom = ppda =proc[] SP
r5 = EP r6 = SP r7 = PC savu retu call trap()
SummaryContext Switching PAR PDR calls savu() for retiring process CPU(SP, EP) u .u_rsav calls retu() for arising process kernel’s 7th-page proc[new] CPU(SP,EP) u .u_rsav text kernel code data user KERNEL ppda SP kernel stack for user EP swappable data segment PAR PDR text data stack USER
Assembler procedures (8-2-1) • savu() + retu() co-routine jump • savu (u.u_rsav) save kernel SP EP => u.u_rsav (save) (omit saving ppda addr – since it’s in p_addr) • retu(proc[i].p_addr) 7-th kernel address reg. => new ppda CPU kernel SP, EP <= from u.u_rsav • aretu() + return non-local goto • aretu(x) SP EP <=X (new stack frame) • then “return” instruction (pop return address) To where? Not to immediate caller … to whatever that was stored in stack before Retiringprocess Arising process