Q3. Suppose we are in following code, at line 4. --What is the entry at the top
ID: 3605320 • Letter: Q
Question
Q3. Suppose we are in following code, at line 4.--What is the entry at the top of kernel stack A ?
--What is the next entry?
--And the next ?
--And the next few entries (their order is not clearly known from the figures) but you can say what they are as a group. give the detail to tell me why the answer is what you write
1 # void swtch(struct context **old, struct context *new); 2 # 3 # Save current register context in old 4 # and then load register context from new. 5 .globl swtch 6 swtch: 7 # Save old registers 8 movl 4(%esp), %eax # put old ptr into eax 9 popl 0(%eax) # save the old IP 10 movl %esp, 4(%eax) # and stack 11 movl %ebx, 8(%eax) # and other registers 12 movl %ecx, 12(%eax) 13 movl %edx, 16(%eax) 14 movl %esi, 20(%eax) 15 movl %edi, 24(%eax) 16 movl %ebp, 28(%eax) 17 18 # Load new registers 19 movl 4(%esp), %eax # put new ptr into eax 20 movl 28(%eax), %ebp # restore other registers 21 movl 24(%eax), %edi 22 movl 20(%eax), %esi 23 movl 16(%eax), %edx 24 movl 12(%eax), %ecx 25 movl 8(%eax), %ebx 26 movl 4(%eax), %esp # stack is switched here 27 pushl 0(%eax) # return addr put in place 28 ret # finally return into new ctxt
Q3. Suppose we are in following code, at line 4.
--What is the entry at the top of kernel stack A ?
--What is the next entry?
--And the next ?
--And the next few entries (their order is not clearly known from the figures) but you can say what they are as a group. give the detail to tell me why the answer is what you write
1 # void swtch(struct context **old, struct context *new); 2 # 3 # Save current register context in old 4 # and then load register context from new. 5 .globl swtch 6 swtch: 7 # Save old registers 8 movl 4(%esp), %eax # put old ptr into eax 9 popl 0(%eax) # save the old IP 10 movl %esp, 4(%eax) # and stack 11 movl %ebx, 8(%eax) # and other registers 12 movl %ecx, 12(%eax) 13 movl %edx, 16(%eax) 14 movl %esi, 20(%eax) 15 movl %edi, 24(%eax) 16 movl %ebp, 28(%eax) 17 18 # Load new registers 19 movl 4(%esp), %eax # put new ptr into eax 20 movl 28(%eax), %ebp # restore other registers 21 movl 24(%eax), %edi 22 movl 20(%eax), %esi 23 movl 16(%eax), %edx 24 movl 12(%eax), %ecx 25 movl 8(%eax), %ebx 26 movl 4(%eax), %esp # stack is switched here 27 pushl 0(%eax) # return addr put in place 28 ret # finally return into new ctxt
Q3. Suppose we are in following code, at line 4.
--What is the entry at the top of kernel stack A ?
--What is the next entry?
--And the next ?
--And the next few entries (their order is not clearly known from the figures) but you can say what they are as a group. Q3. Suppose we are in following code, at line 4.
--What is the entry at the top of kernel stack A ?
--What is the next entry?
--And the next ?
--And the next few entries (their order is not clearly known from the figures) but you can say what they are as a group. give the detail to tell me why the answer is what you write
1 # void swtch(struct context **old, struct context *new); 2 # 3 # Save current register context in old 4 # and then load register context from new. 5 .globl swtch 6 swtch: 7 # Save old registers 8 movl 4(%esp), %eax # put old ptr into eax 9 popl 0(%eax) # save the old IP 10 movl %esp, 4(%eax) # and stack 11 movl %ebx, 8(%eax) # and other registers 12 movl %ecx, 12(%eax) 13 movl %edx, 16(%eax) 14 movl %esi, 20(%eax) 15 movl %edi, 24(%eax) 16 movl %ebp, 28(%eax) 17 18 # Load new registers 19 movl 4(%esp), %eax # put new ptr into eax 20 movl 28(%eax), %ebp # restore other registers 21 movl 24(%eax), %edi 22 movl 20(%eax), %esi 23 movl 16(%eax), %edx 24 movl 12(%eax), %ecx 25 movl 8(%eax), %ebx 26 movl 4(%eax), %esp # stack is switched here 27 pushl 0(%eax) # return addr put in place 28 ret # finally return into new ctxt
Explanation / Answer
# 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(%esp), %eax # put old ptr into eax
popl 0(%eax) # save the old IP
movl %esp, 4(%eax) # and stack
movl %ebx, 8(%eax) # and other registers
movl %ecx, 12(%eax)
movl %edx, 16(%eax)
movl %esi, 20(%eax)
movl %edi, 24(%eax)
movl %ebp, 28(%eax)
# Load new registers
movl 4(%esp), %eax # put new ptr into eax
movl 28(%eax), %ebp # restore other registers
movl 24(%eax), %edi
movl 20(%eax), %esi
movl 16(%eax), %edx
movl 12(%eax), %ecx
movl 8(%eax), %ebx
movl 4(%eax), %esp # stack is switched here
pushl 0(%eax) # return addr put in place
ret # finally return into new ctxt
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.