7fedba83361b705b398de48adcba3bce68e2ae4d
[reactos.git] / reactos / ntoskrnl / include / internal / ke.h
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_KERNEL_H
21 #define __NTOSKRNL_INCLUDE_INTERNAL_KERNEL_H
22
23 /* INCLUDES *****************************************************************/
24
25 #ifndef __ASM__
26 #include <ddk/ntddk.h>
27
28 #include <stdarg.h>
29 #endif /* not __ASM__ */
30
31 /* INTERNAL KERNEL FUNCTIONS ************************************************/
32
33 #ifndef __ASM__
34
35 struct _KTHREAD;
36
37 #endif /* not __ASM__ */
38
39 #define KTRAP_FRAME_DEBUGEBP (0x0)
40 #define KTRAP_FRAME_DEBUGEIP (0x4)
41 #define KTRAP_FRAME_DEBUGARGMARK (0x8)
42 #define KTRAP_FRAME_DEBUGPOINTER (0xC)
43 #define KTRAP_FRAME_TEMPCS (0x10)
44 #define KTRAP_FRAME_TEMPEIP (0x14)
45 #define KTRAP_FRAME_DR0 (0x18)
46 #define KTRAP_FRAME_DR1 (0x1C)
47 #define KTRAP_FRAME_DR2 (0x20)
48 #define KTRAP_FRAME_DR3 (0x24)
49 #define KTRAP_FRAME_DR6 (0x28)
50 #define KTRAP_FRAME_DR7 (0x2C)
51 #define KTRAP_FRAME_GS (0x30)
52 #define KTRAP_FRAME_RESERVED1 (0x32)
53 #define KTRAP_FRAME_ES (0x34)
54 #define KTRAP_FRAME_RESERVED2 (0x36)
55 #define KTRAP_FRAME_DS (0x38)
56 #define KTRAP_FRAME_RESERVED3 (0x3A)
57 #define KTRAP_FRAME_EDX (0x3C)
58 #define KTRAP_FRAME_ECX (0x40)
59 #define KTRAP_FRAME_EAX (0x44)
60 #define KTRAP_FRAME_PREVIOUS_MODE (0x48)
61 #define KTRAP_FRAME_EXCEPTION_LIST (0x4C)
62 #define KTRAP_FRAME_FS (0x50)
63 #define KTRAP_FRAME_RESERVED4 (0x52)
64 #define KTRAP_FRAME_EDI (0x54)
65 #define KTRAP_FRAME_ESI (0x58)
66 #define KTRAP_FRAME_EBX (0x5C)
67 #define KTRAP_FRAME_EBP (0x60)
68 #define KTRAP_FRAME_ERROR_CODE (0x64)
69 #define KTRAP_FRAME_EIP (0x68)
70 #define KTRAP_FRAME_CS (0x6C)
71 #define KTRAP_FRAME_EFLAGS (0x70)
72 #define KTRAP_FRAME_ESP (0x74)
73 #define KTRAP_FRAME_SS (0x78)
74 #define KTRAP_FRAME_RESERVED5 (0x7A)
75 #define KTRAP_FRAME_V86_ES (0x7C)
76 #define KTRAP_FRAME_RESERVED6 (0x7E)
77 #define KTRAP_FRAME_V86_DS (0x80)
78 #define KTRAP_FRAME_RESERVED7 (0x82)
79 #define KTRAP_FRAME_V86_FS (0x84)
80 #define KTRAP_FRAME_RESERVED8 (0x86)
81 #define KTRAP_FRAME_V86_GS (0x88)
82 #define KTRAP_FRAME_RESERVED9 (0x8A)
83 #define KTRAP_FRAME_SIZE (0x8C)
84
85 #ifndef __ASM__
86
87 typedef struct _KTRAP_FRAME
88 {
89 PVOID DebugEbp;
90 PVOID DebugEip;
91 PVOID DebugArgMark;
92 PVOID DebugPointer;
93 PVOID TempCs;
94 PVOID TempEip;
95 PVOID Dr0;
96 PVOID Dr1;
97 PVOID Dr2;
98 PVOID Dr3;
99 PVOID Dr6;
100 PVOID Dr7;
101 USHORT Gs;
102 USHORT Reserved1;
103 USHORT Es;
104 USHORT Reserved2;
105 USHORT Ds;
106 USHORT Reserved3;
107 ULONG Edx;
108 ULONG Ecx;
109 ULONG Eax;
110 ULONG PreviousMode;
111 PVOID ExceptionList;
112 USHORT Fs;
113 USHORT Reserved4;
114 ULONG Edi;
115 ULONG Esi;
116 ULONG Ebx;
117 ULONG Ebp;
118 ULONG ErrorCode;
119 ULONG Eip;
120 ULONG Cs;
121 ULONG Eflags;
122 ULONG Esp;
123 USHORT Ss;
124 USHORT Reserved5;
125 USHORT V86_Es;
126 USHORT Reserved6;
127 USHORT V86_Ds;
128 USHORT Reserved7;
129 USHORT V86_Fs;
130 USHORT Reserved8;
131 USHORT V86_Gs;
132 USHORT Reserved9;
133 } KTRAP_FRAME, *PKTRAP_FRAME;
134
135 VOID KiUpdateSystemTime (KIRQL oldIrql, ULONG Eip);
136
137 VOID KeAcquireDispatcherDatabaseLock(BOOLEAN Wait);
138 VOID KeReleaseDispatcherDatabaseLock(BOOLEAN Wait);
139 BOOLEAN KeDispatcherObjectWake(DISPATCHER_HEADER* hdr);
140
141 #if 0
142 VOID KiInterruptDispatch(ULONG irq);
143 #endif
144 VOID STDCALL KeExpireTimers(PKDPC Apc,
145 PVOID Arg1,
146 PVOID Arg2,
147 PVOID Arg3);
148 VOID KeInitializeDispatcherHeader(DISPATCHER_HEADER* Header, ULONG Type,
149 ULONG Size, ULONG SignalState);
150
151 VOID KeDumpStackFrames(PULONG Frame);
152 ULONG KeAllocateGdtSelector(ULONG Desc[2]);
153 VOID KeFreeGdtSelector(ULONG Entry);
154 BOOLEAN KiTestAlert(VOID);
155 VOID KeRemoveAllWaitsThread(struct _ETHREAD* Thread, NTSTATUS WaitStatus);
156 PULONG KeGetStackTopThread(struct _ETHREAD* Thread);
157 VOID KeContextToTrapFrame(PCONTEXT Context,
158 PKTRAP_FRAME TrapFrame);
159 VOID KeReleaseDispatcherDatabaseLockAtDpcLevel(BOOLEAN Wait);
160 VOID
161 KiDeliverNormalApc(VOID);
162
163 BOOLEAN STDCALL KeRemoveQueueApc (PKAPC Apc);
164
165 /* INITIALIZATION FUNCTIONS *************************************************/
166
167 VOID KeInitExceptions(VOID);
168 VOID KeInitInterrupts(VOID);
169 VOID KeInitTimer(VOID);
170 VOID KeInitDpc(VOID);
171 VOID KeInitDispatcher(VOID);
172 VOID KeInitializeDispatcher(VOID);
173 VOID KeInitializeTimerImpl(VOID);
174 VOID KeInitializeBugCheck(VOID);
175 VOID Phase1Initialization(PVOID Context);
176
177 VOID KeInit1(VOID);
178 VOID KeInit2(VOID);
179
180 BOOLEAN KiDeliverUserApc(PKTRAP_FRAME TrapFrame);
181 VOID
182 NtEarlyInitVdm(VOID);
183 VOID
184 KiAddProfileEvent(KPROFILE_SOURCE Source, ULONG Eip);
185 VOID
186 KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
187 PCONTEXT Context,
188 PKTRAP_FRAME Tf,
189 KPROCESSOR_MODE PreviousMode,
190 BOOLEAN SearchFrames);
191 VOID KeTrapFrameToContext(PKTRAP_FRAME TrapFrame,
192 PCONTEXT Context);
193 struct _KPCR;
194 VOID
195 KiInitializeGdt(struct _KPCR* Pcr);
196 VOID
197 KeApplicationProcessorInit();
198 VOID
199 Ki386ApplicationProcessorInitializeTSS(VOID);
200 VOID
201 Ki386BootInitializeTSS(VOID);
202 VOID
203 KiGdtPrepareForApplicationProcessorInit(ULONG Id);
204 VOID
205 KePrepareForApplicationProcessorInit(ULONG id);
206 VOID
207 Ki386InitializeLdt(VOID);
208 ULONG
209 KiUserTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2);
210 VOID STDCALL
211 KePushAndStackSwitchAndSysRet(ULONG A, ULONG B, ULONG C, ULONG D, ULONG E,
212 ULONG F, PVOID NewStack);
213 VOID STDCALL
214 KeStackSwitchAndRet(PVOID NewStack);
215 VOID STDCALL
216 KeBugCheckWithTf(ULONG BugCheckCode,
217 ULONG BugCheckParameter1,
218 ULONG BugCheckParameter2,
219 ULONG BugCheckParameter3,
220 ULONG BugCheckParameter4,
221 PKTRAP_FRAME Tf);
222 VOID
223 KiDumpTrapFrame(PKTRAP_FRAME Tf, ULONG ExceptionNr, ULONG cr2);
224
225 #endif /* not __ASM__ */
226
227 #define MAXIMUM_PROCESSORS 32
228
229 #endif