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