Make userspace actually work.
[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_entry
36 switch_entry:
37         # Discard thread_switch() arguments.
38         addl $8, %esp
39
40         # Call schedule_tail(prev).
41         pushl %eax
42         .globl schedule_tail
43         call schedule_tail
44         addl $4, %esp
45
46         # Start thread proper.
47         ret