xref: /xv6-public/swtch.S (revision 6710e558)
12c5f7abaSRuss Cox# Context switch
22c5f7abaSRuss Cox#
32c5f7abaSRuss Cox#   void swtch(struct context **old, struct context *new);
4818fc012Srsc#
51ab23170SRobert Morris# Save the current registers on the stack, creating
61ab23170SRobert Morris# a struct context, and save its address in *old.
71ab23170SRobert Morris# Switch stacks to new and pop previously-saved registers.
8818fc012Srsc
9818fc012Srsc.globl swtch
10818fc012Srscswtch:
11818fc012Srsc  movl 4(%esp), %eax
12c100d9eeSkolya  movl 8(%esp), %edx
13818fc012Srsc
14*6710e558SFrans Kaashoek  # Save old callee-saved registers
15c100d9eeSkolya  pushl %ebp
16c100d9eeSkolya  pushl %ebx
17c100d9eeSkolya  pushl %esi
18c100d9eeSkolya  pushl %edi
19818fc012Srsc
20c100d9eeSkolya  # Switch stacks
21c100d9eeSkolya  movl %esp, (%eax)
222c5f7abaSRuss Cox  movl %edx, %esp
23818fc012Srsc
24*6710e558SFrans Kaashoek  # Load new callee-saved registers
25c100d9eeSkolya  popl %edi
26c100d9eeSkolya  popl %esi
27c100d9eeSkolya  popl %ebx
28c100d9eeSkolya  popl %ebp
29818fc012Srsc  ret
30