Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1524 lines
44 KiB

  1. /*++ BUILD Version: 0011 // Increment this if a change has global effects
  2. Module Name:
  3. ntia64.h
  4. Abstract:
  5. User-mode visible IA64 specific structures and constants
  6. Author:
  7. Bernard Lint 21-jun-95
  8. Revision History:
  9. --*/
  10. #ifndef _NTIA64H_
  11. #define _NTIA64H_
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "ia64inst.h"
  19. // begin_ntddk begin_wdm begin_nthal
  20. #ifdef _IA64_
  21. // end_ntddk end_wdm end_nthal
  22. //
  23. // Define breakpoint codes.
  24. //
  25. //
  26. // Define BREAK immediate usage
  27. // IA64 conventions for 21 bit break immediate:
  28. // all zeroes : reserved for break.b instruction
  29. // 000xxxx... : architected software interrupts (divide by zero...)
  30. // 001xxxx... : application software interrupts (reserved for user code)
  31. // 01xxxxx... : debug breakpoints
  32. // 10xxxxx... : system level debug (reserved for subsystems)
  33. // 110xxxx... : normal system calls
  34. // 111xxxx... : fast path system calls for event pair
  35. //
  36. #define BREAK_ASI_BASE 0x000000
  37. #define BREAK_APP_BASE 0x040000
  38. #define BREAK_APP_SUBSYSTEM_OFFSET 0x008000 // used to debug subsystem
  39. #define BREAK_DEBUG_BASE 0x080000
  40. #define BREAK_SYSCALL_BASE 0x180000
  41. #define BREAK_FASTSYS_BASE 0x1C0000
  42. //
  43. // Define Architected Software Interrupts
  44. //
  45. #define UNKNOWN_ERROR_BREAK (BREAK_ASI_BASE+0)
  46. #define INTEGER_DIVIDE_BY_ZERO_BREAK (BREAK_ASI_BASE+1)
  47. #define INTEGER_OVERFLOW_BREAK (BREAK_ASI_BASE+2)
  48. #define RANGE_CHECK_BREAK (BREAK_ASI_BASE+3)
  49. #define NULL_POINTER_DEFERENCE_BREAK (BREAK_ASI_BASE+4)
  50. #define MISALIGNED_DATA_BREAK (BREAK_ASI_BASE+5)
  51. #define DECIMAL_OVERFLOW_BREAK (BREAK_ASI_BASE+6)
  52. #define DECIMAL_DIVIDE_BY_ZERO_BREAK (BREAK_ASI_BASE+7)
  53. #define PACKED_DECIMAL_ERROR_BREAK (BREAK_ASI_BASE+8)
  54. #define INVALID_ASCII_DIGIT_BREAK (BREAK_ASI_BASE+9)
  55. #define INVALID_DECIMAL_DIGIT_BREAK (BREAK_ASI_BASE+10)
  56. #define PARAGRAPH_STACK_OVERFLOW_BREAK (BREAK_ASI_BASE+11)
  57. //
  58. // Define debug related break values
  59. // N.B. KdpTrap() checks for break value >= DEBUG_PRINT_BREAKPOINT
  60. //
  61. #define BREAKPOINT_X86_BREAK 0 // x86 int3
  62. #define BREAKB_BREAKPOINT (BREAK_DEBUG_BASE+0) // reserved for break.b - do not use
  63. #define KERNEL_BREAKPOINT (BREAK_DEBUG_BASE+1) // kernel breakpoint
  64. #define USER_BREAKPOINT (BREAK_DEBUG_BASE+2) // user breakpoint
  65. #define BREAKPOINT_PRINT (BREAK_DEBUG_BASE+20) // debug print breakpoint
  66. #define BREAKPOINT_PROMPT (BREAK_DEBUG_BASE+21) // debug prompt breakpoint
  67. #define BREAKPOINT_STOP (BREAK_DEBUG_BASE+22) // debug stop breakpoint
  68. #define BREAKPOINT_LOAD_SYMBOLS (BREAK_DEBUG_BASE+23) // load symbols breakpoint
  69. #define BREAKPOINT_UNLOAD_SYMBOLS (BREAK_DEBUG_BASE+24) // unload symbols breakpoint
  70. #define BREAKPOINT_BREAKIN (BREAK_DEBUG_BASE+25) // break into kernel debugger
  71. #define BREAKPOINT_COMMAND_STRING (BREAK_DEBUG_BASE+26) // execute a command string
  72. //
  73. // Define IA64 specific read control space commands for the
  74. // Kernel Debugger.
  75. //
  76. #define DEBUG_CONTROL_SPACE_PCR 1
  77. #define DEBUG_CONTROL_SPACE_PRCB 2
  78. #define DEBUG_CONTROL_SPACE_KSPECIAL 3
  79. #define DEBUG_CONTROL_SPACE_THREAD 4
  80. //
  81. // System call break
  82. //
  83. #define BREAK_SYSCALL BREAK_SYSCALL_BASE
  84. //
  85. // Define special fast path even pair client/server system service codes.
  86. //
  87. // N.B. These codes are VERY special. The high three bits signifies a fast path
  88. // event pair service and the low bit signifies what type.
  89. //
  90. #define BREAK_SET_LOW_WAIT_HIGH (BREAK_FASTSYS_BASE|0x20) // fast path event pair service
  91. #define BREAK_SET_HIGH_WAIT_LOW (BREAK_FASTSYS_BASE|0x10) // fast path event pair service
  92. //
  93. // Special subsystem break codes: (from application software interrupt space)
  94. //
  95. #define BREAK_SUBSYSTEM_BASE (BREAK_APP_BASE+BREAK_APP_SUBSYSTEM_OFFSET)
  96. // begin_ntddk begin_nthal
  97. //
  98. // Define size of kernel mode stack.
  99. //
  100. #define KERNEL_STACK_SIZE 0x8000
  101. //
  102. // Define size of large kernel mode stack for callbacks.
  103. //
  104. #define KERNEL_LARGE_STACK_SIZE 0x1A000
  105. //
  106. // Define number of pages to initialize in a large kernel stack.
  107. //
  108. #define KERNEL_LARGE_STACK_COMMIT 0x8000
  109. //
  110. // Define size of kernel mode backing store stack.
  111. //
  112. #define KERNEL_BSTORE_SIZE 0x8000
  113. //
  114. // Define size of large kernel mode backing store for callbacks.
  115. //
  116. #define KERNEL_LARGE_BSTORE_SIZE 0x10000
  117. //
  118. // Define number of pages to initialize in a large kernel backing store.
  119. //
  120. #define KERNEL_LARGE_BSTORE_COMMIT 0x8000
  121. //
  122. // Define base address for kernel and user space.
  123. //
  124. #define UREGION_INDEX 0
  125. #define KREGION_INDEX 7
  126. #define UADDRESS_BASE ((ULONGLONG)UREGION_INDEX << 61)
  127. #define KADDRESS_BASE ((ULONGLONG)KREGION_INDEX << 61)
  128. // end_ntddk end_nthal
  129. //
  130. // Define address of data shared between user and kernel mode.
  131. // Alas, the MM_SHARED_USER_DATA_VA needs to be below 2G for
  132. // compatibility reasons.
  133. //
  134. #define MM_SHARED_USER_DATA_VA (UADDRESS_BASE + 0x7FFE0000)
  135. #define USER_SHARED_DATA ((KUSER_SHARED_DATA * const)MM_SHARED_USER_DATA_VA)
  136. //
  137. // Define address of the wow64 reserved compatibility area.
  138. // The offset needs to be large enough that the CSRSS can fit it's data
  139. // See csr\srvinit.c and the refrence the SharedSection key in the registry.
  140. //
  141. #define WOW64_COMPATIBILITY_AREA_ADDRESS (MM_SHARED_USER_DATA_VA - 0x1000000)
  142. //
  143. // Define address of the system-wide csrss shared section.
  144. //
  145. #define CSR_SYSTEM_SHARED_ADDRESS (WOW64_COMPATIBILITY_AREA_ADDRESS)
  146. //
  147. // Call frame record definition.
  148. //
  149. // There is no standard call frame for IA64, but there is a linked
  150. // list structure used to register exception handlers, this is it.
  151. //
  152. //
  153. // begin_nthal
  154. // Exception Registration structure
  155. //
  156. typedef struct _EXCEPTION_REGISTRATION_RECORD {
  157. struct _EXCEPTION_REGISTRATION_RECORD *Next;
  158. PEXCEPTION_ROUTINE Handler;
  159. } EXCEPTION_REGISTRATION_RECORD;
  160. // end_nthal
  161. typedef EXCEPTION_REGISTRATION_RECORD *PEXCEPTION_REGISTRATION_RECORD;
  162. //
  163. // Define function to return the current Thread Environment Block
  164. //
  165. // stub this out for midl compiler.
  166. // idl files incude this header file for the typedefs and #defines etc.
  167. // midl never generates stubs for the functions declared here.
  168. //
  169. //
  170. // Don't define for GENIA64 since GENIA64.C is built with the x86 compiler.
  171. //
  172. // begin_winnt
  173. #if !defined(__midl) && !defined(GENUTIL) && !defined(_GENIA64_) && defined(_IA64_)
  174. void * _cdecl _rdteb(void);
  175. #if defined(_M_IA64)
  176. #pragma intrinsic(_rdteb)
  177. #define NtCurrentTeb() ((struct _TEB *)_rdteb())
  178. //
  179. // Define functions to get the address of the current fiber and the
  180. // current fiber data.
  181. //
  182. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  183. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  184. // begin_ntddk begin_nthal
  185. void
  186. __yield(
  187. void
  188. );
  189. void
  190. __mf(
  191. void
  192. );
  193. void
  194. __lfetch(
  195. int Level,
  196. VOID CONST *Address
  197. );
  198. void
  199. __lfetchfault(
  200. int Level,
  201. VOID CONST *Address
  202. );
  203. //
  204. // __lfetch control defines.
  205. //
  206. #define MD_LFHINT_NONE 0x00
  207. #define MD_LFHINT_NT1 0x01
  208. #define MD_LFHINT_NT2 0x02
  209. #define MD_LFHINT_NTA 0x03
  210. #pragma intrinsic (__yield)
  211. #pragma intrinsic (__lfetch)
  212. #pragma intrinsic (__lfetchfault)
  213. #pragma intrinsic (__mf)
  214. #define YieldProcessor __yield
  215. #define MemoryBarrier __mf
  216. #define PreFetchCacheLine __lfetch
  217. //
  218. // PreFetchCacheLine level defines.
  219. //
  220. #define PF_TEMPORAL_LEVEL_1 MD_LFHINT_NONE
  221. #define PF_NON_TEMPORAL_LEVEL_ALL MD_LFHINT_NTA
  222. // end_ntddk end_nthal
  223. #else
  224. struct _TEB *
  225. NtCurrentTeb(void);
  226. #endif
  227. #endif // !defined(__midl) && !defined(GENUTIL) && !defined(_GENIA64_) && defined(_M_IA64)
  228. #ifdef _IA64_
  229. // begin_ntddk begin_nthal
  230. //
  231. // The following flags control the contents of the CONTEXT structure.
  232. //
  233. #if !defined(RC_INVOKED)
  234. #define CONTEXT_IA64 0x00080000
  235. #define CONTEXT_CONTROL (CONTEXT_IA64 | 0x00000001L)
  236. #define CONTEXT_LOWER_FLOATING_POINT (CONTEXT_IA64 | 0x00000002L)
  237. #define CONTEXT_HIGHER_FLOATING_POINT (CONTEXT_IA64 | 0x00000004L)
  238. #define CONTEXT_INTEGER (CONTEXT_IA64 | 0x00000008L)
  239. #define CONTEXT_DEBUG (CONTEXT_IA64 | 0x00000010L)
  240. #define CONTEXT_IA32_CONTROL (CONTEXT_IA64 | 0x00000020L) // Includes StIPSR
  241. #define CONTEXT_FLOATING_POINT (CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT)
  242. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_IA32_CONTROL)
  243. #define CONTEXT_ALL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER | CONTEXT_DEBUG | CONTEXT_IA32_CONTROL)
  244. #define CONTEXT_EXCEPTION_ACTIVE 0x8000000
  245. #define CONTEXT_SERVICE_ACTIVE 0x10000000
  246. #define CONTEXT_EXCEPTION_REQUEST 0x40000000
  247. #define CONTEXT_EXCEPTION_REPORTING 0x80000000
  248. #endif // !defined(RC_INVOKED)
  249. //
  250. // Context Frame
  251. //
  252. // This frame has a several purposes: 1) it is used as an argument to
  253. // NtContinue, 2) it is used to construct a call frame for APC delivery,
  254. // 3) it is used to construct a call frame for exception dispatching
  255. // in user mode, 4) it is used in the user level thread creation
  256. // routines, and 5) it is used to to pass thread state to debuggers.
  257. //
  258. // N.B. Because this record is used as a call frame, it must be EXACTLY
  259. // a multiple of 16 bytes in length and aligned on a 16-byte boundary.
  260. //
  261. typedef struct _CONTEXT {
  262. //
  263. // The flags values within this flag control the contents of
  264. // a CONTEXT record.
  265. //
  266. // If the context record is used as an input parameter, then
  267. // for each portion of the context record controlled by a flag
  268. // whose value is set, it is assumed that that portion of the
  269. // context record contains valid context. If the context record
  270. // is being used to modify a thread's context, then only that
  271. // portion of the threads context will be modified.
  272. //
  273. // If the context record is used as an IN OUT parameter to capture
  274. // the context of a thread, then only those portions of the thread's
  275. // context corresponding to set flags will be returned.
  276. //
  277. // The context record is never used as an OUT only parameter.
  278. //
  279. ULONG ContextFlags;
  280. ULONG Fill1[3]; // for alignment of following on 16-byte boundary
  281. //
  282. // This section is specified/returned if the ContextFlags word contains
  283. // the flag CONTEXT_DEBUG.
  284. //
  285. // N.B. CONTEXT_DEBUG is *not* part of CONTEXT_FULL.
  286. //
  287. ULONGLONG DbI0;
  288. ULONGLONG DbI1;
  289. ULONGLONG DbI2;
  290. ULONGLONG DbI3;
  291. ULONGLONG DbI4;
  292. ULONGLONG DbI5;
  293. ULONGLONG DbI6;
  294. ULONGLONG DbI7;
  295. ULONGLONG DbD0;
  296. ULONGLONG DbD1;
  297. ULONGLONG DbD2;
  298. ULONGLONG DbD3;
  299. ULONGLONG DbD4;
  300. ULONGLONG DbD5;
  301. ULONGLONG DbD6;
  302. ULONGLONG DbD7;
  303. //
  304. // This section is specified/returned if the ContextFlags word contains
  305. // the flag CONTEXT_LOWER_FLOATING_POINT.
  306. //
  307. FLOAT128 FltS0;
  308. FLOAT128 FltS1;
  309. FLOAT128 FltS2;
  310. FLOAT128 FltS3;
  311. FLOAT128 FltT0;
  312. FLOAT128 FltT1;
  313. FLOAT128 FltT2;
  314. FLOAT128 FltT3;
  315. FLOAT128 FltT4;
  316. FLOAT128 FltT5;
  317. FLOAT128 FltT6;
  318. FLOAT128 FltT7;
  319. FLOAT128 FltT8;
  320. FLOAT128 FltT9;
  321. //
  322. // This section is specified/returned if the ContextFlags word contains
  323. // the flag CONTEXT_HIGHER_FLOATING_POINT.
  324. //
  325. FLOAT128 FltS4;
  326. FLOAT128 FltS5;
  327. FLOAT128 FltS6;
  328. FLOAT128 FltS7;
  329. FLOAT128 FltS8;
  330. FLOAT128 FltS9;
  331. FLOAT128 FltS10;
  332. FLOAT128 FltS11;
  333. FLOAT128 FltS12;
  334. FLOAT128 FltS13;
  335. FLOAT128 FltS14;
  336. FLOAT128 FltS15;
  337. FLOAT128 FltS16;
  338. FLOAT128 FltS17;
  339. FLOAT128 FltS18;
  340. FLOAT128 FltS19;
  341. FLOAT128 FltF32;
  342. FLOAT128 FltF33;
  343. FLOAT128 FltF34;
  344. FLOAT128 FltF35;
  345. FLOAT128 FltF36;
  346. FLOAT128 FltF37;
  347. FLOAT128 FltF38;
  348. FLOAT128 FltF39;
  349. FLOAT128 FltF40;
  350. FLOAT128 FltF41;
  351. FLOAT128 FltF42;
  352. FLOAT128 FltF43;
  353. FLOAT128 FltF44;
  354. FLOAT128 FltF45;
  355. FLOAT128 FltF46;
  356. FLOAT128 FltF47;
  357. FLOAT128 FltF48;
  358. FLOAT128 FltF49;
  359. FLOAT128 FltF50;
  360. FLOAT128 FltF51;
  361. FLOAT128 FltF52;
  362. FLOAT128 FltF53;
  363. FLOAT128 FltF54;
  364. FLOAT128 FltF55;
  365. FLOAT128 FltF56;
  366. FLOAT128 FltF57;
  367. FLOAT128 FltF58;
  368. FLOAT128 FltF59;
  369. FLOAT128 FltF60;
  370. FLOAT128 FltF61;
  371. FLOAT128 FltF62;
  372. FLOAT128 FltF63;
  373. FLOAT128 FltF64;
  374. FLOAT128 FltF65;
  375. FLOAT128 FltF66;
  376. FLOAT128 FltF67;
  377. FLOAT128 FltF68;
  378. FLOAT128 FltF69;
  379. FLOAT128 FltF70;
  380. FLOAT128 FltF71;
  381. FLOAT128 FltF72;
  382. FLOAT128 FltF73;
  383. FLOAT128 FltF74;
  384. FLOAT128 FltF75;
  385. FLOAT128 FltF76;
  386. FLOAT128 FltF77;
  387. FLOAT128 FltF78;
  388. FLOAT128 FltF79;
  389. FLOAT128 FltF80;
  390. FLOAT128 FltF81;
  391. FLOAT128 FltF82;
  392. FLOAT128 FltF83;
  393. FLOAT128 FltF84;
  394. FLOAT128 FltF85;
  395. FLOAT128 FltF86;
  396. FLOAT128 FltF87;
  397. FLOAT128 FltF88;
  398. FLOAT128 FltF89;
  399. FLOAT128 FltF90;
  400. FLOAT128 FltF91;
  401. FLOAT128 FltF92;
  402. FLOAT128 FltF93;
  403. FLOAT128 FltF94;
  404. FLOAT128 FltF95;
  405. FLOAT128 FltF96;
  406. FLOAT128 FltF97;
  407. FLOAT128 FltF98;
  408. FLOAT128 FltF99;
  409. FLOAT128 FltF100;
  410. FLOAT128 FltF101;
  411. FLOAT128 FltF102;
  412. FLOAT128 FltF103;
  413. FLOAT128 FltF104;
  414. FLOAT128 FltF105;
  415. FLOAT128 FltF106;
  416. FLOAT128 FltF107;
  417. FLOAT128 FltF108;
  418. FLOAT128 FltF109;
  419. FLOAT128 FltF110;
  420. FLOAT128 FltF111;
  421. FLOAT128 FltF112;
  422. FLOAT128 FltF113;
  423. FLOAT128 FltF114;
  424. FLOAT128 FltF115;
  425. FLOAT128 FltF116;
  426. FLOAT128 FltF117;
  427. FLOAT128 FltF118;
  428. FLOAT128 FltF119;
  429. FLOAT128 FltF120;
  430. FLOAT128 FltF121;
  431. FLOAT128 FltF122;
  432. FLOAT128 FltF123;
  433. FLOAT128 FltF124;
  434. FLOAT128 FltF125;
  435. FLOAT128 FltF126;
  436. FLOAT128 FltF127;
  437. //
  438. // This section is specified/returned if the ContextFlags word contains
  439. // the flag CONTEXT_LOWER_FLOATING_POINT | CONTEXT_HIGHER_FLOATING_POINT | CONTEXT_CONTROL.
  440. //
  441. ULONGLONG StFPSR; // FP status
  442. //
  443. // This section is specified/returned if the ContextFlags word contains
  444. // the flag CONTEXT_INTEGER.
  445. //
  446. // N.B. The registers gp, sp, rp are part of the control context
  447. //
  448. ULONGLONG IntGp; // r1, volatile
  449. ULONGLONG IntT0; // r2-r3, volatile
  450. ULONGLONG IntT1; //
  451. ULONGLONG IntS0; // r4-r7, preserved
  452. ULONGLONG IntS1;
  453. ULONGLONG IntS2;
  454. ULONGLONG IntS3;
  455. ULONGLONG IntV0; // r8, volatile
  456. ULONGLONG IntT2; // r9-r11, volatile
  457. ULONGLONG IntT3;
  458. ULONGLONG IntT4;
  459. ULONGLONG IntSp; // stack pointer (r12), special
  460. ULONGLONG IntTeb; // teb (r13), special
  461. ULONGLONG IntT5; // r14-r31, volatile
  462. ULONGLONG IntT6;
  463. ULONGLONG IntT7;
  464. ULONGLONG IntT8;
  465. ULONGLONG IntT9;
  466. ULONGLONG IntT10;
  467. ULONGLONG IntT11;
  468. ULONGLONG IntT12;
  469. ULONGLONG IntT13;
  470. ULONGLONG IntT14;
  471. ULONGLONG IntT15;
  472. ULONGLONG IntT16;
  473. ULONGLONG IntT17;
  474. ULONGLONG IntT18;
  475. ULONGLONG IntT19;
  476. ULONGLONG IntT20;
  477. ULONGLONG IntT21;
  478. ULONGLONG IntT22;
  479. ULONGLONG IntNats; // Nat bits for r1-r31
  480. // r1-r31 in bits 1 thru 31.
  481. ULONGLONG Preds; // predicates, preserved
  482. ULONGLONG BrRp; // return pointer, b0, preserved
  483. ULONGLONG BrS0; // b1-b5, preserved
  484. ULONGLONG BrS1;
  485. ULONGLONG BrS2;
  486. ULONGLONG BrS3;
  487. ULONGLONG BrS4;
  488. ULONGLONG BrT0; // b6-b7, volatile
  489. ULONGLONG BrT1;
  490. //
  491. // This section is specified/returned if the ContextFlags word contains
  492. // the flag CONTEXT_CONTROL.
  493. //
  494. // Other application registers
  495. ULONGLONG ApUNAT; // User Nat collection register, preserved
  496. ULONGLONG ApLC; // Loop counter register, preserved
  497. ULONGLONG ApEC; // Epilog counter register, preserved
  498. ULONGLONG ApCCV; // CMPXCHG value register, volatile
  499. ULONGLONG ApDCR; // Default control register (TBD)
  500. // Register stack info
  501. ULONGLONG RsPFS; // Previous function state, preserved
  502. ULONGLONG RsBSP; // Backing store pointer, preserved
  503. ULONGLONG RsBSPSTORE;
  504. ULONGLONG RsRSC; // RSE configuration, volatile
  505. ULONGLONG RsRNAT; // RSE Nat collection register, preserved
  506. // Trap Status Information
  507. ULONGLONG StIPSR; // Interruption Processor Status
  508. ULONGLONG StIIP; // Interruption IP
  509. ULONGLONG StIFS; // Interruption Function State
  510. // iA32 related control registers
  511. ULONGLONG StFCR; // copy of Ar21
  512. ULONGLONG Eflag; // Eflag copy of Ar24
  513. ULONGLONG SegCSD; // iA32 CSDescriptor (Ar25)
  514. ULONGLONG SegSSD; // iA32 SSDescriptor (Ar26)
  515. ULONGLONG Cflag; // Cr0+Cr4 copy of Ar27
  516. ULONGLONG StFSR; // x86 FP status (copy of AR28)
  517. ULONGLONG StFIR; // x86 FP status (copy of AR29)
  518. ULONGLONG StFDR; // x86 FP status (copy of AR30)
  519. ULONGLONG UNUSEDPACK; // added to pack StFDR to 16-bytes
  520. } CONTEXT, *PCONTEXT;
  521. //
  522. // Plabel descriptor structure definition
  523. //
  524. typedef struct _PLABEL_DESCRIPTOR {
  525. ULONGLONG EntryPoint;
  526. ULONGLONG GlobalPointer;
  527. } PLABEL_DESCRIPTOR, *PPLABEL_DESCRIPTOR;
  528. // end_winnt
  529. // end_ntddk end_nthal
  530. #endif // _IA64_
  531. #define CONTEXT_TO_PROGRAM_COUNTER(Context) ((Context)->StIIP \
  532. | (((Context)->StIPSR & (IPSR_RI_MASK)) >> (PSR_RI-2)))
  533. #define PROGRAM_COUNTER_TO_CONTEXT(Context, ProgramCounter) ((Context)->StIIP = (ProgramCounter) & ~(0x0fI64), \
  534. (Context)->StIPSR &= ~(IPSR_RI_MASK), \
  535. (Context)->StIPSR |= ((ProgramCounter) & 0x0cI64) << (PSR_RI-2), \
  536. (Context)->StIPSR = ((Context)->StIPSR & (IPSR_RI_MASK)) == (IPSR_RI_MASK) ? \
  537. (Context)->StIPSR & ~(IPSR_RI_MASK) : (Context)->StIPSR )
  538. #define CONTEXT_LENGTH (sizeof(CONTEXT))
  539. #define CONTEXT_ALIGN (16)
  540. #define CONTEXT_ROUND (CONTEXT_ALIGN - 1)
  541. //
  542. // Nonvolatile context pointer record.
  543. //
  544. // The IA64 architecture currently doesn't have any nonvolatile kernel context
  545. // as we capture everything in either the trap or exception frames on
  546. // transition from user to kernel mode. We allocate a single bogus
  547. // pointer field as usually this structure is made up of pointers to
  548. // places in the kernel stack where the various nonvolatile items were
  549. // pushed on to the kernel stack.
  550. //
  551. // TBD *** Need to fill in this structure with the relevant fields
  552. // when we start storing the nonvolatile information only when
  553. // necessary.
  554. //
  555. typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
  556. PFLOAT128 FltS0;
  557. PFLOAT128 FltS1;
  558. PFLOAT128 FltS2;
  559. PFLOAT128 FltS3;
  560. PFLOAT128 HighFloatingContext[10];
  561. PFLOAT128 FltS4;
  562. PFLOAT128 FltS5;
  563. PFLOAT128 FltS6;
  564. PFLOAT128 FltS7;
  565. PFLOAT128 FltS8;
  566. PFLOAT128 FltS9;
  567. PFLOAT128 FltS10;
  568. PFLOAT128 FltS11;
  569. PFLOAT128 FltS12;
  570. PFLOAT128 FltS13;
  571. PFLOAT128 FltS14;
  572. PFLOAT128 FltS15;
  573. PFLOAT128 FltS16;
  574. PFLOAT128 FltS17;
  575. PFLOAT128 FltS18;
  576. PFLOAT128 FltS19;
  577. PULONGLONG IntS0;
  578. PULONGLONG IntS1;
  579. PULONGLONG IntS2;
  580. PULONGLONG IntS3;
  581. PULONGLONG IntSp;
  582. PULONGLONG IntS0Nat;
  583. PULONGLONG IntS1Nat;
  584. PULONGLONG IntS2Nat;
  585. PULONGLONG IntS3Nat;
  586. PULONGLONG IntSpNat;
  587. PULONGLONG Preds;
  588. PULONGLONG BrRp;
  589. PULONGLONG BrS0;
  590. PULONGLONG BrS1;
  591. PULONGLONG BrS2;
  592. PULONGLONG BrS3;
  593. PULONGLONG BrS4;
  594. PULONGLONG ApUNAT;
  595. PULONGLONG ApLC;
  596. PULONGLONG ApEC;
  597. PULONGLONG RsPFS;
  598. PULONGLONG StFSR;
  599. PULONGLONG StFIR;
  600. PULONGLONG StFDR;
  601. PULONGLONG Cflag;
  602. } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
  603. // begin_nthal
  604. // IA64 Register Definitions
  605. #if !(defined(MIDL_PASS) || defined(__midl))
  606. // Processor Status Register (PSR) structure
  607. #define IA64_USER_PL 3
  608. #define IA64_KERNEL_PL 0
  609. struct _PSR {
  610. // User/System mask
  611. ULONGLONG psr_rv0 :1; // 0
  612. ULONGLONG psr_be :1; // 1
  613. ULONGLONG psr_up :1; // 2
  614. ULONGLONG psr_ac :1; // 3
  615. ULONGLONG psr_mfl :1; // 4
  616. ULONGLONG psr_mfh :1; // 5
  617. ULONGLONG psr_rv1 :7; // 6-12
  618. // System mask only
  619. ULONGLONG psr_ic :1; // 13
  620. ULONGLONG psr_i :1; // 14
  621. ULONGLONG psr_pk :1; // 15
  622. ULONGLONG psr_rv2 :1; // 16
  623. ULONGLONG psr_dt :1; // 17
  624. ULONGLONG psr_dfl :1; // 18
  625. ULONGLONG psr_dfh :1; // 19
  626. ULONGLONG psr_sp :1; // 20
  627. ULONGLONG psr_pp :1; // 21
  628. ULONGLONG psr_di :1; // 22
  629. ULONGLONG psr_si :1; // 23
  630. ULONGLONG psr_db :1; // 24
  631. ULONGLONG psr_lp :1; // 25
  632. ULONGLONG psr_tb :1; // 26
  633. ULONGLONG psr_rt :1; // 27
  634. ULONGLONG psr_rv3 :4; // 28-31
  635. // Neither
  636. ULONGLONG psr_cpl :2; // 32-33
  637. ULONGLONG psr_is :1; // 34
  638. ULONGLONG psr_mc :1; // 35
  639. ULONGLONG psr_it :1; // 36
  640. ULONGLONG psr_id :1; // 37
  641. ULONGLONG psr_da :1; // 38
  642. ULONGLONG psr_dd :1; // 39
  643. ULONGLONG psr_ss :1; // 40
  644. ULONGLONG psr_ri :2; // 41-42
  645. ULONGLONG psr_ed :1; // 43
  646. ULONGLONG psr_bn :1; // 44
  647. ULONGLONG psr_ia :1; // 45
  648. ULONGLONG psr_rv4 :18; // 46-63
  649. };
  650. typedef union _UPSR {
  651. ULONGLONG ull;
  652. struct _PSR sb;
  653. } PSR, *PPSR;
  654. //
  655. // Define hardware Floating Point Status Register.
  656. //
  657. // Floating Point Status Register (FPSR) structure
  658. struct _FPSR {
  659. // Trap disable
  660. ULONGLONG fpsr_vd:1;
  661. ULONGLONG fpsr_dd:1;
  662. ULONGLONG fpsr_zd:1;
  663. ULONGLONG fpsr_od:1;
  664. ULONGLONG fpsr_ud:1;
  665. ULONGLONG fpsr_id:1;
  666. // Status Field 0 - Controls
  667. ULONGLONG fpsr_ftz0:1;
  668. ULONGLONG fpsr_wre0:1;
  669. ULONGLONG fpsr_pc0:2;
  670. ULONGLONG fpsr_rc0:2;
  671. ULONGLONG fpsr_td0:1;
  672. // Status Field 0 - Flags
  673. ULONGLONG fpsr_v0:1;
  674. ULONGLONG fpsr_d0:1;
  675. ULONGLONG fpsr_z0:1;
  676. ULONGLONG fpsr_o0:1;
  677. ULONGLONG fpsr_u0:1;
  678. ULONGLONG fpsr_i0:1;
  679. // Status Field 1 - Controls
  680. ULONGLONG fpsr_ftz1:1;
  681. ULONGLONG fpsr_wre1:1;
  682. ULONGLONG fpsr_pc1:2;
  683. ULONGLONG fpsr_rc1:2;
  684. ULONGLONG fpsr_td1:1;
  685. // Status Field 1 - Flags
  686. ULONGLONG fpsr_v1:1;
  687. ULONGLONG fpsr_d1:1;
  688. ULONGLONG fpsr_z1:1;
  689. ULONGLONG fpsr_o1:1;
  690. ULONGLONG fpsr_u1:1;
  691. ULONGLONG fpsr_i1:1;
  692. // Status Field 2 - Controls
  693. ULONGLONG fpsr_ftz2:1;
  694. ULONGLONG fpsr_wre2:1;
  695. ULONGLONG fpsr_pc2:2;
  696. ULONGLONG fpsr_rc2:2;
  697. ULONGLONG fpsr_td2:1;
  698. // Status Field 2 - Flags
  699. ULONGLONG fpsr_v2:1;
  700. ULONGLONG fpsr_d2:1;
  701. ULONGLONG fpsr_z2:1;
  702. ULONGLONG fpsr_o2:1;
  703. ULONGLONG fpsr_u2:1;
  704. ULONGLONG fpsr_i2:1;
  705. // Status Field 3 - Controls
  706. ULONGLONG fpsr_ftz3:1;
  707. ULONGLONG fpsr_wre3:1;
  708. ULONGLONG fpsr_pc3:2;
  709. ULONGLONG fpsr_rc3:2;
  710. ULONGLONG fpsr_td3:1;
  711. // Status Field 2 - Flags
  712. ULONGLONG fpsr_v3:1;
  713. ULONGLONG fpsr_d3:1;
  714. ULONGLONG fpsr_z3:1;
  715. ULONGLONG fpsr_o3:1;
  716. ULONGLONG fpsr_u3:1;
  717. ULONGLONG fpsr_i3:1;
  718. // Reserved -- must be zero
  719. ULONGLONG fpsr_res:6;
  720. };
  721. typedef union _UFPSR {
  722. ULONGLONG ull;
  723. struct _FPSR sb;
  724. } FPSR, *PFPSR;
  725. //
  726. // Define hardware Default Control Register (DCR)
  727. //
  728. // DCR structure
  729. struct _DCR {
  730. ULONGLONG dcr_pp:1; // Default privileged performance monitor enable
  731. ULONGLONG dcr_be:1; // Default interruption big endian bit
  732. ULONGLONG dcr_lc:1; // Lock Check Enable
  733. ULONGLONG dcr_res1:5; // DCR Reserved
  734. ULONGLONG dcr_dm:1; // Defer data TLB miss faults (for spec loads)
  735. ULONGLONG dcr_dp:1; // Defer data not present faults (for spec loads)
  736. ULONGLONG dcr_dk:1; // Defer data key miss faults (for spec loads)
  737. ULONGLONG dcr_dx:1; // Defer data key permission faults (for spec loads)
  738. ULONGLONG dcr_dr:1; // Defer data access rights faults (for spec loads)
  739. ULONGLONG dcr_da:1; // Defer data access faults (for spec loads)
  740. ULONGLONG dcr_dd:1; // Defer data debug faults (for spec loads)
  741. ULONGLONG dcr_du:1; // Defer data unaligned reference faults (for spec loads)
  742. ULONGLONG dcr_res2:48; // DCR reserved
  743. };
  744. typedef union _UDCR {
  745. ULONGLONG ull;
  746. struct _DCR sb;
  747. } DCR, *PDCR;
  748. //
  749. // Define hardware RSE Configuration Register
  750. //
  751. // RSC structure
  752. struct _RSC {
  753. ULONGLONG rsc_mode:2; // Mode field
  754. ULONGLONG rsc_pl:2; // RSE privilege level
  755. ULONGLONG rsc_be:1; // RSE Endian mode (0 = little; 1 = big)
  756. ULONGLONG rsc_res0:11; // RSC reserved
  757. ULONGLONG rsc_loadrs:14; // RSC loadrs distance (in 64-bit words)
  758. ULONGLONG rsc_preload:14; // Software field in reserved part of register
  759. ULONGLONG rsc_res1:20; // RSC reserved
  760. };
  761. typedef union _URSC {
  762. ULONGLONG ull;
  763. struct _RSC sb;
  764. } RSC, *PRSC;
  765. //
  766. // Define hardware Interruption Status Register (ISR)
  767. //
  768. // ISR structure
  769. struct _ISR {
  770. ULONGLONG isr_code:16; // code
  771. ULONGLONG isr_vector:8; // iA32 vector
  772. ULONGLONG isr_res0:8; // ISR reserved
  773. ULONGLONG isr_x:1; // Execute exception
  774. ULONGLONG isr_w:1; // Write exception
  775. ULONGLONG isr_r:1; // Read exception
  776. ULONGLONG isr_na:1; // Non-access exception
  777. ULONGLONG isr_sp:1; // Speculative load exception
  778. ULONGLONG isr_rs:1; // Register stack exception
  779. ULONGLONG isr_ir:1; // Invalid register frame
  780. ULONGLONG isr_ni:1; // Nested interruption
  781. ULONGLONG isr_res1:1; // ISR reserved
  782. ULONGLONG isr_ei:2; // Instruction slot
  783. ULONGLONG isr_ed:1; // Exception deferral
  784. ULONGLONG isr_res2:20; // ISR reserved
  785. };
  786. typedef union _UISR {
  787. ULONGLONG ull;
  788. struct _ISR sb;
  789. } ISR, *PISR;
  790. //
  791. // Define hardware Previous Function State (PFS)
  792. //
  793. #define PFS_MAXIMUM_REGISTER_SIZE 96
  794. #define PFS_MAXIMUM_PREDICATE_SIZE 48
  795. struct _IA64_PFS {
  796. ULONGLONG pfs_sof:7; // Size of frame
  797. ULONGLONG pfs_sol:7; // Size of locals
  798. ULONGLONG pfs_sor:4; // Size of rotating portion of stack frame
  799. ULONGLONG pfs_rrb_gr:7; // Register rename base for general registers
  800. ULONGLONG pfs_rrb_fr:7; // Register rename base for floating-point registers
  801. ULONGLONG pfs_rrb_pr:6; // Register rename base for predicate registers
  802. ULONGLONG pfs_reserved1:14; // Reserved must be zero
  803. ULONGLONG pfs_pec:6; // Previous Epilog Count
  804. ULONGLONG pfs_reserved2:4; // Reserved must be zero
  805. ULONGLONG pfs_ppl:2; // Previous Privilege Level
  806. };
  807. typedef union _UIA64_PFS {
  808. ULONGLONG ull;
  809. struct _IA64_PFS sb;
  810. } IA64_PFS, *PIA64_PFS;
  811. struct _IA64_BSP {
  812. ULONGLONG bsplow : 3; // Size of frame
  813. ULONGLONG bsp83 : 6; // Size of locals
  814. ULONGLONG bsphigh : 55;
  815. };
  816. typedef union _UIA64_BSP {
  817. ULONGLONG ull;
  818. struct _IA64_BSP sb;
  819. } IA64_BSP;
  820. #endif // MIDL_PASS
  821. //
  822. // EM Debug Register related fields.
  823. //
  824. #define DBR_RDWR 0xC000000000000000ULL
  825. #define DBR_WR 0x4000000000000000ULL
  826. #define DBR_RD 0x8000000000000000ULL
  827. #define IBR_EX 0x8000000000000000ULL
  828. #define DBG_REG_PLM_USER 0x0800000000000000ULL
  829. #define DBG_MASK_MASK 0x00FFFFFFFFFFFFFFULL
  830. #define DBG_REG_MASK(VAL) (ULONGLONG)(((((ULONGLONG)(VAL) \
  831. << 8) >> 8)) ^ DBG_MASK_MASK)
  832. #define DBG_MASK_LENGTH(DBG) (ULONGLONG)(DBG_REG_MASK(DBG))
  833. #define IS_DBR_RDWR(DBR) (((DBR) & DBR_RDWR) == DBR_RDWR)
  834. #define IS_DBR_WR(DBR) (((DBR) & DBR_RDWR) == DBR_WR)
  835. #define IS_DBR_RD(DBR) (((DBR) & DBR_RDWR) == DBR_RD)
  836. #define IS_IBR_EX(IBR) (((IBR) & IBR_EX) == IBR_EX)
  837. #define DBR_ACTIVE(DBR) (IS_DBR_RDWR(DBR) || IS_DBR_WR(DBR) || IS_DBR_RD(DBR))
  838. #define IBR_ACTIVE(IBR) (IS_IBR_EX(IBR))
  839. #define DBR_SET_IA_RW(DBR, T, F) (DBR_ACTIVE(DBR) ? (T) : (F))
  840. #define IBR_SET_IA_RW(IBR, T, F) (IBR_ACTIVE(IBR) ? (T) : (F))
  841. #define SET_IF_DBR_RDWR(DBR, T, F) (IS_DBR_RDWR(DBR) ? (T) : (F))
  842. #define SET_IF_DBR_WR(DBR, T, F) (IS_DBR_WR(DBR) ? (T) : (F))
  843. #define SET_IF_IBR_EX(DBR, T, F) (IS_IBR_EX(DBR) ? (T) : (F))
  844. //
  845. // Get the iA mode Debgug R/W Debug register value from the
  846. // specified EM debug registers.
  847. //
  848. // N.B. Arbitrary order of checking DBR then IBR.
  849. //
  850. // TBD Not sure how to get DR7_RW_IORW from EM Debug Info?
  851. //
  852. #define DBG_EM_ENABLE_TO_IA_RW(DBR, IBR) (UCHAR) \
  853. DBR_SET_IA_RW(DBR, SET_IF_DBR_RDWR(DBR, DR7_RW_DWR, \
  854. SET_IF_DBR_WR(DBR, DR7_RW_DW, 0)), \
  855. SET_IF_IBR_EX(IBR, SET_IF_IBR_EX(IBR, DR7_RW_IX, 0), 0))
  856. //
  857. // Get the iA mode Len Debug register value from the
  858. // specified EM debug registers.
  859. //
  860. // N.B. Arbitrary order of checking DBR then IBR.
  861. //
  862. //
  863. #define IA_DR_LENGTH(VAL) ((UCHAR)((((VAL) << 62) >> 62) + 1))
  864. #define DBG_EM_MASK_TO_IA_LEN(DBR, IBR) \
  865. ((UCHAR)((DBR_ACTIVE(DBR) ? IA_DR_LENGTH(DBG_MASK_LENGTH(DBR)) : \
  866. (DBR_ACTIVE(IBR) ? IA_DR_LENGTH(DBG_MASK_LENGTH(IBR)) : 0))))
  867. //
  868. // Get the iA mode Len Debug register value from the
  869. // specified EM debug registers.
  870. //
  871. // N.B. Arbitrary order of checking DBR then IBR.
  872. //
  873. //
  874. #define DBG_EM_ADDR_TO_IA_ADDR(DBR, IBR) \
  875. (UCHAR)(DBR_ACTIVE(DBR) ? (ULONG) DBR : \
  876. (DBR_ACTIVE(IBR) ? (ULONG) IBR : 0))
  877. //
  878. // Extract iA mode FP Status Registers from EM mode Context
  879. //
  880. #define RES_FTR(FTR) ((FTR) & 0x000000005555FFC0ULL)
  881. #define RES_FCW(FCW) ((FCW) & 0x0F3F) // Bits 6-7, 12-15 Reserved
  882. #define FPSTAT_FSW(FPSR, FTR) \
  883. (ULONG)((((FPSR) << 45) >> 58) | ((RES_FTR(FTR) << 48) >> 48))
  884. #define FPSTAT_FCW(FPSR) (ULONG)(((FPSR) << 53) >> 53)
  885. #define FPSTAT_FTW(FTR) (ULONG)(((FTR) << 32) >> 48)
  886. #define FPSTAT_EOFF(FIR) (ULONG)(((FIR) << 32) >> 32)
  887. #define FPSTAT_ESEL(FIR) (ULONG)(((FIR) << 16) >> 48)
  888. #define FPSTAT_DOFF(FDR) (ULONG)(((FDR) << 32) >> 32)
  889. #define FPSTAT_DSEL(FDR) (ULONG)(((FDR) << 16) >> 48)
  890. #define FPSTAT_CR0(KR0) (ULONG)(((KR0) << 32) >> 32)
  891. //
  892. // Setting FPSR from IA Mode Registers
  893. //
  894. // Bits Map as Follows: FPSR[11:0] <= FCW[11:0]
  895. // FPSR[12:12] <= Reserved (must be zero)
  896. // FPSR[18:13] <= FSW[5:0]
  897. // FPSR[57:19] <= FPSR residual data
  898. // FPSR[59:58] <= Reserved (must be zero)
  899. // FPSR[63:60] <= FPSR residual data
  900. //
  901. #define IA_SET_FPSR(FPSR, FSW, FCW) \
  902. (ULONGLONG)(((ULONGLONG)(FPSR) & 0xF3FFFFFFFFF80000ULL) | \
  903. (((ULONG)(FSW) & 0x0000002FUL) << 13) | \
  904. ((ULONG)(FCW) & 0x0F3FUL))
  905. #define IA_SET_FTR(FTR, FTW, FSW) \
  906. (ULONGLONG)(((ULONGLONG)(FTR) & 0x0000000000000000ULL) | \
  907. ((ULONGLONG)(FTW) << 16) | \
  908. ((ULONG)(FSW) & 0xFFC0UL))
  909. #define IA_SET_FDR(FDS, FEA) (ULONGLONG)((((ULONGLONG)(FDS) << 48) >> 16) | (ULONG)(FEA))
  910. #define IA_SET_FIR(FOP,FCS,FIP) (ULONGLONG)((((ULONGLONG)(FOP) << 52) >> 4) | \
  911. (ULONG)(((FCS) << 48) >> 16) | (ULONG)(FIP))
  912. #define IA_SET_CFLAG(CLFAG, CR0) (ULONGLONG)(((ULONGLONG)(CLFAG) & 0x000001ffe005003fULL) | CR0)
  913. //
  914. // Fields related to iA mode Debug Register 7 - Dr7.
  915. //
  916. #define DR7_RW_IX 0x00000000UL
  917. #define DR7_RW_DW 0x00000001UL
  918. #define DR7_RW_IORW 0x00000002UL
  919. #define DR7_RW_DWR 0x00000003UL
  920. #define DR7_RW_DISABLE 0xFFFFFFFFUL
  921. #define DR7_L0(DR7) ((ULONG)(DR7) & 0x00000001UL)
  922. #define DR7_L1(DR7) ((ULONG)(DR7) & 0x00000004UL)
  923. #define DR7_L2(DR7) ((ULONG)(DR7) & 0x00000010UL)
  924. #define DR7_L3(DR7) ((ULONG)(DR7) & 0x00000040UL)
  925. #define SET_DR7_L0(DR7) ((ULONG)(DR7) &= 0x00000001UL)
  926. #define SET_DR7_L1(DR7) ((ULONG)(DR7) &= 0x00000004UL)
  927. #define SET_DR7_L2(DR7) ((ULONG)(DR7) &= 0x00000010UL)
  928. #define SET_DR7_L3(DR7) ((ULONG)(DR7) &= 0x00000040UL)
  929. #define DR7_DB0_RW(DR7) (DR7_L0(DR7) ? (((ULONG)(DR7) >> 16) & 0x00000003UL) : DR7_RW_DISABLE)
  930. #define DR7_DB0_LEN(DR7) (DR7_L0(DR7) ? (((ULONG)(DR7) >> 18) & 0x00000003UL) : DR7_RW_DISABLE)
  931. #define DR7_DB1_RW(DR7) (DR7_L1(DR7) ? (((ULONG)(DR7) >> 20) & 0x00000003UL) : DR7_RW_DISABLE)
  932. #define DR7_DB1_LEN(DR7) (DR7_L1(DR7) ? (((ULONG)(DR7) >> 22) & 0x00000003UL) : DR7_RW_DISABLE)
  933. #define DR7_DB2_RW(DR7) (DR7_L2(DR7) ? (((ULONG)(DR7) >> 24) & 0x00000003UL) : DR7_RW_DISABLE)
  934. #define DR7_DB2_LEN(DR7) (DR7_L2(DR7) ? (((ULONG)(DR7) >> 26) & 0x00000003UL) : DR7_RW_DISABLE)
  935. #define DR7_DB3_RW(DR7) (DR7_L3(DR7) ? (((ULONG)(DR7) >> 28) & 0x00000003UL) : DR7_RW_DISABLE)
  936. #define DR7_DB3_LEN(DR7) (DR7_L3(DR7) ? (((ULONG)(DR7) >> 30) & 0x00000003UL) : DR7_RW_DISABLE)
  937. #define SET_DR7_DB0_RW(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 16))
  938. #define SET_DR7_DB0_LEN(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 18))
  939. #define SET_DR7_DB1_RW(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 20))
  940. #define SET_DR7_DB1_LEN(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 22))
  941. #define SET_DR7_DB2_RW(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 24))
  942. #define SET_DR7_DB2_LEN(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 26))
  943. #define SET_DR7_DB3_RW(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 28))
  944. #define SET_DR7_DB3_LEN(DR7,VAL) ((ULONG)(DR7) |= ((VAL & 0x00000003UL) << 30))
  945. #define DR_ADDR_L0(DR) (DR7_L0(DR) ? ((ULONG)(DR)) : 0UL)
  946. #define DR_ADDR_L1(DR) (DR7_L1(DR) ? ((ULONG)(DR)) : 0UL)
  947. #define DR_ADDR_L2(DR) (DR7_L2(DR) ? ((ULONG)(DR)) : 0UL)
  948. #define DR_ADDR_L3(DR) (DR7_L3(DR) ? ((ULONG)(DR)) : 0UL)
  949. // end_nthal
  950. //
  951. // Define IA64 exception handling structures and function prototypes.
  952. // **** TBD ****
  953. //
  954. // Unwind information structure definition.
  955. //
  956. // N.B. If the EHANDLER flag is set, personality routine should be calle
  957. // during search for an exception handler. If the UHANDLER flag is
  958. // set, the personality routine should be called during the second
  959. // unwind.
  960. //
  961. #define UNW_FLAG_EHANDLER(x) ((x) & 0x1)
  962. #define UNW_FLAG_UHANDLER(x) ((x) & 0x2)
  963. // Version 2 = soft2.3 conventions
  964. // Version 3 = soft2.6 conventions
  965. #define GetLanguageSpecificData(f, base) \
  966. ((((PUNWIND_INFO)(base + f->UnwindInfoAddress))->Version <= 2) ? \
  967. (((PVOID)(base + f->UnwindInfoAddress + sizeof(UNWIND_INFO) + \
  968. ((PUNWIND_INFO)(base+f->UnwindInfoAddress))->DataLength*sizeof(ULONGLONG) + sizeof(ULONGLONG)))) : \
  969. (((PVOID)(base + f->UnwindInfoAddress + sizeof(UNWIND_INFO) + \
  970. ((PUNWIND_INFO)(base+f->UnwindInfoAddress))->DataLength*sizeof(ULONGLONG) + sizeof(ULONG)))))
  971. typedef struct _UNWIND_INFO {
  972. USHORT Version; // Version Number
  973. USHORT Flags; // Flags
  974. ULONG DataLength; // Length of Descriptor Data
  975. } UNWIND_INFO, *PUNWIND_INFO;
  976. // begin_winnt
  977. //
  978. // Function table entry structure definition.
  979. //
  980. typedef struct _RUNTIME_FUNCTION {
  981. ULONG BeginAddress;
  982. ULONG EndAddress;
  983. ULONG UnwindInfoAddress;
  984. } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
  985. // end_winnt
  986. //
  987. // Scope table structure definition
  988. //
  989. // One table entry is created by the C compiler for each try-except or
  990. // try-finally scope. Nested scopes are ordered from inner to outer scope.
  991. // Current scope is passively maintained by PC-mapping (function tables).
  992. //
  993. typedef struct _SCOPE_TABLE {
  994. ULONG Count;
  995. struct
  996. {
  997. ULONG BeginAddress;
  998. ULONG EndAddress;
  999. ULONG HandlerAddress; // filter/termination handler
  1000. ULONG JumpTarget; // continuation address
  1001. // e.g. exception handler
  1002. } ScopeRecord[1];
  1003. } SCOPE_TABLE, *PSCOPE_TABLE;
  1004. //
  1005. // Bit position in IP for low order bit of slot number
  1006. //
  1007. #define IA64_IP_SLOT 2
  1008. /*++
  1009. ULONGLONG
  1010. RtlIa64InsertIPSlotNumber(
  1011. IN ULONGLONG IP,
  1012. IN ULONG SlotNumber
  1013. )
  1014. Routine Description:
  1015. This macro inserts the slot number into
  1016. the low order bits of the IP.
  1017. Arguments:
  1018. IP - the IP
  1019. SlotNumber - the slot number
  1020. Return Value:
  1021. IP combined with slot number
  1022. --*/
  1023. #define RtlIa64InsertIPSlotNumber(IP, SlotNumber) \
  1024. ((IP) | (SlotNumber << IA64_IP_SLOT))
  1025. /*++
  1026. VOID
  1027. RtlIa64IncrementIP(
  1028. IN ULONG CurrentSlot,
  1029. IN OUT ULONGLONG Psr,
  1030. IN OUT ULONGLONG Ip
  1031. )
  1032. Routine Description:
  1033. This macro increments the IP given the current IP and slot within the
  1034. IP. The function puts the new slot number in the PSR and increments the
  1035. IP if necessary.
  1036. Arguments:
  1037. CurrentSlot - Current slot number in low order 2 bits
  1038. Psr - PSR that will contain the new slot number
  1039. Ip - IP that will contain the new IP, if updated
  1040. Return Value:
  1041. None
  1042. Note: This routine will silently do nothing if the slot number is invalid
  1043. --*/
  1044. #define RtlIa64IncrementIP(CurrentSlot, Psr, Ip) \
  1045. \
  1046. switch ((CurrentSlot) & 0x3) { \
  1047. \
  1048. /* Advance psr.ri based on current slot number */ \
  1049. \
  1050. case 0: \
  1051. Psr = ((Psr) & ~(3ULL << PSR_RI)) | (1ULL << PSR_RI); \
  1052. break; \
  1053. \
  1054. case 1: \
  1055. Psr = ((Psr) & ~(3ULL << PSR_RI)) | (2ULL << PSR_RI); \
  1056. break; \
  1057. \
  1058. case 2: \
  1059. Psr = ((Psr) & ~(3ULL << PSR_RI)); \
  1060. Ip = (Ip) + 16; /* Wrap slot number -- need to incr IP */ \
  1061. break; \
  1062. \
  1063. default: \
  1064. break; \
  1065. }
  1066. // begin_winnt
  1067. //
  1068. // Define dynamic function table entry.
  1069. //
  1070. typedef
  1071. PRUNTIME_FUNCTION
  1072. (*PGET_RUNTIME_FUNCTION_CALLBACK) (
  1073. IN ULONG64 ControlPc,
  1074. IN PVOID Context
  1075. );
  1076. // end_winnt
  1077. typedef enum _FUNCTION_TABLE_TYPE {
  1078. RF_SORTED,
  1079. RF_UNSORTED,
  1080. RF_CALLBACK
  1081. } FUNCTION_TABLE_TYPE;
  1082. typedef struct _DYNAMIC_FUNCTION_TABLE {
  1083. LIST_ENTRY Links;
  1084. PRUNTIME_FUNCTION FunctionTable;
  1085. LARGE_INTEGER TimeStamp;
  1086. ULONG64 MinimumAddress;
  1087. ULONG64 MaximumAddress;
  1088. ULONG64 BaseAddress;
  1089. ULONG64 TargetGp;
  1090. PGET_RUNTIME_FUNCTION_CALLBACK Callback;
  1091. PVOID Context;
  1092. PWSTR OutOfProcessCallbackDll;
  1093. FUNCTION_TABLE_TYPE Type;
  1094. ULONG EntryCount;
  1095. } DYNAMIC_FUNCTION_TABLE, *PDYNAMIC_FUNCTION_TABLE;
  1096. // begin_winnt
  1097. typedef
  1098. NTSTATUS
  1099. (*POUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK) (
  1100. IN HANDLE Process,
  1101. IN PVOID TableAddress,
  1102. OUT PULONG Entries,
  1103. OUT PRUNTIME_FUNCTION* Functions
  1104. );
  1105. #define OUT_OF_PROCESS_FUNCTION_TABLE_CALLBACK_EXPORT_NAME \
  1106. "OutOfProcessFunctionTableCallback"
  1107. // end_winnt
  1108. #define RF_BEGIN_ADDRESS(Base,RF) (( (SIZE_T) Base + (RF)->BeginAddress) & (0xFFFFFFFFFFFFFFF0)) // Instruction Size 16 bytes
  1109. #define RF_END_ADDRESS(Base, RF) (((SIZE_T) Base + (RF)->EndAddress+15) & (0xFFFFFFFFFFFFFFF0)) // Instruction Size 16 bytes
  1110. //
  1111. // Define unwind history table structure.
  1112. //
  1113. #define UNWIND_HISTORY_TABLE_SIZE 12
  1114. typedef struct _UNWIND_HISTORY_TABLE_ENTRY {
  1115. ULONG64 ImageBase;
  1116. ULONG64 Gp;
  1117. PRUNTIME_FUNCTION FunctionEntry;
  1118. } UNWIND_HISTORY_TABLE_ENTRY, *PUNWIND_HISTORY_TABLE_ENTRY;
  1119. #define UNWIND_HISTORY_TABLE_NONE 0
  1120. #define UNWIND_HISTORY_TABLE_GLOBAL 1
  1121. #define UNWIND_HISTORY_TABLE_LOCAL 2
  1122. typedef struct _UNWIND_HISTORY_TABLE {
  1123. ULONG Count;
  1124. UCHAR Search;
  1125. ULONG64 LowAddress;
  1126. ULONG64 HighAddress;
  1127. UNWIND_HISTORY_TABLE_ENTRY Entry[UNWIND_HISTORY_TABLE_SIZE];
  1128. } UNWIND_HISTORY_TABLE, *PUNWIND_HISTORY_TABLE;
  1129. typedef struct _FRAME_POINTERS {
  1130. ULONGLONG MemoryStackFp;
  1131. ULONGLONG BackingStoreFp;
  1132. } FRAME_POINTERS, *PFRAME_POINTERS;
  1133. typedef struct _DISPATCHER_CONTEXT {
  1134. FRAME_POINTERS EstablisherFrame;
  1135. ULONGLONG ControlPc;
  1136. ULONGLONG ImageBase;
  1137. PRUNTIME_FUNCTION FunctionEntry;
  1138. PCONTEXT ContextRecord;
  1139. PUNWIND_HISTORY_TABLE HistoryTable;
  1140. ULONG64 TargetGp;
  1141. ULONG Index;
  1142. } DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
  1143. //
  1144. // Define C structured exception handing function prototypes.
  1145. //
  1146. VOID
  1147. RtlInitializeHistoryTable (
  1148. VOID
  1149. );
  1150. PRUNTIME_FUNCTION
  1151. RtlLookupFunctionEntry (
  1152. IN ULONGLONG ControlPc,
  1153. OUT PULONGLONG ImageBase,
  1154. OUT PULONGLONG TargetGp
  1155. );
  1156. PRUNTIME_FUNCTION
  1157. RtlLookupFunctionTable (
  1158. IN PVOID ControlPc,
  1159. OUT PVOID *ImageBase,
  1160. OUT PULONG64 Gp,
  1161. OUT PULONG SizeOfTable
  1162. );
  1163. PLIST_ENTRY
  1164. RtlGetFunctionTableListHead (
  1165. VOID
  1166. );
  1167. // begin_winnt
  1168. BOOLEAN
  1169. RtlAddFunctionTable(
  1170. IN PRUNTIME_FUNCTION FunctionTable,
  1171. IN ULONG EntryCount,
  1172. IN ULONGLONG BaseAddress,
  1173. IN ULONGLONG TargetGp
  1174. );
  1175. BOOLEAN
  1176. RtlInstallFunctionTableCallback (
  1177. IN ULONG64 TableIdentifier,
  1178. IN ULONG64 BaseAddress,
  1179. IN ULONG Length,
  1180. IN ULONG64 TargetGp,
  1181. IN PGET_RUNTIME_FUNCTION_CALLBACK Callback,
  1182. IN PVOID Context,
  1183. IN PCWSTR OutOfProcessCallbackDll OPTIONAL
  1184. );
  1185. BOOLEAN
  1186. RtlDeleteFunctionTable (
  1187. IN PRUNTIME_FUNCTION FunctionTable
  1188. );
  1189. VOID
  1190. RtlRestoreContext (
  1191. IN PCONTEXT ContextRecord,
  1192. IN struct _EXCEPTION_RECORD *ExceptionRecord OPTIONAL
  1193. );
  1194. // end_winnt
  1195. ULONGLONG
  1196. RtlVirtualUnwind (
  1197. IN ULONGLONG ImageBase,
  1198. IN ULONGLONG ControlPc,
  1199. IN PRUNTIME_FUNCTION FunctionEntry,
  1200. IN OUT PCONTEXT ContextRecord,
  1201. OUT PBOOLEAN InFunction,
  1202. OUT PFRAME_POINTERS EstablisherFrame,
  1203. IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers OPTIONAL
  1204. );
  1205. struct _EXCEPTION_POINTERS;
  1206. typedef
  1207. LONG
  1208. (*EXCEPTION_FILTER) (
  1209. ULONGLONG MemoryStackFp,
  1210. ULONGLONG BackingStoreFp,
  1211. ULONG ExceptionCode,
  1212. struct _EXCEPTION_POINTERS *ExceptionPointers
  1213. );
  1214. typedef
  1215. VOID
  1216. (*TERMINATION_HANDLER) (
  1217. ULONGLONG MemoryStackFp,
  1218. ULONGLONG BackingStoreFp,
  1219. BOOLEAN is_abnormal
  1220. );
  1221. #ifdef _IA64_
  1222. // begin_winnt
  1223. VOID
  1224. __jump_unwind (
  1225. ULONGLONG TargetMsFrame,
  1226. ULONGLONG TargetBsFrame,
  1227. ULONGLONG TargetPc
  1228. );
  1229. #endif // _IA64_
  1230. // end_winnt
  1231. // begin_ntddk begin_wdm begin_nthal
  1232. #endif // _IA64_
  1233. // end_ntddk end_wdm end_nthal
  1234. #ifdef __cplusplus
  1235. }
  1236. #endif
  1237. #endif // _NTIA64H_