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.

670 lines
18 KiB

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