xref: /xv6-public/swtch.S (revision 818fc012)
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
20  # Load new registers
21  movl 4(%esp), %eax  # not 8(%esp) - popped return address above
22
23  movl 28(%eax), %ebp
24  movl 24(%eax), %edi
25  movl 20(%eax), %esi
26  movl 16(%eax), %edx
27  movl 12(%eax), %ecx
28  movl 8(%eax), %ebx
29  movl 4(%eax), %esp
30  pushl 0(%eax)  # %eip
31
32  ret
33