1 #include "threads/switch.h"
3 #### struct thread *switch_threads (struct thread *cur, struct thread *next);
5 #### Switches from CUR, which must be the running thread, to NEXT,
6 #### which must also be running switch_threads(), returning CUR in
9 #### This function works by assuming that the thread we're switching
10 #### into is also running switch_threads(). Thus, all it has to do is
11 #### preserve a few registers on the stack, then switch stacks and
12 #### restore the registers. As part of switching stacks we record the
13 #### current stack pointer in CUR's thread structure.
15 .intel_syntax noprefix
19 # Save caller's register state.
21 # Note that the SVR4 ABI allows us to destroy eax, ecx, edx,
22 # but requires us to preserve ebx, ebp, esi, edi. See
23 # [SysV-ABI-386] pages 3-11 and 3-12 for details.
25 # This stack frame must match the one set up by thread_create().
31 # Get offsetof (struct thread, stack).
32 .globl thread_stack_ofs
33 mov edx, thread_stack_ofs
35 # Save current stack pointer to old thread's stack, if any.
36 mov eax, SWITCH_CUR[esp]
42 # Restore stack pointer from new thread's stack.
43 mov ecx, SWITCH_NEXT[esp]
46 # Restore caller's register state.
55 # Discard switch_threads() arguments.
58 # Call schedule_tail(prev).
64 # Start thread proper.