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.

4091 lines
102 KiB

  1. /*++
  2. Module Name:
  3. ia64.h
  4. Abstract:
  5. This module contains the IA64 hardware specific header file.
  6. Author:
  7. David N. Cutler (davec) 31-Mar-1990
  8. Revision History:
  9. Bernard Lint 6-Jun-1995: IA64 version based on MIPS version.
  10. --*/
  11. #ifndef _IA64H_
  12. #define _IA64H_
  13. #if !(defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_)) && !defined(_BLDR_)
  14. #define ExRaiseException RtlRaiseException
  15. #define ExRaiseStatus RtlRaiseStatus
  16. #endif
  17. //
  18. // Interruption history
  19. //
  20. // N.B. Currently the history records are saved in the 2nd half of the 8K
  21. // PCR page. Therefore, we can only keep track of up to the latest
  22. // 128 interruption records, each of 32 bytes in size. Also, the PCR
  23. // structure cannot be greater than 4K. In the future, the interruption
  24. // history records may become part of the KPCR structure.
  25. //
  26. typedef struct _IHISTORY_RECORD {
  27. ULONGLONG InterruptionType;
  28. ULONGLONG IIP;
  29. ULONGLONG IPSR;
  30. ULONGLONG Extra0;
  31. } IHISTORY_RECORD;
  32. #define MAX_NUMBER_OF_IHISTORY_RECORDS 128
  33. //
  34. // For PSR bit field definitions
  35. //
  36. #include "kxia64.h"
  37. // begin_ntddk begin_wdm begin_nthal begin_ntndis begin_ntosp
  38. #if defined(_IA64_)
  39. //
  40. // Types to use to contain PFNs and their counts.
  41. //
  42. typedef ULONG PFN_COUNT;
  43. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  44. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  45. //
  46. // Indicate that the IA64 compiler supports the pragma textout construct.
  47. //
  48. #define ALLOC_PRAGMA 1
  49. //
  50. // Define intrinsic calls and their prototypes
  51. //
  52. #include "ia64reg.h"
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. unsigned __int64 __getReg (int);
  57. void __setReg (int, unsigned __int64);
  58. void __isrlz (void);
  59. void __dsrlz (void);
  60. void __fwb (void);
  61. void __mf (void);
  62. void __mfa (void);
  63. void __synci (void);
  64. __int64 __thash (__int64);
  65. __int64 __ttag (__int64);
  66. void __ptcl (__int64, __int64);
  67. void __ptcg (__int64, __int64);
  68. void __ptcga (__int64, __int64);
  69. void __ptri (__int64, __int64);
  70. void __ptrd (__int64, __int64);
  71. void __invalat (void);
  72. void __break (int);
  73. void __fc (__int64);
  74. void __fci (__int64);
  75. void __sum (int);
  76. void __rsm (int);
  77. void _ReleaseSpinLock( unsigned __int64 *);
  78. void __yield();
  79. void __lfetch(int, void const *);
  80. void __lfetchfault(int, void const *);
  81. #ifdef _M_IA64
  82. #pragma intrinsic (__getReg)
  83. #pragma intrinsic (__setReg)
  84. #pragma intrinsic (__isrlz)
  85. #pragma intrinsic (__dsrlz)
  86. #pragma intrinsic (__fwb)
  87. #pragma intrinsic (__mf)
  88. #pragma intrinsic (__mfa)
  89. #pragma intrinsic (__synci)
  90. #pragma intrinsic (__thash)
  91. #pragma intrinsic (__ttag)
  92. #pragma intrinsic (__ptcl)
  93. #pragma intrinsic (__ptcg)
  94. #pragma intrinsic (__ptcga)
  95. #pragma intrinsic (__ptri)
  96. #pragma intrinsic (__ptrd)
  97. #pragma intrinsic (__invalat)
  98. #pragma intrinsic (__break)
  99. #pragma intrinsic (__fc)
  100. #pragma intrinsic (__fci)
  101. #pragma intrinsic (__sum)
  102. #pragma intrinsic (__rsm)
  103. #pragma intrinsic (_ReleaseSpinLock)
  104. #pragma intrinsic (__yield)
  105. #pragma intrinsic (__lfetch)
  106. #pragma intrinsic (__lfetchfault)
  107. #endif // _M_IA64
  108. #ifdef __cplusplus
  109. }
  110. #endif
  111. // end_ntndis
  112. //
  113. // Define length of interrupt vector table.
  114. //
  115. #define MAXIMUM_VECTOR 256
  116. // end_wdm
  117. //
  118. // IA64 specific interlocked operation result values.
  119. //
  120. #define RESULT_ZERO 0
  121. #define RESULT_NEGATIVE 1
  122. #define RESULT_POSITIVE 2
  123. //
  124. // Interlocked result type is portable, but its values are machine specific.
  125. // Constants for values are in i386.h, mips.h, etc.
  126. //
  127. typedef enum _INTERLOCKED_RESULT {
  128. ResultNegative = RESULT_NEGATIVE,
  129. ResultZero = RESULT_ZERO,
  130. ResultPositive = RESULT_POSITIVE
  131. } INTERLOCKED_RESULT;
  132. //
  133. // Convert portable interlock interfaces to architecture specific interfaces.
  134. //
  135. #if PRAGMA_DEPRECATED_DDK
  136. #pragma deprecated(ExInterlockedIncrementLong) // Use InterlockedIncrement
  137. #pragma deprecated(ExInterlockedDecrementLong) // Use InterlockedDecrement
  138. #pragma deprecated(ExInterlockedExchangeUlong) // Use InterlockedExchange
  139. #endif
  140. #define ExInterlockedIncrementLong(Addend, Lock) \
  141. ExIa64InterlockedIncrementLong(Addend)
  142. #define ExInterlockedDecrementLong(Addend, Lock) \
  143. ExIa64InterlockedDecrementLong(Addend)
  144. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  145. ExIa64InterlockedExchangeUlong(Target, Value)
  146. NTKERNELAPI
  147. INTERLOCKED_RESULT
  148. ExIa64InterlockedIncrementLong (
  149. IN PLONG Addend
  150. );
  151. NTKERNELAPI
  152. INTERLOCKED_RESULT
  153. ExIa64InterlockedDecrementLong (
  154. IN PLONG Addend
  155. );
  156. NTKERNELAPI
  157. ULONG
  158. ExIa64InterlockedExchangeUlong (
  159. IN PULONG Target,
  160. IN ULONG Value
  161. );
  162. // begin_wdm
  163. //
  164. // IA64 Interrupt Definitions.
  165. //
  166. //
  167. // Define length of interrupt object dispatch code in longwords.
  168. //
  169. #define DISPATCH_LENGTH 2*2 // Length of dispatch code template in 32-bit words
  170. // Begin of a block of definitions that must be synchronized with kxia64.h.
  171. //
  172. //
  173. // Define Interrupt Request Levels.
  174. //
  175. #define PASSIVE_LEVEL 0 // Passive release level
  176. #define LOW_LEVEL 0 // Lowest interrupt level
  177. #define APC_LEVEL 1 // APC interrupt level
  178. #define DISPATCH_LEVEL 2 // Dispatcher level
  179. #define CMC_LEVEL 3 // Correctable machine check level
  180. #define DEVICE_LEVEL_BASE 4 // 4 - 11 - Device IRQLs
  181. #define PC_LEVEL 12 // Performance Counter IRQL
  182. #define IPI_LEVEL 14 // IPI IRQL
  183. #define CLOCK_LEVEL 13 // Clock Timer IRQL
  184. #define POWER_LEVEL 15 // Power failure level
  185. #define PROFILE_LEVEL 15 // Profiling level
  186. #define HIGH_LEVEL 15 // Highest interrupt level
  187. // end_ntddk end_wdm end_ntosp
  188. #if defined(NT_UP)
  189. #define SYNCH_LEVEL DISPATCH_LEVEL // Synchronization level - UP
  190. #else
  191. #define SYNCH_LEVEL (IPI_LEVEL-2) // Synchronization level - MP
  192. #endif
  193. //
  194. // Define profile intervals.
  195. //
  196. #define DEFAULT_PROFILE_COUNT 0x40000000 // ~= 20 seconds @50mhz
  197. #define DEFAULT_PROFILE_INTERVAL (10 * 1000 * 10) // 10 milliseconds
  198. #define MAXIMUM_PROFILE_INTERVAL (10 * 1000 * 1000) // 1 second
  199. #define MINIMUM_PROFILE_INTERVAL (10 * 500) // 500 microseconds
  200. // end_nthal
  201. //
  202. // The current IRQL is maintained in the TPR.mic field. The
  203. // shift count is the number of bits to shift right to extract the
  204. // IRQL from the TPR. See the GET/SET_IRQL macros.
  205. //
  206. #define TPR_MIC 4
  207. #define TPR_IRQL_SHIFT TPR_MIC
  208. // To go from vector number <-> IRQL we just do a shift
  209. #define VECTOR_IRQL_SHIFT TPR_IRQL_SHIFT
  210. //
  211. // Interrupt Vector Definitions
  212. //
  213. #define APC_VECTOR APC_LEVEL << VECTOR_IRQL_SHIFT
  214. #define DISPATCH_VECTOR DISPATCH_LEVEL << VECTOR_IRQL_SHIFT
  215. //
  216. // End of a block of definitions that must be synchronized with kxia64.h.
  217. //
  218. //
  219. // Define maximum size of flush multiple TB request.
  220. //
  221. #define FLUSH_MULTIPLE_MAXIMUM 100
  222. // begin_ntddk begin_wdm begin_nthal begin_ntosp
  223. #if defined(_M_IA64) && !defined(RC_INVOKED)
  224. #define InterlockedAdd _InterlockedAdd
  225. #define InterlockedIncrement _InterlockedIncrement
  226. #define InterlockedIncrementAcquire _InterlockedIncrement_acq
  227. #define InterlockedIncrementRelease _InterlockedIncrement_rel
  228. #define InterlockedDecrement _InterlockedDecrement
  229. #define InterlockedDecrementAcquire _InterlockedDecrement_acq
  230. #define InterlockedDecrementRelease _InterlockedDecrement_rel
  231. #define InterlockedExchange _InterlockedExchange
  232. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  233. #define InterlockedAdd64 _InterlockedAdd64
  234. #define InterlockedIncrement64 _InterlockedIncrement64
  235. #define InterlockedDecrement64 _InterlockedDecrement64
  236. #define InterlockedExchange64 _InterlockedExchange64
  237. #define InterlockedExchangeAcquire64 _InterlockedExchange64_acq
  238. #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
  239. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  240. #define InterlockedCompareExchangeAcquire64 _InterlockedCompareExchange64_acq
  241. #define InterlockedCompareExchangeRelease64 _InterlockedCompareExchange64_rel
  242. #define InterlockedCompareExchange _InterlockedCompareExchange
  243. #define InterlockedCompareExchangeAcquire _InterlockedCompareExchange_acq
  244. #define InterlockedCompareExchangeRelease _InterlockedCompareExchange_rel
  245. #define InterlockedExchangePointer _InterlockedExchangePointer
  246. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  247. #ifdef __cplusplus
  248. extern "C" {
  249. #endif
  250. LONG
  251. __cdecl
  252. InterlockedAdd (
  253. LONG volatile *Addend,
  254. LONG Value
  255. );
  256. LONGLONG
  257. __cdecl
  258. InterlockedAdd64 (
  259. LONGLONG volatile *Addend,
  260. LONGLONG Value
  261. );
  262. LONG
  263. __cdecl
  264. InterlockedIncrement(
  265. IN OUT LONG volatile *Addend
  266. );
  267. LONG
  268. __cdecl
  269. InterlockedDecrement(
  270. IN OUT LONG volatile *Addend
  271. );
  272. LONG
  273. __cdecl
  274. InterlockedIncrementAcquire(
  275. IN OUT LONG volatile *Addend
  276. );
  277. LONG
  278. __cdecl
  279. InterlockedDecrementAcquire(
  280. IN OUT LONG volatile *Addend
  281. );
  282. LONG
  283. __cdecl
  284. InterlockedIncrementRelease(
  285. IN OUT LONG volatile *Addend
  286. );
  287. LONG
  288. __cdecl
  289. InterlockedDecrementRelease(
  290. IN OUT LONG volatile *Addend
  291. );
  292. LONG
  293. __cdecl
  294. InterlockedExchange(
  295. IN OUT LONG volatile *Target,
  296. IN LONG Value
  297. );
  298. LONG
  299. __cdecl
  300. InterlockedExchangeAdd(
  301. IN OUT LONG volatile *Addend,
  302. IN LONG Value
  303. );
  304. LONG
  305. __cdecl
  306. InterlockedCompareExchange (
  307. IN OUT LONG volatile *Destination,
  308. IN LONG ExChange,
  309. IN LONG Comperand
  310. );
  311. LONG
  312. __cdecl
  313. InterlockedCompareExchangeRelease (
  314. IN OUT LONG volatile *Destination,
  315. IN LONG ExChange,
  316. IN LONG Comperand
  317. );
  318. LONG
  319. __cdecl
  320. InterlockedCompareExchangeAcquire (
  321. IN OUT LONG volatile *Destination,
  322. IN LONG ExChange,
  323. IN LONG Comperand
  324. );
  325. LONGLONG
  326. __cdecl
  327. InterlockedIncrement64(
  328. IN OUT LONGLONG volatile *Addend
  329. );
  330. LONGLONG
  331. __cdecl
  332. InterlockedDecrement64(
  333. IN OUT LONGLONG volatile *Addend
  334. );
  335. LONGLONG
  336. __cdecl
  337. InterlockedExchange64(
  338. IN OUT LONGLONG volatile *Target,
  339. IN LONGLONG Value
  340. );
  341. LONGLONG
  342. __cdecl
  343. InterlockedExchangeAcquire64(
  344. IN OUT LONGLONG volatile *Target,
  345. IN LONGLONG Value
  346. );
  347. LONGLONG
  348. __cdecl
  349. InterlockedExchangeAdd64(
  350. IN OUT LONGLONG volatile *Addend,
  351. IN LONGLONG Value
  352. );
  353. LONGLONG
  354. __cdecl
  355. InterlockedCompareExchange64 (
  356. IN OUT LONGLONG volatile *Destination,
  357. IN LONGLONG ExChange,
  358. IN LONGLONG Comperand
  359. );
  360. LONGLONG
  361. __cdecl
  362. InterlockedCompareExchangeAcquire64 (
  363. IN OUT LONGLONG volatile *Destination,
  364. IN LONGLONG ExChange,
  365. IN LONGLONG Comperand
  366. );
  367. LONGLONG
  368. __cdecl
  369. InterlockedCompareExchangeRelease64 (
  370. IN OUT LONGLONG volatile *Destination,
  371. IN LONGLONG ExChange,
  372. IN LONGLONG Comperand
  373. );
  374. PVOID
  375. __cdecl
  376. InterlockedCompareExchangePointer (
  377. IN OUT PVOID volatile *Destination,
  378. IN PVOID Exchange,
  379. IN PVOID Comperand
  380. );
  381. PVOID
  382. __cdecl
  383. InterlockedExchangePointer(
  384. IN OUT PVOID volatile *Target,
  385. IN PVOID Value
  386. );
  387. #if !defined (InterlockedAnd64)
  388. #define InterlockedAnd64 InterlockedAnd64_Inline
  389. LONGLONG
  390. FORCEINLINE
  391. InterlockedAnd64_Inline (
  392. IN OUT LONGLONG volatile *Destination,
  393. IN LONGLONG Value
  394. )
  395. {
  396. LONGLONG Old;
  397. do {
  398. Old = *Destination;
  399. } while (InterlockedCompareExchange64(Destination,
  400. Old & Value,
  401. Old) != Old);
  402. return Old;
  403. }
  404. #endif
  405. #if !defined (InterlockedOr64)
  406. #define InterlockedOr64 InterlockedOr64_Inline
  407. LONGLONG
  408. FORCEINLINE
  409. InterlockedOr64_Inline (
  410. IN OUT LONGLONG volatile *Destination,
  411. IN LONGLONG Value
  412. )
  413. {
  414. LONGLONG Old;
  415. do {
  416. Old = *Destination;
  417. } while (InterlockedCompareExchange64(Destination,
  418. Old | Value,
  419. Old) != Old);
  420. return Old;
  421. }
  422. #endif
  423. #if !defined (InterlockedXor64)
  424. #define InterlockedXor64 InterlockedXor64_Inline
  425. LONGLONG
  426. FORCEINLINE
  427. InterlockedXor64_Inline (
  428. IN OUT LONGLONG volatile *Destination,
  429. IN LONGLONG Value
  430. )
  431. {
  432. LONGLONG Old;
  433. do {
  434. Old = *Destination;
  435. } while (InterlockedCompareExchange64(Destination,
  436. Old ^ Value,
  437. Old) != Old);
  438. return Old;
  439. }
  440. #endif
  441. #pragma intrinsic(_InterlockedAdd)
  442. #pragma intrinsic(_InterlockedIncrement)
  443. #pragma intrinsic(_InterlockedIncrement_acq)
  444. #pragma intrinsic(_InterlockedIncrement_rel)
  445. #pragma intrinsic(_InterlockedDecrement)
  446. #pragma intrinsic(_InterlockedDecrement_acq)
  447. #pragma intrinsic(_InterlockedDecrement_rel)
  448. #pragma intrinsic(_InterlockedExchange)
  449. #pragma intrinsic(_InterlockedCompareExchange)
  450. #pragma intrinsic(_InterlockedCompareExchange_acq)
  451. #pragma intrinsic(_InterlockedCompareExchange_rel)
  452. #pragma intrinsic(_InterlockedExchangeAdd)
  453. #pragma intrinsic(_InterlockedAdd64)
  454. #pragma intrinsic(_InterlockedIncrement64)
  455. #pragma intrinsic(_InterlockedDecrement64)
  456. #pragma intrinsic(_InterlockedExchange64)
  457. #pragma intrinsic(_InterlockedExchange64_acq)
  458. #pragma intrinsic(_InterlockedCompareExchange64)
  459. #pragma intrinsic(_InterlockedCompareExchange64_acq)
  460. #pragma intrinsic(_InterlockedCompareExchange64_rel)
  461. #pragma intrinsic(_InterlockedExchangeAdd64)
  462. #pragma intrinsic(_InterlockedExchangePointer)
  463. #pragma intrinsic(_InterlockedCompareExchangePointer)
  464. #ifdef __cplusplus
  465. }
  466. #endif
  467. #endif // defined(_M_IA64) && !defined(RC_INVOKED)
  468. // end_wdm
  469. __forceinline
  470. LONG
  471. InterlockedAnd (
  472. IN OUT LONG volatile *Target,
  473. LONG Set
  474. )
  475. {
  476. LONG i;
  477. LONG j;
  478. j = *Target;
  479. do {
  480. i = j;
  481. j = InterlockedCompareExchange(Target,
  482. i & Set,
  483. i);
  484. } while (i != j);
  485. return j;
  486. }
  487. __forceinline
  488. LONG
  489. InterlockedOr (
  490. IN OUT LONG volatile *Target,
  491. IN LONG Set
  492. )
  493. {
  494. LONG i;
  495. LONG j;
  496. j = *Target;
  497. do {
  498. i = j;
  499. j = InterlockedCompareExchange(Target,
  500. i | Set,
  501. i);
  502. } while (i != j);
  503. return j;
  504. }
  505. __forceinline
  506. LONG
  507. InterlockedXor (
  508. IN OUT LONG volatile *Target,
  509. IN LONG Set
  510. )
  511. {
  512. LONG i;
  513. LONG j;
  514. j = *Target;
  515. do {
  516. i = j;
  517. j = InterlockedCompareExchange(Target,
  518. i ^ Set,
  519. i);
  520. } while (i != j);
  521. return j;
  522. }
  523. // end_ntddk end_nthal end_ntosp
  524. #define KiSynchIrql SYNCH_LEVEL // enable portable code
  525. #define KiProfileIrql PROFILE_LEVEL // enable portable code
  526. //
  527. // Sanitize FPSR based on processor mode.
  528. //
  529. // If kernel mode, then
  530. // let caller specify all bits, except reserved
  531. //
  532. // If user mode, then
  533. // let the caller specify all bits, except reserved
  534. //
  535. __forceinline
  536. ULONG64
  537. SANITIZE_FSR(ULONG64 fsr, MODE mode)
  538. {
  539. UNREFERENCED_PARAMETER(mode);
  540. fsr &= ~(MASK_IA64(FPSR_MBZ0,FPSR_MBZ0_V)| MASK_IA64(FPSR_TD0, 1));
  541. if (((fsr >> FPSR_PC0) & 3i64) == 1) {
  542. fsr = fsr | (3i64 << FPSR_PC0);
  543. }
  544. if (((fsr >> FPSR_PC1) & 3i64) == 1) {
  545. fsr = fsr | (3i64 << FPSR_PC1);
  546. }
  547. if (((fsr >> FPSR_PC2) & 3i64) == 1) {
  548. fsr = fsr | (3i64 << FPSR_PC2);
  549. }
  550. if (((fsr >> FPSR_PC3) & 3i64) == 1) {
  551. fsr = fsr | (3i64 << FPSR_PC3);
  552. }
  553. return fsr;
  554. }
  555. //
  556. // Define SANITIZE_PSR for IA64
  557. //
  558. // If kernel mode, then
  559. // force clearing of BE, SP, CPL, MC, PK, DFL, reserved (MBZ)
  560. // force the setting of IC, DT, DFH, DI, LP, RT, IT
  561. // let caller specify UP, AC, I, BN, PP, SI, DB, TB, IS, ID, DA, DD, SS, RI, ED
  562. //
  563. // If user mode, then
  564. // force clearing of MC, PK, LP, DFH, reserved
  565. // force the setting of BN, IC, I, DT, RT, CPL, IT
  566. // let caller specify BE, UP, PP, AC, DFL, SP, SI, DI, DB, TB, IS, ID, DA, DD, SS, RI, ED
  567. //
  568. #define PSR_KERNEL_CLR (MASK_IA64(PSR_MBZ4,1i64) | MASK_IA64(PSR_BE,1i64) | MASK_IA64(PSR_MBZ0,PSR_MBZ0_V) | \
  569. MASK_IA64(PSR_PK,1i64) | MASK_IA64(PSR_MBZ1,PSR_MBZ1_V) | MASK_IA64(PSR_DFL, 1i64) | \
  570. MASK_IA64(PSR_SP,1i64) | MASK_IA64(PSR_MBZ2,PSR_MBZ2_V) | MASK_IA64(PSR_CPL,0x3i64) | \
  571. MASK_IA64(PSR_MC,1i64) | MASK_IA64(PSR_MBZ3,PSR_MBZ3_V))
  572. #define PSR_KERNEL_SET (MASK_IA64(PSR_IC,1i64) | MASK_IA64(PSR_DT,1i64) | \
  573. MASK_IA64(PSR_DI,1i64) | MASK_IA64(PSR_RT,1i64) | \
  574. MASK_IA64(PSR_IT,1i64))
  575. #define PSR_KERNEL_CPY (MASK_IA64(PSR_UP,1i64) | MASK_IA64(PSR_AC,1i64) | MASK_IA64(PSR_MFL,1i64) | \
  576. MASK_IA64(PSR_MFH,1i64) | MASK_IA64(PSR_I,1i64) | MASK_IA64(PSR_DFH,1i64) | \
  577. MASK_IA64(PSR_PP,1i64) | MASK_IA64(PSR_SI,1i64) | MASK_IA64(PSR_DB,1i64) | \
  578. MASK_IA64(PSR_LP,1i64) | MASK_IA64(PSR_TB,1i64) | MASK_IA64(PSR_IS,1i64) | \
  579. MASK_IA64(PSR_DA,1i64) | MASK_IA64(PSR_DD,1i64) | MASK_IA64(PSR_SS,1i64) | \
  580. MASK_IA64(PSR_ID,1i64) | MASK_IA64(PSR_RI,0x3i64) | MASK_IA64(PSR_ED,1i64) | \
  581. MASK_IA64(PSR_BN,1i64) | MASK_IA64(PSR_IA,1i64))
  582. #define PSR_USER_CLR (MASK_IA64(PSR_MBZ4,1i64) | MASK_IA64(PSR_MBZ0,PSR_MBZ0_V) | MASK_IA64(PSR_PK,1i64) | \
  583. MASK_IA64(PSR_MBZ1,PSR_MBZ1_V) | MASK_IA64(PSR_DFL,1i64) | MASK_IA64(PSR_SP,1i64) | \
  584. MASK_IA64(PSR_SI,1i64) | MASK_IA64(PSR_MBZ2,PSR_MBZ2_V) | MASK_IA64(PSR_LP,1i64) | \
  585. MASK_IA64(PSR_MBZ3,PSR_MBZ3_V) | MASK_IA64(PSR_MC,1i64) | MASK_IA64(PSR_DA,1i64) | \
  586. MASK_IA64(PSR_IA,1i64))
  587. #define PSR_USER_SET (MASK_IA64(PSR_IC,1i64) | MASK_IA64(PSR_I,1i64) | \
  588. MASK_IA64(PSR_DT,1i64) | MASK_IA64(PSR_PP,1i64) | \
  589. MASK_IA64(PSR_RT,1i64) | MASK_IA64(PSR_CPL,0x3i64) | \
  590. MASK_IA64(PSR_IT,1i64) | MASK_IA64(PSR_BN,1i64))
  591. #define PSR_USER_CPY (MASK_IA64(PSR_BE,1i64) | MASK_IA64(PSR_UP,1i64) | \
  592. MASK_IA64(PSR_AC,1i64) | MASK_IA64(PSR_MFL,1i64) | MASK_IA64(PSR_MFH,1i64) | \
  593. MASK_IA64(PSR_DFH,1i64) | MASK_IA64(PSR_DI,1i64) | MASK_IA64(PSR_DB,1i64) | \
  594. MASK_IA64(PSR_TB,1i64) | MASK_IA64(PSR_IS,1i64) | MASK_IA64(PSR_ID,1i64) | \
  595. MASK_IA64(PSR_DD,1i64) | MASK_IA64(PSR_SS, 1i64) | \
  596. MASK_IA64(PSR_RI,0x3i64) | MASK_IA64(PSR_ED,1i64))
  597. #define PSR_DEBUG_SET (MASK_IA64(PSR_DB,1i64) | MASK_IA64(PSR_SS,1i64) | MASK_IA64(PSR_TB,1i64) | \
  598. MASK_IA64(PSR_ID,1i64) | MASK_IA64(PSR_DD,1i64))
  599. extern ULONGLONG UserPsrSetMask;
  600. __forceinline
  601. ULONG64
  602. SANITIZE_PSR(ULONG64 psr, MODE mode){
  603. psr = (mode) == KernelMode ?
  604. (PSR_KERNEL_SET | ((psr) & (PSR_KERNEL_CPY | ~PSR_KERNEL_CLR))) :
  605. (UserPsrSetMask | ((psr) & (PSR_USER_CPY | ~PSR_USER_CLR)));
  606. if (((psr >> PSR_RI) & 3) == 3) {
  607. //
  608. // 3 is an invalid slot number; sanitize it to zero
  609. //
  610. psr &= ~(3i64 << PSR_RI);
  611. }
  612. return(psr);
  613. }
  614. //
  615. // Define SANITIZE_IFS for IA64
  616. //
  617. __forceinline
  618. ULONG64
  619. SANITIZE_IFS(ULONG64 pfsarg, MODE mode){
  620. IA64_PFS pfs;
  621. ULONGLONG sof;
  622. UNREFERENCED_PARAMETER(mode);
  623. pfs.ull = pfsarg;
  624. //
  625. // There is no previous EC or previous privilege level in IFS
  626. //
  627. pfs.sb.pfs_pec = 0;
  628. pfs.sb.pfs_ppl = 0;
  629. pfs.sb.pfs_reserved1 = 0;
  630. pfs.sb.pfs_reserved2 = 0;
  631. //
  632. // Set the valid bit.
  633. //
  634. pfs.ull |= MASK_IA64(IFS_V,1i64);
  635. //
  636. // Verify the size of frame is not greater than allowed.
  637. //
  638. sof = pfs.sb.pfs_sof;
  639. if (sof > PFS_MAXIMUM_REGISTER_SIZE) {
  640. sof = PFS_MAXIMUM_REGISTER_SIZE;
  641. pfs.sb.pfs_sof = PFS_MAXIMUM_REGISTER_SIZE;
  642. }
  643. //
  644. // Verify the size of locals is not greater than size of frame.
  645. //
  646. if (sof < pfs.sb.pfs_sol) {
  647. pfs.sb.pfs_sol = sof;
  648. }
  649. //
  650. // Verify the size of locals is not greater than size of frame.
  651. //
  652. if (sof < (pfs.sb.pfs_sor * 8)) {
  653. pfs.sb.pfs_sor = sof / 8;
  654. }
  655. //
  656. // Verify rename bases are less than the size of the rotaing regions.
  657. //
  658. if (pfs.sb.pfs_rrb_gr >= (pfs.sb.pfs_sor * 8)) {
  659. pfs.sb.pfs_rrb_gr = 0;
  660. }
  661. if (pfs.sb.pfs_rrb_fr >= PFS_MAXIMUM_REGISTER_SIZE) {
  662. pfs.sb.pfs_rrb_fr = 0;
  663. }
  664. if (pfs.sb.pfs_rrb_pr >= PFS_MAXIMUM_PREDICATE_SIZE) {
  665. pfs.sb.pfs_rrb_pr = 0;
  666. }
  667. return(pfs.ull);
  668. }
  669. __forceinline
  670. ULONG64
  671. SANITIZE_PFS(ULONG64 pfsarg, MODE mode){
  672. IA64_PFS pfs;
  673. ULONGLONG sof;
  674. pfs.ull = pfsarg;
  675. if (mode != KernelMode) {
  676. pfs.sb.pfs_ppl = IA64_USER_PL;
  677. }
  678. pfs.sb.pfs_reserved1 = 0;
  679. pfs.sb.pfs_reserved2 = 0;
  680. //
  681. // Verify the size of frame is not greater than allowed.
  682. //
  683. sof = pfs.sb.pfs_sof;
  684. if (sof > PFS_MAXIMUM_REGISTER_SIZE) {
  685. sof = PFS_MAXIMUM_REGISTER_SIZE;
  686. pfs.sb.pfs_sof = PFS_MAXIMUM_REGISTER_SIZE;
  687. }
  688. //
  689. // Verify the size of locals is not greater than size of frame.
  690. //
  691. if (sof < pfs.sb.pfs_sol) {
  692. pfs.sb.pfs_sol = sof;
  693. }
  694. //
  695. // Verify the size of locals is not greater than size of frame.
  696. //
  697. if (sof < (pfs.sb.pfs_sor * 8)) {
  698. pfs.sb.pfs_sor = sof / 8;
  699. }
  700. //
  701. // Verify rename bases are less than the size of the rotaing regions.
  702. //
  703. if (pfs.sb.pfs_rrb_gr >= (pfs.sb.pfs_sor * 8)) {
  704. pfs.sb.pfs_rrb_gr = 0;
  705. }
  706. if (pfs.sb.pfs_rrb_fr >= PFS_MAXIMUM_REGISTER_SIZE) {
  707. pfs.sb.pfs_rrb_fr = 0;
  708. }
  709. if (pfs.sb.pfs_rrb_pr >= PFS_MAXIMUM_PREDICATE_SIZE) {
  710. pfs.sb.pfs_rrb_pr = 0;
  711. }
  712. return(pfs.ull);
  713. }
  714. //
  715. // Function used to zero the software field of RSC that contains the size of
  716. // RSE frame to be preloaded on kernel exit and sanitize the reserved fields.
  717. // This function does not the the PL used by the RSE.
  718. //
  719. __forceinline
  720. ULONG64
  721. ZERO_PRELOAD_SIZE(ULONG64 RseRsc){
  722. RSC rseRsc;
  723. rseRsc.ull = RseRsc;
  724. rseRsc.sb.rsc_be = 0;
  725. rseRsc.sb.rsc_preload = 0;
  726. rseRsc.sb.rsc_res0 = 0;
  727. rseRsc.sb.rsc_res1 = 0;
  728. return(rseRsc.ull);
  729. }
  730. //
  731. // Function used to sanitize the RSC.
  732. // This function does not modify the preload size.
  733. //
  734. __forceinline
  735. ULONG64
  736. SANITIZE_RSC(ULONG64 RseRsc, MODE mode){
  737. RSC rseRsc;
  738. rseRsc.ull = RseRsc;
  739. if (mode != KernelMode) {
  740. rseRsc.sb.rsc_pl = IA64_USER_PL;
  741. }
  742. rseRsc.sb.rsc_be = 0;
  743. rseRsc.sb.rsc_res0 = 0;
  744. rseRsc.sb.rsc_res1 = 0;
  745. return(rseRsc.ull);
  746. }
  747. extern ULONGLONG KiIA64DCR;
  748. #define SANITIZE_DCR(dcr, mode) \
  749. ((mode) == KernelMode ? dcr : KiIA64DCR)
  750. //
  751. // Macro to sanitize debug registers
  752. //
  753. #define SANITIZE_DR(dr, mode) \
  754. ((mode) == KernelMode ? \
  755. (dr) : \
  756. (dr & ~(0x7i64 << DR_PLM0)) /* disable pl 0-2 */ \
  757. )
  758. #define SANITIZE_AR21_FCR(FCR,mode) \
  759. (((FCR)&0x0000FFBF00001F3Fi64)|0x40i64)
  760. /*
  761. bits 0-7 correspond to standard flags (zero, parity, etc) with certain bits set or cleared. Ok for user to modify.
  762. bit 8 is the trap flag. I don't know if the ia32 debuggers use this or not, but no harm is done letting users set/clear this bit.
  763. bit 9 is the interrupt enable flag. This value is ignored based on values in the cflg register. This value is always set for compatibility with x86 apps.
  764. bits 10/11 are more standard flags, ok for the user to set/clear
  765. bits 12-15 are OS related flags, must be zero (iopl, nt)
  766. bit 16 is resume flag. Can be set/cleared by OS, should be passed back to user.
  767. bit 17 is vm flag. Not used by wow, should be cleared.
  768. bit 18 is ac flag. OK to be set by user.
  769. bit 19/20 are virtual interrupt flags. Not used by wow so should be cleared
  770. bit 21 is cpuid check, ok for user to set/clear
  771. */
  772. #define SANITIZE_AR24_EFLAGS(EFLAGS,mode) \
  773. (((EFLAGS)&0x0000000000250FD7i64)|0x0202i64)
  774. /*
  775. bit 0 is protected mode and should always be 1
  776. bits 1-3 are related to emulation of x87. Wow does not allow for emulation of x87 so must be zero.
  777. bit 4 is ignored and always returns 1.
  778. bit 5 is numeric exception and is ignored and treated as 1. No harm if set or cleared.
  779. bit 6 enables use of TSS permission map. wow expects this bit to be zero.
  780. bit 7 is IF enable. Wow does not allow modifying the eflags.if bit so should be zero
  781. bit 8 is IF intercept. Wow depends on this behavior so should be set.
  782. bit 9-15 is not used and must be 0
  783. bit 16 is write protect and is ignored. No harm if set or cleared.
  784. bit 17 is not used and must be 0
  785. bit 18 is alignment check. No harm if set/cleared.
  786. bits 19-28 are not used and must be 0
  787. bit 29 is disable write-through and are ignored. No harm if set or cleared.
  788. bit 30 is cache disable and is ignored. No harm if set or cleared.
  789. bit 31 is paging enabled and is ignored. No harm if set or cleared.
  790. bit 32 is VME bit. Wow depends on some behaviors of vme and should be set.
  791. bit 33 is PVI bit. Wow does not use virtual interrupts. Should be cleared
  792. bit 34 is rdtsc bit. No harm if set or cleared.
  793. bits 35-39 are ia32 OS extensions and are ignored. No harm if set or cleared.
  794. bit 40 is rdpmc. No harm if set or cleared.
  795. bit 41 is FXSR enable. No harm if set or cleared.
  796. bit 42 is simd exception extension. No harm if set or cleared.
  797. */
  798. #define SANITIZE_AR27_CFLG(CFLG,mode) \
  799. ((CFLG)&(0x000007FDE0050131i64) | 0x100000111i64)
  800. #define SANITIZE_AR28_FSR(FSR,mode) \
  801. ((FSR)&0x0000FFBF5555FFFFi64)
  802. #define SANITIZE_AR29_FIR(FIR,mode) \
  803. ((FIR)&0x07FFFFFFFFFFFFFFi64)
  804. #define SANITIZE_AR30_FDR(FDR,mode) \
  805. ((FDR)&0x0000FFFFFFFFFFFFi64)
  806. // begin_nthal
  807. //
  808. // Define interrupt request physical address (maps to HAL virtual address)
  809. //
  810. #define INTERRUPT_REQUEST_PHYSICAL_ADDRESS 0xFFE00000
  811. //
  812. // Define Address of Processor Control Registers.
  813. //
  814. //
  815. // Define Pointer to Processor Control Registers.
  816. //
  817. #define KIPCR ((ULONG_PTR)(KADDRESS_BASE + 0xFFFF0000)) // kernel address of first PCR
  818. #define PCR ((KPCR * const)KIPCR)
  819. //
  820. // Define address for epc system calls
  821. //
  822. #define MM_EPC_VA (KADDRESS_BASE + 0xFFA00000)
  823. //
  824. // Define Base Address of PAL Mapping
  825. //
  826. //
  827. #define HAL_PAL_VIRTUAL_ADDRESS (KADDRESS_BASE + 0xE0000000)
  828. //
  829. // Get address of current processor block.
  830. //
  831. #define KeGetCurrentPrcb() PCR->Prcb
  832. // begin_ntddk begin_wdm begin_ntosp
  833. #define KI_USER_SHARED_DATA ((ULONG_PTR)(KADDRESS_BASE + 0xFFFE0000))
  834. #define SharedUserData ((KUSER_SHARED_DATA * const)KI_USER_SHARED_DATA)
  835. // end_wdm
  836. //
  837. // Get address of processor control region.
  838. //
  839. #define KeGetPcr() PCR
  840. //
  841. // Get address of current kernel thread object.
  842. //
  843. #if defined(_M_IA64)
  844. #define KeGetCurrentThread() PCR->CurrentThread
  845. #endif
  846. //
  847. // Get current processor number.
  848. //
  849. #define KeGetCurrentProcessorNumber() ((ULONG)(PCR->Number))
  850. //
  851. // Get data cache fill size.
  852. //
  853. #if PRAGMA_DEPRECATED_DDK
  854. #pragma deprecated(KeGetDcacheFillSize) // Use GetDmaAlignment
  855. #endif
  856. #define KeGetDcacheFillSize() PCR->DcacheFillSize
  857. // end_ntddk end_nthal end_ntosp
  858. //
  859. // Test if executing a DPC.
  860. //
  861. BOOLEAN
  862. KeIsExecutingDpc (
  863. VOID
  864. );
  865. //
  866. // Save & Restore floating point state
  867. //
  868. // begin_ntddk begin_wdm begin_ntosp
  869. #define KeSaveFloatingPointState(a) STATUS_SUCCESS
  870. #define KeRestoreFloatingPointState(a) STATUS_SUCCESS
  871. // end_ntddk end_wdm end_ntosp
  872. // begin_ntddk begin_nthal begin_ntndis begin_wdm begin_ntosp
  873. //
  874. //
  875. // VOID
  876. // KeMemoryBarrierWithoutFence (
  877. // VOID
  878. // )
  879. //
  880. //
  881. // Routine Description:
  882. //
  883. // This function cases ordering of memory acceses generated by the compiler.
  884. //
  885. //
  886. // Arguments:
  887. //
  888. // None.
  889. //
  890. // Return Value:
  891. //
  892. // None.
  893. //--
  894. #ifdef __cplusplus
  895. extern "C" {
  896. #endif
  897. VOID
  898. _ReadWriteBarrier (
  899. VOID
  900. );
  901. #ifdef __cplusplus
  902. }
  903. #endif
  904. #pragma intrinsic(_ReadWriteBarrier)
  905. #define KeMemoryBarrierWithoutFence() _ReadWriteBarrier()
  906. //++
  907. //
  908. //
  909. // VOID
  910. // KeMemoryBarrier (
  911. // VOID
  912. // )
  913. //
  914. //
  915. // Routine Description:
  916. //
  917. // This function cases ordering of memory acceses as generated by the compiler and
  918. // as seen by other processors.
  919. //
  920. //
  921. // Arguments:
  922. //
  923. // None.
  924. //
  925. // Return Value:
  926. //
  927. // None.
  928. //--
  929. #define KE_MEMORY_BARRIER_REQUIRED
  930. #define KeMemoryBarrier() {_ReadWriteBarrier();__mf ();_ReadWriteBarrier();}
  931. //
  932. // Define the page size
  933. //
  934. #define PAGE_SIZE 0x2000
  935. //
  936. // Define the number of trailing zeroes in a page aligned virtual address.
  937. // This is used as the shift count when shifting virtual addresses to
  938. // virtual page numbers.
  939. //
  940. #define PAGE_SHIFT 13L
  941. // end_ntddk end_nthal end_ntndis end_wdm end_ntosp
  942. //
  943. // Define the page size and shift for large pages.
  944. //
  945. #define LARGE_PAGE_SIZE 0x1000000
  946. #define LARGE_PAGE_SHIFT 24L
  947. // begin_nthal
  948. //
  949. // IA64 hardware structures
  950. //
  951. //
  952. // A Page Table Entry on an IA64 has the following definition.
  953. //
  954. #define _HARDWARE_PTE_WORKING_SET_BITS 11
  955. typedef struct _HARDWARE_PTE {
  956. ULONG64 Valid : 1;
  957. ULONG64 Rsvd0 : 1;
  958. ULONG64 Cache : 3;
  959. ULONG64 Accessed : 1;
  960. ULONG64 Dirty : 1;
  961. ULONG64 Owner : 2;
  962. ULONG64 Execute : 1;
  963. ULONG64 Write : 1;
  964. ULONG64 Rsvd1 : PAGE_SHIFT - 12;
  965. ULONG64 CopyOnWrite : 1;
  966. ULONG64 PageFrameNumber : 50 - PAGE_SHIFT;
  967. ULONG64 Rsvd2 : 2;
  968. ULONG64 Exception : 1;
  969. ULONGLONG SoftwareWsIndex : _HARDWARE_PTE_WORKING_SET_BITS;
  970. } HARDWARE_PTE, *PHARDWARE_PTE;
  971. //
  972. // Fill TB entry
  973. //
  974. // Filling TB entry on demand by VHPT H/W seems faster than done by s/w.
  975. // Determining I/D side of TLB, disabling/enabling PSR.i and ic bits,
  976. // serialization, writing to IIP, IDA, IDTR and IITR seem just too much
  977. // compared to VHPT searching it automatically.
  978. //
  979. #define KiVhptEntry(va) ((PVOID)__thash((__int64)va))
  980. #define KiVhptEntryTag(va) ((ULONGLONG)__ttag((__int64)va))
  981. #define KiFlushSingleTb(va) \
  982. __ptcl((__int64)va,PAGE_SHIFT << 2); __isrlz()
  983. #define KeFillEntryTb( Virtual) \
  984. KiFlushSingleTb(Virtual);
  985. #define KiFlushFixedInstTbEx(Invalid, va, pssize) \
  986. __ptri((__int64)va, (pssize) << 2); __isrlz()
  987. #define KiFlushFixedInstTb(Invalid, va) \
  988. KiFlushFixedInstTbEx(Invalid, va, PAGE_SHIFT)
  989. #define KiFlushFixedDataTbEx(Invalid, va, pssize) \
  990. __ptrd((__int64)va, (pssize) << 2); __dsrlz()
  991. #define KiFlushFixedDataTb(Invalid, va) \
  992. KiFlushFixedDataTbEx(Invalid, va, PAGE_SHIFT)
  993. NTKERNELAPI
  994. VOID
  995. KeFillLargeEntryTb (
  996. IN HARDWARE_PTE Pte[2],
  997. IN PVOID Virtual,
  998. IN ULONG PageSize
  999. );
  1000. //
  1001. // Fill TB fixed entry
  1002. //
  1003. NTKERNELAPI
  1004. VOID
  1005. KeFillFixedEntryTb (
  1006. IN HARDWARE_PTE Pte[2],
  1007. IN PVOID Virtual,
  1008. IN ULONG PageSize,
  1009. IN ULONG Index
  1010. );
  1011. NTKERNELAPI
  1012. VOID
  1013. KeFillFixedLargeEntryTb (
  1014. IN HARDWARE_PTE Pte[2],
  1015. IN PVOID Virtual,
  1016. IN ULONG PageSize,
  1017. IN ULONG Index
  1018. );
  1019. #define INST_TB_BASE 0x80000000
  1020. #define DATA_TB_BASE 0
  1021. #define INST_TB_KERNEL_INDEX (INST_TB_BASE|ITR_KERNEL_INDEX)
  1022. #define INST_TB_EPC_INDEX (INST_TB_BASE|ITR_EPC_INDEX)
  1023. #define INST_TB_HAL_INDEX (INST_TB_BASE|ITR_HAL_INDEX)
  1024. #define INST_TB_PAL_INDEX (INST_TB_BASE|ITR_PAL_INDEX)
  1025. #define DATA_TB_DRIVER0_INDEX (DATA_TB_BASE|DTR_DRIVER0_INDEX)
  1026. #define DATA_TB_DRIVER1_INDEX (DATA_TB_BASE|DTR_DRIVER1_INDEX)
  1027. #define DATA_TB_KTBASE_INDEX (DATA_TB_BASE|DTR_KTBASE_INDEX)
  1028. #define DATA_TB_UTBASE_INDEX (DATA_TB_BASE|DTR_UTBASE_INDEX)
  1029. #define DATA_TB_STBASE_INDEX (DATA_TB_BASE|DTR_STBASE_INDEX)
  1030. #define DATA_TB_IOPORT_INDEX (DATA_TB_BASE|DTR_IO_PORT_INDEX)
  1031. #define DATA_TB_KTBASE_TMP_INDEX (DATA_TB_BASE|DTR_KTBASE_INDEX_TMP)
  1032. #define DATA_TB_UTBASE_TMP_INDEX (DATA_TB_BASE|DTR_UTBASE_INDEX_TMP)
  1033. #define DATA_TB_HAL_INDEX (DATA_TB_BASE|DTR_HAL_INDEX)
  1034. #define DATA_TB_PAL_INDEX (DATA_TB_BASE|DTR_PAL_INDEX)
  1035. //
  1036. // Fill Inst TB entry
  1037. //
  1038. NTKERNELAPI
  1039. VOID
  1040. KeFillInstEntryTb (
  1041. IN HARDWARE_PTE Pte,
  1042. IN PVOID Virtual
  1043. );
  1044. NTKERNELAPI
  1045. VOID
  1046. KeFlushCurrentTb (
  1047. VOID
  1048. );
  1049. #define KiFlushProcessTb() \
  1050. KeFlushEntireTb(FALSE, TRUE);
  1051. //
  1052. // Get a VHPT entry address
  1053. //
  1054. PVOID
  1055. KiVhptEntry64(
  1056. IN ULONG VirtualPageNumber
  1057. );
  1058. //
  1059. // Get a VHPT entry TAG value
  1060. //
  1061. ULONGLONG
  1062. KiVhptEntryTag64(
  1063. IN ULONG VirtualPageNumber
  1064. );
  1065. //
  1066. // Fill a VHPT entry
  1067. //
  1068. VOID
  1069. KiFillEntryVhpt(
  1070. IN PHARDWARE_PTE PointerPte,
  1071. IN PVOID Virtual
  1072. );
  1073. //
  1074. // Flush the kernel portions of Tb
  1075. //
  1076. VOID
  1077. KeFlushKernelTb(
  1078. IN BOOLEAN AllProcessors
  1079. );
  1080. //
  1081. // Flush the user portions of Tb
  1082. //
  1083. VOID
  1084. KeFlushUserTb(
  1085. IN BOOLEAN AllProcessors
  1086. );
  1087. //
  1088. // Data cache, instruction cache, I/O buffer, and write buffer flush routine
  1089. // prototypes.
  1090. //
  1091. NTKERNELAPI
  1092. VOID
  1093. KeChangeColorPage (
  1094. IN PVOID NewColor,
  1095. IN PVOID OldColor,
  1096. IN ULONG PageFrame
  1097. );
  1098. NTKERNELAPI
  1099. VOID
  1100. KeSweepDcache (
  1101. IN BOOLEAN AllProcessors
  1102. );
  1103. #define KeSweepCurrentDcache()
  1104. NTKERNELAPI
  1105. VOID
  1106. KeSweepIcache (
  1107. IN BOOLEAN AllProcessors
  1108. );
  1109. NTKERNELAPI
  1110. VOID
  1111. KeSweepIcacheRange (
  1112. IN BOOLEAN AllProcessors,
  1113. IN PVOID BaseAddress,
  1114. IN SIZE_T Length
  1115. );
  1116. NTKERNELAPI
  1117. VOID
  1118. KeSweepCurrentIcacheRange (
  1119. IN PVOID BaseAddress,
  1120. IN SIZE_T Length
  1121. );
  1122. NTKERNELAPI
  1123. VOID
  1124. KeSweepCurrentIcache();
  1125. NTKERNELAPI
  1126. VOID
  1127. KeSweepCacheRangeWithDrain (
  1128. IN BOOLEAN AllProcessors,
  1129. IN PVOID BaseAddress,
  1130. IN ULONG Length
  1131. );
  1132. // begin_ntddk begin_ntndis begin_wdm begin_ntosp
  1133. //
  1134. // Cache and write buffer flush functions.
  1135. //
  1136. NTKERNELAPI
  1137. VOID
  1138. KeFlushIoBuffers (
  1139. IN PMDL Mdl,
  1140. IN BOOLEAN ReadOperation,
  1141. IN BOOLEAN DmaOperation
  1142. );
  1143. // end_ntddk end_ntndis end_wdm end_ntosp
  1144. //
  1145. // Clock, profile, and interprocessor interrupt functions.
  1146. //
  1147. struct _KEXCEPTION_FRAME;
  1148. struct _KTRAP_FRAME;
  1149. NTKERNELAPI
  1150. VOID
  1151. KeIpiInterrupt (
  1152. IN struct _KTRAP_FRAME *TrapFrame
  1153. );
  1154. #define KeYieldProcessor __yield
  1155. NTKERNELAPI
  1156. VOID
  1157. KeProfileInterrupt (
  1158. IN struct _KTRAP_FRAME *TrapFrame
  1159. );
  1160. NTKERNELAPI
  1161. VOID
  1162. KeProfileInterruptWithSource (
  1163. IN struct _KTRAP_FRAME *TrapFrame,
  1164. IN KPROFILE_SOURCE ProfileSource
  1165. );
  1166. NTKERNELAPI
  1167. VOID
  1168. KeUpdateRunTime (
  1169. IN struct _KTRAP_FRAME *TrapFrame
  1170. );
  1171. NTKERNELAPI
  1172. VOID
  1173. KeUpdateSystemTime (
  1174. IN struct _KTRAP_FRAME *TrapFrame,
  1175. IN ULONG Increment
  1176. );
  1177. //
  1178. // The following function prototypes are exported for use in MP HALs.
  1179. //
  1180. #if defined(NT_UP)
  1181. #define KiAcquireSpinLock(SpinLock)
  1182. #else
  1183. NTKERNELAPI
  1184. VOID
  1185. KiAcquireSpinLock (
  1186. IN PKSPIN_LOCK SpinLock
  1187. );
  1188. #endif
  1189. #if defined(NT_UP)
  1190. #define KiReleaseSpinLock(SpinLock)
  1191. #else
  1192. VOID
  1193. KiReleaseSpinLock (
  1194. IN PKSPIN_LOCK SpinLock
  1195. );
  1196. #ifndef CAPKERN_SYNCH_POINTS
  1197. #define KiReleaseSpinLock _ReleaseSpinLock
  1198. #endif
  1199. #endif // !defined(NT_UP)
  1200. //
  1201. // Define cache error routine type and prototype.
  1202. //
  1203. typedef
  1204. VOID
  1205. (*PKCACHE_ERROR_ROUTINE) (
  1206. VOID
  1207. );
  1208. NTKERNELAPI
  1209. VOID
  1210. KeSetCacheErrorRoutine (
  1211. IN PKCACHE_ERROR_ROUTINE Routine
  1212. );
  1213. // begin_ntddk begin_wdm
  1214. //
  1215. // Kernel breakin breakpoint
  1216. //
  1217. VOID
  1218. KeBreakinBreakpoint (
  1219. VOID
  1220. );
  1221. // end_ntddk end_nthal end_wdm
  1222. //
  1223. // Define executive macros for acquiring and releasing executive spinlocks.
  1224. // These macros can ONLY be used by executive components and NOT by drivers.
  1225. // Drivers MUST use the kernel interfaces since they must be MP enabled on
  1226. // all systems.
  1227. //
  1228. #if defined(NT_UP) && !defined(_NTDDK_) && !defined(_NTIFS_)
  1229. #define ExAcquireSpinLock(Lock, OldIrql) KeRaiseIrql(DISPATCH_LEVEL, (OldIrql))
  1230. #define ExReleaseSpinLock(Lock, OldIrql) KeLowerIrql((OldIrql))
  1231. #define ExAcquireSpinLockAtDpcLevel(Lock)
  1232. #define ExReleaseSpinLockFromDpcLevel(Lock)
  1233. #else
  1234. // begin_wdm begin_ntddk begin_ntosp
  1235. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  1236. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  1237. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  1238. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  1239. // end_wdm end_ntddk end_ntosp
  1240. #endif
  1241. //
  1242. // The acquire and release fast lock macros disable and enable interrupts
  1243. // on UP nondebug systems. On MP or debug systems, the spinlock routines
  1244. // are used.
  1245. //
  1246. // N.B. Extreme caution should be observed when using these routines.
  1247. //
  1248. #if defined(_M_IA64)
  1249. VOID
  1250. _disable (
  1251. VOID
  1252. );
  1253. VOID
  1254. _enable (
  1255. VOID
  1256. );
  1257. #pragma intrinsic(_disable)
  1258. #pragma intrinsic(_enable)
  1259. #endif
  1260. #if defined(NT_UP) && !DBG
  1261. #define ExAcquireFastLock(Lock, OldIrql) _disable()
  1262. #else
  1263. #define ExAcquireFastLock(Lock, OldIrql) \
  1264. ExAcquireSpinLock(Lock, OldIrql)
  1265. #endif
  1266. #if defined(NT_UP) && !DBG
  1267. #define ExReleaseFastLock(Lock, OldIrql) _enable()
  1268. #else
  1269. #define ExReleaseFastLock(Lock, OldIrql) \
  1270. ExReleaseSpinLock(Lock, OldIrql)
  1271. #endif
  1272. //
  1273. // Data and instruction bus error function prototypes.
  1274. //
  1275. BOOLEAN
  1276. KeBusError (
  1277. IN PEXCEPTION_RECORD ExceptionRecord,
  1278. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  1279. IN struct _KTRAP_FRAME *TrapFrame,
  1280. IN PVOID VirtualAddress,
  1281. IN PHYSICAL_ADDRESS PhysicalAddress
  1282. );
  1283. VOID
  1284. KiDataBusError (
  1285. IN PEXCEPTION_RECORD ExceptionRecord,
  1286. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  1287. IN struct _KTRAP_FRAME *TrapFrame
  1288. );
  1289. VOID
  1290. KiInstructionBusError (
  1291. IN PEXCEPTION_RECORD ExceptionRecord,
  1292. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  1293. IN struct _KTRAP_FRAME *TrapFrame
  1294. );
  1295. //
  1296. // Define query tick count macro.
  1297. //
  1298. // begin_ntddk begin_nthal begin_ntosp
  1299. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  1300. // begin_wdm
  1301. #define KeQueryTickCount(CurrentCount ) \
  1302. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  1303. // end_wdm
  1304. #else
  1305. // end_ntddk end_nthal end_ntosp
  1306. //
  1307. // Define query tick count macro.
  1308. //
  1309. #define KiQueryTickCount(CurrentCount) \
  1310. *(PULONGLONG)(CurrentCount) = KeTickCount.QuadPart;
  1311. //
  1312. // Define query interrupt time macro.
  1313. //
  1314. #define KiQueryInterruptTime(CurrentTime) { \
  1315. C_ASSERT((FIELD_OFFSET(KUSER_SHARED_DATA, InterruptTime) & 7) == 0); \
  1316. ((PLARGE_INTEGER)(CurrentTime))->QuadPart = *(volatile LONG64 *)(&SharedUserData->InterruptTime); \
  1317. }
  1318. // begin_ntddk begin_nthal begin_ntosp
  1319. NTKERNELAPI
  1320. VOID
  1321. KeQueryTickCount (
  1322. OUT PLARGE_INTEGER CurrentCount
  1323. );
  1324. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  1325. // end_ntddk end_nthal end_ntosp
  1326. //
  1327. // The following function prototypes must be in the module since they are
  1328. // machine dependent.
  1329. //
  1330. ULONG
  1331. KiEmulateBranch (
  1332. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  1333. IN struct _KTRAP_FRAME *TrapFrame
  1334. );
  1335. BOOLEAN
  1336. KiEmulateFloating (
  1337. IN OUT PEXCEPTION_RECORD ExceptionRecord,
  1338. IN OUT struct _KEXCEPTION_FRAME *ExceptionFrame,
  1339. IN OUT struct _KTRAP_FRAME *TrapFrame
  1340. );
  1341. BOOLEAN
  1342. KiEmulateReference (
  1343. IN OUT PEXCEPTION_RECORD ExceptionRecord,
  1344. IN OUT struct _KEXCEPTION_FRAME *ExceptionFrame,
  1345. IN OUT struct _KTRAP_FRAME *TrapFrame
  1346. );
  1347. ULONGLONG
  1348. KiGetRegisterValue (
  1349. IN ULONG Register,
  1350. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  1351. IN struct _KTRAP_FRAME *TrapFrame
  1352. );
  1353. VOID
  1354. KiSetRegisterValue (
  1355. IN ULONG Register,
  1356. IN ULONGLONG Value,
  1357. OUT struct _KEXCEPTION_FRAME *ExceptionFrame,
  1358. OUT struct _KTRAP_FRAME *TrapFrame
  1359. );
  1360. FLOAT128
  1361. KiGetFloatRegisterValue (
  1362. IN ULONG Register,
  1363. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  1364. IN struct _KTRAP_FRAME *TrapFrame
  1365. );
  1366. VOID
  1367. KiSetFloatRegisterValue (
  1368. IN ULONG Register,
  1369. IN FLOAT128 Value,
  1370. OUT struct _KEXCEPTION_FRAME *ExceptionFrame,
  1371. OUT struct _KTRAP_FRAME *TrapFrame
  1372. );
  1373. VOID
  1374. KiAdvanceInstPointer(
  1375. IN OUT struct _KTRAP_FRAME *TrapFrame
  1376. );
  1377. VOID
  1378. KiRequestSoftwareInterrupt (
  1379. KIRQL RequestIrql
  1380. );
  1381. // begin_ntddk begin_nthal begin_ntndis begin_wdm begin_ntosp
  1382. //
  1383. // I/O space read and write macros.
  1384. //
  1385. NTHALAPI
  1386. UCHAR
  1387. READ_PORT_UCHAR (
  1388. PUCHAR RegisterAddress
  1389. );
  1390. NTHALAPI
  1391. USHORT
  1392. READ_PORT_USHORT (
  1393. PUSHORT RegisterAddress
  1394. );
  1395. NTHALAPI
  1396. ULONG
  1397. READ_PORT_ULONG (
  1398. PULONG RegisterAddress
  1399. );
  1400. NTHALAPI
  1401. VOID
  1402. READ_PORT_BUFFER_UCHAR (
  1403. PUCHAR portAddress,
  1404. PUCHAR readBuffer,
  1405. ULONG readCount
  1406. );
  1407. NTHALAPI
  1408. VOID
  1409. READ_PORT_BUFFER_USHORT (
  1410. PUSHORT portAddress,
  1411. PUSHORT readBuffer,
  1412. ULONG readCount
  1413. );
  1414. NTHALAPI
  1415. VOID
  1416. READ_PORT_BUFFER_ULONG (
  1417. PULONG portAddress,
  1418. PULONG readBuffer,
  1419. ULONG readCount
  1420. );
  1421. NTHALAPI
  1422. VOID
  1423. WRITE_PORT_UCHAR (
  1424. PUCHAR portAddress,
  1425. UCHAR Data
  1426. );
  1427. NTHALAPI
  1428. VOID
  1429. WRITE_PORT_USHORT (
  1430. PUSHORT portAddress,
  1431. USHORT Data
  1432. );
  1433. NTHALAPI
  1434. VOID
  1435. WRITE_PORT_ULONG (
  1436. PULONG portAddress,
  1437. ULONG Data
  1438. );
  1439. NTHALAPI
  1440. VOID
  1441. WRITE_PORT_BUFFER_UCHAR (
  1442. PUCHAR portAddress,
  1443. PUCHAR writeBuffer,
  1444. ULONG writeCount
  1445. );
  1446. NTHALAPI
  1447. VOID
  1448. WRITE_PORT_BUFFER_USHORT (
  1449. PUSHORT portAddress,
  1450. PUSHORT writeBuffer,
  1451. ULONG writeCount
  1452. );
  1453. NTHALAPI
  1454. VOID
  1455. WRITE_PORT_BUFFER_ULONG (
  1456. PULONG portAddress,
  1457. PULONG writeBuffer,
  1458. ULONG writeCount
  1459. );
  1460. #define READ_REGISTER_UCHAR(x) \
  1461. (__mf(), *(volatile UCHAR * const)(x))
  1462. #define READ_REGISTER_USHORT(x) \
  1463. (__mf(), *(volatile USHORT * const)(x))
  1464. #define READ_REGISTER_ULONG(x) \
  1465. (__mf(), *(volatile ULONG * const)(x))
  1466. #define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
  1467. PUCHAR registerBuffer = x; \
  1468. PUCHAR readBuffer = y; \
  1469. ULONG readCount; \
  1470. __mf(); \
  1471. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  1472. *readBuffer = *(volatile UCHAR * const)(registerBuffer); \
  1473. } \
  1474. }
  1475. #define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
  1476. PUSHORT registerBuffer = x; \
  1477. PUSHORT readBuffer = y; \
  1478. ULONG readCount; \
  1479. __mf(); \
  1480. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  1481. *readBuffer = *(volatile USHORT * const)(registerBuffer); \
  1482. } \
  1483. }
  1484. #define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
  1485. PULONG registerBuffer = x; \
  1486. PULONG readBuffer = y; \
  1487. ULONG readCount; \
  1488. __mf(); \
  1489. for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
  1490. *readBuffer = *(volatile ULONG * const)(registerBuffer); \
  1491. } \
  1492. }
  1493. #define WRITE_REGISTER_UCHAR(x, y) { \
  1494. *(volatile UCHAR * const)(x) = y; \
  1495. KeFlushWriteBuffer(); \
  1496. }
  1497. #define WRITE_REGISTER_USHORT(x, y) { \
  1498. *(volatile USHORT * const)(x) = y; \
  1499. KeFlushWriteBuffer(); \
  1500. }
  1501. #define WRITE_REGISTER_ULONG(x, y) { \
  1502. *(volatile ULONG * const)(x) = y; \
  1503. KeFlushWriteBuffer(); \
  1504. }
  1505. #define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
  1506. PUCHAR registerBuffer = x; \
  1507. PUCHAR writeBuffer = y; \
  1508. ULONG writeCount; \
  1509. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  1510. *(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
  1511. } \
  1512. KeFlushWriteBuffer(); \
  1513. }
  1514. #define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
  1515. PUSHORT registerBuffer = x; \
  1516. PUSHORT writeBuffer = y; \
  1517. ULONG writeCount; \
  1518. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  1519. *(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
  1520. } \
  1521. KeFlushWriteBuffer(); \
  1522. }
  1523. #define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
  1524. PULONG registerBuffer = x; \
  1525. PULONG writeBuffer = y; \
  1526. ULONG writeCount; \
  1527. for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
  1528. *(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
  1529. } \
  1530. KeFlushWriteBuffer(); \
  1531. }
  1532. // end_ntddk end_ntndis end_wdm end_ntosp
  1533. //
  1534. // Higher FP volatile
  1535. //
  1536. // This structure defines the higher FP volatile registers.
  1537. //
  1538. typedef struct _KHIGHER_FP_VOLATILE {
  1539. // volatile higher floating registers f32 - f127
  1540. FLOAT128 FltF32;
  1541. FLOAT128 FltF33;
  1542. FLOAT128 FltF34;
  1543. FLOAT128 FltF35;
  1544. FLOAT128 FltF36;
  1545. FLOAT128 FltF37;
  1546. FLOAT128 FltF38;
  1547. FLOAT128 FltF39;
  1548. FLOAT128 FltF40;
  1549. FLOAT128 FltF41;
  1550. FLOAT128 FltF42;
  1551. FLOAT128 FltF43;
  1552. FLOAT128 FltF44;
  1553. FLOAT128 FltF45;
  1554. FLOAT128 FltF46;
  1555. FLOAT128 FltF47;
  1556. FLOAT128 FltF48;
  1557. FLOAT128 FltF49;
  1558. FLOAT128 FltF50;
  1559. FLOAT128 FltF51;
  1560. FLOAT128 FltF52;
  1561. FLOAT128 FltF53;
  1562. FLOAT128 FltF54;
  1563. FLOAT128 FltF55;
  1564. FLOAT128 FltF56;
  1565. FLOAT128 FltF57;
  1566. FLOAT128 FltF58;
  1567. FLOAT128 FltF59;
  1568. FLOAT128 FltF60;
  1569. FLOAT128 FltF61;
  1570. FLOAT128 FltF62;
  1571. FLOAT128 FltF63;
  1572. FLOAT128 FltF64;
  1573. FLOAT128 FltF65;
  1574. FLOAT128 FltF66;
  1575. FLOAT128 FltF67;
  1576. FLOAT128 FltF68;
  1577. FLOAT128 FltF69;
  1578. FLOAT128 FltF70;
  1579. FLOAT128 FltF71;
  1580. FLOAT128 FltF72;
  1581. FLOAT128 FltF73;
  1582. FLOAT128 FltF74;
  1583. FLOAT128 FltF75;
  1584. FLOAT128 FltF76;
  1585. FLOAT128 FltF77;
  1586. FLOAT128 FltF78;
  1587. FLOAT128 FltF79;
  1588. FLOAT128 FltF80;
  1589. FLOAT128 FltF81;
  1590. FLOAT128 FltF82;
  1591. FLOAT128 FltF83;
  1592. FLOAT128 FltF84;
  1593. FLOAT128 FltF85;
  1594. FLOAT128 FltF86;
  1595. FLOAT128 FltF87;
  1596. FLOAT128 FltF88;
  1597. FLOAT128 FltF89;
  1598. FLOAT128 FltF90;
  1599. FLOAT128 FltF91;
  1600. FLOAT128 FltF92;
  1601. FLOAT128 FltF93;
  1602. FLOAT128 FltF94;
  1603. FLOAT128 FltF95;
  1604. FLOAT128 FltF96;
  1605. FLOAT128 FltF97;
  1606. FLOAT128 FltF98;
  1607. FLOAT128 FltF99;
  1608. FLOAT128 FltF100;
  1609. FLOAT128 FltF101;
  1610. FLOAT128 FltF102;
  1611. FLOAT128 FltF103;
  1612. FLOAT128 FltF104;
  1613. FLOAT128 FltF105;
  1614. FLOAT128 FltF106;
  1615. FLOAT128 FltF107;
  1616. FLOAT128 FltF108;
  1617. FLOAT128 FltF109;
  1618. FLOAT128 FltF110;
  1619. FLOAT128 FltF111;
  1620. FLOAT128 FltF112;
  1621. FLOAT128 FltF113;
  1622. FLOAT128 FltF114;
  1623. FLOAT128 FltF115;
  1624. FLOAT128 FltF116;
  1625. FLOAT128 FltF117;
  1626. FLOAT128 FltF118;
  1627. FLOAT128 FltF119;
  1628. FLOAT128 FltF120;
  1629. FLOAT128 FltF121;
  1630. FLOAT128 FltF122;
  1631. FLOAT128 FltF123;
  1632. FLOAT128 FltF124;
  1633. FLOAT128 FltF125;
  1634. FLOAT128 FltF126;
  1635. FLOAT128 FltF127;
  1636. } KHIGHER_FP_VOLATILE, *PKHIGHER_FP_VOLATILE;
  1637. //
  1638. // Debug registers
  1639. //
  1640. // This structure defines the hardware debug registers.
  1641. // We allow space for 4 pairs of instruction and 4 pairs of data debug registers
  1642. // The hardware may actually have more.
  1643. //
  1644. typedef struct _KDEBUG_REGISTERS {
  1645. ULONGLONG DbI0;
  1646. ULONGLONG DbI1;
  1647. ULONGLONG DbI2;
  1648. ULONGLONG DbI3;
  1649. ULONGLONG DbI4;
  1650. ULONGLONG DbI5;
  1651. ULONGLONG DbI6;
  1652. ULONGLONG DbI7;
  1653. ULONGLONG DbD0;
  1654. ULONGLONG DbD1;
  1655. ULONGLONG DbD2;
  1656. ULONGLONG DbD3;
  1657. ULONGLONG DbD4;
  1658. ULONGLONG DbD5;
  1659. ULONGLONG DbD6;
  1660. ULONGLONG DbD7;
  1661. } KDEBUG_REGISTERS, *PKDEBUG_REGISTERS;
  1662. //
  1663. // misc. application registers (mapped to IA-32 registers)
  1664. //
  1665. typedef struct _KAPPLICATION_REGISTERS {
  1666. ULONGLONG Ar21;
  1667. ULONGLONG Ar24;
  1668. ULONGLONG Unused; // AR 25 is now treated as a volitile register.
  1669. ULONGLONG Ar26;
  1670. ULONGLONG Ar27;
  1671. ULONGLONG Ar28;
  1672. ULONGLONG Ar29;
  1673. ULONGLONG Ar30;
  1674. } KAPPLICATION_REGISTERS, *PKAPPLICATION_REGISTERS;
  1675. //
  1676. // performance registers
  1677. //
  1678. typedef struct _KPERFORMANCE_REGISTERS {
  1679. ULONGLONG Perfr0;
  1680. ULONGLONG Perfr1;
  1681. ULONGLONG Perfr2;
  1682. ULONGLONG Perfr3;
  1683. ULONGLONG Perfr4;
  1684. ULONGLONG Perfr5;
  1685. ULONGLONG Perfr6;
  1686. ULONGLONG Perfr7;
  1687. } KPERFORMANCE_REGISTERS, *PKPERFORMANCE_REGISTERS;
  1688. //
  1689. // Thread State save area. Currently, beginning of Kernel Stack
  1690. //
  1691. // This structure defines the area for:
  1692. //
  1693. // higher fp register save/restore
  1694. // user debug register save/restore.
  1695. //
  1696. // The order of these area is significant.
  1697. //
  1698. typedef struct _KTHREAD_STATE_SAVEAREA {
  1699. KAPPLICATION_REGISTERS AppRegisters;
  1700. KPERFORMANCE_REGISTERS PerfRegisters;
  1701. KHIGHER_FP_VOLATILE HigherFPVolatile;
  1702. KDEBUG_REGISTERS DebugRegisters;
  1703. } KTHREAD_STATE_SAVEAREA, *PKTHREAD_STATE_SAVEAREA;
  1704. #define KTHREAD_STATE_SAVEAREA_LENGTH ((sizeof(KTHREAD_STATE_SAVEAREA) + 15) & ~((ULONG_PTR)15))
  1705. #define GET_HIGH_FLOATING_POINT_REGISTER_SAVEAREA(StackBase) \
  1706. (PKHIGHER_FP_VOLATILE) &(((PKTHREAD_STATE_SAVEAREA)(((ULONG_PTR)StackBase - sizeof(KTHREAD_STATE_SAVEAREA)) & ~((ULONG_PTR)15)))->HigherFPVolatile)
  1707. #define GET_DEBUG_REGISTER_SAVEAREA() \
  1708. (PKDEBUG_REGISTERS) &(((PKTHREAD_STATE_SAVEAREA)(((ULONG_PTR)KeGetCurrentThread()->StackBase - sizeof(KTHREAD_STATE_SAVEAREA)) & ~((ULONG_PTR)15)))->DebugRegisters)
  1709. #define GET_APPLICATION_REGISTER_SAVEAREA(StackBase) \
  1710. (PKAPPLICATION_REGISTERS) &(((PKTHREAD_STATE_SAVEAREA)(((ULONG_PTR)StackBase - sizeof(KTHREAD_STATE_SAVEAREA)) & ~((ULONG_PTR)15)))->AppRegisters)
  1711. //
  1712. // Exception frame
  1713. //
  1714. // This frame is established when handling an exception. It provides a place
  1715. // to save all preserved registers. The volatile registers will already
  1716. // have been saved in a trap frame. Also used as part of switch frame built
  1717. // at thread switch.
  1718. //
  1719. // The frame is 16-byte aligned to maintain 16-byte alignment for the stack,
  1720. //
  1721. typedef struct _KEXCEPTION_FRAME {
  1722. // Preserved application registers
  1723. ULONGLONG ApEC; // epilogue count
  1724. ULONGLONG ApLC; // loop count
  1725. ULONGLONG IntNats; // Nats for S0-S3; i.e. ar.UNAT after spill
  1726. // Preserved (saved) interger registers, s0-s3
  1727. ULONGLONG IntS0;
  1728. ULONGLONG IntS1;
  1729. ULONGLONG IntS2;
  1730. ULONGLONG IntS3;
  1731. // Preserved (saved) branch registers, bs0-bs4
  1732. ULONGLONG BrS0;
  1733. ULONGLONG BrS1;
  1734. ULONGLONG BrS2;
  1735. ULONGLONG BrS3;
  1736. ULONGLONG BrS4;
  1737. // Preserved (saved) floating point registers, f2 - f5, f16 - f31
  1738. FLOAT128 FltS0;
  1739. FLOAT128 FltS1;
  1740. FLOAT128 FltS2;
  1741. FLOAT128 FltS3;
  1742. FLOAT128 FltS4;
  1743. FLOAT128 FltS5;
  1744. FLOAT128 FltS6;
  1745. FLOAT128 FltS7;
  1746. FLOAT128 FltS8;
  1747. FLOAT128 FltS9;
  1748. FLOAT128 FltS10;
  1749. FLOAT128 FltS11;
  1750. FLOAT128 FltS12;
  1751. FLOAT128 FltS13;
  1752. FLOAT128 FltS14;
  1753. FLOAT128 FltS15;
  1754. FLOAT128 FltS16;
  1755. FLOAT128 FltS17;
  1756. FLOAT128 FltS18;
  1757. FLOAT128 FltS19;
  1758. } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
  1759. //
  1760. // Switch frame
  1761. //
  1762. // This frame is established when doing a thread switch in SwapContext. It
  1763. // provides a place to save the preserved kernel state at the point of the
  1764. // switch registers.
  1765. // The volatile registers are scratch across the call to SwapContext.
  1766. //
  1767. // The frame is 16-byte aligned to maintain 16-byte alignment for the stack,
  1768. //
  1769. typedef struct _KSWITCH_FRAME {
  1770. ULONGLONG SwitchPredicates; // Predicates for Switch
  1771. ULONGLONG SwitchRp; // return pointer for Switch
  1772. ULONGLONG SwitchPFS; // PFS for Switch
  1773. ULONGLONG SwitchFPSR; // ProcessorFP status at thread switch
  1774. ULONGLONG SwitchBsp;
  1775. ULONGLONG SwitchRnat;
  1776. // ULONGLONG Pad;
  1777. KEXCEPTION_FRAME SwitchExceptionFrame;
  1778. } KSWITCH_FRAME, *PKSWITCH_FRAME;
  1779. // Trap frame
  1780. // This frame is established when handling a trap. It provides a place to
  1781. // save all volatile registers. The nonvolatile registers are saved in an
  1782. // exception frame or through the normal C calling conventions for saved
  1783. // registers. Its size must be a multiple of 16 bytes.
  1784. //
  1785. // N.B - the 16-byte alignment is required to maintain the stack alignment.
  1786. //
  1787. #define KTRAP_FRAME_ARGUMENTS (8 * 8) // up to 8 in-memory syscall args
  1788. typedef struct _KTRAP_FRAME {
  1789. //
  1790. // Reserved for additional memory arguments and stack scratch area
  1791. // The size of Reserved[] must be a multiple of 16 bytes.
  1792. //
  1793. ULONGLONG Reserved[(KTRAP_FRAME_ARGUMENTS+16)/8];
  1794. // Temporary (volatile) FP registers - f6-f15 (don't use f32+ in kernel)
  1795. FLOAT128 FltT0;
  1796. FLOAT128 FltT1;
  1797. FLOAT128 FltT2;
  1798. FLOAT128 FltT3;
  1799. FLOAT128 FltT4;
  1800. FLOAT128 FltT5;
  1801. FLOAT128 FltT6;
  1802. FLOAT128 FltT7;
  1803. FLOAT128 FltT8;
  1804. FLOAT128 FltT9;
  1805. // Temporary (volatile) interger registers
  1806. ULONGLONG IntGp; // global pointer (r1)
  1807. ULONGLONG IntT0;
  1808. ULONGLONG IntT1;
  1809. // The following 4 registers fill in space of preserved (S0-S3) to align Nats
  1810. ULONGLONG ApUNAT; // ar.UNAT on kernel entry
  1811. ULONGLONG ApCCV; // ar.CCV
  1812. ULONGLONG SegCSD; // Second register for 16 byte values
  1813. ULONGLONG Preds; // Predicates
  1814. ULONGLONG IntV0; // return value (r8)
  1815. ULONGLONG IntT2;
  1816. ULONGLONG IntT3;
  1817. ULONGLONG IntT4;
  1818. ULONGLONG IntSp; // stack pointer (r12)
  1819. ULONGLONG IntTeb; // teb (r13)
  1820. ULONGLONG IntT5;
  1821. ULONGLONG IntT6;
  1822. ULONGLONG IntT7;
  1823. ULONGLONG IntT8;
  1824. ULONGLONG IntT9;
  1825. ULONGLONG IntT10;
  1826. ULONGLONG IntT11;
  1827. ULONGLONG IntT12;
  1828. ULONGLONG IntT13;
  1829. ULONGLONG IntT14;
  1830. ULONGLONG IntT15;
  1831. ULONGLONG IntT16;
  1832. ULONGLONG IntT17;
  1833. ULONGLONG IntT18;
  1834. ULONGLONG IntT19;
  1835. ULONGLONG IntT20;
  1836. ULONGLONG IntT21;
  1837. ULONGLONG IntT22;
  1838. ULONGLONG IntNats; // Temporary (volatile) registers' Nats directly from ar.UNAT at point of spill
  1839. ULONGLONG BrRp; // Return pointer on kernel entry
  1840. ULONGLONG BrT0; // Temporary (volatile) branch registers (b6-b7)
  1841. ULONGLONG BrT1;
  1842. // Register stack info
  1843. ULONGLONG RsRSC; // RSC on kernel entry
  1844. ULONGLONG RsBSP; // BSP on kernel entry
  1845. ULONGLONG RsBSPSTORE; // User BSP Store at point of switch to kernel backing store
  1846. ULONGLONG RsRNAT; // old RNAT at point of switch to kernel backing store
  1847. ULONGLONG RsPFS; // PFS on kernel entry
  1848. // Trap Status Information
  1849. ULONGLONG StIPSR; // Interruption Processor Status Register
  1850. ULONGLONG StIIP; // Interruption IP
  1851. ULONGLONG StIFS; // Interruption Function State
  1852. ULONGLONG StFPSR; // FP status
  1853. ULONGLONG StISR; // Interruption Status Register
  1854. ULONGLONG StIFA; // Interruption Data Address
  1855. ULONGLONG StIIPA; // Last executed bundle address
  1856. ULONGLONG StIIM; // Interruption Immediate
  1857. ULONGLONG StIHA; // Interruption Hash Address
  1858. ULONG OldIrql; // Previous Irql.
  1859. ULONG PreviousMode; // Previous Mode.
  1860. ULONGLONG TrapFrame;// Previous Trap Frame
  1861. //
  1862. // Exception record
  1863. //
  1864. UCHAR ExceptionRecord[(sizeof(EXCEPTION_RECORD) + 15) & (~15)];
  1865. // End of frame marker (for debugging)
  1866. ULONGLONG NewBSP; // NewBSP When a stack switch occur this is the value of the new BSP
  1867. ULONGLONG EOFMarker;
  1868. } KTRAP_FRAME, *PKTRAP_FRAME;
  1869. #define KTRAP_FRAME_LENGTH ((sizeof(KTRAP_FRAME) + 15) & (~15))
  1870. #define KTRAP_FRAME_ALIGN (16)
  1871. #define KTRAP_FRAME_ROUND (KTRAP_FRAME_ALIGN - 1)
  1872. #define KTRAP_FRAME_EOF 0xe0f0e0f0e0f0e000i64
  1873. //
  1874. // Use the lowest 4 bits of EOFMarker field to encode the trap frame type
  1875. //
  1876. #define SYSCALL_FRAME 0
  1877. #define INTERRUPT_FRAME 1
  1878. #define EXCEPTION_FRAME 2
  1879. #define CONTEXT_FRAME 10
  1880. #define MODIFIED_FRAME 0x20
  1881. #define TRAP_FRAME_TYPE(tf) (tf->EOFMarker & 0xf)
  1882. //
  1883. // Define the kernel mode and user mode callback frame structures.
  1884. //
  1885. //
  1886. // The frame saved by KiCallUserMode is defined here to allow
  1887. // the kernel debugger to trace the entire kernel stack
  1888. // when usermode callouts are pending.
  1889. //
  1890. // N.B. The size of the following structure must be a multiple of 16 bytes
  1891. // and it must be 16-byte aligned.
  1892. //
  1893. typedef struct _KCALLOUT_FRAME {
  1894. ULONGLONG BrRp;
  1895. ULONGLONG RsPFS;
  1896. ULONGLONG Preds;
  1897. ULONGLONG ApUNAT;
  1898. ULONGLONG ApLC;
  1899. ULONGLONG RsRNAT;
  1900. ULONGLONG IntNats;
  1901. ULONGLONG IntS0;
  1902. ULONGLONG IntS1;
  1903. ULONGLONG IntS2;
  1904. ULONGLONG IntS3;
  1905. ULONGLONG BrS0;
  1906. ULONGLONG BrS1;
  1907. ULONGLONG BrS2;
  1908. ULONGLONG BrS3;
  1909. ULONGLONG BrS4;
  1910. FLOAT128 FltS0; // 16-byte aligned boundary
  1911. FLOAT128 FltS1;
  1912. FLOAT128 FltS2;
  1913. FLOAT128 FltS3;
  1914. FLOAT128 FltS4;
  1915. FLOAT128 FltS5;
  1916. FLOAT128 FltS6;
  1917. FLOAT128 FltS7;
  1918. FLOAT128 FltS8;
  1919. FLOAT128 FltS9;
  1920. FLOAT128 FltS10;
  1921. FLOAT128 FltS11;
  1922. FLOAT128 FltS12;
  1923. FLOAT128 FltS13;
  1924. FLOAT128 FltS14;
  1925. FLOAT128 FltS15;
  1926. FLOAT128 FltS16;
  1927. FLOAT128 FltS17;
  1928. FLOAT128 FltS18;
  1929. FLOAT128 FltS19;
  1930. ULONGLONG A0; // saved argument registers a0-a2
  1931. ULONGLONG A1;
  1932. ULONGLONG CbStk; // saved callback stack address
  1933. ULONGLONG InStack; // saved initial stack address
  1934. ULONGLONG CbBStore; // saved callback stack address
  1935. ULONGLONG InBStore; // saved initial stack address
  1936. ULONGLONG TrFrame; // saved callback trap frame address
  1937. ULONGLONG TrStIIP; // saved continuation address
  1938. } KCALLOUT_FRAME, *PKCALLOUT_FRAME;
  1939. typedef struct _UCALLOUT_FRAME {
  1940. PVOID Buffer;
  1941. ULONG Length;
  1942. ULONG ApiNumber;
  1943. ULONGLONG IntSp;
  1944. ULONGLONG RsPFS;
  1945. ULONGLONG BrRp;
  1946. ULONGLONG Pad;
  1947. } UCALLOUT_FRAME, *PUCALLOUT_FRAME;
  1948. // end_nthal
  1949. // begin_ntddk begin_wdm begin_ntosp
  1950. //
  1951. // Non-volatile floating point state
  1952. //
  1953. typedef struct _KFLOATING_SAVE {
  1954. ULONG Reserved;
  1955. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  1956. // end_ntddk end_wdm end_ntosp
  1957. #define STATUS_IA64_INVALID_STACK STATUS_BAD_STACK
  1958. //
  1959. // iA32 control bits definition
  1960. //
  1961. //
  1962. // Define constants to access the bits in CR0.
  1963. //
  1964. #define CR0_PG 0x80000000 // paging
  1965. #define CR0_ET 0x00000010 // extension type (80387)
  1966. #define CR0_TS 0x00000008 // task switched
  1967. #define CR0_EM 0x00000004 // emulate math coprocessor
  1968. #define CR0_MP 0x00000002 // math present
  1969. #define CR0_PE 0x00000001 // protection enable
  1970. //
  1971. // More CR0 bits; these only apply to the 80486.
  1972. //
  1973. #define CR0_CD 0x40000000 // cache disable
  1974. #define CR0_NW 0x20000000 // not write-through
  1975. #define CR0_AM 0x00040000 // alignment mask
  1976. #define CR0_WP 0x00010000 // write protect
  1977. #define CR0_NE 0x00000020 // numeric error
  1978. //
  1979. // Define constants to access CFLG bits
  1980. //
  1981. #define CFLG_IO 0x00000040 // IO bit map checking on
  1982. #define CFLG_IF 0x00000080 // EFLAG.if to control external interrupt
  1983. #define CFLG_II 0x00000100 // enable EFLAG.if interception
  1984. //
  1985. // CR4 bits; These only apply to Pentium
  1986. //
  1987. #define CR4_VME 0x00000001 // V86 mode extensions
  1988. #define CR4_PVI 0x00000002 // Protected mode virtual interrupts
  1989. #define CR4_TSD 0x00000004 // Time stamp disable
  1990. #define CR4_DE 0x00000008 // Debugging Extensions
  1991. #define CR4_PSE 0x00000010 // Page size extensions
  1992. #define CR4_PAE 0x00000020 // Physical address extensions
  1993. #define CR4_MCE 0x00000040 // Machine check enable
  1994. #define CR4_PGE 0x00000080 // Page global enable
  1995. #define CR4_FXSR 0x00000200 // FXSR used by OS
  1996. #define CR4_XMMEXCPT 0x00000400 // XMMI used by OS
  1997. //
  1998. // Define constants to access ThNpxState
  1999. //
  2000. #define NPX_STATE_NOT_LOADED (CR0_TS | CR0_MP)
  2001. #define NPX_STATE_LOADED 0
  2002. //
  2003. // begin_nthal
  2004. //
  2005. // Machine type definitions
  2006. //
  2007. #define MACHINE_TYPE_ISA 0
  2008. #define MACHINE_TYPE_EISA 1
  2009. #define MACHINE_TYPE_MCA 2
  2010. //
  2011. // PAL Interface
  2012. //
  2013. // iA-64 defined PAL function IDs in decimal format as in the PAL spec
  2014. // All PAL calls done through HAL. HAL may block some calls
  2015. //
  2016. #define PAL_CACHE_FLUSH 1I64
  2017. #define PAL_CACHE_INFO 2I64
  2018. #define PAL_CACHE_INIT 3I64
  2019. #define PAL_CACHE_SUMMARY 4I64
  2020. #define PAL_PTCE_INFO 6I64
  2021. #define PAL_MEM_ATTRIB 5I64
  2022. #define PAL_VM_INFO 7I64
  2023. #define PAL_VM_SUMMARY 8I64
  2024. #define PAL_BUS_GET_FEATURES 9I64
  2025. #define PAL_BUS_SET_FEATURES 10I64
  2026. #define PAL_DEBUG_INFO 11I64
  2027. #define PAL_FIXED_ADDR 12I64
  2028. #define PAL_FREQ_BASE 13I64
  2029. #define PAL_FREQ_RATIOS 14I64
  2030. #define PAL_PERF_MON_INFO 15I64
  2031. #define PAL_PLATFORM_ADDR 16I64
  2032. #define PAL_PROC_GET_FEATURES 17I64
  2033. #define PAL_PROC_SET_FEATURES 18I64
  2034. #define PAL_RSE_INFO 19I64
  2035. #define PAL_VERSION 20I64
  2036. #define PAL_MC_CLEAR_LOG 21I64
  2037. #define PAL_MC_DRAIN 22I64
  2038. #define PAL_MC_EXPECTED 23I64
  2039. #define PAL_MC_DYNAMIC_STATE 24I64
  2040. #define PAL_MC_ERROR_INFO 25I64
  2041. #define PAL_MC_RESUME 26I64
  2042. #define PAL_MC_REGISTER_MEM 27I64
  2043. #define PAL_HALT 28I64
  2044. #define PAL_HALT_LIGHT 29I64
  2045. #define PAL_COPY_INFO 30I64
  2046. #define PAL_CACHE_LINE_INIT 31I64
  2047. #define PAL_PMI_ENTRYPOINT 32I64
  2048. #define PAL_ENTER_IA_32_ENV 33I64
  2049. #define PAL_VM_PAGE_SIZE 34I64
  2050. #define PAL_MEM_FOR_TEST 37I64
  2051. #define PAL_CACHE_PROT_INFO 38I64
  2052. #define PAL_REGISTER_INFO 39I64
  2053. #define PAL_SHUTDOWN 44I64
  2054. #define PAL_PREFETCH_VISIBILITY 41I64
  2055. #define PAL_COPY_PAL 256I64
  2056. #define PAL_HALT_INFO 257I64
  2057. #define PAL_TEST_PROC 258I64
  2058. #define PAL_CACHE_READ 259I64
  2059. #define PAL_CACHE_WRITE 260I64
  2060. #define PAL_VM_TR_READ 261I64
  2061. //
  2062. // iA-64 defined PAL return values
  2063. //
  2064. #define PAL_STATUS_INVALID_CACHELINE 1I64
  2065. #define PAL_STATUS_SUPPORT_NOT_NEEDED 1I64
  2066. #define PAL_STATUS_SUCCESS 0
  2067. #define PAL_STATUS_NOT_IMPLEMENTED -1I64
  2068. #define PAL_STATUS_INVALID_ARGUMENT -2I64
  2069. #define PAL_STATUS_ERROR -3I64
  2070. #define PAL_STATUS_UNABLE_TO_INIT_CACHE_LEVEL_AND_TYPE -4I64
  2071. #define PAL_STATUS_NOT_FOUND_IN_CACHE -5I64
  2072. #define PAL_STATUS_NO_ERROR_INFO_AVAILABLE -6I64
  2073. // end_nthal
  2074. //
  2075. // Define constants used in selector tests.
  2076. //
  2077. // RPL_MASK is the real value for extracting RPL values. IT IS THE WRONG
  2078. // CONSTANT TO USE FOR MODE TESTING.
  2079. //
  2080. // MODE_MASK is the value for deciding the current mode.
  2081. // WARNING: MODE_MASK assumes that all code runs at either ring-0
  2082. // or ring-3. Ring-1 or Ring-2 support will require changing
  2083. // this value and all of the code that refers to it.
  2084. #define MODE_MASK 1
  2085. #define RPL_MASK 3
  2086. //
  2087. // SetProcessInformation Structure for ProcessSetIoHandlers info class
  2088. //
  2089. typedef struct _PROCESS_IO_PORT_HANDLER_INFORMATION {
  2090. BOOLEAN Install; // true if handlers to be installed
  2091. ULONG NumEntries;
  2092. ULONG Context;
  2093. PEMULATOR_ACCESS_ENTRY EmulatorAccessEntries;
  2094. } PROCESS_IO_PORT_HANDLER_INFORMATION, *PPROCESS_IO_PORT_HANDLER_INFORMATION;
  2095. //
  2096. // Used for cleaning up ia32 contexts
  2097. // This is taken from i386.h
  2098. //
  2099. #define EFLAGS_DF_MASK 0x00000400L
  2100. #define EFLAGS_INTERRUPT_MASK 0x00000200L
  2101. #define EFLAGS_V86_MASK 0x00020000L
  2102. #define EFLAGS_ALIGN_CHECK 0x00040000L
  2103. #define EFLAGS_IOPL_MASK 0x00003000L
  2104. #define EFLAGS_VIF 0x00080000L
  2105. #define EFLAGS_VIP 0x00100000L
  2106. #define EFLAGS_USER_SANITIZE 0x003e0dd7L
  2107. // begin_windbgkd begin_nthal
  2108. #ifdef _IA64_
  2109. //
  2110. // Stack Registers for IA64
  2111. //
  2112. typedef struct _STACK_REGISTERS {
  2113. ULONGLONG IntR32;
  2114. ULONGLONG IntR33;
  2115. ULONGLONG IntR34;
  2116. ULONGLONG IntR35;
  2117. ULONGLONG IntR36;
  2118. ULONGLONG IntR37;
  2119. ULONGLONG IntR38;
  2120. ULONGLONG IntR39;
  2121. ULONGLONG IntR40;
  2122. ULONGLONG IntR41;
  2123. ULONGLONG IntR42;
  2124. ULONGLONG IntR43;
  2125. ULONGLONG IntR44;
  2126. ULONGLONG IntR45;
  2127. ULONGLONG IntR46;
  2128. ULONGLONG IntR47;
  2129. ULONGLONG IntR48;
  2130. ULONGLONG IntR49;
  2131. ULONGLONG IntR50;
  2132. ULONGLONG IntR51;
  2133. ULONGLONG IntR52;
  2134. ULONGLONG IntR53;
  2135. ULONGLONG IntR54;
  2136. ULONGLONG IntR55;
  2137. ULONGLONG IntR56;
  2138. ULONGLONG IntR57;
  2139. ULONGLONG IntR58;
  2140. ULONGLONG IntR59;
  2141. ULONGLONG IntR60;
  2142. ULONGLONG IntR61;
  2143. ULONGLONG IntR62;
  2144. ULONGLONG IntR63;
  2145. ULONGLONG IntR64;
  2146. ULONGLONG IntR65;
  2147. ULONGLONG IntR66;
  2148. ULONGLONG IntR67;
  2149. ULONGLONG IntR68;
  2150. ULONGLONG IntR69;
  2151. ULONGLONG IntR70;
  2152. ULONGLONG IntR71;
  2153. ULONGLONG IntR72;
  2154. ULONGLONG IntR73;
  2155. ULONGLONG IntR74;
  2156. ULONGLONG IntR75;
  2157. ULONGLONG IntR76;
  2158. ULONGLONG IntR77;
  2159. ULONGLONG IntR78;
  2160. ULONGLONG IntR79;
  2161. ULONGLONG IntR80;
  2162. ULONGLONG IntR81;
  2163. ULONGLONG IntR82;
  2164. ULONGLONG IntR83;
  2165. ULONGLONG IntR84;
  2166. ULONGLONG IntR85;
  2167. ULONGLONG IntR86;
  2168. ULONGLONG IntR87;
  2169. ULONGLONG IntR88;
  2170. ULONGLONG IntR89;
  2171. ULONGLONG IntR90;
  2172. ULONGLONG IntR91;
  2173. ULONGLONG IntR92;
  2174. ULONGLONG IntR93;
  2175. ULONGLONG IntR94;
  2176. ULONGLONG IntR95;
  2177. ULONGLONG IntR96;
  2178. ULONGLONG IntR97;
  2179. ULONGLONG IntR98;
  2180. ULONGLONG IntR99;
  2181. ULONGLONG IntR100;
  2182. ULONGLONG IntR101;
  2183. ULONGLONG IntR102;
  2184. ULONGLONG IntR103;
  2185. ULONGLONG IntR104;
  2186. ULONGLONG IntR105;
  2187. ULONGLONG IntR106;
  2188. ULONGLONG IntR107;
  2189. ULONGLONG IntR108;
  2190. ULONGLONG IntR109;
  2191. ULONGLONG IntR110;
  2192. ULONGLONG IntR111;
  2193. ULONGLONG IntR112;
  2194. ULONGLONG IntR113;
  2195. ULONGLONG IntR114;
  2196. ULONGLONG IntR115;
  2197. ULONGLONG IntR116;
  2198. ULONGLONG IntR117;
  2199. ULONGLONG IntR118;
  2200. ULONGLONG IntR119;
  2201. ULONGLONG IntR120;
  2202. ULONGLONG IntR121;
  2203. ULONGLONG IntR122;
  2204. ULONGLONG IntR123;
  2205. ULONGLONG IntR124;
  2206. ULONGLONG IntR125;
  2207. ULONGLONG IntR126;
  2208. ULONGLONG IntR127;
  2209. // Nat bits for stack registers
  2210. ULONGLONG IntNats2; // r32-r95 in bit positions 1 to 63
  2211. ULONGLONG IntNats3; // r96-r127 in bit position 1 to 31
  2212. } STACK_REGISTERS, *PSTACK_REGISTERS;
  2213. //
  2214. // Special Registers for IA64
  2215. //
  2216. typedef struct _KSPECIAL_REGISTERS {
  2217. // Kernel debug breakpoint registers
  2218. ULONGLONG KernelDbI0; // Instruction debug registers
  2219. ULONGLONG KernelDbI1;
  2220. ULONGLONG KernelDbI2;
  2221. ULONGLONG KernelDbI3;
  2222. ULONGLONG KernelDbI4;
  2223. ULONGLONG KernelDbI5;
  2224. ULONGLONG KernelDbI6;
  2225. ULONGLONG KernelDbI7;
  2226. ULONGLONG KernelDbD0; // Data debug registers
  2227. ULONGLONG KernelDbD1;
  2228. ULONGLONG KernelDbD2;
  2229. ULONGLONG KernelDbD3;
  2230. ULONGLONG KernelDbD4;
  2231. ULONGLONG KernelDbD5;
  2232. ULONGLONG KernelDbD6;
  2233. ULONGLONG KernelDbD7;
  2234. // Kernel performance monitor registers
  2235. ULONGLONG KernelPfC0; // Performance configuration registers
  2236. ULONGLONG KernelPfC1;
  2237. ULONGLONG KernelPfC2;
  2238. ULONGLONG KernelPfC3;
  2239. ULONGLONG KernelPfC4;
  2240. ULONGLONG KernelPfC5;
  2241. ULONGLONG KernelPfC6;
  2242. ULONGLONG KernelPfC7;
  2243. ULONGLONG KernelPfD0; // Performance data registers
  2244. ULONGLONG KernelPfD1;
  2245. ULONGLONG KernelPfD2;
  2246. ULONGLONG KernelPfD3;
  2247. ULONGLONG KernelPfD4;
  2248. ULONGLONG KernelPfD5;
  2249. ULONGLONG KernelPfD6;
  2250. ULONGLONG KernelPfD7;
  2251. // kernel bank shadow (hidden) registers
  2252. ULONGLONG IntH16;
  2253. ULONGLONG IntH17;
  2254. ULONGLONG IntH18;
  2255. ULONGLONG IntH19;
  2256. ULONGLONG IntH20;
  2257. ULONGLONG IntH21;
  2258. ULONGLONG IntH22;
  2259. ULONGLONG IntH23;
  2260. ULONGLONG IntH24;
  2261. ULONGLONG IntH25;
  2262. ULONGLONG IntH26;
  2263. ULONGLONG IntH27;
  2264. ULONGLONG IntH28;
  2265. ULONGLONG IntH29;
  2266. ULONGLONG IntH30;
  2267. ULONGLONG IntH31;
  2268. // Application Registers
  2269. // - CPUID Registers - AR
  2270. ULONGLONG ApCPUID0; // Cpuid Register 0
  2271. ULONGLONG ApCPUID1; // Cpuid Register 1
  2272. ULONGLONG ApCPUID2; // Cpuid Register 2
  2273. ULONGLONG ApCPUID3; // Cpuid Register 3
  2274. ULONGLONG ApCPUID4; // Cpuid Register 4
  2275. ULONGLONG ApCPUID5; // Cpuid Register 5
  2276. ULONGLONG ApCPUID6; // Cpuid Register 6
  2277. ULONGLONG ApCPUID7; // Cpuid Register 7
  2278. // - Kernel Registers - AR
  2279. ULONGLONG ApKR0; // Kernel Register 0 (User RO)
  2280. ULONGLONG ApKR1; // Kernel Register 1 (User RO)
  2281. ULONGLONG ApKR2; // Kernel Register 2 (User RO)
  2282. ULONGLONG ApKR3; // Kernel Register 3 (User RO)
  2283. ULONGLONG ApKR4; // Kernel Register 4
  2284. ULONGLONG ApKR5; // Kernel Register 5
  2285. ULONGLONG ApKR6; // Kernel Register 6
  2286. ULONGLONG ApKR7; // Kernel Register 7
  2287. ULONGLONG ApITC; // Interval Timer Counter
  2288. // Global control registers
  2289. ULONGLONG ApITM; // Interval Timer Match register
  2290. ULONGLONG ApIVA; // Interrupt Vector Address
  2291. ULONGLONG ApPTA; // Page Table Address
  2292. ULONGLONG ApGPTA; // ia32 Page Table Address
  2293. ULONGLONG StISR; // Interrupt status
  2294. ULONGLONG StIFA; // Interruption Faulting Address
  2295. ULONGLONG StITIR; // Interruption TLB Insertion Register
  2296. ULONGLONG StIIPA; // Interruption Instruction Previous Address (RO)
  2297. ULONGLONG StIIM; // Interruption Immediate register (RO)
  2298. ULONGLONG StIHA; // Interruption Hash Address (RO)
  2299. // - External Interrupt control registers (SAPIC)
  2300. ULONGLONG SaLID; // Local SAPIC ID
  2301. ULONGLONG SaIVR; // Interrupt Vector Register (RO)
  2302. ULONGLONG SaTPR; // Task Priority Register
  2303. ULONGLONG SaEOI; // End Of Interrupt
  2304. ULONGLONG SaIRR0; // Interrupt Request Register 0 (RO)
  2305. ULONGLONG SaIRR1; // Interrupt Request Register 1 (RO)
  2306. ULONGLONG SaIRR2; // Interrupt Request Register 2 (RO)
  2307. ULONGLONG SaIRR3; // Interrupt Request Register 3 (RO)
  2308. ULONGLONG SaITV; // Interrupt Timer Vector
  2309. ULONGLONG SaPMV; // Performance Monitor Vector
  2310. ULONGLONG SaCMCV; // Corrected Machine Check Vector
  2311. ULONGLONG SaLRR0; // Local Interrupt Redirection Vector 0
  2312. ULONGLONG SaLRR1; // Local Interrupt Redirection Vector 1
  2313. // System Registers
  2314. // - Region registers
  2315. ULONGLONG Rr0; // Region register 0
  2316. ULONGLONG Rr1; // Region register 1
  2317. ULONGLONG Rr2; // Region register 2
  2318. ULONGLONG Rr3; // Region register 3
  2319. ULONGLONG Rr4; // Region register 4
  2320. ULONGLONG Rr5; // Region register 5
  2321. ULONGLONG Rr6; // Region register 6
  2322. ULONGLONG Rr7; // Region register 7
  2323. // - Protection Key registers
  2324. ULONGLONG Pkr0; // Protection Key register 0
  2325. ULONGLONG Pkr1; // Protection Key register 1
  2326. ULONGLONG Pkr2; // Protection Key register 2
  2327. ULONGLONG Pkr3; // Protection Key register 3
  2328. ULONGLONG Pkr4; // Protection Key register 4
  2329. ULONGLONG Pkr5; // Protection Key register 5
  2330. ULONGLONG Pkr6; // Protection Key register 6
  2331. ULONGLONG Pkr7; // Protection Key register 7
  2332. ULONGLONG Pkr8; // Protection Key register 8
  2333. ULONGLONG Pkr9; // Protection Key register 9
  2334. ULONGLONG Pkr10; // Protection Key register 10
  2335. ULONGLONG Pkr11; // Protection Key register 11
  2336. ULONGLONG Pkr12; // Protection Key register 12
  2337. ULONGLONG Pkr13; // Protection Key register 13
  2338. ULONGLONG Pkr14; // Protection Key register 14
  2339. ULONGLONG Pkr15; // Protection Key register 15
  2340. // - Translation Lookaside buffers
  2341. ULONGLONG TrI0; // Instruction Translation Register 0
  2342. ULONGLONG TrI1; // Instruction Translation Register 1
  2343. ULONGLONG TrI2; // Instruction Translation Register 2
  2344. ULONGLONG TrI3; // Instruction Translation Register 3
  2345. ULONGLONG TrI4; // Instruction Translation Register 4
  2346. ULONGLONG TrI5; // Instruction Translation Register 5
  2347. ULONGLONG TrI6; // Instruction Translation Register 6
  2348. ULONGLONG TrI7; // Instruction Translation Register 7
  2349. ULONGLONG TrD0; // Data Translation Register 0
  2350. ULONGLONG TrD1; // Data Translation Register 1
  2351. ULONGLONG TrD2; // Data Translation Register 2
  2352. ULONGLONG TrD3; // Data Translation Register 3
  2353. ULONGLONG TrD4; // Data Translation Register 4
  2354. ULONGLONG TrD5; // Data Translation Register 5
  2355. ULONGLONG TrD6; // Data Translation Register 6
  2356. ULONGLONG TrD7; // Data Translation Register 7
  2357. // - Machine Specific Registers
  2358. ULONGLONG SrMSR0; // Machine Specific Register 0
  2359. ULONGLONG SrMSR1; // Machine Specific Register 1
  2360. ULONGLONG SrMSR2; // Machine Specific Register 2
  2361. ULONGLONG SrMSR3; // Machine Specific Register 3
  2362. ULONGLONG SrMSR4; // Machine Specific Register 4
  2363. ULONGLONG SrMSR5; // Machine Specific Register 5
  2364. ULONGLONG SrMSR6; // Machine Specific Register 6
  2365. ULONGLONG SrMSR7; // Machine Specific Register 7
  2366. } KSPECIAL_REGISTERS, *PKSPECIAL_REGISTERS;
  2367. //
  2368. // Processor State structure.
  2369. //
  2370. typedef struct _KPROCESSOR_STATE {
  2371. struct _CONTEXT ContextFrame;
  2372. struct _KSPECIAL_REGISTERS SpecialRegisters;
  2373. } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
  2374. #endif // _IA64_
  2375. // end_windbgkd
  2376. //
  2377. // DPC data structure definition.
  2378. //
  2379. typedef struct _KDPC_DATA {
  2380. LIST_ENTRY DpcListHead;
  2381. KSPIN_LOCK DpcLock;
  2382. volatile ULONG DpcQueueDepth;
  2383. ULONG DpcCount;
  2384. } KDPC_DATA, *PKDPC_DATA;
  2385. //
  2386. // Processor Control Block (PRCB)
  2387. //
  2388. #define PRCB_MINOR_VERSION 1
  2389. #define PRCB_MAJOR_VERSION 1
  2390. #define PRCB_BUILD_DEBUG 0x0001
  2391. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  2392. struct _RESTART_BLOCK;
  2393. typedef struct _KPRCB {
  2394. //
  2395. // Major and minor version numbers of the PCR.
  2396. //
  2397. USHORT MinorVersion;
  2398. USHORT MajorVersion;
  2399. //
  2400. // Start of the architecturally defined section of the PRCB. This section
  2401. // may be directly addressed by vendor/platform specific HAL code and will
  2402. // not change from version to version of NT.
  2403. //
  2404. //
  2405. struct _KTHREAD *CurrentThread;
  2406. struct _KTHREAD *RESTRICTED_POINTER NextThread;
  2407. struct _KTHREAD *IdleThread;
  2408. CCHAR Number;
  2409. CCHAR WakeIdle;
  2410. USHORT BuildType;
  2411. KAFFINITY SetMember;
  2412. struct _RESTART_BLOCK *RestartBlock;
  2413. ULONG_PTR PcrPage;
  2414. ULONG Spare0[4];
  2415. //
  2416. // Processor Idendification Registers.
  2417. //
  2418. ULONG ProcessorModel;
  2419. ULONG ProcessorRevision;
  2420. ULONG ProcessorFamily;
  2421. ULONG ProcessorArchRev;
  2422. ULONGLONG ProcessorSerialNumber;
  2423. ULONGLONG ProcessorFeatureBits;
  2424. UCHAR ProcessorVendorString[16];
  2425. //
  2426. // Space reserved for the system.
  2427. //
  2428. ULONGLONG SystemReserved[8];
  2429. //
  2430. // Space reserved for the HAL.
  2431. //
  2432. ULONGLONG HalReserved[16];
  2433. //
  2434. // End of the architecturally defined section of the PRCB.
  2435. // end_nthal
  2436. //
  2437. ULONG DpcTime;
  2438. ULONG InterruptTime;
  2439. ULONG KernelTime;
  2440. ULONG UserTime;
  2441. ULONG InterruptCount;
  2442. ULONG DispatchInterruptCount;
  2443. ULONG DebugDpcTime;
  2444. ULONG Spare1[4];
  2445. ULONG PageColor;
  2446. //
  2447. // MP information.
  2448. //
  2449. struct _KNODE *ParentNode;
  2450. KAFFINITY MultiThreadProcessorSet;
  2451. volatile ULONG IpiFrozen;
  2452. struct _KPROCESSOR_STATE ProcessorState;
  2453. PVOID Spare2[6];
  2454. //
  2455. // Per-processor data for various hot code which resides in the
  2456. // kernel image. Each processor is given it's own copy of the data
  2457. // to lessen the cache impact of sharing the data between multiple
  2458. // processors.
  2459. //
  2460. PVOID SpareHotData[2]; // Used by PerfSetLogging
  2461. //
  2462. // Cache manager performance counters.
  2463. // N.B. This is carefully aligned to be on a cache line boundary.
  2464. //
  2465. ULONG CcFastReadNoWait;
  2466. ULONG CcFastReadWait;
  2467. ULONG CcFastReadNotPossible;
  2468. ULONG CcCopyReadNoWait;
  2469. ULONG CcCopyReadWait;
  2470. ULONG CcCopyReadNoWaitMiss;
  2471. //
  2472. // Kernel performance counters.
  2473. //
  2474. ULONG KeAlignmentFixupCount;
  2475. ULONG KeContextSwitches;
  2476. ULONG KeDcacheFlushCount;
  2477. ULONG KeExceptionDispatchCount;
  2478. ULONG KeFirstLevelTbFills;
  2479. ULONG KeFloatingEmulationCount;
  2480. ULONG KeIcacheFlushCount;
  2481. ULONG KeSecondLevelTbFills;
  2482. ULONG KeSystemCalls;
  2483. //
  2484. // Reserved for future counters.
  2485. //
  2486. ULONG ReservedCounter[8];
  2487. //
  2488. // I/O IRP float.
  2489. //
  2490. LONG LookasideIrpFloat;
  2491. //
  2492. // Per processor lock queue entries.
  2493. //
  2494. // N.B. The following padding is such that the first lock entry falls in the
  2495. // last 16 bytes of a cache line. This makes the dispatcher lock and
  2496. // the other locks lie in separate cache lines.
  2497. //
  2498. ULONGLONG Spare3[34];
  2499. KSPIN_LOCK_QUEUE LockQueue[16];
  2500. ULONGLONG Spare4[2];
  2501. //
  2502. // Nonpaged per processor lookaside lists.
  2503. // N.B. This is carefully aligned to be on a cache line boundary.
  2504. //
  2505. PP_LOOKASIDE_LIST PPLookasideList[16];
  2506. //
  2507. // Nonpaged per processor small pool lookaside lists.
  2508. //
  2509. PP_LOOKASIDE_LIST PPNPagedLookasideList[POOL_SMALL_LISTS];
  2510. //
  2511. // Paged per processor small pool lookaside lists.
  2512. //
  2513. PP_LOOKASIDE_LIST PPPagedLookasideList[POOL_SMALL_LISTS];
  2514. //
  2515. // MP interprocessor request packet barrier.
  2516. //
  2517. // N.B. This is carefully allocated in a different cache line from
  2518. // the request packet.
  2519. //
  2520. volatile KAFFINITY PacketBarrier;
  2521. ULONGLONG Spare5[31];
  2522. //
  2523. // MP interprocessor request packet and summary.
  2524. //
  2525. // N.B. This is carefully aligned to be on a cache line boundary.
  2526. //
  2527. volatile PVOID CurrentPacket[3];
  2528. volatile KAFFINITY TargetSet;
  2529. volatile PKIPI_WORKER WorkerRoutine;
  2530. // N.B. Place MHz here so we can keep alignment and size
  2531. // of this structure unchanged.
  2532. ULONG MHz;
  2533. ULONG Spare6;
  2534. ULONGLONG Spare7[10];
  2535. //
  2536. // N.B. These two fields must be on a cache boundary and adjacent.
  2537. //
  2538. volatile ULONG RequestSummary;
  2539. volatile struct _KPRCB *SignalDone;
  2540. ULONGLONG Spare8[14];
  2541. //
  2542. // DPC listhead, counts, and batching parameters.
  2543. // N.B. This is carefully aligned to be on a cache line boundary.
  2544. //
  2545. KDPC_DATA DpcData[2];
  2546. ULONG MaximumDpcQueueDepth;
  2547. ULONG DpcRequestRate;
  2548. ULONG MinimumDpcRate;
  2549. ULONG DpcLastCount;
  2550. ULONG DpcInterruptRequested;
  2551. ULONG DpcThreadRequested;
  2552. ULONG DpcRoutineActive;
  2553. ULONG DpcThreadActive;
  2554. union {
  2555. ULONGLONG TimerHand; // On x86 this is 32 bits and can end up being zero
  2556. ULONGLONG TimerRequest; // for a timer request so two field are need.
  2557. }; // On IA64 we can make it the same.
  2558. ULONG ThreadDpcEnable;
  2559. ULONG QuantumEnd;
  2560. LONG DpcSetEventRequest;
  2561. ULONG AdjustDpcThreshold;
  2562. LARGE_INTEGER StartCount;
  2563. //
  2564. // DPC thread and generic call DPC.
  2565. // N.B. This is carefully aligned to be on a cache line boundary.
  2566. //
  2567. PVOID DpcThread;
  2568. KEVENT DpcEvent;
  2569. KDPC CallDpc;
  2570. volatile BOOLEAN IdleSchedule;
  2571. UCHAR Spare9[7];
  2572. KSPIN_LOCK PrcbLock;
  2573. SINGLE_LIST_ENTRY DeferredReadyListHead;
  2574. ULONG64 Spare10[1];
  2575. //
  2576. // Per-processor ready summary and ready queues.
  2577. //
  2578. // N.B. This is carefully aligned to be on a cache line boundary.
  2579. //
  2580. LIST_ENTRY WaitListHead;
  2581. ULONG ReadySummary;
  2582. ULONG SelectNextLast;
  2583. LIST_ENTRY DispatcherReadyListHead[MAXIMUM_PRIORITY];
  2584. ULONG64 Spare11[13];
  2585. //
  2586. // Debug & Processor Information
  2587. //
  2588. BOOLEAN SkipTick;
  2589. KIRQL DebuggerSavedIRQL;
  2590. //
  2591. // Processor ID from HAL (ACPI ID/EID).
  2592. //
  2593. USHORT ProcessorId;
  2594. //
  2595. // Processors power state
  2596. //
  2597. PROCESSOR_POWER_STATE PowerState;
  2598. // begin_nthal
  2599. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
  2600. // end_nthal
  2601. C_ASSERT(((FIELD_OFFSET(KPRCB, LockQueue) + sizeof(KSPIN_LOCK_QUEUE)) & (128 - 1)) == 0);
  2602. C_ASSERT((FIELD_OFFSET(KPRCB, PPLookasideList) & (128 - 1)) == 0);
  2603. C_ASSERT((FIELD_OFFSET(KPRCB, PPNPagedLookasideList) & (128 - 1)) == 0);
  2604. C_ASSERT((FIELD_OFFSET(KPRCB, PacketBarrier) & (128 - 1)) == 0);
  2605. C_ASSERT((FIELD_OFFSET(KPRCB, CurrentPacket) & (128 - 1)) == 0);
  2606. C_ASSERT((FIELD_OFFSET(KPRCB, RequestSummary) & (128 - 1)) == 0);
  2607. C_ASSERT((FIELD_OFFSET(KPRCB, DpcData) & (128 - 1)) == 0);
  2608. C_ASSERT(((FIELD_OFFSET(KPRCB, DpcRoutineActive)) & (1)) == 0);
  2609. C_ASSERT((FIELD_OFFSET(KPRCB, DpcThread) & (128 - 1)) == 0);
  2610. C_ASSERT((FIELD_OFFSET(KPRCB, WaitListHead) & (128 - 1)) == 0);
  2611. C_ASSERT((FIELD_OFFSET(KPRCB, CcFastReadNoWait) & (128 - 1)) == 0);
  2612. C_ASSERT(sizeof(KPRCB) < PAGE_SIZE);
  2613. // begin_nthal
  2614. //
  2615. // OS_MCA, OS_INIT HandOff State definitions
  2616. //
  2617. // Note: The following definitions *must* match the definions of the
  2618. // corresponding SAL Revision Hand-Off structures.
  2619. //
  2620. typedef struct _SAL_HANDOFF_STATE {
  2621. ULONGLONG PalProcEntryPoint;
  2622. ULONGLONG SalProcEntryPoint;
  2623. ULONGLONG SalGlobalPointer;
  2624. LONGLONG RendezVousResult;
  2625. ULONGLONG SalReturnAddress;
  2626. ULONGLONG MinStateSavePtr;
  2627. } SAL_HANDOFF_STATE, *PSAL_HANDOFF_STATE;
  2628. typedef struct _OS_HANDOFF_STATE {
  2629. ULONGLONG Result;
  2630. ULONGLONG SalGlobalPointer;
  2631. ULONGLONG MinStateSavePtr;
  2632. ULONGLONG SalReturnAddress;
  2633. ULONGLONG NewContextFlag;
  2634. } OS_HANDOFF_STATE, *POS_HANDOFF_STATE;
  2635. //
  2636. // per processor OS_MCA and OS_INIT resource structure
  2637. //
  2638. #define SER_EVENT_STACK_FRAME_ENTRIES 8
  2639. typedef struct _SAL_EVENT_RESOURCES {
  2640. SAL_HANDOFF_STATE SalToOsHandOff;
  2641. OS_HANDOFF_STATE OsToSalHandOff;
  2642. PVOID StateDump;
  2643. ULONGLONG StateDumpPhysical;
  2644. PVOID BackStore;
  2645. ULONGLONG BackStoreLimit;
  2646. PVOID Stack;
  2647. ULONGLONG StackLimit;
  2648. PULONGLONG PTOM;
  2649. ULONGLONG StackFrame[SER_EVENT_STACK_FRAME_ENTRIES];
  2650. PVOID EventPool;
  2651. ULONG EventPoolSize;
  2652. } SAL_EVENT_RESOURCES, *PSAL_EVENT_RESOURCES;
  2653. //
  2654. // PAL Mini-save area, used by MCA and INIT
  2655. //
  2656. typedef struct _PAL_MINI_SAVE_AREA {
  2657. ULONGLONG IntNats; // Nat bits for r1-r31
  2658. // r1-r31 in bits 1 thru 31.
  2659. ULONGLONG IntGp; // r1, volatile
  2660. ULONGLONG IntT0; // r2-r3, volatile
  2661. ULONGLONG IntT1; //
  2662. ULONGLONG IntS0; // r4-r7, preserved
  2663. ULONGLONG IntS1;
  2664. ULONGLONG IntS2;
  2665. ULONGLONG IntS3;
  2666. ULONGLONG IntV0; // r8, volatile
  2667. ULONGLONG IntT2; // r9-r11, volatile
  2668. ULONGLONG IntT3;
  2669. ULONGLONG IntT4;
  2670. ULONGLONG IntSp; // stack pointer (r12), special
  2671. ULONGLONG IntTeb; // teb (r13), special
  2672. ULONGLONG IntT5; // r14-r31, volatile
  2673. ULONGLONG IntT6;
  2674. ULONGLONG B0R16; // Bank 0 registers 16-31
  2675. ULONGLONG B0R17;
  2676. ULONGLONG B0R18;
  2677. ULONGLONG B0R19;
  2678. ULONGLONG B0R20;
  2679. ULONGLONG B0R21;
  2680. ULONGLONG B0R22;
  2681. ULONGLONG B0R23;
  2682. ULONGLONG B0R24;
  2683. ULONGLONG B0R25;
  2684. ULONGLONG B0R26;
  2685. ULONGLONG B0R27;
  2686. ULONGLONG B0R28;
  2687. ULONGLONG B0R29;
  2688. ULONGLONG B0R30;
  2689. ULONGLONG B0R31;
  2690. ULONGLONG IntT7; // Bank 1 registers 16-31
  2691. ULONGLONG IntT8;
  2692. ULONGLONG IntT9;
  2693. ULONGLONG IntT10;
  2694. ULONGLONG IntT11;
  2695. ULONGLONG IntT12;
  2696. ULONGLONG IntT13;
  2697. ULONGLONG IntT14;
  2698. ULONGLONG IntT15;
  2699. ULONGLONG IntT16;
  2700. ULONGLONG IntT17;
  2701. ULONGLONG IntT18;
  2702. ULONGLONG IntT19;
  2703. ULONGLONG IntT20;
  2704. ULONGLONG IntT21;
  2705. ULONGLONG IntT22;
  2706. ULONGLONG Preds; // predicates, preserved
  2707. ULONGLONG BrRp; // return pointer, b0, preserved
  2708. ULONGLONG RsRSC; // RSE configuration, volatile
  2709. ULONGLONG StIIP; // Interruption IP
  2710. ULONGLONG StIPSR; // Interruption Processor Status
  2711. ULONGLONG StIFS; // Interruption Function State
  2712. ULONGLONG XIP; // Event IP
  2713. ULONGLONG XPSR; // Event Processor Status
  2714. ULONGLONG XFS; // Event Function State
  2715. } PAL_MINI_SAVE_AREA, *PPAL_MINI_SAVE_AREA;
  2716. // begin_ntddk begin_ntosp
  2717. //
  2718. // Define Processor Control Region Structure.
  2719. //
  2720. #define PCR_MINOR_VERSION 1
  2721. #define PCR_MAJOR_VERSION 1
  2722. typedef struct _KPCR {
  2723. //
  2724. // Major and minor version numbers of the PCR.
  2725. //
  2726. ULONG MinorVersion;
  2727. ULONG MajorVersion;
  2728. //
  2729. // Start of the architecturally defined section of the PCR. This section
  2730. // may be directly addressed by vendor/platform specific HAL code and will
  2731. // not change from version to version of NT.
  2732. //
  2733. //
  2734. // First and second level cache parameters.
  2735. //
  2736. ULONG FirstLevelDcacheSize;
  2737. ULONG FirstLevelDcacheFillSize;
  2738. ULONG FirstLevelIcacheSize;
  2739. ULONG FirstLevelIcacheFillSize;
  2740. ULONG SecondLevelDcacheSize;
  2741. ULONG SecondLevelDcacheFillSize;
  2742. ULONG SecondLevelIcacheSize;
  2743. ULONG SecondLevelIcacheFillSize;
  2744. //
  2745. // Data cache alignment and fill size used for cache flushing and alignment.
  2746. // These fields are set to the larger of the first and second level data
  2747. // cache fill sizes.
  2748. //
  2749. ULONG DcacheAlignment;
  2750. ULONG DcacheFillSize;
  2751. //
  2752. // Instruction cache alignment and fill size used for cache flushing and
  2753. // alignment. These fields are set to the larger of the first and second
  2754. // level data cache fill sizes.
  2755. //
  2756. ULONG IcacheAlignment;
  2757. ULONG IcacheFillSize;
  2758. //
  2759. // Processor identification from PrId register.
  2760. //
  2761. ULONG ProcessorId;
  2762. //
  2763. // Profiling data.
  2764. //
  2765. ULONG ProfileInterval;
  2766. ULONG ProfileCount;
  2767. //
  2768. // Stall execution count and scale factor.
  2769. //
  2770. ULONG StallExecutionCount;
  2771. ULONG StallScaleFactor;
  2772. ULONG InterruptionCount;
  2773. //
  2774. // Space reserved for the system.
  2775. //
  2776. ULONGLONG SystemReserved[6];
  2777. //
  2778. // Space reserved for the HAL
  2779. //
  2780. ULONGLONG HalReserved[64];
  2781. //
  2782. // IRQL mapping tables.
  2783. //
  2784. UCHAR IrqlMask[64];
  2785. UCHAR IrqlTable[64];
  2786. //
  2787. // External Interrupt vectors.
  2788. //
  2789. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  2790. //
  2791. // Reserved interrupt vector mask.
  2792. //
  2793. ULONG ReservedVectors;
  2794. //
  2795. // Processor affinity mask.
  2796. //
  2797. KAFFINITY SetMember;
  2798. //
  2799. // Complement of the processor affinity mask.
  2800. //
  2801. KAFFINITY NotMember;
  2802. //
  2803. // Pointer to processor control block.
  2804. //
  2805. struct _KPRCB *Prcb;
  2806. //
  2807. // Shadow copy of Prcb->CurrentThread for fast access
  2808. //
  2809. struct _KTHREAD *CurrentThread;
  2810. //
  2811. // Processor number.
  2812. //
  2813. CCHAR Number; // Processor Number
  2814. // end_ntddk end_ntosp
  2815. CCHAR PollSlot; // Used by the clock routine track when we should break in.
  2816. UCHAR KernelDebugActive; // debug register active in kernel flag
  2817. UCHAR CurrentIrql; // Current IRQL
  2818. union {
  2819. USHORT SoftwareInterruptPending; // Software Interrupt Pending Flag
  2820. struct {
  2821. UCHAR ApcInterrupt; // 0x01 if APC int pending
  2822. UCHAR DispatchInterrupt; // 0x01 if dispatch int pending
  2823. };
  2824. };
  2825. //
  2826. // Address of per processor SAPIC EOI Table
  2827. //
  2828. PVOID EOITable;
  2829. //
  2830. // IA-64 Machine Check Events trackers
  2831. //
  2832. UCHAR InOsMca;
  2833. UCHAR InOsInit;
  2834. UCHAR InOsCmc;
  2835. UCHAR InOsCpe;
  2836. ULONG InOsULONG_Spare; // Spare ULONG
  2837. PSAL_EVENT_RESOURCES OsMcaResourcePtr;
  2838. PSAL_EVENT_RESOURCES OsInitResourcePtr;
  2839. //
  2840. // End of the architecturally defined section of the PCR. This section
  2841. // may be directly addressed by vendor/platform specific HAL code and will
  2842. // not change from version to version of NT.
  2843. //
  2844. // end_nthal
  2845. //
  2846. // OS Part
  2847. //
  2848. //
  2849. // Address of the thread who currently owns the high fp register set
  2850. //
  2851. struct _KTHREAD *HighFpOwner;
  2852. // Per processor kernel (ntoskrnl.exe) global pointer
  2853. ULONGLONG KernelGP;
  2854. // Per processor initial kernel stack for current thread
  2855. ULONGLONG InitialStack;
  2856. // Per processor pointer to kernel BSP
  2857. ULONGLONG InitialBStore;
  2858. // Per processor kernel stack limit
  2859. ULONGLONG StackLimit;
  2860. // Per processor kernel backing store limit
  2861. ULONGLONG BStoreLimit;
  2862. // Per processor panic kernel stack
  2863. ULONGLONG PanicStack;
  2864. //
  2865. // Save area for kernel entry/exit
  2866. //
  2867. ULONGLONG SavedIIM;
  2868. ULONGLONG SavedIFA;
  2869. KSPIN_LOCK FpbLock;
  2870. ULONGLONG ForwardProgressBuffer[16];
  2871. PVOID Pcb; // holds KPROCESS for MP region synchronization
  2872. //
  2873. // Nt page table base addresses
  2874. //
  2875. ULONGLONG PteUbase;
  2876. ULONGLONG PteKbase;
  2877. ULONGLONG PteSbase;
  2878. ULONGLONG PdeUbase;
  2879. ULONGLONG PdeKbase;
  2880. ULONGLONG PdeSbase;
  2881. ULONGLONG PdeUtbase;
  2882. ULONGLONG PdeKtbase;
  2883. ULONGLONG PdeStbase;
  2884. //
  2885. // The actual resources for the OS_INIT and OS_MCA handlers
  2886. // are placed at the end of the PCR structure so that auto
  2887. // can be used to get to get between the public and private
  2888. // sections of the PCR in the traps and context routines.
  2889. //
  2890. SAL_EVENT_RESOURCES OsMcaResource;
  2891. SAL_EVENT_RESOURCES OsInitResource;
  2892. // begin_nthal begin_ntddk begin_ntosp
  2893. } KPCR, *PKPCR;
  2894. // end_nthal end_ntddk end_ntosp
  2895. //
  2896. // Prototype for get current IRQL.
  2897. //
  2898. #if !(defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_) || defined(_NTOSP_)) && !defined(_BLDR_)
  2899. VOID
  2900. KiCheckForSoftwareInterrupt (
  2901. KIRQL RequestIrql
  2902. );
  2903. __forceinline
  2904. KIRQL
  2905. KeGetCurrentIrql()
  2906. /*++
  2907. Routine Description:
  2908. This function return the current IRQL.
  2909. Arguments:
  2910. None.
  2911. Return Value:
  2912. The current IRQL is returned as the function value.
  2913. --*/
  2914. {
  2915. return( KeGetPcr()->CurrentIrql);
  2916. }
  2917. __forceinline
  2918. VOID
  2919. KeLowerIrql (
  2920. IN KIRQL NewIrql
  2921. )
  2922. /*++
  2923. Routine Description:
  2924. This function lowers the IRQL to the specified value.
  2925. Arguments:
  2926. NewIrql - Supplies the new IRQL value.
  2927. Return Value:
  2928. None.
  2929. --*/
  2930. {
  2931. ASSERT(KeGetCurrentIrql() >= NewIrql);
  2932. __setReg( CV_IA64_SaTPR, (NewIrql << TPR_IRQL_SHIFT));
  2933. KeGetPcr()->CurrentIrql = NewIrql;
  2934. //
  2935. // If lowering below DISPATCH_LEVEL, check for pending
  2936. // software interrupts that could run now.
  2937. //
  2938. if (NewIrql < DISPATCH_LEVEL &&
  2939. NewIrql < KeGetPcr()->SoftwareInterruptPending ) {
  2940. KiCheckForSoftwareInterrupt(NewIrql);
  2941. }
  2942. }
  2943. #define KeRaiseIrql(a,b) *(b) = KfRaiseIrql(a)
  2944. __forceinline
  2945. KIRQL
  2946. KfRaiseIrql (
  2947. IN KIRQL NewIrql
  2948. )
  2949. /*++
  2950. Routine Description:
  2951. This function raises the current IRQL to the specified value and returns
  2952. the previous IRQL.
  2953. Arguments:
  2954. NewIrql (cl) - Supplies the new IRQL value.
  2955. Return Value:
  2956. The previous IRQL is retured as the function value.
  2957. --*/
  2958. {
  2959. KIRQL OldIrql;
  2960. OldIrql = KeGetCurrentIrql();
  2961. ASSERT(OldIrql <= NewIrql);
  2962. __setReg( CV_IA64_SaTPR, (NewIrql << TPR_IRQL_SHIFT));
  2963. KeGetPcr()->CurrentIrql = NewIrql;
  2964. return OldIrql;
  2965. }
  2966. __forceinline
  2967. KIRQL
  2968. KeRaiseIrqlToDpcLevel (
  2969. VOID
  2970. )
  2971. /*++
  2972. Routine Description:
  2973. This function raises the current IRQL to DPC_LEVEL and returns the
  2974. previous IRQL.
  2975. Arguments:
  2976. None.
  2977. Return Value:
  2978. The previous IRQL is retured as the function value.
  2979. --*/
  2980. {
  2981. KIRQL OldIrql;
  2982. OldIrql = KeGetCurrentIrql();
  2983. ASSERT(OldIrql <= DISPATCH_LEVEL);
  2984. __setReg( CV_IA64_SaTPR, (DISPATCH_LEVEL << TPR_IRQL_SHIFT));
  2985. KeGetPcr()->CurrentIrql = DISPATCH_LEVEL;
  2986. return OldIrql;
  2987. }
  2988. __forceinline
  2989. KIRQL
  2990. KeRaiseIrqlToSynchLevel (
  2991. VOID
  2992. )
  2993. /*++
  2994. Routine Description:
  2995. This function raises the current IRQL to SYNCH_LEVEL and returns the
  2996. previous IRQL.
  2997. Arguments:
  2998. Return Value:
  2999. The previous IRQL is retured as the function value.
  3000. --*/
  3001. {
  3002. KIRQL OldIrql;
  3003. OldIrql = KeGetCurrentIrql();
  3004. ASSERT(OldIrql <= SYNCH_LEVEL);
  3005. __setReg( CV_IA64_SaTPR, (SYNCH_LEVEL << TPR_IRQL_SHIFT));
  3006. KeGetPcr()->CurrentIrql = SYNCH_LEVEL;
  3007. return OldIrql;
  3008. }
  3009. #else
  3010. // begin_ntddk begin_wdm begin_ntosp begin_nthal
  3011. NTKERNELAPI
  3012. KIRQL
  3013. KeGetCurrentIrql();
  3014. NTKERNELAPI
  3015. VOID
  3016. KeLowerIrql (
  3017. IN KIRQL NewIrql
  3018. );
  3019. NTKERNELAPI
  3020. VOID
  3021. KeRaiseIrql (
  3022. IN KIRQL NewIrql,
  3023. OUT PKIRQL OldIrql
  3024. );
  3025. // end_wdm
  3026. NTKERNELAPI
  3027. KIRQL
  3028. KeRaiseIrqlToDpcLevel (
  3029. VOID
  3030. );
  3031. NTKERNELAPI
  3032. KIRQL
  3033. KeRaiseIrqlToSynchLevel (
  3034. VOID
  3035. );
  3036. // end_ntddk end_ntosp end_nthal
  3037. #endif
  3038. #define KeGetContextSwitches(Prcb) (Prcb)->KeContextSwitches
  3039. // begin_nthal
  3040. //
  3041. // Define the number of bits to shift to right justify the Page Table Index
  3042. // field of a PTE.
  3043. //
  3044. #define PTI_SHIFT PAGE_SHIFT
  3045. //
  3046. // Define the number of bits to shift to right justify the Page Directory Index
  3047. // field of a PTE.
  3048. //
  3049. #define PDI_SHIFT (PTI_SHIFT + PAGE_SHIFT - PTE_SHIFT)
  3050. #define PDI1_SHIFT (PDI_SHIFT + PAGE_SHIFT - PTE_SHIFT)
  3051. #define PDI_MASK ((1 << (PAGE_SHIFT - PTE_SHIFT)) - 1)
  3052. //
  3053. // Define the number of bits to shift to left to produce page table offset
  3054. // from page table index.
  3055. //
  3056. #define PTE_SHIFT 3
  3057. //
  3058. // Define the number of bits to shift to the right justify the Page Directory
  3059. // Table Entry field.
  3060. //
  3061. #define VHPT_PDE_BITS 40
  3062. //
  3063. // Define the RID for IO Port Space.
  3064. //
  3065. #define RR_IO_PORT 6
  3066. //
  3067. // The following definitions are required for the debugger data block.
  3068. //
  3069. // begin_ntddk begin_ntosp
  3070. //
  3071. // The highest user address reserves 64K bytes for a guard page. This
  3072. // the probing of address from kernel mode to only have to check the
  3073. // starting address for structures of 64k bytes or less.
  3074. //
  3075. extern NTKERNELAPI PVOID MmHighestUserAddress;
  3076. extern NTKERNELAPI PVOID MmSystemRangeStart;
  3077. extern NTKERNELAPI ULONG_PTR MmUserProbeAddress;
  3078. #define MM_HIGHEST_USER_ADDRESS MmHighestUserAddress
  3079. #define MM_USER_PROBE_ADDRESS MmUserProbeAddress
  3080. #define MM_SYSTEM_RANGE_START MmSystemRangeStart
  3081. //
  3082. // The lowest user address reserves the low 64k.
  3083. //
  3084. #define MM_LOWEST_USER_ADDRESS (PVOID)((ULONG_PTR)(UADDRESS_BASE+0x00010000))
  3085. // begin_wdm
  3086. #define MmGetProcedureAddress(Address) (Address)
  3087. #define MmLockPagableCodeSection(PLabelAddress) \
  3088. MmLockPagableDataSection((PVOID)(*((PULONGLONG)PLabelAddress)))
  3089. #define VRN_MASK 0xE000000000000000UI64 // Virtual Region Number mask
  3090. // end_ntddk end_wdm end_ntosp
  3091. #define MI_HIGHEST_USER_ADDRESS (PVOID) (ULONG_PTR)((UADDRESS_BASE + 0x6FC00000000 - 0x10000 - 1)) // highest user address
  3092. #define MI_USER_PROBE_ADDRESS ((ULONG_PTR)(UADDRESS_BASE + 0x6FC00000000UI64 - 0x10000)) // starting address of guard page
  3093. #define MI_SYSTEM_RANGE_START (PVOID) (UADDRESS_BASE + 0x6FC00000000) // start of system space
  3094. //
  3095. // Define the page table base and the page directory base for
  3096. // the TB miss routines and memory management.
  3097. //
  3098. //
  3099. // user/kernel page table base and top addresses
  3100. //
  3101. extern ULONG_PTR KiIA64VaSignedFill;
  3102. extern ULONG_PTR KiIA64PtaSign;
  3103. #define PTA_SIGN KiIA64PtaSign
  3104. #define VA_FILL KiIA64VaSignedFill
  3105. #define SADDRESS_BASE 0x2000000000000000UI64 // session base address
  3106. #define PTE_UBASE PCR->PteUbase
  3107. #define PTE_KBASE PCR->PteKbase
  3108. #define PTE_SBASE PCR->PteSbase
  3109. #define PTE_UTOP (PTE_UBASE|(((ULONG_PTR)1 << PDI1_SHIFT) - 1)) // top level PDR address (user)
  3110. #define PTE_KTOP (PTE_KBASE|(((ULONG_PTR)1 << PDI1_SHIFT) - 1)) // top level PDR address (kernel)
  3111. #define PTE_STOP (PTE_SBASE|(((ULONG_PTR)1 << PDI1_SHIFT) - 1)) // top level PDR address (session)
  3112. //
  3113. // Second level user and kernel PDR address
  3114. //
  3115. #define PDE_UBASE PCR->PdeUbase
  3116. #define PDE_KBASE PCR->PdeKbase
  3117. #define PDE_SBASE PCR->PdeSbase
  3118. #define PDE_UTOP (PDE_UBASE|(((ULONG_PTR)1 << PDI_SHIFT) - 1)) // second level PDR address (user)
  3119. #define PDE_KTOP (PDE_KBASE|(((ULONG_PTR)1 << PDI_SHIFT) - 1)) // second level PDR address (kernel)
  3120. #define PDE_STOP (PDE_SBASE|(((ULONG_PTR)1 << PDI_SHIFT) - 1)) // second level PDR address (session)
  3121. //
  3122. // 8KB first level user and kernel PDR address
  3123. //
  3124. #define PDE_UTBASE PCR->PdeUtbase
  3125. #define PDE_KTBASE PCR->PdeKtbase
  3126. #define PDE_STBASE PCR->PdeStbase
  3127. #define PDE_USELFMAP (PDE_UTBASE|(PAGE_SIZE - (1<<PTE_SHIFT))) // self mapped PPE address (user)
  3128. #define PDE_KSELFMAP (PDE_KTBASE|(PAGE_SIZE - (1<<PTE_SHIFT))) // self mapped PPE address (kernel)
  3129. #define PDE_SSELFMAP (PDE_STBASE|(PAGE_SIZE - (1<<PTE_SHIFT))) // self mapped PPE address (kernel)
  3130. #define PTE_BASE PTE_UBASE
  3131. #define PDE_BASE PDE_UBASE
  3132. #define PDE_TBASE PDE_UTBASE
  3133. #define PDE_SELFMAP PDE_USELFMAP
  3134. #define KSEG0_BASE (KADDRESS_BASE + 0x80000000) // base of kernel
  3135. #define KSEG2_BASE (KADDRESS_BASE + 0xA0000000) // end of kernel
  3136. #define KSEG3_BASE 0x8000000000000000UI64
  3137. #define KSEG3_LIMIT 0x8000100000000000UI64
  3138. #define KSEG4_BASE 0xA000000000000000UI64
  3139. #define KSEG4_LIMIT 0xA000100000000000UI64
  3140. //
  3141. //++
  3142. //PVOID
  3143. //KSEG_ADDRESS (
  3144. // IN ULONG PAGE
  3145. // );
  3146. //
  3147. // Routine Description:
  3148. //
  3149. // This macro returns a KSEG virtual address which maps the page.
  3150. //
  3151. // Arguments:
  3152. //
  3153. // PAGE - Supplies the physical page frame number
  3154. //
  3155. // Return Value:
  3156. //
  3157. // The address of the KSEG address
  3158. //
  3159. //--
  3160. #define KSEG_ADDRESS(PAGE) ((PVOID)(KSEG3_BASE | ((ULONG_PTR)(PAGE) << PAGE_SHIFT)))
  3161. #define KSEG4_ADDRESS(PAGE) ((PVOID)(KSEG4_BASE | ((ULONG_PTR)(PAGE) << PAGE_SHIFT)))
  3162. #define MAXIMUM_FWP_BUFFER_ENTRY 8
  3163. typedef struct _REGION_MAP_INFO {
  3164. ULONG RegionId;
  3165. ULONG PageSize;
  3166. ULONGLONG SequenceNumber;
  3167. } REGION_MAP_INFO, *PREGION_MAP_INFO;
  3168. // begin_ntddk begin_wdm
  3169. //
  3170. // The lowest address for system space.
  3171. //
  3172. #define MM_LOWEST_SYSTEM_ADDRESS ((PVOID)((ULONG_PTR)(KADDRESS_BASE + 0xC0C00000)))
  3173. // end_nthal end_ntddk end_wdm
  3174. #define SYSTEM_BASE (KADDRESS_BASE + 0xC3000000) // start of system space (no typecast)
  3175. //
  3176. // Define macro to initialize directory table base.
  3177. //
  3178. #define INITIALIZE_DIRECTORY_TABLE_BASE(dirbase, pfn) \
  3179. *((PULONGLONG)(dirbase)) = 0; \
  3180. ((PHARDWARE_PTE)(dirbase))->PageFrameNumber = pfn; \
  3181. ((PHARDWARE_PTE)(dirbase))->Accessed = 1; \
  3182. ((PHARDWARE_PTE)(dirbase))->Dirty = 1; \
  3183. ((PHARDWARE_PTE)(dirbase))->Cache = 0; \
  3184. ((PHARDWARE_PTE)(dirbase))->Write = 1; \
  3185. ((PHARDWARE_PTE)(dirbase))->Valid = 1;
  3186. //
  3187. // IA64 function definitions
  3188. //
  3189. //++
  3190. //
  3191. // BOOLEAN
  3192. // KiIsThreadNumericStateSaved(
  3193. // IN PKTHREAD Address
  3194. // )
  3195. //
  3196. // This call is used on a not running thread to see if it's numeric
  3197. // state has been saved in it's context information. On IA64 the
  3198. // numeric state is always saved.
  3199. //
  3200. //--
  3201. #define KiIsThreadNumericStateSaved(a) TRUE
  3202. //++
  3203. //
  3204. // VOID
  3205. // KiRundownThread(
  3206. // IN PKTHREAD Address
  3207. // )
  3208. //
  3209. //--
  3210. #define KiRundownThread(a)
  3211. //
  3212. // ia64 Feature bit definitions
  3213. //
  3214. #define KF_BRL 0x00000001 // processor supports long branch instruction.
  3215. //
  3216. // Define macro to test if x86 feature is present.
  3217. //
  3218. // N.B. All x86 features test TRUE on IA64 systems.
  3219. //
  3220. #define Isx86FeaturePresent(_f_) TRUE
  3221. // begin_nthal begin_ntddk begin_ntndis begin_wdm begin_ntosp
  3222. #endif // defined(_IA64_)
  3223. // end_nthal end_ntddk end_ntndis end_wdm end_ntosp
  3224. #endif // _IA64H_