Source code of Windows XP (NT5)
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.

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