2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ke/i386/ctxswitch.S
5 * PURPOSE: Thread Context Switching
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
8 * Gregor Anich (FPU Code)
11 /* INCLUDES ******************************************************************/
16 EXTERN @KiSwapContextEntry@8:PROC
17 EXTERN @KiSwapContextExit@8:PROC
18 EXTERN @KiRetireDpcList@4:PROC
19 EXTERN @KiEnterV86Mode@4:PROC
20 EXTERN @KiExitV86Mode@4:PROC
21 EXTERN _KeI386FxsrPresent:DWORD
23 /* FUNCTIONS ****************************************************************/
26 PUBLIC @KiSwapContextInternal@0
27 @KiSwapContextInternal@0:
28 /* Build switch frame */
31 jmp @KiSwapContextEntry@8
34 PUBLIC @KiSwapContext@8
36 /* Save 4 registers */
39 /* Save all the non-volatile ones */
45 /* Get the wait IRQL */
48 /* Do the swap with the registers correctly setup */
49 call @KiSwapContextInternal@0
51 /* Return the registers */
62 PUBLIC @KiSwitchThreads@8
64 /* Load the new kernel stack and switch OS to new thread */
66 call @KiSwapContextExit@8
68 /* Now we're on the new thread. Return to the caller to restore registers */
73 PUBLIC @KiRetireDpcListInDpcStack@8
74 @KiRetireDpcListInDpcStack@8:
75 /* Switch stacks and retire DPCs */
79 call @KiRetireDpcList@4
81 /* Return on original stack */
85 PUBLIC _Ki386EnableCurrentLargePage@8
86 _Ki386EnableCurrentLargePage@8:
87 /* Save StartAddress in eax */
90 /* Save new CR3 value in ecx */
93 /* Save flags value */
96 /* Disable interrupts */
99 /* Compute linear address */
100 sub eax, offset _Ki386EnableCurrentLargePage@8
101 add eax, offset _Ki386LargePageIdentityLabel
103 /* Save old CR3 in edx and replace with a new one */
107 /* Jump to the next instruction but in linear mapping */
110 _Ki386LargePageIdentityLabel:
116 /* Jump to the next instruction to clear the prefetch queue */
119 /* Enable Page Size Extension in CR4 */
124 /* Done, now re-enable paging */
128 /* Jump to virtual address */
129 mov eax, offset VirtualSpace
133 /* Restore CR3 contents */
141 /* FIXFIX: Move to C code ****/
142 PUBLIC _Ki386SetupAndExitToV86Mode@4
143 _Ki386SetupAndExitToV86Mode@4:
145 /* Enter V8086 mode */
147 sub esp, (12 + KTRAP_FRAME_LENGTH + NPX_FRAME_LENGTH + 16)
149 call @KiEnterV86Mode@4
153 PUBLIC @Ki386BiosCallReturnAddress@4
154 @Ki386BiosCallReturnAddress@4:
156 /* Exit V8086 mode */
157 call @KiExitV86Mode@4
159 add esp, (12 + KTRAP_FRAME_LENGTH + NPX_FRAME_LENGTH + 16)
164 PUBLIC @Ke386LoadFpuState@4
165 @Ke386LoadFpuState@4:
167 /* Check if we have FXSR and choose which operand to use */
168 test byte ptr [_KeI386FxsrPresent], 1
171 /* Restore all the FPU, MMX, XMM and MXCSR registers */
176 * Just restore the basic FPU registers.
177 * This may raise an exception depending
178 * on the status word, which KiNpxHandler will
179 * need to check for and handle during delayed load
180 * to avoid raising an unhandled exception
181 * and crashing the system.