| 1 | # Context switch |
| 2 | # |
| 3 | # void swtch(struct context **old, struct context *new); |
| 4 | # |
| 5 | # Save the current registers on the stack, creating |
| 6 | # a struct context, and save its address in *old. |
| 7 | # Switch stacks to new and pop previously-saved registers. |
| 8 | |
| 9 | .globl swtch |
| 10 | swtch: |
| 11 | movl 4(%esp), %eax |
| 12 | movl 8(%esp), %edx |
| 13 | |
| 14 | # Save old callee-saved registers |
| 15 | pushl %ebp |
| 16 | pushl %ebx |
| 17 | pushl %esi |
| 18 | pushl %edi |
| 19 | |
| 20 | # Switch stacks |
| 21 | movl %esp, (%eax) |
| 22 | movl %edx, %esp |
| 23 | |
| 24 | # Load new callee-saved registers |
| 25 | popl %edi |
| 26 | popl %esi |
| 27 | popl %ebx |
| 28 | popl %ebp |
| 29 | ret |
| 30 | |