Handed out: Wednesday, September 28, 2005
Due: Wednesday, October 5, 2005
Read: chapters 7, 8 and 11 of Lions'
commentary and the relevant source code.
Hand-In Procedure
You are to turn in this homework during lecture. Please write up your answers to the exercises below and hand them in to a 6.828 staff member by the end of the lecture.
Introduction
In this homework you will investigate how the kernel switches between two processes.
Switching Process Contexts
Start the PDP-11 simulator using the unmodified unix v6 kernel.
We want to break the simulation at line 2228 in swtch() where kernel process 0 (the scheduler) first switches to process 1 using the call to retu() from main() through sched().
Armed with our trusty 'v6 db unix' (the unix file should be in '$V6ROOT/usr/sys/conf') command, we find that the instructions for swtch() (kernel symbol _swtch) begin at location 15544. Disassembling the procedure:
sim> ex -v 15544-16000 15544: JSR R5,3552 15550: TST 117474 15554: BNE 15564 ... 15740: JSR PC,@#2536 15744: JSR PC,4440 ... |
We find a 'JSR PC, @#2536' at memory address 15740 -- the first instruction of retu() lies at memory location 2536. 'JSR PC, 4440' is the next instruction in swtch()'s disassembly -- sureg() lies at location 4440. So these two instructions correspond to lines 2228-2229 of 'slp.c'.
We can tell the simulator to break just before the call to retu():
sim> de BREAK 15740 sim> boot rk0 @unix Breakpoint, PC=015740 (JSR PC,@#2536) R0=000000 R1=015604 R2=063116 R3=000000 R4=000000 R5=141724 KSP=141714 USP=177760 PSW=030000 (CM=0,PM=3,IPL=0,tnzvc) |
Exercise
1. What does rp->p_addr point to in this call to
retu()?
Although you can answer this question without knowing the actual value of rp->p_addr, it is the first argument to retu() so you may step once in the simulation and examine the top of the (kernel) stack. |
The simulator is stopped at the point in the kernel just before retu() is called to switch to process 1. Now make the simulator execute this call:
sim> de break 15744 sim> cont Breakpoint, PC=015744 (JSR PC,4440) R0=140004 R1=015744 R2=063116 R3=000000 R4=000000 R5=141760 KSP=141740 USP=177760 PSW=030010 (CM=0,PM=3,IPL=0,tNzvc) |
Exercise
2. What was loaded into the sixth kernel segment address register
and what does this value represent?
This load happens at line 740 in retu() You can examine the kernel segment registers using the command 'ex kipar0-kipdr7' in the PDP-11 simulator. |
Exercise 3. What does the global symbol '_u' refer to? It is declared on line 1440 (in m40.s). |
This completes the homework.