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 6.globl swtch 7swtch: 8 # Save old registers 9 movl 4(%esp), %eax 10 11 popl 0(%eax) # %eip 12 movl %esp, 4(%eax) 13 movl %ebx, 8(%eax) 14 movl %ecx, 12(%eax) 15 movl %edx, 16(%eax) 16 movl %esi, 20(%eax) 17 movl %edi, 24(%eax) 18 movl %ebp, 28(%eax) 19 movl %ss, %ebx 20 movl %ebx, 32(%eax) 21 22 # Load new registers 23 movl 4(%esp), %eax # not 8(%esp) - popped return address above 24 25 movl 32(%eax), %ebx 26 movl %ebx, %ss 27 movl 28(%eax), %ebp 28 movl 24(%eax), %edi 29 movl 20(%eax), %esi 30 movl 16(%eax), %edx 31 movl 12(%eax), %ecx 32 movl 8(%eax), %ebx 33 movl 4(%eax), %esp 34 pushl 0(%eax) # %eip 35 36 ret 37