b00823af50044cd4e2cfb0a1f73fbd5802d18fd5
[pintos-anon] / src / threads / switch.S
1 #include "switch.h"
2
3         .globl switch_threads 
4 switch_threads:
5         # Save caller's register state.
6         # Note that the SVR4 ABI allows us to destroy %eax, %ecx, %edx.
7         # This stack frame must match the one set up by thread_create().
8         pushl %ebx
9         pushl %ebp
10         pushl %esi
11         pushl %edi
12
13         # Get offsetof (struct thread, stack).
14         .globl thread_stack_ofs
15         mov thread_stack_ofs, %edx
16
17         # Save current stack pointer to old thread's stack, if any.
18         movl SWITCH_CUR(%esp), %eax
19         test %eax, %eax
20         jz 1f
21         movl %esp, (%eax,%edx,1)
22 1:
23
24         # Restore stack pointer from new thread's stack.
25         movl SWITCH_NEXT(%esp), %ecx
26         movl (%ecx,%edx,1), %esp
27
28         # Restore caller's register state.
29         popl %edi
30         popl %esi
31         popl %ebp
32         popl %ebx
33         ret
34
35         .globl switch_thunk
36 switch_thunk:
37         addl $8, %esp
38         ret