73d1cbcf71db180a1b2e27371a9520fd0a244d0b
[reactos.git] / ntoskrnl / ke / i386 / trap.s
1 /*
2 * FILE: ntoskrnl/ke/i386/trap.S
3 * COPYRIGHT: See COPYING in the top level directory
4 * PURPOSE: System Traps, Entrypoints and Exitpoints
5 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
6 * Timo Kreuzer (timo.kreuzer@reactos.org)
7 * NOTE: See asmmacro.S for the shared entry/exit code.
8 */
9
10 /* INCLUDES ******************************************************************/
11
12 #include <asm.inc>
13 #include <ks386.inc>
14 #include <internal/i386/asmmacro.S>
15
16 MACRO(GENERATE_IDT_STUB, Number)
17 idt _KiUnexpectedInterrupt&Number, INT_32_DPL0
18 ENDM
19
20 MACRO(GENERATE_INT_HANDLER, Number)
21 //.func KiUnexpectedInterrupt&Number
22 _KiUnexpectedInterrupt&Number:
23 push PRIMARY_VECTOR_BASE + Number
24 jmp _KiEndUnexpectedRange@0
25 //.endfunc
26 ENDM
27
28 EXTERN _KiTrap02:PROC
29
30 /* GLOBALS *******************************************************************/
31
32 .data
33 ASSUME nothing
34
35 PUBLIC _KiIdt
36 _KiIdt:
37 /* This is the Software Interrupt Table that we handle in this file: */
38 idt _KiTrap00, INT_32_DPL0 /* INT 00: Divide Error (#DE) */
39 idt _KiTrap01, INT_32_DPL0 /* INT 01: Debug Exception (#DB) */
40 idt _KiTrap02, INT_32_DPL0 /* INT 02: NMI Interrupt */
41 idt _KiTrap03, INT_32_DPL3 /* INT 03: Breakpoint Exception (#BP) */
42 idt _KiTrap04, INT_32_DPL3 /* INT 04: Overflow Exception (#OF) */
43 idt _KiTrap05, INT_32_DPL0 /* INT 05: BOUND Range Exceeded (#BR) */
44 idt _KiTrap06, INT_32_DPL0 /* INT 06: Invalid Opcode Code (#UD) */
45 idt _KiTrap07, INT_32_DPL0 /* INT 07: Device Not Available (#NM) */
46 idt _KiTrap08, INT_32_DPL0 /* INT 08: Double Fault Exception (#DF) */
47 idt _KiTrap09, INT_32_DPL0 /* INT 09: RESERVED */
48 idt _KiTrap0A, INT_32_DPL0 /* INT 0A: Invalid TSS Exception (#TS) */
49 idt _KiTrap0B, INT_32_DPL0 /* INT 0B: Segment Not Present (#NP) */
50 idt _KiTrap0C, INT_32_DPL0 /* INT 0C: Stack Fault Exception (#SS) */
51 idt _KiTrap0D, INT_32_DPL0 /* INT 0D: General Protection (#GP) */
52 idt _KiTrap0E, INT_32_DPL0 /* INT 0E: Page-Fault Exception (#PF) */
53 idt _KiTrap0F, INT_32_DPL0 /* INT 0F: RESERVED */
54 idt _KiTrap10, INT_32_DPL0 /* INT 10: x87 FPU Error (#MF) */
55 idt _KiTrap11, INT_32_DPL0 /* INT 11: Align Check Exception (#AC) */
56 idt _KiTrap0F, INT_32_DPL0 /* INT 12: Machine Check Exception (#MC)*/
57 idt _KiTrap0F, INT_32_DPL0 /* INT 13: SIMD FPU Exception (#XF) */
58 REPEAT 22
59 idt _KiTrap0F, INT_32_DPL0 /* INT 14-29: UNDEFINED INTERRUPTS */
60 ENDR
61 idt _KiGetTickCount, INT_32_DPL3 /* INT 2A: Get Tick Count Handler */
62 idt _KiCallbackReturn, INT_32_DPL3 /* INT 2B: User-Mode Callback Return */
63 idt _KiRaiseAssertion, INT_32_DPL3 /* INT 2C: Debug Assertion Handler */
64 idt _KiDebugService, INT_32_DPL3 /* INT 2D: Debug Service Handler */
65 idt _KiSystemService, INT_32_DPL3 /* INT 2E: System Call Service Handler */
66 idt _KiTrap0F, INT_32_DPL0 /* INT 2F: RESERVED */
67 i = 0
68 REPEAT 208
69 GENERATE_IDT_STUB %i
70 i = i + 1
71 ENDR
72
73 PUBLIC _KiIdtDescriptor
74 _KiIdtDescriptor:
75 .short 0
76 .short HEX(7FF)
77 .long _KiIdt
78
79 PUBLIC _KiUnexpectedEntrySize
80 _KiUnexpectedEntrySize:
81 .long _KiUnexpectedInterrupt1 - _KiUnexpectedInterrupt0
82
83 /******************************************************************************/
84 .code
85
86 TRAP_ENTRY KiTrap00, KI_PUSH_FAKE_ERROR_CODE
87 TRAP_ENTRY KiTrap01, KI_PUSH_FAKE_ERROR_CODE
88 TRAP_ENTRY KiTrap03, KI_PUSH_FAKE_ERROR_CODE
89 TRAP_ENTRY KiTrap04, KI_PUSH_FAKE_ERROR_CODE
90 TRAP_ENTRY KiTrap05, KI_PUSH_FAKE_ERROR_CODE
91 TRAP_ENTRY KiTrap06, KI_PUSH_FAKE_ERROR_CODE
92 TRAP_ENTRY KiTrap07, KI_PUSH_FAKE_ERROR_CODE
93 TRAP_ENTRY KiTrap08, 0
94 TRAP_ENTRY KiTrap09, KI_PUSH_FAKE_ERROR_CODE
95 TRAP_ENTRY KiTrap0A, 0
96 TRAP_ENTRY KiTrap0B, 0
97 TRAP_ENTRY KiTrap0C, 0
98 TRAP_ENTRY KiTrap0D, 0
99 TRAP_ENTRY KiTrap0E, 0
100 TRAP_ENTRY KiTrap0F, KI_PUSH_FAKE_ERROR_CODE
101 TRAP_ENTRY KiTrap10, KI_PUSH_FAKE_ERROR_CODE
102 TRAP_ENTRY KiTrap11, KI_PUSH_FAKE_ERROR_CODE
103 TRAP_ENTRY KiTrap13, KI_PUSH_FAKE_ERROR_CODE
104 TRAP_ENTRY KiGetTickCount, KI_PUSH_FAKE_ERROR_CODE
105 TRAP_ENTRY KiCallbackReturn, KI_PUSH_FAKE_ERROR_CODE
106 TRAP_ENTRY KiRaiseAssertion, KI_PUSH_FAKE_ERROR_CODE
107 TRAP_ENTRY KiDebugService, KI_PUSH_FAKE_ERROR_CODE
108 TRAP_ENTRY KiUnexpectedInterruptTail, 0
109
110 ALIGN 4
111 EXTERN @KiInterruptTemplateHandler@8:PROC
112 PUBLIC _KiInterruptTemplate
113 _KiInterruptTemplate:
114 KiEnterTrap KI_PUSH_FAKE_ERROR_CODE
115 PUBLIC _KiInterruptTemplate2ndDispatch
116 _KiInterruptTemplate2ndDispatch:
117 mov edx, 0
118 PUBLIC _KiInterruptTemplateObject
119 _KiInterruptTemplateObject:
120 mov eax, offset @KiInterruptTemplateHandler@8
121 jmp eax
122 PUBLIC _KiInterruptTemplateDispatch
123 _KiInterruptTemplateDispatch:
124
125 EXTERN @KiSystemServiceHandler@8:PROC
126 PUBLIC _KiSystemService
127 _KiSystemService:
128 KiEnterTrap (KI_PUSH_FAKE_ERROR_CODE OR KI_NONVOLATILES_ONLY OR KI_DONT_SAVE_SEGS)
129 KiCallHandler @KiSystemServiceHandler@8
130
131 EXTERN @KiFastCallEntryHandler@8:PROC
132 PUBLIC _KiFastCallEntry
133 _KiFastCallEntry:
134 KiEnterTrap (KI_FAST_SYSTEM_CALL OR KI_NONVOLATILES_ONLY OR KI_DONT_SAVE_SEGS)
135 KiCallHandler @KiFastCallEntryHandler@8
136
137 PUBLIC _KiStartUnexpectedRange@0
138 _KiStartUnexpectedRange@0:
139 i = 0
140 REPEAT 208
141 GENERATE_INT_HANDLER %i
142 i = i + 1
143 ENDR
144 PUBLIC _KiEndUnexpectedRange@0
145 _KiEndUnexpectedRange@0:
146 jmp _KiUnexpectedInterruptTail
147
148
149 /* EXIT CODE *****************************************************************/
150
151 KiTrapExitStub KiSystemCallReturn, (KI_RESTORE_EAX OR KI_RESTORE_EFLAGS OR KI_EXIT_JMP)
152 KiTrapExitStub KiSystemCallSysExitReturn, (KI_RESTORE_EAX OR KI_RESTORE_FS OR KI_RESTORE_EFLAGS OR KI_EXIT_SYSCALL)
153 KiTrapExitStub KiSystemCallTrapReturn, (KI_RESTORE_EAX OR KI_RESTORE_FS OR KI_EXIT_IRET)
154
155 KiTrapExitStub KiEditedTrapReturn, (KI_RESTORE_VOLATILES OR KI_RESTORE_EFLAGS OR KI_EDITED_FRAME OR KI_EXIT_RET)
156 KiTrapExitStub KiTrapReturn, (KI_RESTORE_VOLATILES OR KI_RESTORE_SEGMENTS OR KI_EXIT_IRET)
157 KiTrapExitStub KiTrapReturnNoSegments, (KI_RESTORE_VOLATILES OR KI_EXIT_IRET)
158
159 #ifdef _MSC_VER
160 EXTERN _PsConvertToGuiThread@0:PROC
161
162 PUBLIC _KiConvertToGuiThread@0
163 _KiConvertToGuiThread@0:
164 /* Calculate the stack frame offset in ebx */
165 mov ebx, ebp
166 sub ebx, esp
167
168 /* Call the worker function */
169 call _PsConvertToGuiThread@0
170
171 /* Adjust ebp to the new stack */
172 mov ebp, esp
173 add ebp, ebx
174
175 /* return to the caller */
176 ret
177 #endif
178
179 END