Sync with trunk (48237)
[reactos.git] / include / ndk / amd64 / asm.h
1 /*++ NDK Version: 0095
2
3 Copyright (c) Timo Kreuzer. All rights reserved.
4
5 Header Name:
6
7 amd64/asm.h
8
9 Abstract:
10
11 ASM Offsets for dealing with de-referencing structures in registers.
12
13 Author:
14
15 Timo Kreuzer (timo.kreuzer@reactos.org) 06-Sep-2008
16
17 --*/
18 #ifndef _ASM_AMD64_H
19 #define _ASM_AMD64_H
20
21 #ifndef HEX
22 #ifdef _USE_ML
23 #define HEX(x) x##h
24 #else
25 #define HEX(val) 0x0##val
26 #endif
27 #endif
28
29 #define SIZEOF_FX_SAVE_AREA 528 // HACK
30
31 //
32 // CPU Modes
33 //
34 #define KernelMode HEX(0)
35 #define UserMode HEX(1)
36
37 //
38 // CPU Types
39 //
40 #define CPU_INTEL HEX(1)
41 #define CPU_AMD HEX(2)
42
43 //
44 // KTSS Offsets
45 //
46 #define KTSS64_RSP0 HEX(04)
47 #define KTSS64_RSP1 HEX(0c)
48 #define KTSS64_RSP2 HEX(14)
49 #define KTSS64_IST HEX(1c)
50 #define KTSS64_IO_MAP_BASE HEX(66)
51
52 //
53 // KTHREAD Offsets
54 //
55 #define KTHREAD_DEBUG_ACTIVE HEX(03)
56 #define KTHREAD_INITIAL_STACK HEX(28)
57 #define KTHREAD_STACK_LIMIT HEX(30)
58 #define KTHREAD_WAIT_IRQL HEX(156)
59
60 //
61 // KPRCB Offsets
62 //
63 #define KPRCB_CurrentThread HEX(08)
64
65
66 //
67 // KPCR Offsets
68 //
69 #define KPCR_TSS_BASE HEX(08)
70 #define KPCR_SELF HEX(18)
71 #define KPCR_STALL_SCALE_FACTOR HEX(64)
72 #define KPCR_PRCB HEX(180
73
74 //
75 // KTRAP_FRAME Offsets
76 //
77 #define KTRAP_FRAME_P1Home HEX(00)
78 #define KTRAP_FRAME_P2Home HEX(08)
79 #define KTRAP_FRAME_P3Home HEX(10)
80 #define KTRAP_FRAME_P4Home HEX(18)
81 #define KTRAP_FRAME_P5 HEX(20)
82 #define KTRAP_FRAME_PreviousMode HEX(28)
83 #define KTRAP_FRAME_PreviousIrql HEX(29)
84 #define KTRAP_FRAME_FaultIndicator HEX(2A)
85 #define KTRAP_FRAME_ExceptionActive HEX(2B)
86 #define KTRAP_FRAME_MxCsr HEX(2C)
87 #define KTRAP_FRAME_Rax HEX(30)
88 #define KTRAP_FRAME_Rcx HEX(38)
89 #define KTRAP_FRAME_Rdx HEX(40)
90 #define KTRAP_FRAME_R8 HEX(48)
91 #define KTRAP_FRAME_R9 HEX(50)
92 #define KTRAP_FRAME_R10 HEX(58)
93 #define KTRAP_FRAME_R11 HEX(60)
94 #define KTRAP_FRAME_GsBase HEX(68)
95 #define KTRAP_FRAME_Xmm0 HEX(70)
96 #define KTRAP_FRAME_Xmm1 HEX(80)
97 #define KTRAP_FRAME_Xmm2 HEX(90)
98 #define KTRAP_FRAME_Xmm3 HEX(A0)
99 #define KTRAP_FRAME_Xmm4 HEX(B0)
100 #define KTRAP_FRAME_Xmm5 HEX(C0)
101 #define KTRAP_FRAME_FaultAddress HEX(D0)
102 #define KTRAP_FRAME_Dr0 HEX(D8)
103 #define KTRAP_FRAME_Dr1 HEX(E0)
104 #define KTRAP_FRAME_Dr2 HEX(E8)
105 #define KTRAP_FRAME_Dr3 HEX(F0)
106 #define KTRAP_FRAME_Dr6 HEX(F8)
107 #define KTRAP_FRAME_Dr7 HEX(100)
108 #define KTRAP_FRAME_DebugControl HEX(108)
109 #define KTRAP_FRAME_LastBranchToRip HEX(110)
110 #define KTRAP_FRAME_LastBranchFromRip HEX(118)
111 #define KTRAP_FRAME_LastExceptionToRip HEX(120)
112 #define KTRAP_FRAME_LastExceptionFromRip HEX(128)
113 #define KTRAP_FRAME_SegDs HEX(130)
114 #define KTRAP_FRAME_SegEs HEX(132)
115 #define KTRAP_FRAME_SegFs HEX(134)
116 #define KTRAP_FRAME_SegGs HEX(136)
117 #define KTRAP_FRAME_TrapFrame HEX(138)
118 #define KTRAP_FRAME_Rbx HEX(140)
119 #define KTRAP_FRAME_Rdi HEX(148)
120 #define KTRAP_FRAME_Rsi HEX(150)
121 #define KTRAP_FRAME_Rbp HEX(158)
122 #define KTRAP_FRAME_ErrorCode HEX(160)
123 #define KTRAP_FRAME_Rip HEX(168)
124 #define KTRAP_FRAME_SegCs HEX(170)
125 #define KTRAP_FRAME_Logging HEX(173)
126 #define KTRAP_FRAME_EFlags HEX(178)
127 #define KTRAP_FRAME_Rsp HEX(180)
128 #define KTRAP_FRAME_SegSs HEX(188)
129 #define KTRAP_FRAME_CodePatchCycle HEX(18c)
130 #define SIZE_KTRAP_FRAME HEX(190)
131 #define KTRAP_FRAME_ALIGN HEX(10)
132 #define KTRAP_FRAME_LENGTH HEX(190)
133
134 //
135 // CONTEXT Offsets
136 //
137 #define CONTEXT_P1Home 0
138 #define CONTEXT_P2Home HEX(08)
139 #define CONTEXT_P3Home HEX(10)
140 #define CONTEXT_P4Home HEX(18)
141 #define CONTEXT_P5Home HEX(20)
142 #define CONTEXT_P6Home HEX(28)
143 #define CONTEXT_ContextFlags HEX(30)
144 #define CONTEXT_MxCsr HEX(34)
145 #define CONTEXT_SegCs HEX(38)
146 #define CONTEXT_SegDs HEX(3a)
147 #define CONTEXT_SegEs HEX(3c)
148 #define CONTEXT_SegFs HEX(3e)
149 #define CONTEXT_SegGs HEX(40)
150 #define CONTEXT_SegSs HEX(42)
151 #define CONTEXT_EFlags HEX(44)
152 #define CONTEXT_Dr0 HEX(48)
153 #define CONTEXT_Dr1 HEX(50)
154 #define CONTEXT_Dr2 HEX(58)
155 #define CONTEXT_Dr3 HEX(60)
156 #define CONTEXT_Dr6 HEX(68)
157 #define CONTEXT_Dr7 HEX(70)
158 #define CONTEXT_Rax HEX(78)
159 #define CONTEXT_Rcx HEX(80)
160 #define CONTEXT_Rdx HEX(88)
161 #define CONTEXT_Rbx HEX(90)
162 #define CONTEXT_Rsp HEX(98)
163 #define CONTEXT_Rbp HEX(a0)
164 #define CONTEXT_Rsi HEX(a8)
165 #define CONTEXT_Rdi HEX(b0)
166 #define CONTEXT_R8 HEX(b8)
167 #define CONTEXT_R9 HEX(c0)
168 #define CONTEXT_R10 HEX(c8)
169 #define CONTEXT_R11 HEX(d0)
170 #define CONTEXT_R12 HEX(d8)
171 #define CONTEXT_R13 HEX(e0)
172 #define CONTEXT_R14 HEX(e8)
173 #define CONTEXT_R15 HEX(f0)
174 #define CONTEXT_Rip HEX(f8)
175 #define CONTEXT_Header HEX(100)
176 #define CONTEXT_Legacy HEX(120)
177 #define CONTEXT_Xmm0 HEX(1a0)
178 #define CONTEXT_Xmm1 HEX(1b0)
179 #define CONTEXT_Xmm2 HEX(1c0)
180 #define CONTEXT_Xmm3 HEX(1d0)
181 #define CONTEXT_Xmm4 HEX(1e0)
182 #define CONTEXT_Xmm5 HEX(1f0)
183 #define CONTEXT_Xmm6 HEX(200)
184 #define CONTEXT_Xmm7 HEX(210)
185 #define CONTEXT_Xmm8 HEX(220)
186 #define CONTEXT_Xmm9 HEX(230)
187 #define CONTEXT_Xmm10 HEX(240)
188 #define CONTEXT_Xmm11 HEX(250)
189 #define CONTEXT_Xmm12 HEX(260)
190 #define CONTEXT_Xmm13 HEX(270)
191 #define CONTEXT_Xmm14 HEX(280)
192 #define CONTEXT_Xmm15 HEX(290)
193 #define CONTEXT_VectorRegister HEX(300)
194 #define CONTEXT_VectorControl HEX(4a0)
195 #define CONTEXT_DebugControl HEX(4a8)
196 #define CONTEXT_LastBranchToRip HEX(4b0)
197 #define CONTEXT_LastBranchFromRip HEX(4b8)
198 #define CONTEXT_LastExceptionToRip HEX(4c0)
199 #define CONTEXT_LastExceptionFromRip HEX(4c8)
200
201 //
202 // KEXCEPTION_FRAME offsets
203 //
204 #define KEXCEPTION_FRAME_P1Home HEX(000)
205 #define KEXCEPTION_FRAME_P2Home HEX(008)
206 #define KEXCEPTION_FRAME_P3Home HEX(010)
207 #define KEXCEPTION_FRAME_P4Home HEX(018)
208 #define KEXCEPTION_FRAME_P5 HEX(020)
209 #define KEXCEPTION_FRAME_InitialStack HEX(028)
210 #define KEXCEPTION_FRAME_Xmm6 HEX(030)
211 #define KEXCEPTION_FRAME_Xmm7 HEX(040)
212 #define KEXCEPTION_FRAME_Xmm8 HEX(050)
213 #define KEXCEPTION_FRAME_Xmm9 HEX(060)
214 #define KEXCEPTION_FRAME_Xmm10 HEX(070)
215 #define KEXCEPTION_FRAME_Xmm11 HEX(080)
216 #define KEXCEPTION_FRAME_Xmm12 HEX(090)
217 #define KEXCEPTION_FRAME_Xmm13 HEX(0A0)
218 #define KEXCEPTION_FRAME_Xmm14 HEX(0B0)
219 #define KEXCEPTION_FRAME_Xmm15 HEX(0C0)
220 #define KEXCEPTION_FRAME_TrapFrame HEX(0D0)
221 #define KEXCEPTION_FRAME_CallbackStack HEX(0D8)
222 #define KEXCEPTION_FRAME_OutputBuffer HEX(0E0)
223 #define KEXCEPTION_FRAME_OutputLength HEX(0E8)
224 #define KEXCEPTION_FRAME_MxCsr HEX(0F0)
225 #define KEXCEPTION_FRAME_Rbp HEX(0F8)
226 #define KEXCEPTION_FRAME_Rbx HEX(100)
227 #define KEXCEPTION_FRAME_Rdi HEX(108)
228 #define KEXCEPTION_FRAME_Rsi HEX(110)
229 #define KEXCEPTION_FRAME_R12 HEX(118)
230 #define KEXCEPTION_FRAME_R13 HEX(120)
231 #define KEXCEPTION_FRAME_R14 HEX(128)
232 #define KEXCEPTION_FRAME_R15 HEX(130)
233 #define KEXCEPTION_FRAME_Return HEX(138)
234 #define SIZE_KEXCEPTION_FRAME HEX(140)
235
236
237 //
238 // EXCEPTION_RECORD Offsets
239 //
240 #define EXCEPTION_RECORD_ExceptionCode HEX(00)
241 #define EXCEPTION_RECORD_ExceptionFlags HEX(04)
242 #define EXCEPTION_RECORD_ExceptionRecord HEX(08)
243 #define EXCEPTION_RECORD_ExceptionAddress HEX(10)
244 #define EXCEPTION_RECORD_NumberParameters HEX(18)
245 #define EXCEPTION_RECORD_ExceptionInformation HEX(20)
246 #define SIZE_EXCEPTION_RECORD HEX(98)
247
248 //
249 // CR0
250 //
251 #define CR0_PE HEX(1)
252 #define CR0_MP HEX(2)
253 #define CR0_EM HEX(4)
254 #define CR0_TS HEX(8)
255 #define CR0_ET HEX(10)
256 #define CR0_NE HEX(20)
257 #define CR0_WP HEX(10000)
258 #define CR0_AM HEX(40000)
259 #define CR0_NW HEX(20000000)
260 #define CR0_CD HEX(40000000)
261 #define CR0_PG HEX(80000000)
262
263 #ifdef _ASM_
264 //
265 // CR4
266 //
267 #define CR4_VME HEX(1)
268 #define CR4_PVI HEX(2)
269 #define CR4_TSD HEX(4)
270 #define CR4_DE HEX(8)
271 #define CR4_PSE HEX(10)
272 #define CR4_PAE HEX(20)
273 #define CR4_MCE HEX(40)
274 #define CR4_PGE HEX(80)
275 #define CR4_FXSR HEX(200)
276 #define CR4_XMMEXCPT HEX(400)
277 #endif
278
279 //
280 // Generic Definitions
281 //
282 #define PRIMARY_VECTOR_BASE HEX(30)
283 #define MAXIMUM_IDTVECTOR HEX(FF)
284
285 //
286 // Usermode callout frame definitions
287 //
288 #define CBSTACK_STACK HEX(0)
289 #define CBSTACK_TRAP_FRAME HEX(8)
290 #define CBSTACK_CALLBACK_STACK HEX(10)
291 #define CBSTACK_RBP HEX(18)
292 #define CBSTACK_RESULT HEX(20)
293 #define CBSTACK_RESULT_LENGTH HEX(28)
294
295
296 /* Following ones are ASM only! ***********************************************/
297
298 #ifdef __ASM__
299
300 //
301 // PCR Access
302 //
303 #define PCR gs:
304
305 //
306 // EFLAGS
307 //
308 #define EFLAGS_TF HEX(100)
309 #define EFLAGS_INTERRUPT_MASK HEX(200)
310 #define EFLAGS_NESTED_TASK HEX(4000)
311 #define EFLAGS_V86_MASK HEX(20000)
312 #define EFLAGS_ALIGN_CHECK HEX(40000)
313 #define EFLAGS_VIF HEX(80000)
314 #define EFLAGS_VIP HEX(100000)
315 #define EFLAG_SIGN HEX(8000)
316 #define EFLAG_ZERO HEX(4000)
317 #define EFLAG_SELECT (EFLAG_SIGN + EFLAG_ZERO)
318 #define EFLAGS_USER_SANITIZE HEX(3F4DD7)
319
320 //
321 // Exception codes
322 //
323 #define EXCEPTION_DIVIDED_BY_ZERO HEX(00000)
324 #define EXCEPTION_DEBUG HEX(00001)
325 #define EXCEPTION_NMI HEX(00002)
326 #define EXCEPTION_INT3 HEX(00003)
327 #define EXCEPTION_BOUND_CHECK HEX(00005)
328 #define EXCEPTION_INVALID_OPCODE HEX(00006)
329 #define EXCEPTION_NPX_NOT_AVAILABLE HEX(00007)
330 #define EXCEPTION_DOUBLE_FAULT HEX(00008)
331 #define EXCEPTION_NPX_OVERRUN HEX(00009)
332 #define EXCEPTION_INVALID_TSS HEX(0000A)
333 #define EXCEPTION_SEGMENT_NOT_PRESENT HEX(0000B)
334 #define EXCEPTION_STACK_FAULT HEX(0000C)
335 #define EXCEPTION_GP_FAULT HEX(0000D)
336 #define EXCEPTION_RESERVED_TRAP HEX(0000F)
337 #define EXCEPTION_NPX_ERROR HEX(00010)
338 #define EXCEPTION_ALIGNMENT_CHECK HEX(00011)
339
340 //
341 // NTSTATUS values
342 //
343 #define STATUS_ACCESS_VIOLATION HEX(C0000005)
344 #define STATUS_IN_PAGE_ERROR HEX(C0000006)
345 #define STATUS_GUARD_PAGE_VIOLATION HEX(80000001)
346 #define STATUS_PRIVILEGED_INSTRUCTION HEX(C0000096)
347 #define STATUS_STACK_OVERFLOW HEX(C00000FD)
348 #define KI_EXCEPTION_ACCESS_VIOLATION HEX(10000004)
349 #define STATUS_INVALID_SYSTEM_SERVICE HEX(C000001C)
350 #define STATUS_NO_CALLBACK_ACTIVE HEX(C0000258)
351 #define STATUS_CALLBACK_POP_STACK HEX(C0000423)
352 #define STATUS_ARRAY_BOUNDS_EXCEEDED HEX(C000008C)
353 #define STATUS_ILLEGAL_INSTRUCTION HEX(C000001D)
354 #define STATUS_INVALID_LOCK_SEQUENCE HEX(C000001E)
355 #define STATUS_BREAKPOINT HEX(80000003)
356 #define STATUS_SINGLE_STEP HEX(80000004)
357 #define STATUS_INTEGER_DIVIDE_BY_ZERO HEX(C0000094)
358 #define STATUS_INTEGER_OVERFLOW HEX(C0000095)
359 #define STATUS_FLOAT_DENORMAL_OPERAND HEX(C000008D)
360 #define STATUS_FLOAT_DIVIDE_BY_ZERO HEX(C000008E)
361 #define STATUS_FLOAT_INEXACT_RESULT HEX(C000008F)
362 #define STATUS_FLOAT_INVALID_OPERATION HEX(C0000090)
363 #define STATUS_FLOAT_OVERFLOW HEX(C0000091)
364 #define STATUS_FLOAT_STACK_CHECK HEX(C0000092)
365 #define STATUS_FLOAT_UNDERFLOW HEX(C0000093)
366 #define STATUS_FLOAT_MULTIPLE_FAULTS HEX(C00002B4)
367 #define STATUS_FLOAT_MULTIPLE_TRAPS HEX(C00002B5)
368 #define STATUS_ASSERTION_FAILURE HEX(C0000420)
369
370 //
371 // Bugcheck Codes
372 //
373 #define APC_INDEX_MISMATCH HEX(01)
374 #define IRQL_NOT_GREATER_OR_EQUAL HEX(09)
375 #define IRQL_NOT_LESS_OR_EQUAL HEX(0A)
376 #define TRAP_CAUSE_UNKNOWN HEX(12)
377 #define KMODE_EXCEPTION_NOT_HANDLED HEX(13)
378 #define IRQL_GT_ZERO_AT_SYSTEM_SERVICE HEX(4A)
379 #define UNEXPECTED_KERNEL_MODE_TRAP HEX(7F)
380 #define ATTEMPTED_SWITCH_FROM_DPC HEX(B8)
381 #define HARDWARE_INTERRUPT_STORM HEX(F2)
382
383 //
384 // IRQL Levels
385 //
386 #define PASSIVE_LEVEL 0
387 #define LOW_LEVEL 0
388 #define APC_LEVEL 1
389 #define DISPATCH_LEVEL 2
390 #define CLOCK_LEVEL 13
391 #define IPI_LEVEL 14
392 #define POWER_LEVEL 14
393 #define PROFILE_LEVEL 15
394 #define HIGH_LEVEL 15
395
396 //
397 // Quantum Decrements
398 //
399 #define CLOCK_QUANTUM_DECREMENT HEX(3)
400
401 //
402 // Machine types
403 //
404 #define MACHINE_TYPE_ISA HEX(0000)
405 #define MACHINE_TYPE_EISA HEX(0001)
406 #define MACHINE_TYPE_MCA HEX(0002)
407
408 //
409 // Kernel Feature Bits
410 //
411 #define KF_RDTSC HEX(00000002)
412
413 //
414 // Kernel Stack Size
415 //
416 #define KERNEL_STACK_SIZE HEX(6000)
417
418 #endif // __ASM__
419
420 #endif // !_ASM_AMD64_H
421