- NDK 0.98, now with versionned headers. Too many changes to list, see the TinyKRNL...
[reactos.git] / reactos / include / ndk / i386 / ketypes.h
1 /*++ NDK Version: 0098
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 (alexi@tinykrnl.org) - Updated - 27-Feb-2006
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 // Selector Names
38 //
39 #define RPL_MASK 0x0003
40 #define MODE_MASK 0x0001
41 #define KGDT_R0_CODE (0x8)
42 #define KGDT_R0_DATA (0x10)
43 #define KGDT_R3_CODE (0x18)
44 #define KGDT_R3_DATA (0x20)
45 #define KGDT_TSS (0x28)
46 #define KGDT_R0_PCR (0x30)
47 #define KGDT_R3_TEB (0x38)
48 #define KGDT_LDT (0x48)
49 #define KGDT_DF_TSS (0x50)
50 #define KGDT_NMI_TSS (0x58)
51
52 //
53 // CR4
54 //
55 #define CR4_VME 0x1
56 #define CR4_PVI 0x2
57 #define CR4_TSD 0x4
58 #define CR4_DE 0x8
59 #define CR4_PSE 0x10
60 #define CR4_PAE 0x20
61 #define CR4_MCE 0x40
62 #define CR4_PGE 0x80
63 #define CR4_FXSR 0x200
64 #define CR4_XMMEXCPT 0x400
65
66 //
67 // EFlags
68 //
69 #define EFLAGS_TF 0x100
70 #define EFLAGS_INTERRUPT_MASK 0x200
71 #define EFLAGS_NESTED_TASK 0x4000
72 #define EFLAGS_V86_MASK 0x20000
73 #define EFLAGS_ALIGN_CHECK 0x40000
74 #define EFLAGS_VIF 0x80000
75 #define EFLAGS_VIP 0x100000
76 #define EFLAG_SIGN 0x8000
77 #define EFLAG_ZERO 0x4000
78
79 #ifndef NTOS_MODE_USER
80 //
81 // IPI Types
82 //
83 #define IPI_APC 1
84 #define IPI_DPC 2
85 #define IPI_FREEZE 4
86 #define IPI_PACKET_READY 8
87 #define IPI_SYNCH_REQUEST 16
88
89 //
90 // FN/FX (FPU) Save Area Structures
91 //
92 typedef struct _FNSAVE_FORMAT
93 {
94 ULONG ControlWord;
95 ULONG StatusWord;
96 ULONG TagWord;
97 ULONG ErrorOffset;
98 ULONG ErrorSelector;
99 ULONG DataOffset;
100 ULONG DataSelector;
101 UCHAR RegisterArea[80];
102 } FNSAVE_FORMAT, *PFNSAVE_FORMAT;
103
104 typedef struct _FXSAVE_FORMAT
105 {
106 USHORT ControlWord;
107 USHORT StatusWord;
108 USHORT TagWord;
109 USHORT ErrorOpcode;
110 ULONG ErrorOffset;
111 ULONG ErrorSelector;
112 ULONG DataOffset;
113 ULONG DataSelector;
114 ULONG MXCsr;
115 ULONG MXCsrMask;
116 UCHAR RegisterArea[128];
117 UCHAR Reserved3[128];
118 UCHAR Reserved4[224];
119 UCHAR Align16Byte[8];
120 } FXSAVE_FORMAT, *PFXSAVE_FORMAT;
121
122 typedef struct _FX_SAVE_AREA
123 {
124 union
125 {
126 FNSAVE_FORMAT FnArea;
127 FXSAVE_FORMAT FxArea;
128 } U;
129 ULONG NpxSavedCpu;
130 ULONG Cr0NpxState;
131 } FX_SAVE_AREA, *PFX_SAVE_AREA;
132
133 //
134 // Trap Frame Definition
135 //
136 typedef struct _KTRAP_FRAME
137 {
138 ULONG DbgEbp;
139 ULONG DbgEip;
140 ULONG DbgArgMark;
141 ULONG DbgArgPointer;
142 ULONG TempSegCs;
143 ULONG TempEsp;
144 ULONG Dr0;
145 ULONG Dr1;
146 ULONG Dr2;
147 ULONG Dr3;
148 ULONG Dr6;
149 ULONG Dr7;
150 ULONG SegGs;
151 ULONG SegEs;
152 ULONG SegDs;
153 ULONG Edx;
154 ULONG Ecx;
155 ULONG Eax;
156 ULONG PreviousPreviousMode;
157 struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
158 ULONG SegFs;
159 ULONG Edi;
160 ULONG Esi;
161 ULONG Ebx;
162 ULONG Ebp;
163 ULONG ErrCode;
164 ULONG Eip;
165 ULONG SegCs;
166 ULONG EFlags;
167 ULONG HardwareEsp;
168 ULONG HardwareSegSs;
169 ULONG V86Es;
170 ULONG V86Ds;
171 ULONG V86Fs;
172 ULONG V86Gs;
173 } KTRAP_FRAME, *PKTRAP_FRAME;
174
175 //
176 // LDT Entry Definition
177 //
178 typedef struct _LDT_ENTRY
179 {
180 USHORT LimitLow;
181 USHORT BaseLow;
182 union
183 {
184 struct
185 {
186 UCHAR BaseMid;
187 UCHAR Flags1;
188 UCHAR Flags2;
189 UCHAR BaseHi;
190 } Bytes;
191 struct
192 {
193 ULONG BaseMid:8;
194 ULONG Type:5;
195 ULONG Dpl:2;
196 ULONG Pres:1;
197 ULONG LimitHi:4;
198 ULONG Sys:1;
199 ULONG Reserved_0:1;
200 ULONG Default_Big:1;
201 ULONG Granularity:1;
202 ULONG BaseHi:8;
203 } Bits;
204 } HighWord;
205 } LDT_ENTRY, *PLDT_ENTRY, *LPLDT_ENTRY;
206
207 //
208 // GDT Entry Definition
209 //
210 typedef struct _KGDTENTRY
211 {
212 USHORT LimitLow;
213 USHORT BaseLow;
214 union
215 {
216 struct
217 {
218 UCHAR BaseMid;
219 UCHAR Flags1;
220 UCHAR Flags2;
221 UCHAR BaseHi;
222 } Bytes;
223 struct
224 {
225 ULONG BaseMid:8;
226 ULONG Type:5;
227 ULONG Dpl:2;
228 ULONG Pres:1;
229 ULONG LimitHi:4;
230 ULONG Sys:1;
231 ULONG Reserved_0:1;
232 ULONG Default_Big:1;
233 ULONG Granularity:1;
234 ULONG BaseHi:8;
235 } Bits;
236 } HighWord;
237 } KGDTENTRY, *PKGDTENTRY;
238
239 //
240 // IDT Entry Access Definition
241 //
242 typedef struct _KIDT_ACCESS
243 {
244 union
245 {
246 struct
247 {
248 UCHAR Reserved;
249 UCHAR SegmentType:4;
250 UCHAR SystemSegmentFlag:1;
251 UCHAR Dpl:2;
252 UCHAR Present:1;
253 };
254 USHORT Value;
255 };
256 } KIDT_ACCESS, *PKIDT_ACCESS;
257
258 //
259 // IDT Entry Definition
260 //
261 typedef struct _KIDTENTRY
262 {
263 USHORT Offset;
264 USHORT Selector;
265 USHORT Access;
266 USHORT ExtendedOffset;
267 } KIDTENTRY, *PKIDTENTRY;
268
269 typedef struct _DESCRIPTOR
270 {
271 USHORT Pad;
272 USHORT Limit;
273 ULONG Base;
274 } KDESCRIPTOR, *PKDESCRIPTOR;
275
276 //
277 // Special Registers Structure (outside of CONTEXT)
278 //
279 typedef struct _KSPECIAL_REGISTERS
280 {
281 ULONG Cr0;
282 ULONG Cr2;
283 ULONG Cr3;
284 ULONG Cr4;
285 ULONG KernelDr0;
286 ULONG KernelDr1;
287 ULONG KernelDr2;
288 ULONG KernelDr3;
289 ULONG KernelDr6;
290 ULONG KernelDr7;
291 KDESCRIPTOR Gdtr;
292 KDESCRIPTOR Idtr;
293 USHORT Tr;
294 USHORT Ldtr;
295 ULONG Reserved[6];
296 } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
297
298 //
299 // Processor State Data
300 //
301 #pragma pack(push,4)
302 typedef struct _KPROCESSOR_STATE
303 {
304 CONTEXT ContextFrame;
305 KSPECIAL_REGISTERS SpecialRegisters;
306 } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
307
308 //
309 // Processor Region Control Block
310 //
311 typedef struct _KPRCB
312 {
313 USHORT MinorVersion;
314 USHORT MajorVersion;
315 struct _KTHREAD *CurrentThread;
316 struct _KTHREAD *NextThread;
317 struct _KTHREAD *IdleThread;
318 UCHAR Number;
319 UCHAR Reserved;
320 USHORT BuildType;
321 KAFFINITY SetMember;
322 UCHAR CpuType;
323 UCHAR CpuID;
324 USHORT CpuStep;
325 KPROCESSOR_STATE ProcessorState;
326 ULONG KernelReserved[16];
327 ULONG HalReserved[16];
328 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
329 ULONG CFlushSize;
330 UCHAR PrcbPad0[88];
331 #else
332 UCHAR PrcbPad0[92];
333 #endif
334 KSPIN_LOCK_QUEUE LockQueue[LockQueueMaximumLock];
335 struct _KTHREAD *NpxThread;
336 ULONG InterruptCount;
337 ULONG KernelTime;
338 ULONG UserTime;
339 ULONG DpcTime;
340 ULONG DebugDpcTime;
341 ULONG InterruptTime;
342 ULONG AdjustDpcThreshold;
343 ULONG PageColor;
344 UCHAR SkipTick;
345 UCHAR DebuggerSavedIRQL;
346 #if (NTDDI_VERSION >= NTDDI_WS03)
347 UCHAR NodeColor;
348 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
349 UCHAR PollSlot;
350 #else
351 UCHAR Spare1;
352 #endif
353 ULONG NodeShiftedColor;
354 #else
355 UCHAR Spare1[6];
356 #endif
357 struct _KNODE *ParentNode;
358 ULONG MultiThreadProcessorSet;
359 struct _KPRCB *MultiThreadSetMaster;
360 #if (NTDDI_VERSION >= NTDDI_WS03)
361 ULONG SecondaryColorMask;
362 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
363 ULONG DpcTimeLimit;
364 #else
365 LONG Sleeping;
366 #endif
367 #else
368 ULONG ThreadStartCount[2];
369 #endif
370 ULONG CcFastReadNoWait;
371 ULONG CcFastReadWait;
372 ULONG CcFastReadNotPossible;
373 ULONG CcCopyReadNoWait;
374 ULONG CcCopyReadWait;
375 ULONG CcCopyReadNoWaitMiss;
376 #if (NTDDI_VERSION < NTDDI_LONGHORN)
377 ULONG KeAlignmentFixupCount;
378 #endif
379 ULONG SpareCounter0;
380 #if (NTDDI_VERSION < NTDDI_LONGHORN)
381 ULONG KeContextSwitches;
382 ULONG KeDcacheFlushCount;
383 ULONG KeExceptionDispatchCount;
384 ULONG KeFirstLevelTbFills;
385 ULONG KeFloatingEmulationCount;
386 ULONG KeIcacheFlushCount;
387 ULONG KeSecondLevelTbFills;
388 ULONG KeSystemCalls;
389 #endif
390 ULONG IoReadOperationCount;
391 ULONG IoWriteOperationCount;
392 ULONG IoOtherOperationCount;
393 LARGE_INTEGER IoReadTransferCount;
394 LARGE_INTEGER IoWriteTransferCount;
395 LARGE_INTEGER IoOtherTransferCount;
396 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
397 ULONG CcFastMdlReadNoWait;
398 ULONG CcFastMdlReadWait;
399 ULONG CcFastMdlReadNotPossible;
400 ULONG CcMapDataNoWait;
401 ULONG CcMapDataWait;
402 ULONG CcPinMappedDataCount;
403 ULONG CcPinReadNoWait;
404 ULONG CcPinReadWait;
405 ULONG CcMdlReadNoWait;
406 ULONG CcMdlReadWait;
407 ULONG CcLazyWriteHotSpots;
408 ULONG CcLazyWriteIos;
409 ULONG CcLazyWritePages;
410 ULONG CcDataFlushes;
411 ULONG CcDataPages;
412 ULONG CcLostDelayedWrites;
413 ULONG CcFastReadResourceMiss;
414 ULONG CcCopyReadWaitMiss;
415 ULONG CcFastMdlReadResourceMiss;
416 ULONG CcMapDataNoWaitMiss;
417 ULONG CcMapDataWaitMiss;
418 ULONG CcPinReadNoWaitMiss;
419 ULONG CcPinReadWaitMiss;
420 ULONG CcMdlReadNoWaitMiss;
421 ULONG CcMdlReadWaitMiss;
422 ULONG CcReadAheadIos;
423 ULONG KeAlignmentFixupCount;
424 ULONG KeExceptionDispatchCount;
425 ULONG KeSystemCalls;
426 ULONG PrcbPad1[3];
427 #else
428 ULONG SpareCounter1[8];
429 #endif
430 PP_LOOKASIDE_LIST PPLookasideList[16];
431 PP_LOOKASIDE_LIST PPNPagedLookasideList[32];
432 PP_LOOKASIDE_LIST PPPagedLookasideList[32];
433 ULONG PacketBarrier;
434 ULONG ReverseStall;
435 PVOID IpiFrame;
436 UCHAR PrcbPad2[52];
437 PVOID CurrentPacket[3];
438 ULONG TargetSet;
439 PKIPI_WORKER WorkerRoutine;
440 ULONG IpiFrozen;
441 UCHAR PrcbPad3[40];
442 ULONG RequestSummary;
443 struct _KPRCB *SignalDone;
444 UCHAR PrcbPad4[56];
445 struct _KDPC_DATA DpcData[2];
446 PVOID DpcStack;
447 ULONG MaximumDpcQueueDepth;
448 ULONG DpcRequestRate;
449 ULONG MinimumDpcRate;
450 UCHAR DpcInterruptRequested;
451 UCHAR DpcThreadRequested;
452 UCHAR DpcRoutineActive;
453 UCHAR DpcThreadActive;
454 ULONG PrcbLock;
455 ULONG DpcLastCount;
456 ULONG TimerHand;
457 ULONG TimerRequest;
458 PVOID DpcThread;
459 KEVENT DpcEvent;
460 UCHAR ThreadDpcEnable;
461 BOOLEAN QuantumEnd;
462 UCHAR PrcbPad50;
463 UCHAR IdleSchedule;
464 LONG DpcSetEventRequest;
465 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
466 LONG Sleeping;
467 ULONG PeriodicCount;
468 ULONG PeriodicBias;
469 UCHAR PrcbPad5[6];
470 #else
471 UCHAR PrcbPad5[18];
472 #endif
473 LONG TickOffset;
474 KDPC CallDpc;
475 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
476 LONG ClockKeepAlive;
477 UCHAR ClockCheckSlot;
478 UCHAR ClockPollCycle;
479 UCHAR PrcbPad6[2];
480 LONG DpcWatchdogPeriod;
481 LONG DpcWatchDogCount;
482 LONG ThreadWatchdogPeriod;
483 LONG ThreadWatchDogCount;
484 ULONG PrcbPad70[2];
485 #else
486 ULONG PrcbPad7[8];
487 #endif
488 LIST_ENTRY WaitListHead;
489 ULONG ReadySummary;
490 ULONG QueueIndex;
491 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
492 SINGLE_LIST_ENTRY DeferredReadyListHead;
493 ULONGLONG StartCycles;
494 ULONGLONG CycleTime;
495 ULONGLONG PrcbPad71[3];
496 LIST_ENTRY DispatcherReadyListHead[32];
497 #else
498 LIST_ENTRY DispatcherReadyListHead[32];
499 SINGLE_LIST_ENTRY DeferredReadyListHead;
500 ULONG PrcbPad72[11];
501 #endif
502 PVOID ChainedInterruptList;
503 LONG LookasideIrpFloat;
504 LONG MmPageFaultCount;
505 LONG MmCopyOnWriteCount;
506 LONG MmTransitionCount;
507 LONG MmCacheTransitionCount;
508 LONG MmDemandZeroCount;
509 LONG MmPageReadCount;
510 LONG MmPageReadIoCount;
511 LONG MmCacheReadCount;
512 LONG MmCacheIoCount;
513 LONG MmDirtyPagesWriteCount;
514 LONG MmDirtyWriteIoCount;
515 LONG MmMappedPagesWriteCount;
516 LONG MmMappedWriteIoCount;
517 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
518 ULONG CachedCommit;
519 ULONG CachedResidentAvailable;
520 PVOID HyperPte;
521 UCHAR CpuVendor;
522 UCHAR PrcbPad9[3];
523 #else
524 ULONG SpareFields0[1];
525 #endif
526 CHAR VendorString[13];
527 UCHAR InitialApicId;
528 UCHAR LogicalProcessorsPerPhysicalProcessor;
529 ULONG MHz;
530 ULONG FeatureBits;
531 LARGE_INTEGER UpdateSignature;
532 LARGE_INTEGER IsrTime;
533 LARGE_INTEGER SpareField1;
534 FX_SAVE_AREA NpxSaveArea;
535 PROCESSOR_POWER_STATE PowerState;
536 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
537 KDPC DpcWatchdogDoc;
538 KTIMER DpcWatchdogTimer;
539 PVOID WheaInfo;
540 PVOID EtwSupport;
541 SLIST_HEADER InterruptObjectPool;
542 LARGE_INTEGER HyperCallPagePhysical;
543 LARGE_INTEGER HyperCallPageVirtual;
544 PVOID RateControl;
545 CACHE_DESCRIPTOR Cache[5];
546 ULONG CacheCount;
547 ULONG CacheProcessorMask[5];
548 UCHAR LogicalProcessorsPerCore;
549 UCHAR PrcbPad8[3];
550 ULONG PackageProcessorSet;
551 ULONG CoreProcessorSet;
552 #endif
553 } KPRCB, *PKPRCB;
554
555 //
556 // Processor Control Region
557 //
558 typedef struct _KIPCR
559 {
560 union
561 {
562 NT_TIB NtTib;
563 struct
564 {
565 struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
566 PVOID Used_StackBase;
567 PVOID PerfGlobalGroupMask;
568 PVOID TssCopy;
569 ULONG ContextSwitches;
570 KAFFINITY SetMemberCopy;
571 PVOID Used_Self;
572 };
573 };
574 struct _KPCR *Self;
575 struct _KPRCB *Prcb;
576 KIRQL Irql;
577 ULONG IRR;
578 ULONG IrrActive;
579 ULONG IDR;
580 PVOID KdVersionBlock;
581 PKIDTENTRY IDT;
582 #ifdef _REACTOS_
583 PUSHORT GDT;
584 #else
585 PKGDTENTRY GDT;
586 #endif
587 struct _KTSS *TSS;
588 USHORT MajorVersion;
589 USHORT MinorVersion;
590 KAFFINITY SetMember;
591 ULONG StallScaleFactor;
592 UCHAR SparedUnused;
593 UCHAR Number;
594 UCHAR Reserved;
595 UCHAR L2CacheAssociativity;
596 ULONG VdmAlert;
597 ULONG KernelReserved[14];
598 ULONG SecondLevelCacheSize;
599 ULONG HalReserved[16];
600 ULONG InterruptMode;
601 UCHAR Spare1;
602 ULONG KernelReserved2[17];
603 KPRCB PrcbData;
604 } KIPCR, *PKIPCR;
605 #pragma pack(pop)
606
607 //
608 // TSS Definition
609 //
610 typedef struct _KiIoAccessMap
611 {
612 UCHAR DirectionMap[32];
613 UCHAR IoMap[8196];
614 } KIIO_ACCESS_MAP;
615
616 #include <pshpack1.h>
617 typedef struct _KTSS
618 {
619 USHORT Backlink;
620 USHORT Reserved0;
621 ULONG Esp0;
622 USHORT Ss0;
623 USHORT Reserved1;
624 ULONG NotUsed1[4];
625 ULONG CR3;
626 ULONG Eip;
627 ULONG NotUsed2[9];
628 USHORT Es;
629 USHORT Reserved2;
630 USHORT Cs;
631 USHORT Reserved3;
632 USHORT Ss;
633 USHORT Reserved4;
634 USHORT Ds;
635 USHORT Reserved5;
636 USHORT Fs;
637 USHORT Reserved6;
638 USHORT Gs;
639 USHORT Reserved7;
640 USHORT LDT;
641 USHORT Reserved8;
642 USHORT Flags;
643 USHORT IoMapBase;
644 KIIO_ACCESS_MAP IoMaps[1];
645 UCHAR IntDirectionMap[32];
646 } KTSS, *PKTSS;
647 #include <poppack.h>
648
649 //
650 // i386 CPUs don't have exception frames
651 //
652 typedef struct _KEXCEPTION_FRAME KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
653 #endif
654 #endif