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