1 .globl entry, __switch_context, __exit_context, halt
8 * We start execution from here.
9 * It is assumed that CPU is in 32-bit protected mode and
10 * all segments are 4GB and base zero (flat model).
13 /* Save boot context and switch to our main context.
14 * Main context is statically defined in C.
19 /* We get here when the main context switches back to
21 * Return to previous bootloader.
26 * Switch execution context
27 * This saves registers, segments, and GDT in the stack, then
28 * switches the stack, and restores everything from the new stack.
29 * This function takes no argument. New stack pointer is
30 * taken from global variable __context, and old stack pointer
31 * is also saved to __context. This way we can just jump to
32 * this routine to get back to the original context.
34 * Call this routine with lcall or pushl %cs; call.
37 /* Save everything in current stack */
45 movw %ss, (%esp) /* 0 */
49 /* Swap %cs and %eip on the stack, so lret will work */
55 /* At this point we don't know if we are on flat segment
56 * or relocated. So compute the address offset from %eip.
57 * Assuming CS.base==DS.base==SS.base.
63 /* Interrupts are not allowed... */
66 /* Current context pointer is our stack pointer */
69 /* Normalize the ctx pointer */
72 /* Swap it with new value */
73 xchgl %esi, __context(%ebx)
75 /* Adjust new ctx pointer for current address offset */
78 /* Load new %ss and %esp to temporary */
85 /* Load new stack segment with new GDT */
88 /* Set new stack pointer, but we have to adjust it because
89 * pushal saves %esp value before pushal, and we want the value
94 /* Load the rest from new stack */
102 /* Finally, load new %cs and %eip */
106 /* Get back to the original context */
108 call __switch_context
110 /* We get here if the other context attempt to switch to this
111 * dead context. This should not happen. */