Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2175 lines
45 KiB

  1. /*++
  2. Copyright (c) 1993 Digital Equipment Corporation
  3. Module Name:
  4. alpha.h
  5. Abstract:
  6. The Alpha hardware specific header file.
  7. Author:
  8. Joe Notarangelo 31-Mar-1992 (based on mips.h by Dave Cutler)
  9. Revision History:
  10. Jeff McLeman (mcleman) 21-Jul-1992
  11. Add bus types for ISA and EISA
  12. Thomas Van Baak (tvb) 9-Jul-1992
  13. Created proper Alpha Exception and Trap structure definitions.
  14. --*/
  15. #ifndef _ALPHAH_
  16. #define _ALPHAH_
  17. // begin_ntddk begin_wdm begin_nthal begin_ntndis begin_ntosp
  18. #if defined(_ALPHA_)
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. //
  23. // Types to use to contain PFNs and their counts.
  24. //
  25. typedef ULONG PFN_COUNT;
  26. typedef LONG_PTR SPFN_NUMBER, *PSPFN_NUMBER;
  27. typedef ULONG_PTR PFN_NUMBER, *PPFN_NUMBER;
  28. //
  29. // Define maximum size of flush multiple TB request.
  30. //
  31. #define FLUSH_MULTIPLE_MAXIMUM 16
  32. //
  33. // Indicate that the Alpha compiler supports the pragma textout construct.
  34. //
  35. #define ALLOC_PRAGMA 1
  36. // end_wdm
  37. #define POWER_LEVEL 7
  38. // end_ntndis end_ntosp
  39. // begin_wdm
  40. //
  41. // Include the Alpha instruction definitions
  42. //
  43. #include "alphaops.h"
  44. //
  45. // Include reference machine definitions.
  46. //
  47. #include "alpharef.h"
  48. // end_ntddk end_wdm
  49. //
  50. // Define intrinsic PAL calls and their prototypes
  51. //
  52. void __di(void);
  53. void __MB(void);
  54. void __dtbis(void *);
  55. void __ei(void);
  56. void *__rdpcr(void);
  57. void *__rdthread(void);
  58. void __ssir(unsigned long);
  59. unsigned char __swpirql(unsigned char);
  60. void __tbia(void);
  61. void __tbis(void *);
  62. void __tbisasn(void *, unsigned long);
  63. #if defined(_M_ALPHA) || defined(_M_AXP64)
  64. #pragma intrinsic(__di)
  65. #pragma intrinsic(__MB)
  66. #pragma intrinsic(__dtbis)
  67. #pragma intrinsic(__ei)
  68. #pragma intrinsic(__rdpcr)
  69. #pragma intrinsic(__rdthread)
  70. #pragma intrinsic(__ssir)
  71. #pragma intrinsic(__swpirql)
  72. #pragma intrinsic(__tbia)
  73. #pragma intrinsic(__tbis)
  74. #pragma intrinsic(__tbisasn)
  75. #endif
  76. //
  77. // Define Alpha Axp Processor Ids.
  78. //
  79. #if !defined(PROCESSOR_ALPHA_21064)
  80. #define PROCESSOR_ALPHA_21064 (21064)
  81. #endif // !PROCESSOR_ALPHA_21064
  82. #if !defined(PROCESSOR_ALPHA_21164)
  83. #define PROCESSOR_ALPHA_21164 (21164)
  84. #endif // !PROCESSOR_ALPHA_21164
  85. #if !defined(PROCESSOR_ALPHA_21066)
  86. #define PROCESSOR_ALPHA_21066 (21066)
  87. #endif // !PROCESSOR_ALPHA_21066
  88. #if !defined(PROCESSOR_ALPHA_21068)
  89. #define PROCESSOR_ALPHA_21068 (21068)
  90. #endif // !PROCESSOR_ALPHA_21068
  91. #if !defined(PROCESSOR_ALPHA_21164PC)
  92. #define PROCESSOR_ALPHA_21164PC (21165)
  93. #endif // !PROCESSOR_ALPHA_21164PC
  94. #if !defined(PROCESSOR_ALPHA_21264)
  95. #define PROCESSOR_ALPHA_21264 (21264)
  96. #endif // !PROCESSOR_ALPHA_21264
  97. // end_nthal
  98. //
  99. // Define Processor Control Region Structure.
  100. //
  101. typedef
  102. VOID
  103. (*PKTRAP_ROUTINE)(
  104. VOID
  105. );
  106. // begin_ntddk begin_nthal
  107. //
  108. // Define macro to generate import names.
  109. //
  110. #define IMPORT_NAME(name) __imp_##name
  111. //
  112. // Define length of interrupt vector table.
  113. //
  114. // begin_ntosp
  115. #define MAXIMUM_VECTOR 256
  116. //
  117. // Define bus error routine type.
  118. //
  119. struct _EXCEPTION_RECORD;
  120. struct _KEXCEPTION_FRAME;
  121. struct _KTRAP_FRAME;
  122. typedef
  123. BOOLEAN
  124. (*PKBUS_ERROR_ROUTINE) (
  125. IN struct _EXCEPTION_RECORD *ExceptionRecord,
  126. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  127. IN struct _KTRAP_FRAME *TrapFrame
  128. );
  129. #define PCR_MINOR_VERSION 1
  130. #define PCR_MAJOR_VERSION 1
  131. typedef struct _KPCR {
  132. //
  133. // Major and minor version numbers of the PCR.
  134. //
  135. ULONG MinorVersion;
  136. ULONG MajorVersion;
  137. //
  138. // Start of the architecturally defined section of the PCR. This section
  139. // may be directly addressed by vendor/platform specific PAL/HAL code and will
  140. // not change from version to version of NT.
  141. //
  142. // PALcode information.
  143. //
  144. ULONGLONG PalBaseAddress;
  145. ULONG PalMajorVersion;
  146. ULONG PalMinorVersion;
  147. ULONG PalSequenceVersion;
  148. ULONG PalMajorSpecification;
  149. ULONG PalMinorSpecification;
  150. //
  151. // Firmware restart information.
  152. //
  153. ULONGLONG FirmwareRestartAddress;
  154. PVOID RestartBlock;
  155. //
  156. // Reserved per-processor region for the PAL (3K-8 bytes).
  157. //
  158. ULONGLONG PalReserved[383];
  159. //
  160. // Alignment fixup count updated by PAL and read by kernel.
  161. //
  162. ULONGLONG PalAlignmentFixupCount;
  163. //
  164. // Panic Stack Address.
  165. //
  166. PVOID PanicStack;
  167. //
  168. // Processor parameters.
  169. //
  170. ULONG ProcessorType;
  171. ULONG ProcessorRevision;
  172. ULONG PhysicalAddressBits;
  173. ULONG MaximumAddressSpaceNumber;
  174. ULONG PageSize;
  175. ULONG FirstLevelDcacheSize;
  176. ULONG FirstLevelDcacheFillSize;
  177. ULONG FirstLevelIcacheSize;
  178. ULONG FirstLevelIcacheFillSize;
  179. //
  180. // System Parameters.
  181. //
  182. ULONG FirmwareRevisionId;
  183. UCHAR SystemType[8];
  184. ULONG SystemVariant;
  185. ULONG SystemRevision;
  186. UCHAR SystemSerialNumber[16];
  187. ULONG CycleClockPeriod;
  188. ULONG SecondLevelCacheSize;
  189. ULONG SecondLevelCacheFillSize;
  190. ULONG ThirdLevelCacheSize;
  191. ULONG ThirdLevelCacheFillSize;
  192. ULONG FourthLevelCacheSize;
  193. ULONG FourthLevelCacheFillSize;
  194. //
  195. // Pointer to processor control block.
  196. //
  197. struct _KPRCB *Prcb;
  198. //
  199. // Processor identification.
  200. //
  201. CCHAR Number;
  202. KAFFINITY SetMember;
  203. //
  204. // Reserved per-processor region for the HAL (.5K bytes).
  205. //
  206. ULONGLONG HalReserved[64];
  207. //
  208. // IRQL mapping tables.
  209. //
  210. ULONG IrqlTable[8];
  211. #define SFW_IMT_ENTRIES 4
  212. #define HDW_IMT_ENTRIES 128
  213. struct _IRQLMASK {
  214. USHORT IrqlTableIndex; // synchronization irql level
  215. USHORT IDTIndex; // vector in IDT
  216. } IrqlMask[SFW_IMT_ENTRIES + HDW_IMT_ENTRIES];
  217. //
  218. // Interrupt Dispatch Table (IDT).
  219. //
  220. PKINTERRUPT_ROUTINE InterruptRoutine[MAXIMUM_VECTOR];
  221. //
  222. // Reserved vectors mask, these vectors cannot be attached to via
  223. // standard interrupt objects.
  224. //
  225. ULONG ReservedVectors;
  226. //
  227. // Complement of processor affinity mask.
  228. //
  229. KAFFINITY NotMember;
  230. ULONG InterruptInProgress;
  231. ULONG DpcRequested;
  232. //
  233. // Pointer to machine check handler
  234. //
  235. PKBUS_ERROR_ROUTINE MachineCheckError;
  236. //
  237. // DPC Stack.
  238. //
  239. PVOID DpcStack;
  240. //
  241. // End of the architecturally defined section of the PCR. This section
  242. // may be directly addressed by vendor/platform specific HAL code and will
  243. // not change from version to version of NT. Some of these values are
  244. // reserved for chip-specific palcode.
  245. // end_ntddk end_nthal
  246. //
  247. //
  248. // Start of the operating system release dependent section of the PCR.
  249. // This section may change from release to release and should not be
  250. // addressed by vendor/platform specific HAL code.
  251. ULONG Spare1;
  252. //
  253. // Current process id.
  254. //
  255. ULONG CurrentPid;
  256. //
  257. // Spare field.
  258. //
  259. ULONG Spare2;
  260. //
  261. // System service dispatch start and end address used by get/set context.
  262. //
  263. ULONG_PTR SystemServiceDispatchStart;
  264. ULONG_PTR SystemServiceDispatchEnd;
  265. //
  266. // Pointer to Idle thread.
  267. //
  268. struct _KTHREAD *IdleThread;
  269. } KPCR, *PKPCR; // ntddk nthal
  270. // end_ntosp
  271. // Define Processor Status Register structure
  272. //
  273. typedef struct _PSR {
  274. ULONG MODE: 1;
  275. ULONG INTERRUPT_ENABLE: 1;
  276. ULONG IRQL: 3;
  277. } PSR, *PPSR;
  278. //
  279. // Define Interrupt Enable Register structure
  280. //
  281. typedef struct _IE {
  282. ULONG SoftwareInterruptEnables: 2;
  283. ULONG HardwareInterruptEnables: 6;
  284. } IE, *PIE;
  285. #define HARDWARE_PTE_DIRTY_MASK 0x4
  286. #if defined(_AXP64_)
  287. #define _HARDWARE_PTE_WORKING_SET_BITS 14
  288. typedef struct _HARDWARE_PTE {
  289. ULONGLONG Valid : 1;
  290. ULONGLONG Reserved1 : 1;
  291. ULONGLONG FaultOnWrite : 1;
  292. ULONGLONG Reserved2 : 1;
  293. ULONGLONG Global : 1;
  294. ULONGLONG GranularityHint : 2;
  295. ULONGLONG Reserved3 : 1;
  296. ULONGLONG KernelReadAccess : 1;
  297. ULONGLONG UserReadAccess : 1;
  298. ULONGLONG Reserved4 : 2;
  299. ULONGLONG KernelWriteAccess : 1;
  300. ULONGLONG UserWriteAccess : 1;
  301. ULONGLONG Reserved5 : 2;
  302. ULONGLONG Write : 1;
  303. ULONGLONG CopyOnWrite: 1;
  304. ULONGLONG SoftwareWsIndex : _HARDWARE_PTE_WORKING_SET_BITS;
  305. ULONGLONG PageFrameNumber : 32;
  306. } HARDWARE_PTE, *PHARDWARE_PTE;
  307. //
  308. // Define initialize page directory base
  309. //
  310. #define INITIALIZE_DIRECTORY_TABLE_BASE(dirbase, pfn) \
  311. *((PULONGLONG)(dirbase)) = 0; \
  312. ((PHARDWARE_PTE)(dirbase))->PageFrameNumber = pfn; \
  313. ((PHARDWARE_PTE)(dirbase))->Write = 1; \
  314. ((PHARDWARE_PTE)(dirbase))->KernelReadAccess = 1; \
  315. ((PHARDWARE_PTE)(dirbase))->KernelWriteAccess = 1; \
  316. ((PHARDWARE_PTE)(dirbase))->Global = 0; \
  317. ((PHARDWARE_PTE)(dirbase))->FaultOnWrite = 0; \
  318. ((PHARDWARE_PTE)(dirbase))->Valid = 1;
  319. #else
  320. typedef struct _HARDWARE_PTE {
  321. ULONG Valid: 1;
  322. ULONG Owner: 1;
  323. ULONG Dirty: 1;
  324. ULONG reserved: 1;
  325. ULONG Global: 1;
  326. ULONG GranularityHint: 2;
  327. ULONG Write: 1;
  328. ULONG CopyOnWrite: 1;
  329. ULONG PageFrameNumber: 23;
  330. } HARDWARE_PTE, *PHARDWARE_PTE;
  331. //
  332. // Define initialize page directory base
  333. //
  334. #define INITIALIZE_DIRECTORY_TABLE_BASE(dirbase, pfn) \
  335. ((PHARDWARE_PTE)(dirbase))->PageFrameNumber = pfn; \
  336. ((PHARDWARE_PTE)(dirbase))->Global = 0; \
  337. ((PHARDWARE_PTE)(dirbase))->Dirty = 1; \
  338. ((PHARDWARE_PTE)(dirbase))->Valid = 1;
  339. #endif
  340. // begin_nthal
  341. //
  342. // Define some constants for bus type
  343. //
  344. #define MACHINE_TYPE_ISA 0
  345. #define MACHINE_TYPE_EISA 2
  346. //
  347. // Define pointer to Processor Control Registers
  348. //
  349. // begin_ntddk
  350. #define PCR ((PKPCR)__rdpcr())
  351. // begin_ntosp
  352. #if defined(_AXP64_)
  353. #define KI_USER_SHARED_DATA 0xffffffffff000000UI64
  354. #else
  355. #define KI_USER_SHARED_DATA 0xff000000UL
  356. #endif
  357. #define SharedUserData ((KUSER_SHARED_DATA * const) KI_USER_SHARED_DATA)
  358. // begin_wdm
  359. //
  360. // length of dispatch code in interrupt template
  361. //
  362. #define DISPATCH_LENGTH 4
  363. //
  364. // Define IRQL levels across the architecture.
  365. //
  366. #define PASSIVE_LEVEL 0
  367. #define LOW_LEVEL 0
  368. #define APC_LEVEL 1
  369. #define DISPATCH_LEVEL 2
  370. #define HIGH_LEVEL 7
  371. #define SYNCH_LEVEL (IPI_LEVEL-1)
  372. // end_ntddk end_wdm end_nthal end_ntosp
  373. #define KiProfileIrql PROFILE_LEVEL // enable portable code
  374. //
  375. // Define interrupt levels that cannot be connected
  376. //
  377. #define ILLEGAL_LEVEL ( (1<<0) | (1<<APC_LEVEL) | (1<<DISPATCH_LEVEL) | \
  378. (1<<CLOCK_LEVEL) | (1<<IPI_LEVEL) )
  379. //
  380. // Sanitize FPCR and PSR based on processor mode.
  381. //
  382. // ## tvb&jn - need to replace these with proper macros.
  383. //
  384. #define SANITIZE_FPCR(fpcr, mode) (fpcr)
  385. //
  386. // Define SANITIZE_PSR for Alpha.
  387. //
  388. // If kernel mode, then caller specifies psr
  389. //
  390. // If user mode, then
  391. // force mode bit to user (1)
  392. // force interrupt enable bit to true (1)
  393. // force irql to 0
  394. //
  395. // In both cases insure that extraneous bits are not set
  396. //
  397. #define SANITIZE_PSR(psr, mode) \
  398. ( ((mode) == KernelMode) ? \
  399. (psr & 0x3f) : \
  400. (0x3) )
  401. // begin_nthal begin_ntosp
  402. //
  403. // Exception frame
  404. //
  405. // This frame is established when handling an exception. It provides a place
  406. // to save all nonvolatile registers. The volatile registers will already
  407. // have been saved in a trap frame.
  408. //
  409. // The layout of the record conforms to a standard call frame since it is
  410. // used as such. Thus it contains a place to save a return address and is
  411. // padded so that it is EXACTLY a multiple of 32 bytes in length.
  412. //
  413. //
  414. // N.B - the 32-byte alignment is more stringent than required by the
  415. // calling standard (which requires 16-byte alignment), the 32-byte alignment
  416. // is established for performance reasons in the interaction with the PAL.
  417. //
  418. typedef struct _KEXCEPTION_FRAME {
  419. ULONGLONG IntRa; // return address register, ra
  420. ULONGLONG FltF2; // nonvolatile floating registers, f2 - f9
  421. ULONGLONG FltF3;
  422. ULONGLONG FltF4;
  423. ULONGLONG FltF5;
  424. ULONGLONG FltF6;
  425. ULONGLONG FltF7;
  426. ULONGLONG FltF8;
  427. ULONGLONG FltF9;
  428. ULONGLONG IntS0; // nonvolatile integer registers, s0 - s5
  429. ULONGLONG IntS1;
  430. ULONGLONG IntS2;
  431. ULONGLONG IntS3;
  432. ULONGLONG IntS4;
  433. ULONGLONG IntS5;
  434. ULONGLONG IntFp; // frame pointer register, fp/s6
  435. ULONGLONG SwapReturn;
  436. ULONG Psr; // processor status
  437. ULONG Fill[5]; // padding for 32-byte stack frame alignment
  438. // N.B. - Ulongs from the filler section are used
  439. // in ctxsw.s - do not delete
  440. } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
  441. // end_ntosp
  442. //
  443. // Trap Frame
  444. //
  445. // This frame is established when handling a trap. It provides a place to
  446. // save all volatile registers. The nonvolatile registers are saved in an
  447. // exception frame or through the normal C calling conventions for saved
  448. // registers.
  449. //
  450. // The layout of the record conforms to a standard call frame since it is
  451. // used as such. Thus it contains a place to save a return address and is
  452. // padded so that it is EXACTLY a multiple of 32 bytes in length.
  453. //
  454. //
  455. // N.B - the 32-byte alignment is more stringent than required by the
  456. // calling standard (which requires 16-byte alignment), the 32-byte alignment
  457. // is established for performance reasons in the interaction with the PAL.
  458. //
  459. typedef struct _KTRAP_FRAME {
  460. //
  461. // Fields saved in the PALcode.
  462. //
  463. ULONGLONG IntSp; // $30: stack pointer register, sp
  464. ULONGLONG Fir; // (fault instruction) continuation address
  465. ULONG Psr; // processor status
  466. ULONG Fill1[1]; // unused
  467. ULONGLONG IntFp; // $15: frame pointer register, fp/s6
  468. ULONGLONG IntA0; // $16: argument registers, a0 - a3
  469. ULONGLONG IntA1; // $17:
  470. ULONGLONG IntA2; // $18:
  471. ULONGLONG IntA3; // $19:
  472. ULONGLONG IntRa; // $26: return address register, ra
  473. ULONGLONG IntGp; // $29: global pointer register, gp
  474. UCHAR ExceptionRecord[(sizeof(EXCEPTION_RECORD) + 15) & (~15)];
  475. //
  476. // Volatile integer registers, s0 - s5 are nonvolatile.
  477. //
  478. ULONGLONG IntV0; // $0: return value register, v0
  479. ULONGLONG IntT0; // $1: temporary registers, t0 - t7
  480. ULONGLONG IntT1; // $2:
  481. ULONGLONG IntT2; // $3:
  482. ULONGLONG IntT3; // $4:
  483. ULONGLONG IntT4; // $5:
  484. ULONGLONG IntT5; // $6:
  485. ULONGLONG IntT6; // $7:
  486. ULONGLONG IntT7; // $8:
  487. ULONGLONG IntT8; // $22: temporary registers, t8 - t11
  488. ULONGLONG IntT9; // $23:
  489. ULONGLONG IntT10; // $24:
  490. ULONGLONG IntT11; // $25:
  491. ULONGLONG IntT12; // $27: temporary register, t12
  492. ULONGLONG IntAt; // $28: assembler temporary register, at
  493. ULONGLONG IntA4; // $20: remaining argument registers a4 - a5
  494. ULONGLONG IntA5; // $21:
  495. //
  496. // Volatile floating point registers, f2 - f9 are nonvolatile.
  497. //
  498. ULONGLONG FltF0; // $f0:
  499. ULONGLONG Fpcr; // floating point control register
  500. ULONGLONG FltF1; // $f1:
  501. ULONGLONG FltF10; // $f10: temporary registers, $f10 - $f30
  502. ULONGLONG FltF11; // $f11:
  503. ULONGLONG FltF12; // $f12:
  504. ULONGLONG FltF13; // $f13:
  505. ULONGLONG FltF14; // $f14:
  506. ULONGLONG FltF15; // $f15:
  507. ULONGLONG FltF16; // $f16:
  508. ULONGLONG FltF17; // $f17:
  509. ULONGLONG FltF18; // $f18:
  510. ULONGLONG FltF19; // $f19:
  511. ULONGLONG FltF20; // $f20:
  512. ULONGLONG FltF21; // $f21:
  513. ULONGLONG FltF22; // $f22:
  514. ULONGLONG FltF23; // $f23:
  515. ULONGLONG FltF24; // $f24:
  516. ULONGLONG FltF25; // $f25:
  517. ULONGLONG FltF26; // $f26:
  518. ULONGLONG FltF27; // $f27:
  519. ULONGLONG FltF28; // $f28:
  520. ULONGLONG FltF29; // $f29:
  521. ULONGLONG FltF30; // $f30:
  522. ULONG OldIrql; // Previous Irql.
  523. ULONG PreviousMode; // Previous Mode.
  524. ULONG_PTR TrapFrame; //
  525. ULONG Fill2[3]; // padding for 32-byte stack frame alignment
  526. } KTRAP_FRAME, *PKTRAP_FRAME;
  527. #define KTRAP_FRAME_LENGTH ((sizeof(KTRAP_FRAME) + 15) & ~15)
  528. #define KTRAP_FRAME_ALIGN (16)
  529. #define KTRAP_FRAME_ROUND (KTRAP_FRAME_ALIGN - 1)
  530. //
  531. // Firmware Frame
  532. //
  533. // The firmware frame is similar to the trap frame, but is built by the PAL
  534. // code that is active when the OS Loader is running. It does not contain an
  535. // exception record or NT style exception information.
  536. //
  537. // Type field defintions and parameters.
  538. //
  539. #define FW_EXC_MCHK 0xdec0 // p1=icPerrStat, p2=dcPerrStat
  540. #define FW_EXC_ARITH 0xdec1 // p1=excSum, p2=excMask
  541. #define FW_EXC_INTERRUPT 0xdec2 // p1=isr, p2=ipl, p3=intid
  542. #define FW_EXC_DFAULT 0xdec3 // p1=sp
  543. #define FW_EXC_ITBMISS 0xdec4 // none
  544. #define FW_EXC_ITBACV 0xdec5 // none
  545. #define FW_EXC_NDTBMISS 0xdec6 // p1=sp
  546. #define FW_EXC_PDTBMISS 0xdec7 // p1=sp
  547. #define FW_EXC_UNALIGNED 0xdec8 // p1=sp
  548. #define FW_EXC_OPCDEC 0xdec9 // p1=sp
  549. #define FW_EXC_FEN 0xdeca // p1=icsr
  550. #define FW_EXC_HALT 0xdecb // not used
  551. #define FW_EXC_BPT 0xdecc // p1=0 - user, p1=1 - kernel, p1=type - call kdbg
  552. #define FW_EXC_GENTRAP 0xdecd // p1=gentrap code
  553. #define FW_EXC_HALT_INTERRUPT 0xdece // p1=isr, p2=ipl, p3=intid
  554. typedef struct _FIRMWARE_FRAME {
  555. ULONGLONG Type;
  556. ULONGLONG Param1;
  557. ULONGLONG Param2;
  558. ULONGLONG Param3;
  559. ULONGLONG Param4;
  560. ULONGLONG Param5;
  561. ULONGLONG Psr;
  562. ULONGLONG Mmcsr;
  563. ULONGLONG Va;
  564. ULONGLONG Fir;
  565. ULONGLONG IntV0;
  566. ULONGLONG IntT0;
  567. ULONGLONG IntT1;
  568. ULONGLONG IntT2;
  569. ULONGLONG IntT3;
  570. ULONGLONG IntT4;
  571. ULONGLONG IntT5;
  572. ULONGLONG IntT6;
  573. ULONGLONG IntT7;
  574. ULONGLONG IntS0;
  575. ULONGLONG IntS1;
  576. ULONGLONG IntS2;
  577. ULONGLONG IntS3;
  578. ULONGLONG IntS4;
  579. ULONGLONG IntS5;
  580. ULONGLONG IntFp;
  581. ULONGLONG IntA0;
  582. ULONGLONG IntA1;
  583. ULONGLONG IntA2;
  584. ULONGLONG IntA3;
  585. ULONGLONG IntA4;
  586. ULONGLONG IntA5;
  587. ULONGLONG IntT8;
  588. ULONGLONG IntT9;
  589. ULONGLONG IntT10;
  590. ULONGLONG IntT11;
  591. ULONGLONG IntRa;
  592. ULONGLONG IntT12;
  593. ULONGLONG IntAt;
  594. ULONGLONG IntGp;
  595. ULONGLONG IntSp;
  596. ULONGLONG IntZero;
  597. ULONGLONG FltF0;
  598. ULONGLONG FltF1;
  599. ULONGLONG FltF2;
  600. ULONGLONG FltF3;
  601. ULONGLONG FltF4;
  602. ULONGLONG FltF5;
  603. ULONGLONG FltF6;
  604. ULONGLONG FltF7;
  605. ULONGLONG FltF8;
  606. ULONGLONG FltF9;
  607. ULONGLONG FltF10;
  608. ULONGLONG FltF11;
  609. ULONGLONG FltF12;
  610. ULONGLONG FltF13;
  611. ULONGLONG FltF14;
  612. ULONGLONG FltF15;
  613. ULONGLONG FltF16;
  614. ULONGLONG FltF17;
  615. ULONGLONG FltF18;
  616. ULONGLONG FltF19;
  617. ULONGLONG FltF20;
  618. ULONGLONG FltF21;
  619. ULONGLONG FltF22;
  620. ULONGLONG FltF23;
  621. ULONGLONG FltF24;
  622. ULONGLONG FltF25;
  623. ULONGLONG FltF26;
  624. ULONGLONG FltF27;
  625. ULONGLONG FltF28;
  626. ULONGLONG FltF29;
  627. ULONGLONG FltF30;
  628. ULONGLONG FltF31;
  629. } FIRMWARE_FRAME, *PFIRMWARE_FRAME;
  630. #define FIRMWARE_FRAME_LENGTH sizeof(FIRMWARE_FRAME)
  631. //
  632. // The frame saved by KiCallUserMode is defined here to allow
  633. // the kernel debugger to trace the entire kernel stack
  634. // when usermode callouts are pending.
  635. //
  636. typedef struct _KCALLOUT_FRAME {
  637. ULONGLONG F2; // saved floating registers f2 - f9
  638. ULONGLONG F3;
  639. ULONGLONG F4;
  640. ULONGLONG F5;
  641. ULONGLONG F6;
  642. ULONGLONG F7;
  643. ULONGLONG F8;
  644. ULONGLONG F9;
  645. ULONGLONG S0; // saved integer registers s0 - s5
  646. ULONGLONG S1;
  647. ULONGLONG S2;
  648. ULONGLONG S3;
  649. ULONGLONG S4;
  650. ULONGLONG S5;
  651. ULONGLONG FP;
  652. ULONGLONG CbStk; // saved callback stack address
  653. ULONGLONG InStk; // saved initial stack address
  654. ULONGLONG TrFr; // saved callback trap frame address
  655. ULONGLONG TrFir;
  656. ULONGLONG Ra; // saved return address
  657. ULONGLONG A0; // saved argument registers a0-a2
  658. ULONGLONG A1;
  659. } KCALLOUT_FRAME, *PKCALLOUT_FRAME;
  660. typedef struct _UCALLOUT_FRAME {
  661. PVOID Buffer;
  662. ULONG Length;
  663. ULONG ApiNumber;
  664. ULONG Pad;
  665. ULONGLONG Sp;
  666. ULONGLONG Ra;
  667. } UCALLOUT_FRAME, *PUCALLOUT_FRAME;
  668. //
  669. // Define Machine Check Status code that is passed in the exception
  670. // record for a machine check exception.
  671. //
  672. typedef struct _MCHK_STATUS {
  673. ULONG Correctable: 1;
  674. ULONG Retryable: 1;
  675. } MCHK_STATUS, *PMCHK_STATUS;
  676. //
  677. // Define the MCES register (Machine Check Error Summary).
  678. //
  679. typedef struct _MCES {
  680. ULONG MachineCheck: 1;
  681. ULONG SystemCorrectable: 1;
  682. ULONG ProcessorCorrectable: 1;
  683. ULONG DisableProcessorCorrectable: 1;
  684. ULONG DisableSystemCorrectable: 1;
  685. ULONG DisableMachineChecks: 1;
  686. } MCES, *PMCES;
  687. // end_nthal
  688. // begin_ntddk begin_wdm begin_ntosp
  689. //
  690. // Non-volatile floating point state
  691. //
  692. typedef struct _KFLOATING_SAVE {
  693. ULONGLONG Fpcr;
  694. ULONGLONG SoftFpcr;
  695. ULONG Reserved1; // These reserved words are here to make it
  696. ULONG Reserved2; // the same size as i386/WDM.
  697. ULONG Reserved3;
  698. ULONG Reserved4;
  699. } KFLOATING_SAVE, *PKFLOATING_SAVE;
  700. // end_ntddk end_wdm end_ntosp
  701. //
  702. // Define Alpha status code aliases. These are internal to PALcode and
  703. // kernel trap handling.
  704. //
  705. #define STATUS_ALPHA_FLOATING_NOT_IMPLEMENTED STATUS_ILLEGAL_FLOAT_CONTEXT
  706. #define STATUS_ALPHA_ARITHMETIC_EXCEPTION STATUS_FLOAT_STACK_CHECK
  707. #define STATUS_ALPHA_GENTRAP STATUS_INSTRUCTION_MISALIGNMENT
  708. //
  709. // Define status code for bad virtual address. This status differs from
  710. // those above in that it will be forwarded to the offending code. In lieu
  711. // of defining a new status code, we wlll alias this to an access violation.
  712. // Code can distinguish this error from an access violation by checking
  713. // the number of parameters: a standard access violation has 2 parameters,
  714. // while a non-canonical virtual address access violation will have 3
  715. // parameters (the third parameter is the upper 32-bits of the non-canonical
  716. // virtual address.
  717. //
  718. #define STATUS_ALPHA_BAD_VIRTUAL_ADDRESS STATUS_ACCESS_VIOLATION
  719. // begin_nthal begin_ntosp
  720. //
  721. // Define the halt reason codes.
  722. //
  723. #define AXP_HALT_REASON_HALT 0
  724. #define AXP_HALT_REASON_REBOOT 1
  725. #define AXP_HALT_REASON_RESTART 2
  726. #define AXP_HALT_REASON_POWERFAIL 3
  727. #define AXP_HALT_REASON_POWEROFF 4
  728. #define AXP_HALT_REASON_PALMCHK 6
  729. #define AXP_HALT_REASON_DBLMCHK 7
  730. // Processor State frame: Before a processor freezes itself, it
  731. // dumps the processor state to the processor state frame for
  732. // debugger to examine. This is used by KeFreezeExecution and
  733. // KeUnfreezeExecution routines.
  734. //
  735. typedef struct _KPROCESSOR_STATE {
  736. struct _CONTEXT ContextFrame;
  737. } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
  738. // begin_ntddk
  739. //
  740. // Processor Control Block (PRCB)
  741. //
  742. #define PRCB_MINOR_VERSION 1
  743. #define PRCB_MAJOR_VERSION 2
  744. #define PRCB_BUILD_DEBUG 0x0001
  745. #define PRCB_BUILD_UNIPROCESSOR 0x0002
  746. typedef struct _KPRCB {
  747. //
  748. // Major and minor version numbers of the PCR.
  749. //
  750. USHORT MinorVersion;
  751. USHORT MajorVersion;
  752. //
  753. // Start of the architecturally defined section of the PRCB. This section
  754. // may be directly addressed by vendor/platform specific HAL code and will
  755. // not change from version to version of NT.
  756. //
  757. struct _KTHREAD *CurrentThread;
  758. struct _KTHREAD *NextThread;
  759. struct _KTHREAD *IdleThread;
  760. CCHAR Number;
  761. CCHAR Reserved;
  762. USHORT BuildType;
  763. KAFFINITY SetMember;
  764. struct _RESTART_BLOCK *RestartBlock;
  765. //
  766. // End of the architecturally defined section of the PRCB. This section
  767. // may be directly addressed by vendor/platform specific HAL code and will
  768. // not change from version to version of NT.
  769. //
  770. // end_ntddk end_nthal
  771. ULONG InterruptCount;
  772. ULONG DpcTime;
  773. ULONG InterruptTime;
  774. ULONG KernelTime;
  775. ULONG UserTime;
  776. KDPC QuantumEndDpc;
  777. //
  778. // Address of PCR.
  779. //
  780. PKPCR Pcr;
  781. //
  782. // MP Information.
  783. //
  784. struct _KNODE * ParentNode; // Node this processor is a member of
  785. PVOID Spare3;
  786. volatile ULONG IpiFrozen;
  787. struct _KPROCESSOR_STATE ProcessorState;
  788. ULONG LastDpcCount;
  789. ULONG DpcBypassCount;
  790. ULONG SoftwareInterrupts;
  791. PKTRAP_FRAME InterruptTrapFrame;
  792. ULONG ApcBypassCount;
  793. ULONG DispatchInterruptCount;
  794. ULONG DebugDpcTime;
  795. PVOID Spares[6];
  796. //
  797. // Spares.
  798. //
  799. PVOID MoreSpares[3];
  800. PKIPI_COUNTS IpiCounts;
  801. //
  802. // Per-processor data for various hot code which resides in the
  803. // kernel image. We give each processor it's own copy of the data
  804. // to lessen the caching impact of sharing the data between multiple
  805. // processors.
  806. //
  807. //
  808. // Spares (formerly fsrtl filelock free lists)
  809. //
  810. PVOID SpareHotData[2];
  811. //
  812. // Cache manager performance counters.
  813. //
  814. ULONG CcFastReadNoWait;
  815. ULONG CcFastReadWait;
  816. ULONG CcFastReadNotPossible;
  817. ULONG CcCopyReadNoWait;
  818. ULONG CcCopyReadWait;
  819. ULONG CcCopyReadNoWaitMiss;
  820. //
  821. // Kernel performance counters.
  822. //
  823. ULONG KeAlignmentFixupCount;
  824. ULONG KeContextSwitches;
  825. ULONG KeDcacheFlushCount;
  826. ULONG KeExceptionDispatchCount;
  827. ULONG KeFirstLevelTbFills;
  828. ULONG KeFloatingEmulationCount;
  829. ULONG KeIcacheFlushCount;
  830. ULONG KeSecondLevelTbFills;
  831. ULONG KeSystemCalls;
  832. ULONG KeByteWordEmulationCount;
  833. //
  834. // Reserved for future counters.
  835. //
  836. ULONG ReservedCounter[1];
  837. //
  838. // I/O system per processor single entry lookaside lists.
  839. //
  840. PVOID SmallIrpFreeEntry;
  841. PVOID LargeIrpFreeEntry;
  842. PVOID MdlFreeEntry;
  843. //
  844. // Object manager per processor single entry lookaside lists.
  845. //
  846. PVOID CreateInfoFreeEntry;
  847. PVOID NameBufferFreeEntry;
  848. //
  849. // Cache manager per processor single entry lookaside lists.
  850. //
  851. PVOID SharedCacheMapEntry;
  852. //
  853. // Spares (formerly fsrtl filelock free lists)
  854. //
  855. #if defined(_AXP64_)
  856. PVOID MoreSpareHotData[1];
  857. #else
  858. PVOID MoreSpareHotData[2];
  859. #endif
  860. //
  861. // Nonpaged per processor lookaside lists.
  862. //
  863. PP_LOOKASIDE_LIST PPLookasideList[16];
  864. //
  865. // Nonpaged per processor small pool lookaside lists.
  866. //
  867. PP_LOOKASIDE_LIST PPNPagedLookasideList[POOL_SMALL_LISTS];
  868. //
  869. // Paged per processor small pool lookaside lists.
  870. //
  871. PP_LOOKASIDE_LIST PPPagedLookasideList[POOL_SMALL_LISTS];
  872. //
  873. // Per processor lock queue entries.
  874. //
  875. KSPIN_LOCK_QUEUE LockQueue[16];
  876. //
  877. // Reserved Pad.
  878. //
  879. #if defined(_AXP64_)
  880. UCHAR ReservedPad[(20 * 8) - 4];
  881. #else
  882. UCHAR ReservedPad[(24 * 8) - 4];
  883. #endif
  884. //
  885. // MP interprocessor request packet barrier.
  886. //
  887. // N.B. This is carefully allocated in a different cache line from
  888. // the request packet.
  889. //
  890. volatile ULONG PacketBarrier;
  891. //
  892. // MP interprocessor request packet and summary.
  893. //
  894. // N.B. This is carefully aligned to be on a cache line boundary.
  895. //
  896. volatile PVOID CurrentPacket[3];
  897. volatile KAFFINITY TargetSet;
  898. volatile PKIPI_WORKER WorkerRoutine;
  899. ULONG CachePad1[11];
  900. //
  901. // N.B. These two longwords must be on a quadword boundary and adjacent.
  902. //
  903. volatile ULONGLONG RequestSummary;
  904. //
  905. // Spare counters.
  906. //
  907. ULONG Spare4[14];
  908. ULONG DpcInterruptRequested;
  909. ULONG Spare5[17];
  910. ULONG CachePad2[1];
  911. ULONG PageColor;
  912. ULONG MaximumDpcQueueDepth;
  913. ULONG MinimumDpcRate;
  914. ULONG AdjustDpcThreshold;
  915. ULONG DpcRequestRate;
  916. LARGE_INTEGER StartCount;
  917. //
  918. // DPC list head, spinlock, and count.
  919. //
  920. LIST_ENTRY DpcListHead;
  921. KSPIN_LOCK DpcLock;
  922. ULONG DpcCount;
  923. ULONG QuantumEnd;
  924. ULONG DpcRoutineActive;
  925. ULONG DpcQueueDepth;
  926. BOOLEAN SkipTick;
  927. //
  928. // Processor's power state
  929. //
  930. PROCESSOR_POWER_STATE PowerState;
  931. } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB; // ntddk nthal
  932. // begin_ntddk begin_wdm begin_nthal begin_ntndis
  933. //
  934. // I/O space read and write macros.
  935. //
  936. // These have to be actual functions on Alpha, because we need
  937. // to shift the VA and OR in the BYTE ENABLES.
  938. //
  939. // These can become INLINEs if we require that ALL Alpha systems shift
  940. // the same number of bits and have the SAME byte enables.
  941. //
  942. // The READ/WRITE_REGISTER_* calls manipulate I/O registers in MEMORY space?
  943. //
  944. // The READ/WRITE_PORT_* calls manipulate I/O registers in PORT space?
  945. //
  946. NTHALAPI
  947. UCHAR
  948. READ_REGISTER_UCHAR(
  949. PUCHAR Register
  950. );
  951. NTHALAPI
  952. USHORT
  953. READ_REGISTER_USHORT(
  954. PUSHORT Register
  955. );
  956. NTHALAPI
  957. ULONG
  958. READ_REGISTER_ULONG(
  959. PULONG Register
  960. );
  961. NTHALAPI
  962. VOID
  963. READ_REGISTER_BUFFER_UCHAR(
  964. PUCHAR Register,
  965. PUCHAR Buffer,
  966. ULONG Count
  967. );
  968. NTHALAPI
  969. VOID
  970. READ_REGISTER_BUFFER_USHORT(
  971. PUSHORT Register,
  972. PUSHORT Buffer,
  973. ULONG Count
  974. );
  975. NTHALAPI
  976. VOID
  977. READ_REGISTER_BUFFER_ULONG(
  978. PULONG Register,
  979. PULONG Buffer,
  980. ULONG Count
  981. );
  982. NTHALAPI
  983. VOID
  984. WRITE_REGISTER_UCHAR(
  985. PUCHAR Register,
  986. UCHAR Value
  987. );
  988. NTHALAPI
  989. VOID
  990. WRITE_REGISTER_USHORT(
  991. PUSHORT Register,
  992. USHORT Value
  993. );
  994. NTHALAPI
  995. VOID
  996. WRITE_REGISTER_ULONG(
  997. PULONG Register,
  998. ULONG Value
  999. );
  1000. NTHALAPI
  1001. VOID
  1002. WRITE_REGISTER_BUFFER_UCHAR(
  1003. PUCHAR Register,
  1004. PUCHAR Buffer,
  1005. ULONG Count
  1006. );
  1007. NTHALAPI
  1008. VOID
  1009. WRITE_REGISTER_BUFFER_USHORT(
  1010. PUSHORT Register,
  1011. PUSHORT Buffer,
  1012. ULONG Count
  1013. );
  1014. NTHALAPI
  1015. VOID
  1016. WRITE_REGISTER_BUFFER_ULONG(
  1017. PULONG Register,
  1018. PULONG Buffer,
  1019. ULONG Count
  1020. );
  1021. NTHALAPI
  1022. UCHAR
  1023. READ_PORT_UCHAR(
  1024. PUCHAR Port
  1025. );
  1026. NTHALAPI
  1027. USHORT
  1028. READ_PORT_USHORT(
  1029. PUSHORT Port
  1030. );
  1031. NTHALAPI
  1032. ULONG
  1033. READ_PORT_ULONG(
  1034. PULONG Port
  1035. );
  1036. NTHALAPI
  1037. VOID
  1038. READ_PORT_BUFFER_UCHAR(
  1039. PUCHAR Port,
  1040. PUCHAR Buffer,
  1041. ULONG Count
  1042. );
  1043. NTHALAPI
  1044. VOID
  1045. READ_PORT_BUFFER_USHORT(
  1046. PUSHORT Port,
  1047. PUSHORT Buffer,
  1048. ULONG Count
  1049. );
  1050. NTHALAPI
  1051. VOID
  1052. READ_PORT_BUFFER_ULONG(
  1053. PULONG Port,
  1054. PULONG Buffer,
  1055. ULONG Count
  1056. );
  1057. NTHALAPI
  1058. VOID
  1059. WRITE_PORT_UCHAR(
  1060. PUCHAR Port,
  1061. UCHAR Value
  1062. );
  1063. NTHALAPI
  1064. VOID
  1065. WRITE_PORT_USHORT(
  1066. PUSHORT Port,
  1067. USHORT Value
  1068. );
  1069. NTHALAPI
  1070. VOID
  1071. WRITE_PORT_ULONG(
  1072. PULONG Port,
  1073. ULONG Value
  1074. );
  1075. NTHALAPI
  1076. VOID
  1077. WRITE_PORT_BUFFER_UCHAR(
  1078. PUCHAR Port,
  1079. PUCHAR Buffer,
  1080. ULONG Count
  1081. );
  1082. NTHALAPI
  1083. VOID
  1084. WRITE_PORT_BUFFER_USHORT(
  1085. PUSHORT Port,
  1086. PUSHORT Buffer,
  1087. ULONG Count
  1088. );
  1089. NTHALAPI
  1090. VOID
  1091. WRITE_PORT_BUFFER_ULONG(
  1092. PULONG Port,
  1093. PULONG Buffer,
  1094. ULONG Count
  1095. );
  1096. // end_ntndis end_wdm
  1097. //
  1098. // Define Interlocked operation result values.
  1099. //
  1100. #define RESULT_ZERO 0
  1101. #define RESULT_NEGATIVE 1
  1102. #define RESULT_POSITIVE 2
  1103. //
  1104. // Interlocked result type is portable, but its values are machine specific.
  1105. // Constants for value are in i386.h, mips.h, etc.
  1106. //
  1107. typedef enum _INTERLOCKED_RESULT {
  1108. ResultNegative = RESULT_NEGATIVE,
  1109. ResultZero = RESULT_ZERO,
  1110. ResultPositive = RESULT_POSITIVE
  1111. } INTERLOCKED_RESULT;
  1112. //
  1113. // Convert portable interlock interfaces to architecture specific interfaces.
  1114. //
  1115. #define ExInterlockedIncrementLong(Addend, Lock) \
  1116. ExAlphaInterlockedIncrementLong(Addend)
  1117. #define ExInterlockedDecrementLong(Addend, Lock) \
  1118. ExAlphaInterlockedDecrementLong(Addend)
  1119. #define ExInterlockedExchangeUlong(Target, Value, Lock) \
  1120. ExAlphaInterlockedExchangeUlong(Target, Value)
  1121. NTKERNELAPI
  1122. INTERLOCKED_RESULT
  1123. ExAlphaInterlockedIncrementLong (
  1124. IN PLONG Addend
  1125. );
  1126. NTKERNELAPI
  1127. INTERLOCKED_RESULT
  1128. ExAlphaInterlockedDecrementLong (
  1129. IN PLONG Addend
  1130. );
  1131. NTKERNELAPI
  1132. ULONG
  1133. ExAlphaInterlockedExchangeUlong (
  1134. IN PULONG Target,
  1135. IN ULONG Value
  1136. );
  1137. // begin_wdm
  1138. #if defined(_M_ALPHA) && !defined(RC_INVOKED)
  1139. #define InterlockedIncrement _InterlockedIncrement
  1140. #define InterlockedDecrement _InterlockedDecrement
  1141. #define InterlockedExchange _InterlockedExchange
  1142. #define InterlockedExchangeAdd _InterlockedExchangeAdd
  1143. LONG
  1144. InterlockedIncrement (
  1145. IN OUT PLONG Addend
  1146. );
  1147. LONG
  1148. InterlockedDecrement (
  1149. IN OUT PLONG Addend
  1150. );
  1151. LONG
  1152. InterlockedExchange (
  1153. IN OUT PLONG Target,
  1154. LONG Value
  1155. );
  1156. #if defined(_M_AXP64)
  1157. #define InterlockedCompareExchange _InterlockedCompareExchange
  1158. #define InterlockedCompareExchange64 _InterlockedCompareExchange64
  1159. #define InterlockedExchangePointer _InterlockedExchangePointer
  1160. #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
  1161. #define InterlockedExchange64 _InterlockedExchange64
  1162. LONG
  1163. InterlockedCompareExchange (
  1164. IN OUT PLONG Destination,
  1165. IN LONG ExChange,
  1166. IN LONG Comperand
  1167. );
  1168. LONGLONG
  1169. InterlockedCompareExchange64 (
  1170. IN OUT PLONGLONG Destination,
  1171. IN LONGLONG ExChange,
  1172. IN LONGLONG Comperand
  1173. );
  1174. PVOID
  1175. InterlockedExchangePointer (
  1176. IN OUT PVOID *Target,
  1177. IN PVOID Value
  1178. );
  1179. PVOID
  1180. InterlockedCompareExchangePointer (
  1181. IN OUT PVOID *Destination,
  1182. IN PVOID ExChange,
  1183. IN PVOID Comperand
  1184. );
  1185. LONGLONG
  1186. InterlockedExchange64(
  1187. IN OUT PLONGLONG Target,
  1188. IN LONGLONG Value
  1189. );
  1190. #pragma intrinsic(_InterlockedCompareExchange64)
  1191. #pragma intrinsic(_InterlockedExchangePointer)
  1192. #pragma intrinsic(_InterlockedCompareExchangePointer)
  1193. #pragma intrinsic(_InterlockedExchange64)
  1194. #else
  1195. #define InterlockedExchangePointer(Target, Value) \
  1196. (PVOID)InterlockedExchange((PLONG)(Target), (LONG)(Value))
  1197. #define InterlockedCompareExchange(Destination, ExChange, Comperand) \
  1198. (LONG)_InterlockedCompareExchange((PVOID *)(Destination), (PVOID)(ExChange), (PVOID)(Comperand))
  1199. #define InterlockedCompareExchangePointer(Destination, ExChange, Comperand) \
  1200. _InterlockedCompareExchange(Destination, ExChange, Comperand)
  1201. PVOID
  1202. _InterlockedCompareExchange (
  1203. IN OUT PVOID *Destination,
  1204. IN PVOID ExChange,
  1205. IN PVOID Comperand
  1206. );
  1207. NTKERNELAPI
  1208. LONGLONG
  1209. InterlockedCompareExchange64 (
  1210. IN OUT PLONGLONG Destination,
  1211. IN LONGLONG Exchange,
  1212. IN LONGLONG Comperand
  1213. );
  1214. NTKERNELAPI
  1215. LONGLONG
  1216. ExpInterlockedCompareExchange64 (
  1217. IN OUT PLONGLONG Destination,
  1218. IN PLONGLONG Exchange,
  1219. IN PLONGLONG Comperand
  1220. );
  1221. #endif
  1222. LONG
  1223. InterlockedExchangeAdd(
  1224. IN OUT PLONG Addend,
  1225. IN LONG Value
  1226. );
  1227. #pragma intrinsic(_InterlockedIncrement)
  1228. #pragma intrinsic(_InterlockedDecrement)
  1229. #pragma intrinsic(_InterlockedExchange)
  1230. #pragma intrinsic(_InterlockedExchangeAdd)
  1231. #pragma intrinsic(_InterlockedCompareExchange)
  1232. #endif
  1233. // there is a lot of other stuff that could go in here
  1234. // probe macros
  1235. // others
  1236. // end_ntddk end_wdm end_nthal end_ntosp
  1237. //
  1238. // Intrinsic interlocked functions.
  1239. //
  1240. // begin_ntddk begin_wdm begin_nthal begin_ntndis begin_ntosp
  1241. //
  1242. // Define the page size for the Alpha ev4 and lca as 8k.
  1243. //
  1244. #define PAGE_SIZE 0x2000
  1245. //
  1246. // Define the number of trailing zeroes in a page aligned virtual address.
  1247. // This is used as the shift count when shifting virtual addresses to
  1248. // virtual page numbers.
  1249. //
  1250. #define PAGE_SHIFT 13L
  1251. // end_ntddk end_wdm end_nthal end_ntndis
  1252. //
  1253. // Define the number of bits to shift to right justify the Page Directory Index
  1254. // field of a PTE.
  1255. //
  1256. #if defined(_AXP64_)
  1257. #define PDI_SHIFT 23
  1258. #define PDI1_SHIFT 33
  1259. #define PDI2_SHIFT 23
  1260. #define PDI_MASK 0x3ff
  1261. #else
  1262. #define PDI_SHIFT 24
  1263. #endif
  1264. //
  1265. // Define the number of bits to shift to right justify the Page Table Index
  1266. // field of a PTE.
  1267. //
  1268. #define PTI_SHIFT 13
  1269. //
  1270. // Define the maximum address space number allowable for the architecture.
  1271. //
  1272. #define ALPHA_AXP_MAXIMUM_ASN 0xffffffff
  1273. // begin_ntddk begin_nthal
  1274. //
  1275. // The highest user address reserves 64K bytes for a guard page. This is so
  1276. // the probing of addresses from kernel mode only have to check the
  1277. // starting address for structures of 64K bytes or less.
  1278. //
  1279. #if defined(_AXP64_)
  1280. #define MM_HIGHEST_USER_ADDRESS (PVOID)0x3FFFFFEFFFF // highest user address
  1281. #define MM_USER_PROBE_ADDRESS 0x3FFFFFF0000UI64 // guard page address
  1282. #define MM_SYSTEM_RANGE_START (PVOID)0xFFFFFC0000000000 // start of system space
  1283. #else
  1284. #define MM_HIGHEST_USER_ADDRESS (PVOID)0x7FFEFFFF // highest user address
  1285. #define MM_USER_PROBE_ADDRESS 0x7FFF0000 // starting address of guard page
  1286. #define MM_SYSTEM_RANGE_START (PVOID)KSEG0_BASE // start of system space
  1287. #endif
  1288. //
  1289. // The following definitions are required for the debugger data block.
  1290. //
  1291. extern PVOID MmHighestUserAddress;
  1292. extern PVOID MmSystemRangeStart;
  1293. extern ULONG_PTR MmUserProbeAddress;
  1294. //
  1295. // The lowest user address reserves the low 64k.
  1296. //
  1297. #define MM_LOWEST_USER_ADDRESS (PVOID)0x00010000
  1298. // begin_wdm
  1299. #define MmGetProcedureAddress(Address) (Address)
  1300. #define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
  1301. // end_ntddk end_wdm end_nthal
  1302. //
  1303. // Define the page table base and the page directory base for
  1304. // the TB miss routines and memory management.
  1305. //
  1306. #if defined(_AXP64_)
  1307. #define PDE_TBASE 0xFFFFFE0180600000UI64 // first level PDR address
  1308. #define PDE_SELFMAP 0xFFFFFE0180601800UI64 // first level PDR self map address
  1309. #define PDE_UBASE 0xFFFFFE0180000000UI64 // user second level PDR address
  1310. #define PDE_KBASE 0xFFFFFE01807FE000UI64 // kernel second level PDR address
  1311. #define PDE_BASE PDE_KBASE // kernel second level PDR address
  1312. #define PTE_BASE 0xFFFFFE0000000000UI64 // page table address
  1313. #define PDE64_BASE 0xFFFFFE0180600000UI64 // first level PDR address
  1314. #define PTE64_BASE 0xFFFFFE0000000000UI64 // page table address
  1315. #define VA_SHIFT (63 - 42) // address sign extend shift count
  1316. #else
  1317. #define PDE_BASE (ULONG)0xC0180000 // first level PDR address
  1318. #define PDE_SELFMAP (ULONG)0xC0180300 // first level PDR self map address
  1319. #define PTE_BASE (ULONG)0xC0000000 // page table address
  1320. #define PDE64_BASE (ULONG)0xC0184000 // first level 64-bit PDR address
  1321. #define PTE64_BASE (ULONG)0xC2000000 // 64-bit page table address
  1322. #endif
  1323. // end_ntosp
  1324. //
  1325. // Generate kernel segment physical address.
  1326. //
  1327. #if defined(_AXP64_)
  1328. #define KSEG_ADDRESS(FrameNumber) \
  1329. ((PVOID)(KSEG43_BASE | ((ULONG_PTR)(FrameNumber) << PAGE_SHIFT)))
  1330. #else
  1331. #define KSEG_ADDRESS(FrameNumber) \
  1332. ((PVOID)(KSEG0_BASE | ((ULONG)(FrameNumber) << PAGE_SHIFT)))
  1333. #endif
  1334. // begin_ntddk begin_wdm
  1335. //
  1336. // The lowest address for system space.
  1337. //
  1338. #if defined(_AXP64_)
  1339. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xFFFFFE0200000000
  1340. #else
  1341. #define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
  1342. #endif
  1343. // end_ntddk end_wdm
  1344. #if defined(_AXP64_)
  1345. #define SYSTEM_BASE 0xFFFFFE0200000000 // start of system space (no typecast)
  1346. #else
  1347. #define SYSTEM_BASE 0xc0800000 // start of system space (no typecast)
  1348. #endif
  1349. // begin_nthal begin_ntddk begin_wdm begin_ntosp
  1350. //
  1351. // Define prototypes to access PCR values
  1352. //
  1353. NTKERNELAPI
  1354. KIRQL
  1355. KeGetCurrentIrql();
  1356. // end_nthal end_ntddk end_wdm
  1357. #if defined(_M_ALPHA)
  1358. #define KeGetCurrentThread() ((struct _KTHREAD *) __rdthread())
  1359. #endif
  1360. // begin_ntddk begin_wdm
  1361. NTSTATUS
  1362. KeSaveFloatingPointState (
  1363. OUT PKFLOATING_SAVE FloatSave
  1364. );
  1365. NTSTATUS
  1366. KeRestoreFloatingPointState (
  1367. IN PKFLOATING_SAVE FloatSave
  1368. );
  1369. // end_ntddk end_wdm
  1370. // begin_nthal
  1371. #define KeGetPreviousMode() (KeGetCurrentThread()->PreviousMode)
  1372. // end_ntosp
  1373. #define KeGetDcacheFillSize() PCR->FirstLevelDcacheFillSize
  1374. //
  1375. // Test if executing DPC.
  1376. //
  1377. BOOLEAN
  1378. KeIsExecutingDpc (
  1379. VOID
  1380. );
  1381. //
  1382. // Return interrupt trap frame
  1383. //
  1384. PKTRAP_FRAME
  1385. KeGetInterruptTrapFrame(
  1386. VOID
  1387. );
  1388. // begin_ntddk begin_ntosp
  1389. //
  1390. // Get address of current PRCB.
  1391. //
  1392. #define KeGetCurrentPrcb() (PCR->Prcb)
  1393. //
  1394. // Get current processor number.
  1395. //
  1396. #define KeGetCurrentProcessorNumber() KeGetCurrentPrcb()->Number
  1397. // end_ntddk end_ntosp
  1398. //
  1399. // Define interface to get pcr address
  1400. //
  1401. PKPCR KeGetPcr(VOID);
  1402. // end_nthal
  1403. //
  1404. // Data cache, instruction cache, I/O buffer, and write buffer flush routine
  1405. // prototypes.
  1406. //
  1407. VOID
  1408. KeSweepDcache (
  1409. IN BOOLEAN AllProcessors
  1410. );
  1411. #define KeSweepCurrentDcache() \
  1412. HalSweepDcache();
  1413. VOID
  1414. KeSweepIcache (
  1415. IN BOOLEAN AllProcessors
  1416. );
  1417. VOID
  1418. KeSweepIcacheRange (
  1419. IN BOOLEAN AllProcessors,
  1420. IN PVOID BaseAddress,
  1421. IN ULONG_PTR Length
  1422. );
  1423. #define KeSweepCurrentIcache() \
  1424. HalSweepIcache();
  1425. VOID
  1426. KeFlushIcacheRange (
  1427. IN BOOLEAN AllProcessors,
  1428. IN PVOID BaseAddress,
  1429. IN ULONG_PTR Length
  1430. );
  1431. // begin_ntddk begin_wdm begin_ntndis begin_nthal begin_ntosp
  1432. //
  1433. // Cache and write buffer flush functions.
  1434. //
  1435. VOID
  1436. KeFlushIoBuffers (
  1437. IN PMDL Mdl,
  1438. IN BOOLEAN ReadOperation,
  1439. IN BOOLEAN DmaOperation
  1440. );
  1441. // end_ntddk end_wdm end_ntndis end_ntosp
  1442. //
  1443. // Clock, profile, and interprocessor interrupt functions.
  1444. //
  1445. struct _KEXCEPTION_FRAME;
  1446. struct _KTRAP_FRAME;
  1447. NTKERNELAPI
  1448. VOID
  1449. KeIpiInterrupt (
  1450. IN struct _KTRAP_FRAME *TrapFrame
  1451. );
  1452. #define KeYieldProcessor()
  1453. NTKERNELAPI
  1454. VOID
  1455. KeProfileInterrupt (
  1456. VOID
  1457. );
  1458. // begin_ntosp
  1459. NTKERNELAPI
  1460. VOID
  1461. KeProfileInterruptWithSource (
  1462. IN KPROFILE_SOURCE ProfileSource
  1463. );
  1464. // end_ntosp
  1465. NTKERNELAPI
  1466. VOID
  1467. KeUpdateRunTime (
  1468. VOID
  1469. );
  1470. NTKERNELAPI
  1471. VOID
  1472. KeUpdateSystemTime (
  1473. IN ULONG TimeIncrement
  1474. );
  1475. //
  1476. // The following function prototypes are exported for use in MP HALs.
  1477. //
  1478. #if defined(NT_UP)
  1479. #define KiAcquireSpinLock(SpinLock)
  1480. #else
  1481. VOID
  1482. KiAcquireSpinLock (
  1483. IN PKSPIN_LOCK SpinLock
  1484. );
  1485. #endif
  1486. #if defined(NT_UP)
  1487. #define KiReleaseSpinLock(SpinLock)
  1488. #else
  1489. VOID
  1490. KiReleaseSpinLock (
  1491. IN PKSPIN_LOCK SpinLock
  1492. );
  1493. #endif
  1494. // end_nthal
  1495. //
  1496. // KeTestSpinLock may be used to spin at low IRQL until the lock is
  1497. // available. The IRQL must then be raised and the lock acquired with
  1498. // KeTryToAcquireSpinLock. If that fails, lower the IRQL and start again.
  1499. //
  1500. #if defined(NT_UP)
  1501. #define KeTestSpinLock(SpinLock) (TRUE)
  1502. #else
  1503. BOOLEAN
  1504. KeTestSpinLock (
  1505. IN PKSPIN_LOCK SpinLock
  1506. );
  1507. #endif
  1508. //
  1509. // Fill TB entry.
  1510. //
  1511. #define KeFillEntryTb(Pte, Virtual, Invalid) \
  1512. if (Invalid != FALSE) { \
  1513. KeFlushSingleTb(Virtual, FALSE, FALSE, Pte, *Pte); \
  1514. }
  1515. NTKERNELAPI // nthal
  1516. VOID // nthal
  1517. KeFlushCurrentTb ( // nthal
  1518. VOID // nthal
  1519. ); // nthal
  1520. // nthal
  1521. //
  1522. // Define machine-specific external references.
  1523. //
  1524. extern ULONG KiInterruptTemplate[];
  1525. //
  1526. // Define machine-dependent function prototypes.
  1527. //
  1528. VOID
  1529. KeFlushDcache (
  1530. IN BOOLEAN AllProcessors,
  1531. IN PVOID BaseAddress OPTIONAL,
  1532. IN ULONG Length
  1533. );
  1534. ULONG
  1535. KiCopyInformation (
  1536. IN OUT PEXCEPTION_RECORD ExceptionRecord1,
  1537. IN PEXCEPTION_RECORD ExceptionRecord2
  1538. );
  1539. BOOLEAN
  1540. KiEmulateByteWord(
  1541. IN OUT PEXCEPTION_RECORD ExceptionRecord,
  1542. IN OUT struct _KEXCEPTION_FRAME *ExceptionFrame,
  1543. IN OUT struct _KTRAP_FRAME *TrapFrame
  1544. );
  1545. BOOLEAN
  1546. KiEmulateFloating (
  1547. IN OUT PEXCEPTION_RECORD ExceptionRecord,
  1548. IN OUT struct _KEXCEPTION_FRAME *ExceptionFrame,
  1549. IN OUT struct _KTRAP_FRAME *TrapFrame,
  1550. IN OUT PSW_FPCR SoftwareFpcr
  1551. );
  1552. BOOLEAN
  1553. KiEmulateReference (
  1554. IN OUT PEXCEPTION_RECORD ExceptionRecord,
  1555. IN OUT struct _KEXCEPTION_FRAME *ExceptionFrame,
  1556. IN OUT struct _KTRAP_FRAME *TrapFrame
  1557. );
  1558. BOOLEAN
  1559. KiFloatingException (
  1560. IN OUT PEXCEPTION_RECORD ExceptionRecord,
  1561. IN OUT struct _KEXCEPTION_FRAME *ExceptionFrame,
  1562. IN OUT struct _KTRAP_FRAME *TrapFrame,
  1563. IN BOOLEAN ImpreciseTrap,
  1564. OUT PULONG SoftFpcrCopy
  1565. );
  1566. ULONGLONG
  1567. KiGetRegisterValue (
  1568. IN ULONG Register,
  1569. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  1570. IN struct _KTRAP_FRAME *TrapFrame
  1571. );
  1572. VOID
  1573. KiSetFloatingStatus (
  1574. IN OUT PEXCEPTION_RECORD ExceptionRecord
  1575. );
  1576. VOID
  1577. KiSetRegisterValue (
  1578. IN ULONG Register,
  1579. IN ULONGLONG Value,
  1580. OUT struct _KEXCEPTION_FRAME *ExceptionFrame,
  1581. OUT struct _KTRAP_FRAME *TrapFrame
  1582. );
  1583. VOID
  1584. KiRequestSoftwareInterrupt (
  1585. KIRQL RequestIrql
  1586. );
  1587. //
  1588. // Define query tick count macro.
  1589. //
  1590. // begin_ntddk begin_nthal begin_ntosp
  1591. #if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  1592. // begin_wdm
  1593. #define KeQueryTickCount(CurrentCount ) \
  1594. *(PULONGLONG)(CurrentCount) = **((volatile ULONGLONG **)(&KeTickCount));
  1595. // end_wdm
  1596. #else
  1597. #define KiQueryTickCount(CurrentCount) \
  1598. *(PULONGLONG)(CurrentCount) = KeTickCount.QuadPart;
  1599. VOID
  1600. KeQueryTickCount (
  1601. OUT PLARGE_INTEGER CurrentCount
  1602. );
  1603. #endif // defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
  1604. // end_ntddk end_nthal end_ntosp
  1605. //
  1606. // Define executive macros for acquiring and releasing executive spinlocks.
  1607. // These macros can ONLY be used by executive components and NOT by drivers.
  1608. // Drivers MUST use the kernel interfaces since they must be MP enabled on
  1609. // all systems.
  1610. //
  1611. // KeRaiseIrql is one instruction shorter than KeAcquireSpinLock on Alpha UP.
  1612. // KeLowerIrql is one instruction shorter than KeReleaseSpinLock.
  1613. //
  1614. #if defined(NT_UP) && !defined(_NTDDK_) && !defined(_NTIFS_)
  1615. #define ExAcquireSpinLock(Lock, OldIrql) KeRaiseIrql(DISPATCH_LEVEL, (OldIrql))
  1616. #define ExReleaseSpinLock(Lock, OldIrql) KeLowerIrql((OldIrql))
  1617. #define ExAcquireSpinLockAtDpcLevel(Lock)
  1618. #define ExReleaseSpinLockFromDpcLevel(Lock)
  1619. #else
  1620. // begin_wdm begin_ntddk begin_ntosp
  1621. #define ExAcquireSpinLock(Lock, OldIrql) KeAcquireSpinLock((Lock), (OldIrql))
  1622. #define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
  1623. #define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
  1624. #define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
  1625. // end_wdm end_ntddk end_ntosp
  1626. #endif
  1627. //
  1628. // The acquire and release fast lock macros disable and enable interrupts
  1629. // on UP nondebug systems. On MP or debug systems, the spinlock routines
  1630. // are used.
  1631. //
  1632. // N.B. Extreme caution should be observed when using these routines.
  1633. //
  1634. #if defined(_M_ALPHA)
  1635. #define _disable() __di()
  1636. #define _enable() __ei()
  1637. #endif
  1638. #if defined(NT_UP) && !DBG
  1639. #define ExAcquireFastLock(Lock, OldIrql) \
  1640. ExAcquireSpinLock(Lock, OldIrql)
  1641. #else
  1642. #define ExAcquireFastLock(Lock, OldIrql) \
  1643. ExAcquireSpinLock(Lock, OldIrql)
  1644. #endif
  1645. #if defined(NT_UP) && !DBG
  1646. #define ExReleaseFastLock(Lock, OldIrql) \
  1647. ExReleaseSpinLock(Lock, OldIrql)
  1648. #else
  1649. #define ExReleaseFastLock(Lock, OldIrql) \
  1650. ExReleaseSpinLock(Lock, OldIrql)
  1651. #endif
  1652. //
  1653. // Alpha function definitions
  1654. //
  1655. //++
  1656. //
  1657. // BOOLEAN
  1658. // KiIsThreadNumericStateSaved(
  1659. // IN PKTHREAD Address
  1660. // )
  1661. //
  1662. // This call is used on a not running thread to see if it's numeric
  1663. // state has been saved in its context information. On Alpha the
  1664. // numeric state is always saved.
  1665. //
  1666. //--
  1667. #define KiIsThreadNumericStateSaved(a) TRUE
  1668. //++
  1669. //
  1670. // VOID
  1671. // KiRundownThread(
  1672. // IN PKTHREAD Address
  1673. // )
  1674. //
  1675. //--
  1676. #define KiRundownThread(a)
  1677. //
  1678. // Alpha Feature bit definitions
  1679. //
  1680. #define KF_BYTE 0x00000001
  1681. //
  1682. // Define macro to test if x86 feature is present.
  1683. //
  1684. // N.B. All x86 features test TRUE on Alpha systems.
  1685. //
  1686. #define Isx86FeaturePresent(_f_) TRUE
  1687. // begin_ntddk begin_wdm begin_nthal begin_ntndis begin_ntosp
  1688. #ifdef __cplusplus
  1689. } // extern "C"
  1690. #endif
  1691. #endif // _ALPHA_
  1692. // end_ntddk end_wdm end_nthal end_ntndis end_ntosp
  1693. #endif // _ALPHAH_