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.

674 lines
18 KiB

  1. /*++
  2. Copyright (c) 1993 IBM Corporation
  3. Module Name:
  4. ntppc.h
  5. Abstract:
  6. User-mode visible PowerPC specific structures and constants
  7. Author:
  8. Rick Simpson 9-July-1993
  9. Based on ntmips.h, by David N. Cutler (davec) 31-Mar-1990
  10. Revision History:
  11. Chuck Bauman 3-August-1993 (Integrate NT product source)
  12. KPCR modifications need to be integrated
  13. because it was removed from ntppc.h.
  14. No changes required otherwise.
  15. --*/
  16. #ifndef _NTPPC_
  17. #define _NTPPC_
  18. #if _MSC_VER > 1000
  19. #pragma once
  20. #endif
  21. #include "ppcinst.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. // begin_ntddk begin_wdm begin_nthal begin_winnt
  26. #if defined(_PPC_)
  27. // end_winnt
  28. //
  29. // Define system time structure.
  30. //
  31. typedef struct _KSYSTEM_TIME {
  32. ULONG LowPart;
  33. LONG High1Time;
  34. LONG High2Time;
  35. } KSYSTEM_TIME, *PKSYSTEM_TIME;
  36. //
  37. // Define unsupported "keywords".
  38. //
  39. #define _cdecl
  40. // end_ntddk end_wdm end_nthal
  41. //
  42. // Define breakpoint codes.
  43. //
  44. // **FINISH** Use MIPS codes unless there's a reason not to
  45. //
  46. #define USER_BREAKPOINT 0 // user breakpoint
  47. #define KERNEL_BREAKPOINT 1 // kernel breakpoint
  48. #define BREAKIN_BREAKPOINT 2 // break into kernel debugger
  49. #define BRANCH_TAKEN_BREAKPOINT 3 // branch taken breakpoint
  50. #define BRANCH_NOT_TAKEN_BREAKPOINT 4 // branch not taken breakpoint
  51. #define SINGLE_STEP_BREAKPOINT 5 // single step breakpoint
  52. #define DIVIDE_OVERFLOW_BREAKPOINT 6 // divide overflow breakpoint
  53. #define DIVIDE_BY_ZERO_BREAKPOINT 7 // divide by zero breakpoint
  54. #define RANGE_CHECK_BREAKPOINT 8 // range check breakpoint
  55. #define STACK_OVERFLOW_BREAKPOINT 9 // MIPS code
  56. #define MULTIPLY_OVERFLOW_BREAKPOINT 10 // multiply overflow breakpoint
  57. #define DEBUG_PRINT_BREAKPOINT 20 // debug print breakpoint
  58. #define DEBUG_PROMPT_BREAKPOINT 21 // debug prompt breakpoint
  59. #define DEBUG_STOP_BREAKPOINT 22 // debug stop breakpoint
  60. #define DEBUG_LOAD_SYMBOLS_BREAKPOINT 23 // load symbols breakpoint
  61. #define DEBUG_UNLOAD_SYMBOLS_BREAKPOINT 24 // unload symbols breakpoint
  62. #define DEBUG_COMMAND_STRING_BREAKPOINT 25 // command string breakpoint
  63. //
  64. // Define PowerPC specific read control space commands for the
  65. // Kernel Debugger. These definitions are for values that must be
  66. // accessed via defined interfaces (Fast path System Call).
  67. //
  68. #define DEBUG_CONTROL_SPACE_PCR 1
  69. //
  70. // Define special fast path system service codes.
  71. //
  72. // N.B. These codes are VERY special. The high bit signifies a fast path
  73. // and the low bits signify what type.
  74. //
  75. #define RETRIEVE_TEB_PTR -3 // fetch address of TEB
  76. #define SET_LOW_WAIT_HIGH -2 // fast path event pair service
  77. #define SET_HIGH_WAIT_LOW -1 // fast path event pair service
  78. // begin_ntddk begin_nthal
  79. //
  80. //
  81. // Define size of kernel mode stack.
  82. //
  83. // **FINISH** This may not be the appropriate value for PowerPC
  84. #define KERNEL_STACK_SIZE 16384
  85. //
  86. // Define size of large kernel mode stack for callbacks.
  87. //
  88. #define KERNEL_LARGE_STACK_SIZE 61440
  89. //
  90. // Define number of pages to initialize in a large kernel stack.
  91. //
  92. #define KERNEL_LARGE_STACK_COMMIT 16384
  93. // begin_wdm
  94. //
  95. // Define bus error routine type.
  96. //
  97. struct _EXCEPTION_RECORD;
  98. struct _KEXCEPTION_FRAME;
  99. struct _KTRAP_FRAME;
  100. typedef
  101. VOID
  102. (*PKBUS_ERROR_ROUTINE) (
  103. IN struct _EXCEPTION_RECORD *ExceptionRecord,
  104. IN struct _KEXCEPTION_FRAME *ExceptionFrame,
  105. IN struct _KTRAP_FRAME *TrapFrame,
  106. IN PVOID VirtualAddress,
  107. IN PHYSICAL_ADDRESS PhysicalAddress
  108. );
  109. //
  110. // Macros to emit eieio, sync, and isync instructions.
  111. //
  112. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  113. void __emit( unsigned const __int32 );
  114. #define __builtin_eieio() __emit( 0x7C0006AC )
  115. #define __builtin_sync() __emit( 0x7C0004AC )
  116. #define __builtin_isync() __emit( 0x4C00012C )
  117. #else
  118. void __builtin_eieio(void);
  119. void __builtin_sync(void);
  120. void __builtin_isync(void);
  121. #endif
  122. // end_ntddk end_wdm end_nthal - Added to replace comment in the KPCR from ntmips.h
  123. //
  124. // Define address of data shared between user and kernel mode.
  125. //
  126. #define USER_SHARED_DATA ((KUSER_SHARED_DATA * const)0xFFFFE000)
  127. // begin_winnt
  128. //
  129. // The address of the TEB is placed into GPR 13 at context switch time
  130. // and should never be destroyed. To get the address of the TEB use
  131. // the compiler intrinsic to access it directly from GPR 13.
  132. //
  133. #if defined(_M_PPC) && defined(_MSC_VER) && (_MSC_VER>=1000)
  134. unsigned __gregister_get( unsigned const regnum );
  135. #define NtCurrentTeb() ((struct _TEB *)__gregister_get(13))
  136. #elif defined(_M_PPC)
  137. struct _TEB * __builtin_get_gpr13(VOID);
  138. #define NtCurrentTeb() ((struct _TEB *)__builtin_get_gpr13())
  139. #endif
  140. //
  141. // Define functions to get the address of the current fiber and the
  142. // current fiber data.
  143. //
  144. #define GetCurrentFiber() (((PNT_TIB)NtCurrentTeb())->FiberData)
  145. #define GetFiberData() (*(PVOID *)(GetCurrentFiber()))
  146. // begin_ntddk begin_nthal
  147. //
  148. // The following flags control the contents of the CONTEXT structure.
  149. //
  150. #if !defined(RC_INVOKED)
  151. #define CONTEXT_CONTROL 0x00000001L
  152. #define CONTEXT_FLOATING_POINT 0x00000002L
  153. #define CONTEXT_INTEGER 0x00000004L
  154. #define CONTEXT_DEBUG_REGISTERS 0x00000008L
  155. #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_FLOATING_POINT | CONTEXT_INTEGER)
  156. #endif
  157. //
  158. // Context Frame
  159. //
  160. // N.B. This frame must be exactly a multiple of 16 bytes in length.
  161. //
  162. // This frame has a several purposes: 1) it is used as an argument to
  163. // NtContinue, 2) it is used to constuct a call frame for APC delivery,
  164. // 3) it is used to construct a call frame for exception dispatching
  165. // in user mode, and 4) it is used in the user level thread creation
  166. // routines.
  167. //
  168. // Requires at least 8-byte alignment (double)
  169. //
  170. typedef struct _CONTEXT {
  171. //
  172. // This section is specified/returned if the ContextFlags word contains
  173. // the flag CONTEXT_FLOATING_POINT.
  174. //
  175. double Fpr0; // Floating registers 0..31
  176. double Fpr1;
  177. double Fpr2;
  178. double Fpr3;
  179. double Fpr4;
  180. double Fpr5;
  181. double Fpr6;
  182. double Fpr7;
  183. double Fpr8;
  184. double Fpr9;
  185. double Fpr10;
  186. double Fpr11;
  187. double Fpr12;
  188. double Fpr13;
  189. double Fpr14;
  190. double Fpr15;
  191. double Fpr16;
  192. double Fpr17;
  193. double Fpr18;
  194. double Fpr19;
  195. double Fpr20;
  196. double Fpr21;
  197. double Fpr22;
  198. double Fpr23;
  199. double Fpr24;
  200. double Fpr25;
  201. double Fpr26;
  202. double Fpr27;
  203. double Fpr28;
  204. double Fpr29;
  205. double Fpr30;
  206. double Fpr31;
  207. double Fpscr; // Floating point status/control reg
  208. //
  209. // This section is specified/returned if the ContextFlags word contains
  210. // the flag CONTEXT_INTEGER.
  211. //
  212. ULONG Gpr0; // General registers 0..31
  213. ULONG Gpr1;
  214. ULONG Gpr2;
  215. ULONG Gpr3;
  216. ULONG Gpr4;
  217. ULONG Gpr5;
  218. ULONG Gpr6;
  219. ULONG Gpr7;
  220. ULONG Gpr8;
  221. ULONG Gpr9;
  222. ULONG Gpr10;
  223. ULONG Gpr11;
  224. ULONG Gpr12;
  225. ULONG Gpr13;
  226. ULONG Gpr14;
  227. ULONG Gpr15;
  228. ULONG Gpr16;
  229. ULONG Gpr17;
  230. ULONG Gpr18;
  231. ULONG Gpr19;
  232. ULONG Gpr20;
  233. ULONG Gpr21;
  234. ULONG Gpr22;
  235. ULONG Gpr23;
  236. ULONG Gpr24;
  237. ULONG Gpr25;
  238. ULONG Gpr26;
  239. ULONG Gpr27;
  240. ULONG Gpr28;
  241. ULONG Gpr29;
  242. ULONG Gpr30;
  243. ULONG Gpr31;
  244. ULONG Cr; // Condition register
  245. ULONG Xer; // Fixed point exception register
  246. //
  247. // This section is specified/returned if the ContextFlags word contains
  248. // the flag CONTEXT_CONTROL.
  249. //
  250. ULONG Msr; // Machine status register
  251. ULONG Iar; // Instruction address register
  252. ULONG Lr; // Link register
  253. ULONG Ctr; // Count register
  254. //
  255. // The flags values within this flag control the contents of
  256. // a CONTEXT record.
  257. //
  258. // If the context record is used as an input parameter, then
  259. // for each portion of the context record controlled by a flag
  260. // whose value is set, it is assumed that that portion of the
  261. // context record contains valid context. If the context record
  262. // is being used to modify a thread's context, then only that
  263. // portion of the threads context will be modified.
  264. //
  265. // If the context record is used as an IN OUT parameter to capture
  266. // the context of a thread, then only those portions of the thread's
  267. // context corresponding to set flags will be returned.
  268. //
  269. // The context record is never used as an OUT only parameter.
  270. //
  271. ULONG ContextFlags;
  272. ULONG Fill[3]; // Pad out to multiple of 16 bytes
  273. //
  274. // This section is specified/returned if CONTEXT_DEBUG_REGISTERS is
  275. // set in ContextFlags. Note that CONTEXT_DEBUG_REGISTERS is NOT
  276. // included in CONTEXT_FULL.
  277. //
  278. ULONG Dr0; // Breakpoint Register 1
  279. ULONG Dr1; // Breakpoint Register 2
  280. ULONG Dr2; // Breakpoint Register 3
  281. ULONG Dr3; // Breakpoint Register 4
  282. ULONG Dr4; // Breakpoint Register 5
  283. ULONG Dr5; // Breakpoint Register 6
  284. ULONG Dr6; // Debug Status Register
  285. ULONG Dr7; // Debug Control Register
  286. } CONTEXT, *PCONTEXT;
  287. // end_ntddk end_nthal
  288. //
  289. // Stack frame header
  290. //
  291. // Order of appearance in stack frame:
  292. // Header (six words)
  293. // Parameters (at least eight words)
  294. // Local variables
  295. // Saved GPRs
  296. // Saved FPRs
  297. //
  298. // Minimum alignment is 8 bytes
  299. typedef struct _STACK_FRAME_HEADER { // GPR 1 points here
  300. ULONG BackChain; // Addr of previous frame
  301. ULONG GlueSaved1; // Used by glue code
  302. ULONG GlueSaved2;
  303. ULONG Reserved1; // Reserved
  304. ULONG Spare1; // Used by tracing, profiling, ...
  305. ULONG Spare2;
  306. ULONG Parameter0; // First 8 parameter words are
  307. ULONG Parameter1; // always present
  308. ULONG Parameter2;
  309. ULONG Parameter3;
  310. ULONG Parameter4;
  311. ULONG Parameter5;
  312. ULONG Parameter6;
  313. ULONG Parameter7;
  314. } STACK_FRAME_HEADER,*PSTACK_FRAME_HEADER;
  315. // end_winnt
  316. #define CONTEXT_TO_PROGRAM_COUNTER(Context) ((Context)->Iar)
  317. #define CONTEXT_LENGTH (sizeof(CONTEXT))
  318. #define CONTEXT_ALIGN (sizeof(double))
  319. #define CONTEXT_ROUND (CONTEXT_ALIGN - 1)
  320. //
  321. // Nonvolatile context pointer record.
  322. //
  323. typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
  324. DOUBLE *FloatingContext[32];
  325. PULONG FpscrContext;
  326. PULONG IntegerContext[32];
  327. PULONG CrContext;
  328. PULONG XerContext;
  329. PULONG MsrContext;
  330. PULONG IarContext;
  331. PULONG LrContext;
  332. PULONG CtrContext;
  333. } KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
  334. // begin_nthal
  335. //
  336. // PowerPC special-purpose registers
  337. //
  338. //
  339. // Define Machine Status Register (MSR) fields
  340. //
  341. typedef struct _MSR {
  342. ULONG LE : 1; // 31 Little-Endian execution mode
  343. ULONG RI : 1; // 30 Recoverable Interrupt
  344. ULONG Rsv1 : 2; // 29..28 reserved
  345. ULONG DR : 1; // 27 Data Relocate
  346. ULONG IR : 1; // 26 Instruction Relocate
  347. ULONG IP : 1; // 25 Interrupt Prefix
  348. ULONG Rsv2 : 1; // 24 reserved
  349. ULONG FE1 : 1; // 23 Floating point Exception mode 1
  350. ULONG BE : 1; // 22 Branch trace Enable
  351. ULONG SE : 1; // 21 Single-step trace Enable
  352. ULONG FE0 : 1; // 20 Floating point Exception mode 0
  353. ULONG ME : 1; // 19 Machine check Enable
  354. ULONG FP : 1; // 18 Floating Point available
  355. ULONG PR : 1; // 17 Problem state
  356. ULONG EE : 1; // 16 External interrupt Enable
  357. ULONG ILE : 1; // 15 Interrupt Little-Endian mode
  358. ULONG IMPL : 1; // 14 Implementation dependent
  359. ULONG POW : 1; // 13 Power management enable
  360. ULONG Rsv3 : 13; // 12..0 reserved
  361. } MSR, *PMSR;
  362. //
  363. // Define Processor Version Register (PVR) fields
  364. //
  365. typedef struct _PVR {
  366. ULONG Revision : 16;
  367. ULONG Version : 16;
  368. } PVR, *PPVR;
  369. // end_nthal
  370. // begin_nthal
  371. //
  372. // Define Condition Register (CR) fields
  373. //
  374. // We name the structure CondR rather than CR, so that a pointer
  375. // to a condition register structure is PCondR rather than PCR.
  376. // (PCR is an NT data structure, the Processor Control Region.)
  377. typedef struct _CondR {
  378. ULONG CR7 : 4; // Eight 4-bit fields; machine numbers
  379. ULONG CR6 : 4; // them in Big-Endian order
  380. ULONG CR5 : 4;
  381. ULONG CR4 : 4;
  382. ULONG CR3 : 4;
  383. ULONG CR2 : 4;
  384. ULONG CR1 : 4;
  385. ULONG CR0 : 4;
  386. } CondR, *PCondR;
  387. //
  388. // Define Fixed Point Exception Register (XER) fields
  389. //
  390. typedef struct _XER {
  391. ULONG Rsv : 29; // 31..3 Reserved
  392. ULONG CA : 1; // 2 Carry
  393. ULONG OV : 1; // 1 Overflow
  394. ULONG SO : 1; // 0 Summary Overflow
  395. } XER, *PXER;
  396. //
  397. // Define Floating Point Status/Control Register (FPSCR) fields
  398. //
  399. typedef struct _FPSCR {
  400. ULONG RN : 2; // 31..30 Rounding control
  401. ULONG NI : 1; // 29 Non-IEEE mode
  402. ULONG XE : 1; // 28 Inexact exception Enable
  403. ULONG ZE : 1; // 27 Zero divide exception Enable
  404. ULONG UE : 1; // 26 Underflow exception Enable
  405. ULONG OE : 1; // 25 Overflow exception Enable
  406. ULONG VE : 1; // 24 Invalid operation exception Enable
  407. ULONG VXCVI : 1; // 23 Invalid op exception (integer convert)
  408. ULONG VXSQRT : 1; // 22 Invalid op exception (square root)
  409. ULONG VXSOFT : 1; // 21 Invalid op exception (software request)
  410. ULONG Res1 : 1; // 20 reserved
  411. ULONG FU : 1; // 19 Result Unordered or NaN
  412. ULONG FE : 1; // 18 Result Equal or zero
  413. ULONG FG : 1; // 17 Result Greater than or positive
  414. ULONG FL : 1; // 16 Result Less than or negative
  415. ULONG C : 1; // 15 Result Class descriptor
  416. ULONG FI : 1; // 14 Fraction Inexact
  417. ULONG FR : 1; // 13 Fraction Rounded
  418. ULONG VXVC : 1; // 12 Invalid op exception (compare)
  419. ULONG VXIMZ : 1; // 11 Invalid op exception (infinity * 0)
  420. ULONG VXZDZ : 1; // 10 Invalid op exception (0 / 0)
  421. ULONG VXIDI : 1; // 9 Invalid op exception (infinity / infinity)
  422. ULONG VXISI : 1; // 8 Invalid op exception (infinity - infinity)
  423. ULONG VXSNAN : 1; // 7 Invalid op exception (signalling NaN)
  424. ULONG XX : 1; // 6 Inexact exception
  425. ULONG ZX : 1; // 5 Zero divide exception
  426. ULONG UX : 1; // 4 Underflow exception
  427. ULONG OX : 1; // 3 Overflow exception
  428. ULONG VX : 1; // 2 Invalid operation exception summary
  429. ULONG FEX : 1; // 1 Enabled Exception summary
  430. ULONG FX : 1; // 0 Exception summary
  431. } FPSCR, *PFPSCR;
  432. // end_nthal
  433. // begin_nthal
  434. //
  435. // Define address space layout as defined by PowerPC memory management.
  436. //
  437. // The names come from MIPS hardwired virtual to first 512MB real.
  438. // We use these values to define the size of the PowerPC kernel BAT.
  439. // Must coordinate with values in ../private/mm/ppc/mippc.h.
  440. // This is 8MB on the PowerPC 601; may be larger for other models.
  441. //
  442. //
  443. #define KUSEG_BASE 0x0 // base of user segment
  444. #define KSEG0_BASE 0x80000000 // base of kernel BAT
  445. #define KSEG1_BASE PCR->Kseg0Top // end of kernel BAT
  446. #define KSEG2_BASE KSEG1_BASE // end of kernel BAT
  447. //
  448. // A valid Page Table Entry has the following definition
  449. //
  450. typedef struct _HARDWARE_PTE {
  451. ULONG Dirty : 2;
  452. ULONG Valid : 1; // software
  453. ULONG GuardedStorage : 1;
  454. ULONG MemoryCoherence : 1;
  455. ULONG CacheDisable : 1;
  456. ULONG WriteThrough : 1;
  457. ULONG Change : 1;
  458. ULONG Reference : 1;
  459. ULONG Write : 1; // software
  460. ULONG CopyOnWrite : 1; // software
  461. ULONG rsvd1 : 1;
  462. ULONG PageFrameNumber : 20;
  463. } HARDWARE_PTE, *PHARDWARE_PTE;
  464. #define HARDWARE_PTE_DIRTY_MASK 0x3
  465. // end_nthal
  466. //
  467. // Define PowerPC exception handling structures and function prototypes.
  468. //
  469. // These are adopted without change from the MIPS implementation.
  470. //
  471. //
  472. // Function table entry structure definition.
  473. //
  474. typedef struct _RUNTIME_FUNCTION {
  475. ULONG BeginAddress;
  476. ULONG EndAddress;
  477. PEXCEPTION_ROUTINE ExceptionHandler;
  478. PVOID HandlerData;
  479. ULONG PrologEndAddress;
  480. } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION;
  481. //
  482. // Scope table structure definition.
  483. //
  484. typedef struct _SCOPE_TABLE {
  485. ULONG Count;
  486. struct
  487. {
  488. ULONG BeginAddress;
  489. ULONG EndAddress;
  490. ULONG HandlerAddress;
  491. ULONG JumpTarget;
  492. } ScopeRecord[1];
  493. } SCOPE_TABLE, *PSCOPE_TABLE;
  494. //
  495. // Runtime Library function prototypes.
  496. //
  497. VOID
  498. RtlCaptureContext (
  499. OUT PCONTEXT ContextRecord
  500. );
  501. PRUNTIME_FUNCTION
  502. RtlLookupFunctionEntry (
  503. IN ULONG ControlPc
  504. );
  505. ULONG
  506. RtlVirtualUnwind (
  507. IN ULONG ControlPc,
  508. IN PRUNTIME_FUNCTION FunctionEntry,
  509. IN OUT PCONTEXT ContextRecord,
  510. OUT PBOOLEAN InFunction,
  511. OUT PULONG EstablisherFrame,
  512. IN OUT PKNONVOLATILE_CONTEXT_POINTERS ContextPointers OPTIONAL,
  513. IN ULONG LowStackLimit,
  514. IN ULONG HighStackLimit
  515. );
  516. //
  517. // Define C structured exception handing function prototypes.
  518. //
  519. typedef struct _DISPATCHER_CONTEXT {
  520. ULONG ControlPc;
  521. PRUNTIME_FUNCTION FunctionEntry;
  522. ULONG EstablisherFrame;
  523. PCONTEXT ContextRecord;
  524. } DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
  525. struct _EXCEPTION_POINTERS;
  526. typedef
  527. LONG
  528. (*EXCEPTION_FILTER) (
  529. struct _EXCEPTION_POINTERS *ExceptionPointers
  530. );
  531. typedef
  532. VOID
  533. (*TERMINATION_HANDLER) (
  534. BOOLEAN is_abnormal
  535. );
  536. // **FINISH** This may need alteration for PowerPC
  537. // begin_winnt
  538. VOID
  539. __jump_unwind (
  540. PVOID Fp,
  541. PVOID TargetPc
  542. );
  543. // end_winnt
  544. // begin_ntddk begin_wdm begin_nthal begin_winnt
  545. #endif // defined(_PPC_)
  546. // end_ntddk end_wdm end_nthal end_winnt
  547. #ifdef __cplusplus
  548. }
  549. #endif
  550. #endif // _NTPPC_