1# Context switch 2# 3# void swtch(struct context **old, struct context *new); 4# 5# Save current register context in old 6# and then load register context from new. 7 8.globl swtch 9swtch: 10 movl 4(%esp), %eax 11 movl 8(%esp), %edx 12 13 # Save old callee-save registers 14 pushl %ebp 15 pushl %ebx 16 pushl %esi 17 pushl %edi 18 19 # Switch stacks 20 movl %esp, (%eax) 21 movl %edx, %esp 22 23 # Load new callee-save registers 24 popl %edi 25 popl %esi 26 popl %ebx 27 popl %ebp 28 ret 29 30# Jump on a new stack, fake C calling conventions 31.globl jstack 32jstack: 33 movl 4(%esp), %esp 34 subl $16, %esp # space for arguments 35 movl $0, %ebp # terminate functions that follow ebp's 36 call mainc # continue at mainc 37