Question: ( 4 ) Why the following context switch code is sufficient so that the old process can restart later without a problem? # void swtch

(4) Why the following context switch code is sufficient so that the old process can
restart later without a problem?
# void swtch (struct context **old, struct context *new);
#
# Save current register context in old
# and then load register context from new.
globl swtch
swtch:
# Save old registers
movl 4(sesp), seax # put old ptr into eax
popl O(seax) # save the old IP
movl sesp, 4(seax) # and stack
movl sebx, 8(seax) # and other registers
movl secx,12(seax)
movl sedx, 16(seax)
movl sesi, 20(seax)
movl sedi, 24(seax)
movl sebp, 28(seax)
# Load new registers
mov14(sesp), seax # put new ptr into eax
movl 28(seax), sebp # restore other registers
movl 24(seax), sedi
movl 20(seax), sesi
movl 16(seax), sedx
movl 12(seax), secx
movl 8(seax), sebx
movl 4(seax), sesp # stack is switched here
pushl 0(seax) # return addr put in place
ret # Einally return into new ctxt
Figure 6.4: The xv6 Context Switch Code
 (4) Why the following context switch code is sufficient so that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!