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
22 /* FUNCTIONS ****************************************************************/
25 PUBLIC @KiSwapContextInternal@0
26 @KiSwapContextInternal@0:
27 /* Build switch frame */
30 jmp @KiSwapContextEntry@8
33 PUBLIC @KiSwapContext@8
35 /* Save 4 registers */
38 /* Save all the non-volatile ones */
44 /* Get the wait IRQL */
47 /* Do the swap with the registers correctly setup */
48 call @KiSwapContextInternal@0
50 /* Return the registers */
61 PUBLIC @KiSwitchThreads@8
63 /* Load the new kernel stack and switch OS to new thread */
65 call @KiSwapContextExit@8
67 /* Now we're on the new thread. Return to the caller to restore registers */
72 PUBLIC @KiRetireDpcListInDpcStack@8
73 @KiRetireDpcListInDpcStack@8:
74 /* Switch stacks and retire DPCs */
78 call @KiRetireDpcList@4
80 /* Return on original stack */
84 PUBLIC _Ki386EnableCurrentLargePage@8
85 _Ki386EnableCurrentLargePage@8:
86 /* Save StartAddress in eax */
89 /* Save new CR3 value in ecx */
92 /* Save flags value */
95 /* Disable interrupts */
98 /* Compute linear address */
99 sub eax, offset _Ki386EnableCurrentLargePage@8
100 add eax, offset _Ki386LargePageIdentityLabel
102 /* Save old CR3 in edx and replace with a new one */
106 /* Jump to the next instruction but in linear mapping */
109 _Ki386LargePageIdentityLabel:
115 /* Jump to the next instruction to clear the prefetch queue */
118 /* Enable Page Size Extension in CR4 */
123 /* Done, now re-enable paging */
127 /* Jump to virtual address */
128 mov eax, offset VirtualSpace
132 /* Restore CR3 contents */
140 /* FIXFIX: Move to C code ****/
141 PUBLIC _Ki386SetupAndExitToV86Mode@4
142 _Ki386SetupAndExitToV86Mode@4:
144 /* Enter V8086 mode */
146 sub esp, (12 + KTRAP_FRAME_LENGTH + NPX_FRAME_LENGTH + 16)
148 call @KiEnterV86Mode@4
152 PUBLIC @Ki386BiosCallReturnAddress@4
153 @Ki386BiosCallReturnAddress@4:
155 /* Exit V8086 mode */
156 call @KiExitV86Mode@4
158 add esp, (12 + KTRAP_FRAME_LENGTH + NPX_FRAME_LENGTH + 16)