3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
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.
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.
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.
20 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_KERNEL_H
21 #define __NTOSKRNL_INCLUDE_INTERNAL_KERNEL_H
23 /* INCLUDES *****************************************************************/
26 #include <ddk/ntddk.h>
29 #endif /* not __ASM__ */
31 /* INTERNAL KERNEL FUNCTIONS ************************************************/
37 #endif /* not __ASM__ */
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)
87 typedef struct _KTRAP_FRAME
133 } KTRAP_FRAME
, *PKTRAP_FRAME
;
135 VOID
KiUpdateSystemTime (KIRQL oldIrql
, ULONG Eip
);
137 VOID
KeAcquireDispatcherDatabaseLock(BOOLEAN Wait
);
138 VOID
KeReleaseDispatcherDatabaseLock(BOOLEAN Wait
);
139 BOOLEAN
KeDispatcherObjectWake(DISPATCHER_HEADER
* hdr
);
142 VOID
KiInterruptDispatch(ULONG irq
);
144 VOID STDCALL
KeExpireTimers(PKDPC Apc
,
148 VOID
KeInitializeDispatcherHeader(DISPATCHER_HEADER
* Header
, ULONG Type
,
149 ULONG Size
, ULONG SignalState
);
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
);
161 KiDeliverNormalApc(VOID
);
163 BOOLEAN STDCALL
KeRemoveQueueApc (PKAPC Apc
);
165 /* INITIALIZATION FUNCTIONS *************************************************/
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
);
180 BOOLEAN
KiDeliverUserApc(PKTRAP_FRAME TrapFrame
);
182 NtEarlyInitVdm(VOID
);
184 KiAddProfileEvent(KPROFILE_SOURCE Source
, ULONG Eip
);
186 KiDispatchException(PEXCEPTION_RECORD ExceptionRecord
,
189 KPROCESSOR_MODE PreviousMode
,
190 BOOLEAN SearchFrames
);
191 VOID
KeTrapFrameToContext(PKTRAP_FRAME TrapFrame
,
195 KiInitializeGdt(struct _KPCR
* Pcr
);
197 KeApplicationProcessorInit();
199 Ki386ApplicationProcessorInitializeTSS(VOID
);
201 Ki386BootInitializeTSS(VOID
);
203 KiGdtPrepareForApplicationProcessorInit(ULONG Id
);
205 KePrepareForApplicationProcessorInit(ULONG id
);
207 Ki386InitializeLdt(VOID
);
209 KiUserTrapHandler(PKTRAP_FRAME Tf
, ULONG ExceptionNr
, PVOID Cr2
);
211 KePushAndStackSwitchAndSysRet(ULONG A
, ULONG B
, ULONG C
, ULONG D
, ULONG E
,
212 ULONG F
, PVOID NewStack
);
214 KeStackSwitchAndRet(PVOID NewStack
);
216 KeBugCheckWithTf(ULONG BugCheckCode
,
217 ULONG BugCheckParameter1
,
218 ULONG BugCheckParameter2
,
219 ULONG BugCheckParameter3
,
220 ULONG BugCheckParameter4
,
223 KiDumpTrapFrame(PKTRAP_FRAME Tf
, ULONG ExceptionNr
, ULONG cr2
);
225 #endif /* not __ASM__ */
227 #define MAXIMUM_PROCESSORS 32