d80b35de136a26400d4380d657a11e26f05b8c65
[reactos.git] / reactos / 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
22 #define SIZEOF_FX_SAVE_AREA 528 // HACK
23
24 //
25 // CPU Modes
26 //
27 #define KernelMode 0x0
28 #define UserMode 0x1
29
30 //
31 // CPU Types
32 //
33 #define CPU_INTEL 0x1
34 #define CPU_AMD 0x2
35
36 //
37 // KTSS Offsets
38 //
39 #define KTSS64_RSP0 0x04
40 #define KTSS64_RSP1 0x0c
41 #define KTSS64_RSP2 0x14
42 #define KTSS64_IST 0x1c
43 #define KTSS64_IO_MAP_BASE 0x66
44
45 //
46 // KTHREAD Offsets
47 //
48 #define KTHREAD_DEBUG_ACTIVE 0x03
49 #define KTHREAD_INITIAL_STACK 0x28
50 #define KTHREAD_STACK_LIMIT 0x30
51 #define KTHREAD_WAIT_IRQL 0x156
52 #define KTHREAD_TEB 0x0B0+0x10
53 #define KTHREAD_KERNEL_STACK 0x038
54 #define KTHREAD_NPX_STATE 0x85
55 #define KTHREAD_SERVICE_TABLE 0x1E8
56 #define KTHREAD_PREVIOUS_MODE 0x137
57 #define KTHREAD_TRAP_FRAME 0x1D8
58 #define KTHREAD_CALLBACK_STACK 0x1E0
59 #define KTHREAD_APCSTATE_PROCESS 0x068
60 #define KPROCESS_DIRECTORY_TABLE_BASE 0x028
61
62 //
63 // KPRCB Offsets
64 //
65 #define KPRCB_CurrentThread 0x08
66
67
68 //
69 // KPCR Offsets
70 //
71 #define KPCR_TSS_BASE 0x08
72 #define KPCR_SELF 0x18
73 #define KPCR_STALL_SCALE_FACTOR 0x64
74 #define KPCR_PRCB 0x180
75
76 //
77 // KTRAP_FRAME Offsets
78 //
79 #define KTRAP_FRAME_P1Home 0x00
80 #define KTRAP_FRAME_P2Home 0x08
81 #define KTRAP_FRAME_P3Home 0x10
82 #define KTRAP_FRAME_P4Home 0x18
83 #define KTRAP_FRAME_P5 0x20
84 #define KTRAP_FRAME_PreviousMode 0x28
85 #define KTRAP_FRAME_PreviousIrql 0x29
86 #define KTRAP_FRAME_FaultIndicator 0x2A
87 #define KTRAP_FRAME_ExceptionActive 0x2B
88 #define KTRAP_FRAME_MxCsr 0x2C
89 #define KTRAP_FRAME_Rax 0x30
90 #define KTRAP_FRAME_Rcx 0x38
91 #define KTRAP_FRAME_Rdx 0x40
92 #define KTRAP_FRAME_R8 0x48
93 #define KTRAP_FRAME_R9 0x50
94 #define KTRAP_FRAME_R10 0x58
95 #define KTRAP_FRAME_R11 0x60
96 #define KTRAP_FRAME_GsBase 0x68
97 #define KTRAP_FRAME_Xmm0 0x70
98 #define KTRAP_FRAME_Xmm1 0x80
99 #define KTRAP_FRAME_Xmm2 0x90
100 #define KTRAP_FRAME_Xmm3 0xA0
101 #define KTRAP_FRAME_Xmm4 0xB0
102 #define KTRAP_FRAME_Xmm5 0xC0
103 #define KTRAP_FRAME_FaultAddress 0xD0
104 #define KTRAP_FRAME_Dr0 0xD8
105 #define KTRAP_FRAME_Dr1 0xE0
106 #define KTRAP_FRAME_Dr2 0xE8
107 #define KTRAP_FRAME_Dr3 0xF0
108 #define KTRAP_FRAME_Dr6 0xF8
109 #define KTRAP_FRAME_Dr7 0x100
110 #define KTRAP_FRAME_DebugControl 0x108
111 #define KTRAP_FRAME_LastBranchToRip 0x110
112 #define KTRAP_FRAME_LastBranchFromRip 0x118
113 #define KTRAP_FRAME_LastExceptionToRip 0x120
114 #define KTRAP_FRAME_LastExceptionFromRip 0x128
115 #define KTRAP_FRAME_SegDs 0x130
116 #define KTRAP_FRAME_SegEs 0x132
117 #define KTRAP_FRAME_SegFs 0x134
118 #define KTRAP_FRAME_SegGs 0x136
119 #define KTRAP_FRAME_TrapFrame 0x138
120 #define KTRAP_FRAME_Rbx 0x140
121 #define KTRAP_FRAME_Rdi 0x148
122 #define KTRAP_FRAME_Rsi 0x150
123 #define KTRAP_FRAME_Rbp 0x158
124 #define KTRAP_FRAME_ErrorCode 0x160
125 #define KTRAP_FRAME_Rip 0x168
126 #define KTRAP_FRAME_SegCs 0x170
127 #define KTRAP_FRAME_Logging 0x173
128 #define KTRAP_FRAME_EFlags 0x178
129 #define KTRAP_FRAME_Rsp 0x180
130 #define KTRAP_FRAME_SegSs 0x188
131 #define KTRAP_FRAME_CodePatchCycle 0x18c
132 #define SIZE_KTRAP_FRAME 0x190
133 #define KTRAP_FRAME_ALIGN 0x10
134 #define KTRAP_FRAME_LENGTH 0x190
135
136 //
137 // CONTEXT Offsets
138 //
139 #define CONTEXT_P1Home 0
140 #define CONTEXT_P2Home 0x08
141 #define CONTEXT_P3Home 0x10
142 #define CONTEXT_P4Home 0x18
143 #define CONTEXT_P5Home 0x20
144 #define CONTEXT_P6Home 0x28
145 #define CONTEXT_ContextFlags 0x30
146 #define CONTEXT_MxCsr 0x34
147 #define CONTEXT_SegCs 0x38
148 #define CONTEXT_SegDs 0x3a
149 #define CONTEXT_SegEs 0x3c
150 #define CONTEXT_SegFs 0x3e
151 #define CONTEXT_SegGs 0x40
152 #define CONTEXT_SegSs 0x42
153 #define CONTEXT_EFlags 0x44
154 #define CONTEXT_Dr0 0x48
155 #define CONTEXT_Dr1 0x50
156 #define CONTEXT_Dr2 0x58
157 #define CONTEXT_Dr3 0x60
158 #define CONTEXT_Dr6 0x68
159 #define CONTEXT_Dr7 0x70
160 #define CONTEXT_Rax 0x78
161 #define CONTEXT_Rcx 0x80
162 #define CONTEXT_Rdx 0x88
163 #define CONTEXT_Rbx 0x90
164 #define CONTEXT_Rsp 0x98
165 #define CONTEXT_Rbp 0xa0
166 #define CONTEXT_Rsi 0xa8
167 #define CONTEXT_Rdi 0xb0
168 #define CONTEXT_R8 0xb8
169 #define CONTEXT_R9 0xc0
170 #define CONTEXT_R10 0xc8
171 #define CONTEXT_R11 0xd0
172 #define CONTEXT_R12 0xd8
173 #define CONTEXT_R13 0xe0
174 #define CONTEXT_R14 0xe8
175 #define CONTEXT_R15 0xf0
176 #define CONTEXT_Rip 0xf8
177 #define CONTEXT_Header 0x100
178 #define CONTEXT_Legacy 0x120
179 #define CONTEXT_Xmm0 0x1a0
180 #define CONTEXT_Xmm1 0x1b0
181 #define CONTEXT_Xmm2 0x1c0
182 #define CONTEXT_Xmm3 0x1d0
183 #define CONTEXT_Xmm4 0x1e0
184 #define CONTEXT_Xmm5 0x1f0
185 #define CONTEXT_Xmm6 0x200
186 #define CONTEXT_Xmm7 0x210
187 #define CONTEXT_Xmm8 0x220
188 #define CONTEXT_Xmm9 0x230
189 #define CONTEXT_Xmm10 0x240
190 #define CONTEXT_Xmm11 0x250
191 #define CONTEXT_Xmm12 0x260
192 #define CONTEXT_Xmm13 0x270
193 #define CONTEXT_Xmm14 0x280
194 #define CONTEXT_Xmm15 0x290
195 #define CONTEXT_VectorRegister 0x300
196 #define CONTEXT_VectorControl 0x4a0
197 #define CONTEXT_DebugControl 0x4a8
198 #define CONTEXT_LastBranchToRip 0x4b0
199 #define CONTEXT_LastBranchFromRip 0x4b8
200 #define CONTEXT_LastExceptionToRip 0x4c0
201 #define CONTEXT_LastExceptionFromRip 0x4c8
202
203 //
204 // EXCEPTION_RECORD Offsets
205 //
206 #define EXCEPTION_RECORD_ExceptionCode 0x00
207 #define EXCEPTION_RECORD_ExceptionFlags 0x04
208 #define EXCEPTION_RECORD_ExceptionRecord 0x08
209 #define EXCEPTION_RECORD_ExceptionAddress 0x10
210 #define EXCEPTION_RECORD_NumberParameters 0x18
211 #define EXCEPTION_RECORD_ExceptionInformation 0x20
212 #define SIZE_EXCEPTION_RECORD 0x98
213
214 //
215 // CR0
216 //
217 #define CR0_PE 0x1
218 #define CR0_MP 0x2
219 #define CR0_EM 0x4
220 #define CR0_TS 0x8
221 #define CR0_ET 0x10
222 #define CR0_NE 0x20
223 #define CR0_WP 0x10000
224 #define CR0_AM 0x40000
225 #define CR0_NW 0x20000000
226 #define CR0_CD 0x40000000
227 #define CR0_PG 0x80000000
228
229 //
230 // CR4
231 //
232 #define CR4_VME 0x1
233 #define CR4_PVI 0x2
234 #define CR4_TSD 0x4
235 #define CR4_DE 0x8
236 #define CR4_PSE 0x10
237 #define CR4_PAE 0x20
238 #define CR4_MCE 0x40
239 #define CR4_PGE 0x80
240 #define CR4_FXSR 0x200
241 #define CR4_XMMEXCPT 0x400
242
243 //
244 // Generic Definitions
245 //
246 #define PRIMARY_VECTOR_BASE 0x30
247 #define MAXIMUM_IDTVECTOR 0xFF
248
249 //
250 // Usermode callout frame definitions
251 //
252 #define CBSTACK_STACK 0x0
253 #define CBSTACK_TRAP_FRAME 0x8
254 #define CBSTACK_CALLBACK_STACK 0x10
255 #define CBSTACK_RBP 0x18
256 #define CBSTACK_RESULT 0x20
257 #define CBSTACK_RESULT_LENGTH 0x28
258 #define CBSTACK_FRAME_POINTER CBSTACK_RBP
259
260
261 /* Following ones are ASM only! ***********************************************/
262
263 #ifdef __ASM__
264
265 //
266 // PCR Access
267 //
268 #define PCR gs:
269
270 //
271 // EFLAGS
272 //
273 #define EFLAGS_TF 0x100
274 #define EFLAGS_INTERRUPT_MASK 0x200
275 #define EFLAGS_NESTED_TASK 0x4000
276 #define EFLAGS_V86_MASK 0x20000
277 #define EFLAGS_ALIGN_CHECK 0x40000
278 #define EFLAGS_VIF 0x80000
279 #define EFLAGS_VIP 0x100000
280 #define EFLAG_SIGN 0x8000
281 #define EFLAG_ZERO 0x4000
282 #define EFLAG_SELECT (EFLAG_SIGN + EFLAG_ZERO)
283 #define EFLAGS_USER_SANITIZE 0x3F4DD7
284
285 //
286 // NTSTATUS and Bugcheck Codes
287 //
288 #define STATUS_ACCESS_VIOLATION 0xC0000005
289 #define STATUS_IN_PAGE_ERROR 0xC0000006
290 #define STATUS_GUARD_PAGE_VIOLATION 0x80000001
291 #define STATUS_PRIVILEGED_INSTRUCTION 0xC0000096
292 #define STATUS_STACK_OVERFLOW 0xC00000FD
293 #define KI_EXCEPTION_ACCESS_VIOLATION 0x10000004
294 #define STATUS_INVALID_SYSTEM_SERVICE 0xC000001C
295 #define STATUS_NO_CALLBACK_ACTIVE 0xC0000258
296 #define STATUS_CALLBACK_POP_STACK 0xC0000423
297 #define STATUS_ARRAY_BOUNDS_EXCEEDED 0xC000008C
298 #define STATUS_ILLEGAL_INSTRUCTION 0xC000001D
299 #define STATUS_INVALID_LOCK_SEQUENCE 0xC000001E
300 #define STATUS_BREAKPOINT 0x80000003
301 #define STATUS_SINGLE_STEP 0x80000004
302 #define STATUS_INTEGER_DIVIDE_BY_ZERO 0xC0000094
303 #define STATUS_INTEGER_OVERFLOW 0xC0000095
304 #define STATUS_FLOAT_DENORMAL_OPERAND 0xC000008D
305 #define STATUS_FLOAT_DIVIDE_BY_ZERO 0xC000008E
306 #define STATUS_FLOAT_INEXACT_RESULT 0xC000008F
307 #define STATUS_FLOAT_INVALID_OPERATION 0xC0000090
308 #define STATUS_FLOAT_OVERFLOW 0xC0000091
309 #define STATUS_FLOAT_STACK_CHECK 0xC0000092
310 #define STATUS_FLOAT_UNDERFLOW 0xC0000093
311 #define STATUS_FLOAT_MULTIPLE_FAULTS 0xC00002B4
312 #define STATUS_FLOAT_MULTIPLE_TRAPS 0xC00002B5
313 #define APC_INDEX_MISMATCH 0x01
314 #define IRQL_NOT_GREATER_OR_EQUAL 0x09
315 #define IRQL_NOT_LESS_OR_EQUAL 0x0A
316 #define TRAP_CAUSE_UNKNOWN 0x12
317 #define KMODE_EXCEPTION_NOT_HANDLED 0x13
318 #define IRQL_GT_ZERO_AT_SYSTEM_SERVICE 0x4A
319 #define UNEXPECTED_KERNEL_MODE_TRAP 0x7F
320 #define ATTEMPTED_SWITCH_FROM_DPC 0xB8
321 #define HARDWARE_INTERRUPT_STORM 0xF2
322
323 //
324 // IRQL Levels
325 //
326 #define PASSIVE_LEVEL 0
327 #define LOW_LEVEL 0
328 #define APC_LEVEL 1
329 #define DISPATCH_LEVEL 2
330 #define CLOCK_LEVEL 13
331 #define IPI_LEVEL 14
332 #define POWER_LEVEL 14
333 #define PROFILE_LEVEL 15
334 #define HIGH_LEVEL 15
335
336 //
337 // Quantum Decrements
338 //
339 #define CLOCK_QUANTUM_DECREMENT 0x3
340
341 //
342 // Machine types
343 //
344 #define MACHINE_TYPE_ISA 0x0000
345 #define MACHINE_TYPE_EISA 0x0001
346 #define MACHINE_TYPE_MCA 0x0002
347
348 //
349 // Kernel Feature Bits
350 //
351 #define KF_RDTSC 0x00000002
352
353 //
354 // Kernel Stack Size
355 //
356 #define KERNEL_STACK_SIZE 0x6000
357
358 #endif // __ASM__
359
360 #endif // !_ASM_AMD64_H
361