- Add some more misc. public definitions and fix exfuncs.h so that it can be included...
[reactos.git] / reactos / include / ndk / i386 / ketypes.h
1 /*++ NDK Version: 0095
2
3 Copyright (c) Alex Ionescu. All rights reserved.
4
5 Header Name:
6
7 ketypes.h (X86)
8
9 Abstract:
10
11 i386 Type definitions for the Kernel services.
12
13 Author:
14
15 Alex Ionescu (alex.ionescu@reactos.com) 06-Oct-2004
16
17 --*/
18
19 #ifndef _I386_KETYPES_H
20 #define _I386_KETYPES_H
21
22 //
23 // Dependencies
24 //
25
26 //
27 // X86 80386 Segment Types
28 //
29 #define I386_TASK_GATE 0x5
30 #define I386_TSS 0x9
31 #define I386_ACTIVE_TSS 0xB
32 #define I386_CALL_GATE 0xC
33 #define I386_INTERRUPT_GATE 0xE
34 #define I386_TRAP_GATE 0xF
35
36 //
37 // IPI Types
38 //
39 #define IPI_APC 1
40 #define IPI_DPC 2
41 #define IPI_FREEZE 3
42 #define IPI_PACKET_READY 4
43 #define IPI_SYNCH_REQUEST 10
44
45 //
46 // FN/FX (FPU) Save Area Structures
47 //
48 typedef struct _FNSAVE_FORMAT
49 {
50 ULONG ControlWord;
51 ULONG StatusWord;
52 ULONG TagWord;
53 ULONG ErrorOffset;
54 ULONG ErrorSelector;
55 ULONG DataOffset;
56 ULONG DataSelector;
57 UCHAR RegisterArea[80];
58 } FNSAVE_FORMAT, *PFNSAVE_FORMAT;
59
60 typedef struct _FXSAVE_FORMAT
61 {
62 USHORT ControlWord;
63 USHORT StatusWord;
64 USHORT TagWord;
65 USHORT ErrorOpcode;
66 ULONG ErrorOffset;
67 ULONG ErrorSelector;
68 ULONG DataOffset;
69 ULONG DataSelector;
70 ULONG MXCsr;
71 ULONG MXCsrMask;
72 UCHAR RegisterArea[128];
73 UCHAR Reserved3[128];
74 UCHAR Reserved4[224];
75 UCHAR Align16Byte[8];
76 } FXSAVE_FORMAT, *PFXSAVE_FORMAT;
77
78 typedef struct _FX_SAVE_AREA
79 {
80 union
81 {
82 FNSAVE_FORMAT FnArea;
83 FXSAVE_FORMAT FxArea;
84 } U;
85 ULONG NpxSavedCpu;
86 ULONG Cr0NpxState;
87 } FX_SAVE_AREA, *PFX_SAVE_AREA;
88
89 //
90 // Trap Frame Definition
91 //
92 typedef struct _KTRAP_FRAME
93 {
94 ULONG DbgEbp;
95 ULONG DbgEip;
96 ULONG DbgArgMark;
97 ULONG DbgArgPointer;
98 ULONG TempSegCs;
99 ULONG TempEsp;
100 ULONG Dr0;
101 ULONG Dr1;
102 ULONG Dr2;
103 ULONG Dr3;
104 ULONG Dr6;
105 ULONG Dr7;
106 ULONG SegGs;
107 ULONG SegEs;
108 ULONG SegDs;
109 ULONG Edx;
110 ULONG Ecx;
111 ULONG Eax;
112 ULONG PreviousPreviousMode;
113 struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
114 ULONG SegFs;
115 ULONG Edi;
116 ULONG Esi;
117 ULONG Ebx;
118 ULONG Ebp;
119 ULONG ErrCode;
120 ULONG Eip;
121 ULONG SegCs;
122 ULONG EFlags;
123 ULONG HardwareEsp;
124 ULONG HardwareSegSs;
125 ULONG V86Es;
126 ULONG V86Ds;
127 ULONG V86Fs;
128 ULONG V86Gs;
129 } KTRAP_FRAME, *PKTRAP_FRAME;
130
131 //
132 // LDT Entry Definition
133 //
134 typedef struct _LDT_ENTRY
135 {
136 USHORT LimitLow;
137 USHORT BaseLow;
138 union
139 {
140 struct
141 {
142 UCHAR BaseMid;
143 UCHAR Flags1;
144 UCHAR Flags2;
145 UCHAR BaseHi;
146 } Bytes;
147 struct
148 {
149 ULONG BaseMid : 8;
150 ULONG Type : 5;
151 ULONG Dpl : 2;
152 ULONG Pres : 1;
153 ULONG LimitHi : 4;
154 ULONG Sys : 1;
155 ULONG Reserved_0 : 1;
156 ULONG Default_Big : 1;
157 ULONG Granularity : 1;
158 ULONG BaseHi : 8;
159 } Bits;
160 } HighWord;
161 } LDT_ENTRY, *PLDT_ENTRY, *LPLDT_ENTRY;
162
163 //
164 // GDT Entry Definition
165 //
166 typedef struct _KGDTENTRY
167 {
168 USHORT LimitLow;
169 USHORT BaseLow;
170 union
171 {
172 struct
173 {
174 UCHAR BaseMid;
175 UCHAR Flags1;
176 UCHAR Flags2;
177 UCHAR BaseHi;
178 } Bytes;
179 struct
180 {
181 ULONG BaseMid : 8;
182 ULONG Type : 5;
183 ULONG Dpl : 2;
184 ULONG Pres : 1;
185 ULONG LimitHi : 4;
186 ULONG Sys : 1;
187 ULONG Reserved_0 : 1;
188 ULONG Default_Big : 1;
189 ULONG Granularity : 1;
190 ULONG BaseHi : 8;
191 } Bits;
192 } HighWord;
193 } KGDTENTRY, *PKGDTENTRY;
194
195 //
196 // IDT Entry Access Definition
197 //
198 typedef struct _KIDT_ACCESS
199 {
200 union
201 {
202 struct
203 {
204 UCHAR Reserved;
205 UCHAR SegmentType:4;
206 UCHAR SystemSegmentFlag:1;
207 UCHAR Dpl:2;
208 UCHAR Present:1;
209 };
210 USHORT Value;
211 };
212 } KIDT_ACCESS, *PKIDT_ACCESS;
213
214 //
215 // IDT Entry Definition
216 //
217 typedef struct _KIDTENTRY
218 {
219 USHORT Offset;
220 USHORT Selector;
221 USHORT Access;
222 USHORT ExtendedOffset;
223 } KIDTENTRY, *PKIDTENTRY;
224
225 //
226 // Page Table Entry Definition
227 //
228 typedef struct _HARDWARE_PTE_X86
229 {
230 ULONG Valid : 1;
231 ULONG Write : 1;
232 ULONG Owner : 1;
233 ULONG WriteThrough : 1;
234 ULONG CacheDisable : 1;
235 ULONG Accessed : 1;
236 ULONG Dirty : 1;
237 ULONG LargePage : 1;
238 ULONG Global : 1;
239 ULONG CopyOnWrite : 1;
240 ULONG Prototype : 1;
241 ULONG reserved : 1;
242 ULONG PageFrameNumber : 20;
243 } HARDWARE_PTE_X86, *PHARDWARE_PTE_X86;
244
245 typedef struct _DESCRIPTOR
246 {
247 USHORT Pad;
248 USHORT Limit;
249 ULONG Base;
250 } KDESCRIPTOR, *PKDESCRIPTOR;
251
252 //
253 // Special Registers Structure (outside of CONTEXT)
254 //
255 typedef struct _KSPECIAL_REGISTERS
256 {
257 ULONG Cr0;
258 ULONG Cr2;
259 ULONG Cr3;
260 ULONG Cr4;
261 ULONG KernelDr0;
262 ULONG KernelDr1;
263 ULONG KernelDr2;
264 ULONG KernelDr3;
265 ULONG KernelDr6;
266 ULONG KernelDr7;
267 KDESCRIPTOR Gdtr;
268 KDESCRIPTOR Idtr;
269 USHORT Tr;
270 USHORT Ldtr;
271 ULONG Reserved[6];
272 } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
273
274 //
275 // Processor State Data
276 //
277 #pragma pack(push,4)
278 typedef struct _KPROCESSOR_STATE
279 {
280 PCONTEXT ContextFrame;
281 KSPECIAL_REGISTERS SpecialRegisters;
282 } KPROCESSOR_STATE;
283
284 //
285 // Processor Region Control Block
286 //
287 typedef struct _KPRCB
288 {
289 USHORT MinorVersion;
290 USHORT MajorVersion;
291 struct _KTHREAD *CurrentThread;
292 struct _KTHREAD *NextThread;
293 struct _KTHREAD *IdleThread;
294 UCHAR Number;
295 UCHAR Reserved;
296 USHORT BuildType;
297 KAFFINITY SetMember;
298 UCHAR CpuType;
299 UCHAR CpuID;
300 USHORT CpuStep;
301 KPROCESSOR_STATE ProcessorState;
302 ULONG KernelReserved[16];
303 ULONG HalReserved[16];
304 UCHAR PrcbPad0[92];
305 PVOID LockQueue[33]; // Used for Queued Spinlocks
306 struct _KTHREAD *NpxThread;
307 ULONG InterruptCount;
308 ULONG KernelTime;
309 ULONG UserTime;
310 ULONG DpcTime;
311 ULONG DebugDpcTime;
312 ULONG InterruptTime;
313 ULONG AdjustDpcThreshold;
314 ULONG PageColor;
315 UCHAR SkipTick;
316 UCHAR DebuggerSavedIRQL;
317 UCHAR Spare1[6];
318 struct _KNODE *ParentNode;
319 ULONG MultiThreadProcessorSet;
320 struct _KPRCB *MultiThreadSetMaster;
321 ULONG ThreadStartCount[2];
322 ULONG CcFastReadNoWait;
323 ULONG CcFastReadWait;
324 ULONG CcFastReadNotPossible;
325 ULONG CcCopyReadNoWait;
326 ULONG CcCopyReadWait;
327 ULONG CcCopyReadNoWaitMiss;
328 ULONG KeAlignmentFixupCount;
329 ULONG KeContextSwitches;
330 ULONG KeDcacheFlushCount;
331 ULONG KeExceptionDispatchCount;
332 ULONG KeFirstLevelTbFills;
333 ULONG KeFloatingEmulationCount;
334 ULONG KeIcacheFlushCount;
335 ULONG KeSecondLevelTbFills;
336 ULONG KeSystemCalls;
337 ULONG IoReadOperationCount;
338 ULONG IoWriteOperationCount;
339 ULONG IoOtherOperationCount;
340 LARGE_INTEGER IoReadTransferCount;
341 LARGE_INTEGER IoWriteTransferCount;
342 LARGE_INTEGER IoOtherTransferCount;
343 ULONG SpareCounter1[8];
344 PP_LOOKASIDE_LIST PPLookasideList[16];
345 PP_LOOKASIDE_LIST PPNPagedLookasideList[32];
346 PP_LOOKASIDE_LIST PPPagedLookasideList[32];
347 ULONG PacketBarrier;
348 ULONG ReverseStall;
349 PVOID IpiFrame;
350 UCHAR PrcbPad2[52];
351 PVOID CurrentPacket[3];
352 ULONG TargetSet;
353 ULONG_PTR WorkerRoutine;
354 ULONG IpiFrozen;
355 UCHAR PrcbPad3[40];
356 ULONG RequestSummary;
357 struct _KPRCB *SignalDone;
358 UCHAR PrcbPad4[56];
359 struct _KDPC_DATA DpcData[2];
360 PVOID DpcStack;
361 ULONG MaximumDpcQueueDepth;
362 ULONG DpcRequestRate;
363 ULONG MinimumDpcRate;
364 UCHAR DpcInterruptRequested;
365 UCHAR DpcThreadRequested;
366 UCHAR DpcRoutineActive;
367 UCHAR DpcThreadActive;
368 ULONG PrcbLock;
369 ULONG DpcLastCount;
370 ULONG TimerHand;
371 ULONG TimerRequest;
372 PVOID DpcThread;
373 struct _KEVENT *DpcEvent;
374 UCHAR ThreadDpcEnable;
375 BOOLEAN QuantumEnd;
376 UCHAR PrcbPad50;
377 UCHAR IdleSchedule;
378 ULONG DpcSetEventRequest;
379 UCHAR PrcbPad5[18];
380 LONG TickOffset;
381 struct _KDPC* CallDpc;
382 ULONG PrcbPad7[8];
383 LIST_ENTRY WaitListHead;
384 ULONG ReadySummary;
385 ULONG SelectNextLast;
386 LIST_ENTRY DispatcherReadyListHead[32];
387 SINGLE_LIST_ENTRY DeferredReadyListHead;
388 ULONG PrcbPad72[11];
389 PVOID ChainedInterruptList;
390 LONG LookasideIrpFloat;
391 LONG MmPageFaultCount;
392 LONG MmCopyOnWriteCount;
393 LONG MmTransitionCount;
394 LONG MmCacheTransitionCount;
395 LONG MmDemandZeroCount;
396 LONG MmPageReadCount;
397 LONG MmPageReadIoCount;
398 LONG MmCacheReadCount;
399 LONG MmCacheIoCount;
400 LONG MmDirtyPagesWriteCount;
401 LONG MmDirtyWriteIoCount;
402 LONG MmMappedPagesWriteCount;
403 LONG MmMappedWriteIoCount;
404 ULONG SpareFields0[1];
405 CHAR VendorString[13];
406 UCHAR InitialApicId;
407 UCHAR LogicalProcessorsPerPhysicalProcessor;
408 ULONG MHz;
409 ULONG FeatureBits;
410 LARGE_INTEGER UpdateSignature;
411 LARGE_INTEGER IsrTime;
412 LARGE_INTEGER SpareField1;
413 FX_SAVE_AREA NpxSaveArea;
414 PROCESSOR_POWER_STATE PowerState;
415 } KPRCB, *PKPRCB;
416
417 //
418 // Processor Control Region
419 //
420 typedef struct _KIPCR
421 {
422 union
423 {
424 NT_TIB NtTib;
425 struct
426 {
427 struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
428 PVOID Used_StackBase;
429 PVOID PerfGlobalGroupMask;
430 PVOID TssCopy;
431 ULONG ContextSwitches;
432 KAFFINITY SetMemberCopy;
433 PVOID Used_Self;
434 };
435 };
436 struct _KPCR *Self; /* 1C */
437 struct _KPRCB *Prcb; /* 20 */
438 KIRQL Irql; /* 24 */
439 ULONG IRR; /* 28 */
440 ULONG IrrActive; /* 2C */
441 ULONG IDR; /* 30 */
442 PVOID KdVersionBlock; /* 34 */
443 #ifdef _REACTOS_
444 PUSHORT IDT; /* 38 */
445 PUSHORT GDT; /* 3C */
446 #else
447 PKIDTENTRY IDT; /* 38 */
448 PKGDTENTRY GDT; /* 3C */
449 #endif
450 struct _KTSS *TSS; /* 40 */
451 USHORT MajorVersion; /* 44 */
452 USHORT MinorVersion; /* 46 */
453 KAFFINITY SetMember; /* 48 */
454 ULONG StallScaleFactor; /* 4C */
455 UCHAR SparedUnused; /* 50 */
456 UCHAR Number; /* 51 */
457 UCHAR Reserved; /* 52 */
458 UCHAR L2CacheAssociativity; /* 53 */
459 ULONG VdmAlert; /* 54 */
460 ULONG KernelReserved[14]; /* 58 */
461 ULONG L2CacheSize; /* 90 */
462 ULONG HalReserved[16]; /* 94 */
463 ULONG InterruptMode; /* D4 */
464 UCHAR KernelReserved2[0x48]; /* D8 */
465 KPRCB PrcbData; /* 120 */
466 } KIPCR, *PKIPCR;
467 #pragma pack(pop)
468
469 //
470 // TSS Definition
471 //
472 typedef struct _KiIoAccessMap
473 {
474 UCHAR DirectionMap[32];
475 UCHAR IoMap[8196];
476 } KIIO_ACCESS_MAP;
477
478 #include <pshpack1.h>
479 typedef struct _KTSS
480 {
481 USHORT Backlink;
482 USHORT Reserved0;
483 ULONG Esp0;
484 USHORT Ss0;
485 USHORT Reserved1;
486 ULONG NotUsed1[4];
487 ULONG CR3;
488 ULONG Eip;
489 ULONG NotUsed2[9];
490 USHORT Es;
491 USHORT Reserved2;
492 USHORT Cs;
493 USHORT Reserved3;
494 USHORT Ss;
495 USHORT Reserved4;
496 USHORT Ds;
497 USHORT Reserved5;
498 USHORT Fs;
499 USHORT Reserved6;
500 USHORT Gs;
501 USHORT Reserved7;
502 USHORT LDT;
503 USHORT Reserved8;
504 USHORT Flags;
505 USHORT IoMapBase;
506 KIIO_ACCESS_MAP IoMaps[1];
507 UCHAR IntDirectionMap[32];
508 } KTSS, *PKTSS;
509 #include <poppack.h>
510
511 //
512 // i386 CPUs don't have exception frames
513 //
514 typedef struct _KEXCEPTION_FRAME KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
515
516 #endif