Sync with trunk (r48545)
[reactos.git] / include / xdk / x86 / ke.h
1 $if (_WDMDDK_)
2 /** Kernel definitions for x86 **/
3
4 /* Interrupt request levels */
5 #define PASSIVE_LEVEL 0
6 #define LOW_LEVEL 0
7 #define APC_LEVEL 1
8 #define DISPATCH_LEVEL 2
9 #define CMCI_LEVEL 5
10 #define PROFILE_LEVEL 27
11 #define CLOCK1_LEVEL 28
12 #define CLOCK2_LEVEL 28
13 #define IPI_LEVEL 29
14 #define POWER_LEVEL 30
15 #define HIGH_LEVEL 31
16 #define CLOCK_LEVEL CLOCK2_LEVEL
17
18 #define KIP0PCRADDRESS 0xffdff000
19 #define KI_USER_SHARED_DATA 0xffdf0000
20 #define SharedUserData ((KUSER_SHARED_DATA * CONST)KI_USER_SHARED_DATA)
21
22 #define PAGE_SIZE 0x1000
23 #define PAGE_SHIFT 12L
24 #define KeGetDcacheFillSize() 1L
25
26 #define EFLAG_SIGN 0x8000
27 #define EFLAG_ZERO 0x4000
28 #define EFLAG_SELECT (EFLAG_SIGN | EFLAG_ZERO)
29
30 #define RESULT_NEGATIVE ((EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
31 #define RESULT_ZERO ((~EFLAG_SIGN & EFLAG_ZERO) & EFLAG_SELECT)
32 #define RESULT_POSITIVE ((~EFLAG_SIGN & ~EFLAG_ZERO) & EFLAG_SELECT)
33
34
35 typedef struct _KFLOATING_SAVE {
36 ULONG ControlWord;
37 ULONG StatusWord;
38 ULONG ErrorOffset;
39 ULONG ErrorSelector;
40 ULONG DataOffset;
41 ULONG DataSelector;
42 ULONG Cr0NpxState;
43 ULONG Spare1;
44 } KFLOATING_SAVE, *PKFLOATING_SAVE;
45
46 extern NTKERNELAPI volatile KSYSTEM_TIME KeTickCount;
47
48 #define YieldProcessor _mm_pause
49
50 FORCEINLINE
51 VOID
52 KeMemoryBarrier(VOID)
53 {
54 volatile LONG Barrier;
55 #if defined(__GNUC__)
56 __asm__ __volatile__ ("xchg %%eax, %0" : : "m" (Barrier) : "%eax");
57 #elif defined(_MSC_VER)
58 __asm xchg [Barrier], eax
59 #endif
60 }
61
62 NTHALAPI
63 KIRQL
64 NTAPI
65 KeGetCurrentIrql(VOID);
66
67 NTHALAPI
68 VOID
69 FASTCALL
70 KfLowerIrql(
71 IN KIRQL NewIrql);
72 #define KeLowerIrql(a) KfLowerIrql(a)
73
74 NTHALAPI
75 KIRQL
76 FASTCALL
77 KfRaiseIrql(
78 IN KIRQL NewIrql);
79 #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
80
81 NTHALAPI
82 KIRQL
83 NTAPI
84 KeRaiseIrqlToDpcLevel(VOID);
85
86 NTHALAPI
87 KIRQL
88 NTAPI
89 KeRaiseIrqlToSynchLevel(VOID);
90
91 NTHALAPI
92 KIRQL
93 FASTCALL
94 KfAcquireSpinLock(
95 IN OUT PKSPIN_LOCK SpinLock);
96 #define KeAcquireSpinLock(a,b) *(b) = KfAcquireSpinLock(a)
97
98 NTHALAPI
99 VOID
100 FASTCALL
101 KfReleaseSpinLock(
102 IN OUT PKSPIN_LOCK SpinLock,
103 IN KIRQL NewIrql);
104 #define KeReleaseSpinLock(a,b) KfReleaseSpinLock(a,b)
105
106 NTKERNELAPI
107 VOID
108 FASTCALL
109 KefAcquireSpinLockAtDpcLevel(
110 IN OUT PKSPIN_LOCK SpinLock);
111 #define KeAcquireSpinLockAtDpcLevel(SpinLock) KefAcquireSpinLockAtDpcLevel(SpinLock)
112
113 NTKERNELAPI
114 VOID
115 FASTCALL
116 KefReleaseSpinLockFromDpcLevel(
117 IN OUT PKSPIN_LOCK SpinLock);
118 #define KeReleaseSpinLockFromDpcLevel(SpinLock) KefReleaseSpinLockFromDpcLevel(SpinLock)
119
120 NTSYSAPI
121 PKTHREAD
122 NTAPI
123 KeGetCurrentThread(VOID);
124
125 NTKERNELAPI
126 NTSTATUS
127 NTAPI
128 KeSaveFloatingPointState(
129 OUT PKFLOATING_SAVE FloatSave);
130
131 NTKERNELAPI
132 NTSTATUS
133 NTAPI
134 KeRestoreFloatingPointState(
135 IN PKFLOATING_SAVE FloatSave);
136
137 /* VOID
138 * KeFlushIoBuffers(
139 * IN PMDL Mdl,
140 * IN BOOLEAN ReadOperation,
141 * IN BOOLEAN DmaOperation)
142 */
143 #define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
144
145 /* x86 and x64 performs a 0x2C interrupt */
146 #define DbgRaiseAssertionFailure __int2c
147
148 FORCEINLINE
149 VOID
150 _KeQueryTickCount(
151 OUT PLARGE_INTEGER CurrentCount)
152 {
153 for (;;) {
154 #ifdef NONAMELESSUNION
155 CurrentCount->s.HighPart = KeTickCount.High1Time;
156 CurrentCount->s.LowPart = KeTickCount.LowPart;
157 if (CurrentCount->s.HighPart == KeTickCount.High2Time) break;
158 #else
159 CurrentCount->HighPart = KeTickCount.High1Time;
160 CurrentCount->LowPart = KeTickCount.LowPart;
161 if (CurrentCount->HighPart == KeTickCount.High2Time) break;
162 #endif
163 YieldProcessor();
164 }
165 }
166 #define KeQueryTickCount(CurrentCount) _KeQueryTickCount(CurrentCount)
167
168 $endif /* _WDMDDK_ */
169 $if (_NTDDK_)
170
171 #define PAUSE_PROCESSOR YieldProcessor();
172
173 #define KERNEL_STACK_SIZE 12288
174 #define KERNEL_LARGE_STACK_SIZE 61440
175 #define KERNEL_LARGE_STACK_COMMIT 12288
176
177 #define SIZE_OF_80387_REGISTERS 80
178
179 #if !defined(RC_INVOKED)
180
181 #define CONTEXT_i386 0x10000
182 #define CONTEXT_i486 0x10000
183 #define CONTEXT_CONTROL (CONTEXT_i386|0x00000001L)
184 #define CONTEXT_INTEGER (CONTEXT_i386|0x00000002L)
185 #define CONTEXT_SEGMENTS (CONTEXT_i386|0x00000004L)
186 #define CONTEXT_FLOATING_POINT (CONTEXT_i386|0x00000008L)
187 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386|0x00000010L)
188 #define CONTEXT_EXTENDED_REGISTERS (CONTEXT_i386|0x00000020L)
189
190 #define CONTEXT_FULL (CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_SEGMENTS)
191 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | \
192 CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS | \
193 CONTEXT_EXTENDED_REGISTERS)
194
195 #define CONTEXT_XSTATE (CONTEXT_i386 | 0x00000040L)
196
197 #endif /* !defined(RC_INVOKED) */
198
199 typedef struct _FLOATING_SAVE_AREA {
200 ULONG ControlWord;
201 ULONG StatusWord;
202 ULONG TagWord;
203 ULONG ErrorOffset;
204 ULONG ErrorSelector;
205 ULONG DataOffset;
206 ULONG DataSelector;
207 UCHAR RegisterArea[SIZE_OF_80387_REGISTERS];
208 ULONG Cr0NpxState;
209 } FLOATING_SAVE_AREA, *PFLOATING_SAVE_AREA;
210
211 #include "pshpack4.h"
212 typedef struct _CONTEXT {
213 ULONG ContextFlags;
214 ULONG Dr0;
215 ULONG Dr1;
216 ULONG Dr2;
217 ULONG Dr3;
218 ULONG Dr6;
219 ULONG Dr7;
220 FLOATING_SAVE_AREA FloatSave;
221 ULONG SegGs;
222 ULONG SegFs;
223 ULONG SegEs;
224 ULONG SegDs;
225 ULONG Edi;
226 ULONG Esi;
227 ULONG Ebx;
228 ULONG Edx;
229 ULONG Ecx;
230 ULONG Eax;
231 ULONG Ebp;
232 ULONG Eip;
233 ULONG SegCs;
234 ULONG EFlags;
235 ULONG Esp;
236 ULONG SegSs;
237 UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION];
238 } CONTEXT;
239 #include "poppack.h"
240
241 #define KeGetPcr() PCR
242
243 #define PCR_MINOR_VERSION 1
244 #define PCR_MAJOR_VERSION 1
245
246 typedef struct _KPCR {
247 union {
248 NT_TIB NtTib;
249 struct {
250 struct _EXCEPTION_REGISTRATION_RECORD *Used_ExceptionList;
251 PVOID Used_StackBase;
252 PVOID Spare2;
253 PVOID TssCopy;
254 ULONG ContextSwitches;
255 KAFFINITY SetMemberCopy;
256 PVOID Used_Self;
257 };
258 };
259 struct _KPCR *SelfPcr;
260 struct _KPRCB *Prcb;
261 KIRQL Irql;
262 ULONG IRR;
263 ULONG IrrActive;
264 ULONG IDR;
265 PVOID KdVersionBlock;
266 struct _KIDTENTRY *IDT;
267 struct _KGDTENTRY *GDT;
268 struct _KTSS *TSS;
269 USHORT MajorVersion;
270 USHORT MinorVersion;
271 KAFFINITY SetMember;
272 ULONG StallScaleFactor;
273 UCHAR SpareUnused;
274 UCHAR Number;
275 UCHAR Spare0;
276 UCHAR SecondLevelCacheAssociativity;
277 ULONG VdmAlert;
278 ULONG KernelReserved[14];
279 ULONG SecondLevelCacheSize;
280 ULONG HalReserved[16];
281 } KPCR, *PKPCR;
282
283 FORCEINLINE
284 ULONG
285 KeGetCurrentProcessorNumber(VOID)
286 {
287 return (ULONG)__readfsbyte(FIELD_OFFSET(KPCR, Number));
288 }
289
290 $endif /* _NTDDK_ */
291
292
293
294