3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
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.
19 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_I386_PS_H
20 #define __NTOSKRNL_INCLUDE_INTERNAL_I386_PS_H
24 #include <ndk/potypes.h> /* FIXME: TEMP HACK */
29 * Defines for accessing KPCR and KTHREAD structure members
31 #define KTHREAD_INITIAL_STACK 0x18
32 #define KTHREAD_STACK_LIMIT 0x1C
33 #define KTHREAD_TEB 0x20
34 #define KTHREAD_KERNEL_STACK 0x28
35 #define KTHREAD_NPX_STATE 0x31
36 #define KTHREAD_STATE 0x2D
37 #define KTHREAD_APCSTATE_PROCESS 0x34 + 0x10
38 #define KTHREAD_PENDING_USER_APC 0x34 + 0x16
39 #define KTHREAD_PENDING_KERNEL_APC 0x34 + 0x15
40 #define KTHREAD_CONTEXT_SWITCHES 0x4C
41 #define KTHREAD_WAIT_IRQL 0x54
42 #define KTHREAD_SERVICE_TABLE 0xDC
43 #define KTHREAD_PREVIOUS_MODE 0x137
44 #define KTHREAD_TRAP_FRAME 0x128
45 #define KTHREAD_CALLBACK_STACK 0x120
48 #define KPROCESS_DIRECTORY_TABLE_BASE 0x18
49 #define KPROCESS_LDT_DESCRIPTOR0 0x20
50 #define KPROCESS_LDT_DESCRIPTOR1 0x24
51 #define KPROCESS_IOPM_OFFSET 0x30
53 #define KPCR_BASE 0xFF000000
55 #define KPCR_EXCEPTION_LIST 0x0
56 #define KPCR_INITIAL_STACK 0x4
57 #define KPCR_STACK_LIMIT 0x8
58 #define KPCR_SELF 0x1C
61 #define KPCR_CURRENT_THREAD 0x124
62 #define KPCR_NPX_THREAD 0x2A4
70 /* Fixme: Use correct types? */
71 typedef struct _KPROCESSOR_STATE
{
72 PCONTEXT ContextFrame
;
73 PVOID SpecialRegisters
;
76 /* ProcessoR Control Block */
77 typedef struct _KPRCB
{
80 struct _KTHREAD
*CurrentThread
;
81 struct _KTHREAD
*NextThread
;
82 struct _KTHREAD
*IdleThread
;
90 KPROCESSOR_STATE ProcessorState
;
91 ULONG KernelReserved
[16];
92 ULONG HalReserved
[16];
94 PVOID LockQueue
[33]; // Used for Queued Spinlocks
95 struct _KTHREAD
*NpxThread
;
102 ULONG AdjustDpcThreshold
;
105 UCHAR DebuggerSavedIRQL
;
107 struct _KNODE
*ParentNode
;
108 ULONG MultiThreadProcessorSet
;
109 struct _KPRCB
*MultiThreadSetMaster
;
110 ULONG ThreadStartCount
[2];
111 ULONG CcFastReadNoWait
;
112 ULONG CcFastReadWait
;
113 ULONG CcFastReadNotPossible
;
114 ULONG CcCopyReadNoWait
;
115 ULONG CcCopyReadWait
;
116 ULONG CcCopyReadNoWaitMiss
;
117 ULONG KeAlignmentFixupCount
;
118 ULONG KeContextSwitches
;
119 ULONG KeDcacheFlushCount
;
120 ULONG KeExceptionDispatchCount
;
121 ULONG KeFirstLevelTbFills
;
122 ULONG KeFloatingEmulationCount
;
123 ULONG KeIcacheFlushCount
;
124 ULONG KeSecondLevelTbFills
;
126 ULONG IoReadOperationCount
;
127 ULONG IoWriteOperationCount
;
128 ULONG IoOtherOperationCount
;
129 LARGE_INTEGER IoReadTransferCount
;
130 LARGE_INTEGER IoWriteTransferCount
;
131 LARGE_INTEGER IoOtherTransferCount
;
132 ULONG SpareCounter1
[8];
133 PP_LOOKASIDE_LIST PPLookasideList
[16];
134 PP_LOOKASIDE_LIST PPNPagedLookasideList
[32];
135 PP_LOOKASIDE_LIST PPPagedLookasideList
[32];
140 PVOID CurrentPacket
[3];
142 ULONG_PTR WorkerRoutine
;
145 ULONG RequestSummary
;
146 struct _KPRCB
*SignalDone
;
148 struct _KDPC_DATA DpcData
[2];
150 ULONG MaximumDpcQueueDepth
;
151 ULONG DpcRequestRate
;
152 ULONG MinimumDpcRate
;
153 UCHAR DpcInterruptRequested
;
154 UCHAR DpcThreadRequested
;
155 UCHAR DpcRoutineActive
;
156 UCHAR DpcThreadActive
;
162 struct _KEVENT
*DpcEvent
;
163 UCHAR ThreadDpcEnable
;
167 ULONG DpcSetEventRequest
;
170 struct _KDPC
* CallDpc
;
172 LIST_ENTRY WaitListHead
;
174 ULONG SelectNextLast
;
175 LIST_ENTRY DispatcherReadyListHead
[32];
176 SINGLE_LIST_ENTRY DeferredReadyListHead
;
178 PVOID ChainedInterruptList
;
179 LONG LookasideIrpFloat
;
180 LONG MmPageFaultCount
;
181 LONG MmCopyOnWriteCount
;
182 LONG MmTransitionCount
;
183 LONG MmCacheTransitionCount
;
184 LONG MmDemandZeroCount
;
185 LONG MmPageReadCount
;
186 LONG MmPageReadIoCount
;
187 LONG MmCacheReadCount
;
189 LONG MmDirtyPagesWriteCount
;
190 LONG MmDirtyWriteIoCount
;
191 LONG MmMappedPagesWriteCount
;
192 LONG MmMappedWriteIoCount
;
193 ULONG SpareFields0
[1];
194 CHAR VendorString
[13];
196 UCHAR LogicalProcessorsPerPhysicalProcessor
;
199 LARGE_INTEGER UpdateSignature
;
200 LARGE_INTEGER IsrTime
;
201 LARGE_INTEGER SpareField1
;
202 FX_SAVE_AREA NpxSaveArea
;
203 PROCESSOR_POWER_STATE PowerState
;
212 * Processor Control Region Thread Information Block
214 typedef struct _KPCR_TIB
{
215 PVOID ExceptionList
; /* 00 */
216 PVOID StackBase
; /* 04 */
217 PVOID StackLimit
; /* 08 */
218 PVOID SubSystemTib
; /* 0C */
220 PVOID FiberData
; /* 10 */
221 DWORD Version
; /* 10 */
223 PVOID ArbitraryUserPointer
; /* 14 */
224 struct _KPCR_TIB
* Self
; /* 18 */
225 } KPCR_TIB
, *PKPCR_TIB
; /* 18 */
228 * Processor Control Region
230 typedef struct _KPCR
{
231 KPCR_TIB Tib
; /* 00 */
232 struct _KPCR
*Self
; /* 1C */
233 struct _KPRCB
*Prcb
; /* 20 */
236 ULONG IrrActive
; /* 2C */
238 PVOID KdVersionBlock
; /* 34 */
239 PUSHORT IDT
; /* 38 */
240 PUSHORT GDT
; /* 3C */
241 struct _KTSS
*TSS
; /* 40 */
242 USHORT MajorVersion
; /* 44 */
243 USHORT MinorVersion
; /* 46 */
244 KAFFINITY SetMember
; /* 48 */
245 ULONG StallScaleFactor
; /* 4C */
246 UCHAR DebugActive
; /* 50 */
247 UCHAR Number
; /* 51 */
248 UCHAR Reserved
; /* 52 */
249 UCHAR L2CacheAssociativity
; /* 53 */
250 ULONG VdmAlert
; /* 54 */
251 ULONG KernelReserved
[14]; /* 58 */
252 ULONG L2CacheSize
; /* 90 */
253 ULONG HalReserved
[16]; /* 94 */
254 ULONG InterruptMode
; /* D4 */
255 UCHAR KernelReserved2
[0x48]; /* D8 */
256 KPRCB PrcbData
; /* 120 */
260 #endif /* __USE_W32API */
265 * This is the complete, internal KPCR structure
267 typedef struct _KIPCR
{
268 KPCR_TIB Tib
; /* 00 */
269 struct _KPCR
*Self
; /* 1C */
270 struct _KPRCB
*Prcb
; /* 20 */
273 ULONG IrrActive
; /* 2C */
275 PVOID KdVersionBlock
; /* 34 */
276 PUSHORT IDT
; /* 38 */
277 PUSHORT GDT
; /* 3C */
278 struct _KTSS
*TSS
; /* 40 */
279 USHORT MajorVersion
; /* 44 */
280 USHORT MinorVersion
; /* 46 */
281 KAFFINITY SetMember
; /* 48 */
282 ULONG StallScaleFactor
; /* 4C */
283 UCHAR SparedUnused
; /* 50 */
284 UCHAR Number
; /* 51 */
285 UCHAR Reserved
; /* 52 */
286 UCHAR L2CacheAssociativity
; /* 53 */
287 ULONG VdmAlert
; /* 54 */
288 ULONG KernelReserved
[14]; /* 58 */
289 ULONG L2CacheSize
; /* 90 */
290 ULONG HalReserved
[16]; /* 94 */
291 ULONG InterruptMode
; /* D4 */
292 UCHAR KernelReserved2
[0x48]; /* D8 */
293 KPRCB PrcbData
; /* 120 */
302 static inline PKPCR
KeGetCurrentKPCR(VOID
)
306 #if defined(__GNUC__)
307 __asm__
__volatile__ ("movl %%fs:0x1C, %0\n\t"
311 #elif defined(_MSC_VER)
312 __asm mov eax
, fs
:0x1C;
313 __asm mov value
, eax
;
315 #error Unknown compiler for inline assembler
317 return((PKPCR
)value
);
320 static inline PKPRCB
KeGetCurrentPrcb(VOID
)
324 #if defined(__GNUC__)
325 __asm__
__volatile__ ("movl %%fs:0x20, %0\n\t"
329 #elif defined(_MSC_VER)
330 __asm mov eax
, fs
:0x20;
331 __asm mov value
, eax
;
333 #error Unknown compiler for inline assembler
335 return((PKPRCB
)value
);
340 #define KeGetCurrentKPCR(X) ((PKPCR)KPCR_BASE)
341 #define KeGetCurrentPrcb() (((PKPCR)KPCR_BASE)->Prcb)
342 #define KeGetCurrentThread(X) (((PKPCR)KPCR_BASE)->PrcbData.CurrentThread)
346 #endif /* __USE_W32API */
350 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_PS_H */