d744cd5eca7d334b8d865ae1ef734dd8df82ec53
[reactos.git] / include / xdk / amd64 / ke.h
1 $if (_WDMDDK_)
2 /** Kernel definitions for AMD64 **/
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 CLOCK_LEVEL 13
11 #define IPI_LEVEL 14
12 #define DRS_LEVEL 14
13 #define POWER_LEVEL 14
14 #define PROFILE_LEVEL 15
15 #define HIGH_LEVEL 15
16
17 #define KI_USER_SHARED_DATA 0xFFFFF78000000000ULL
18 #define SharedUserData ((PKUSER_SHARED_DATA const)KI_USER_SHARED_DATA)
19 #define SharedInterruptTime (KI_USER_SHARED_DATA + 0x8)
20 #define SharedSystemTime (KI_USER_SHARED_DATA + 0x14)
21 #define SharedTickCount (KI_USER_SHARED_DATA + 0x320)
22
23 #define PAGE_SIZE 0x1000
24 #define PAGE_SHIFT 12L
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 Dummy;
37 } KFLOATING_SAVE, *PKFLOATING_SAVE;
38
39 typedef XSAVE_FORMAT XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
40
41 #define KeQueryInterruptTime() \
42 (*(volatile ULONG64*)SharedInterruptTime)
43
44 #define KeQuerySystemTime(CurrentCount) \
45 *(ULONG64*)(CurrentCount) = *(volatile ULONG64*)SharedSystemTime
46
47 #define KeQueryTickCount(CurrentCount) \
48 *(ULONG64*)(CurrentCount) = *(volatile ULONG64*)SharedTickCount
49
50 #define KeGetDcacheFillSize() 1L
51
52 #define YieldProcessor _mm_pause
53
54 FORCEINLINE
55 KIRQL
56 KeGetCurrentIrql(VOID)
57 {
58 return (KIRQL)__readcr8();
59 }
60
61 FORCEINLINE
62 VOID
63 KeLowerIrql(IN KIRQL NewIrql)
64 {
65 //ASSERT(KeGetCurrentIrql() >= NewIrql);
66 __writecr8(NewIrql);
67 }
68
69 FORCEINLINE
70 KIRQL
71 KfRaiseIrql(IN KIRQL NewIrql)
72 {
73 KIRQL OldIrql;
74
75 OldIrql = __readcr8();
76 //ASSERT(OldIrql <= NewIrql);
77 __writecr8(NewIrql);
78 return OldIrql;
79 }
80 #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
81
82 FORCEINLINE
83 KIRQL
84 KeRaiseIrqlToDpcLevel(VOID)
85 {
86 return KfRaiseIrql(DISPATCH_LEVEL);
87 }
88
89 FORCEINLINE
90 KIRQL
91 KeRaiseIrqlToSynchLevel(VOID)
92 {
93 return KfRaiseIrql(12); // SYNCH_LEVEL = IPI_LEVEL - 2
94 }
95
96 FORCEINLINE
97 PKTHREAD
98 KeGetCurrentThread(VOID)
99 {
100 return (struct _KTHREAD *)__readgsqword(0x188);
101 }
102
103 /* VOID
104 * KeFlushIoBuffers(
105 * IN PMDL Mdl,
106 * IN BOOLEAN ReadOperation,
107 * IN BOOLEAN DmaOperation)
108 */
109 #define KeFlushIoBuffers(_Mdl, _ReadOperation, _DmaOperation)
110
111 /* x86 and x64 performs a 0x2C interrupt */
112 #define DbgRaiseAssertionFailure __int2c
113
114 $endif /* _WDMDDK_ */
115 $if (_NTDDK_)
116
117 #define PAUSE_PROCESSOR YieldProcessor();
118
119 #define KERNEL_STACK_SIZE 0x6000
120 #define KERNEL_LARGE_STACK_SIZE 0x12000
121 #define KERNEL_LARGE_STACK_COMMIT KERNEL_STACK_SIZE
122
123 #define KERNEL_MCA_EXCEPTION_STACK_SIZE 0x2000
124
125 #define EXCEPTION_READ_FAULT 0
126 #define EXCEPTION_WRITE_FAULT 1
127 #define EXCEPTION_EXECUTE_FAULT 8
128
129 #if !defined(RC_INVOKED)
130
131 #define CONTEXT_AMD64 0x100000
132
133 #define CONTEXT_CONTROL (CONTEXT_AMD64 | 0x1L)
134 #define CONTEXT_INTEGER (CONTEXT_AMD64 | 0x2L)
135 #define CONTEXT_SEGMENTS (CONTEXT_AMD64 | 0x4L)
136 #define CONTEXT_FLOATING_POINT (CONTEXT_AMD64 | 0x8L)
137 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_AMD64 | 0x10L)
138
139 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_FLOATING_POINT)
140 #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS | CONTEXT_FLOATING_POINT | CONTEXT_DEBUG_REGISTERS)
141
142 #define CONTEXT_XSTATE (CONTEXT_AMD64 | 0x20L)
143
144 #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
145 #define CONTEXT_SERVICE_ACTIVE 0x10000000
146 #define CONTEXT_EXCEPTION_REQUEST 0x40000000
147 #define CONTEXT_EXCEPTION_REPORTING 0x80000000
148
149 #endif /* !defined(RC_INVOKED) */
150
151 #define INITIAL_MXCSR 0x1f80
152 #define INITIAL_FPCSR 0x027f
153
154 typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
155 ULONG64 P1Home;
156 ULONG64 P2Home;
157 ULONG64 P3Home;
158 ULONG64 P4Home;
159 ULONG64 P5Home;
160 ULONG64 P6Home;
161 ULONG ContextFlags;
162 ULONG MxCsr;
163 USHORT SegCs;
164 USHORT SegDs;
165 USHORT SegEs;
166 USHORT SegFs;
167 USHORT SegGs;
168 USHORT SegSs;
169 ULONG EFlags;
170 ULONG64 Dr0;
171 ULONG64 Dr1;
172 ULONG64 Dr2;
173 ULONG64 Dr3;
174 ULONG64 Dr6;
175 ULONG64 Dr7;
176 ULONG64 Rax;
177 ULONG64 Rcx;
178 ULONG64 Rdx;
179 ULONG64 Rbx;
180 ULONG64 Rsp;
181 ULONG64 Rbp;
182 ULONG64 Rsi;
183 ULONG64 Rdi;
184 ULONG64 R8;
185 ULONG64 R9;
186 ULONG64 R10;
187 ULONG64 R11;
188 ULONG64 R12;
189 ULONG64 R13;
190 ULONG64 R14;
191 ULONG64 R15;
192 ULONG64 Rip;
193 union {
194 XMM_SAVE_AREA32 FltSave;
195 struct {
196 M128A Header[2];
197 M128A Legacy[8];
198 M128A Xmm0;
199 M128A Xmm1;
200 M128A Xmm2;
201 M128A Xmm3;
202 M128A Xmm4;
203 M128A Xmm5;
204 M128A Xmm6;
205 M128A Xmm7;
206 M128A Xmm8;
207 M128A Xmm9;
208 M128A Xmm10;
209 M128A Xmm11;
210 M128A Xmm12;
211 M128A Xmm13;
212 M128A Xmm14;
213 M128A Xmm15;
214 } DUMMYSTRUCTNAME;
215 } DUMMYUNIONNAME;
216 M128A VectorRegister[26];
217 ULONG64 VectorControl;
218 ULONG64 DebugControl;
219 ULONG64 LastBranchToRip;
220 ULONG64 LastBranchFromRip;
221 ULONG64 LastExceptionToRip;
222 ULONG64 LastExceptionFromRip;
223 } CONTEXT;
224
225 #define PCR_MINOR_VERSION 1
226 #define PCR_MAJOR_VERSION 1
227
228 typedef struct _KPCR
229 {
230 _ANONYMOUS_UNION union
231 {
232 NT_TIB NtTib;
233 _ANONYMOUS_STRUCT struct
234 {
235 union _KGDTENTRY64 *GdtBase;
236 struct _KTSS64 *TssBase;
237 ULONG64 UserRsp;
238 struct _KPCR *Self;
239 struct _KPRCB *CurrentPrcb;
240 PKSPIN_LOCK_QUEUE LockArray;
241 PVOID Used_Self;
242 };
243 };
244 union _KIDTENTRY64 *IdtBase;
245 ULONG64 Unused[2];
246 KIRQL Irql;
247 UCHAR SecondLevelCacheAssociativity;
248 UCHAR ObsoleteNumber;
249 UCHAR Fill0;
250 ULONG Unused0[3];
251 USHORT MajorVersion;
252 USHORT MinorVersion;
253 ULONG StallScaleFactor;
254 PVOID Unused1[3];
255 ULONG KernelReserved[15];
256 ULONG SecondLevelCacheSize;
257 ULONG HalReserved[16];
258 ULONG Unused2;
259 PVOID KdVersionBlock;
260 PVOID Unused3;
261 ULONG PcrAlign1[24];
262 } KPCR, *PKPCR;
263
264 FORCEINLINE
265 PKPCR
266 KeGetPcr(VOID)
267 {
268 return (PKPCR)__readgsqword(FIELD_OFFSET(KPCR, Self));
269 }
270
271 FORCEINLINE
272 ULONG
273 KeGetCurrentProcessorNumber(VOID)
274 {
275 return (ULONG)__readgsword(0x184);
276 }
277
278 $endif /* _NTDDK_ */