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.

291 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. ia64 psr
  5. Abstract:
  6. KD Extension Api
  7. Author:
  8. Thierry Fevrier (v-thief)
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. typedef struct _EM_PSR {
  16. unsigned __int64 reserved0:1; // 0 : reserved
  17. unsigned __int64 be:1; // 1 : Big-Endian
  18. unsigned __int64 up:1; // 2 : User Performance monitor enable
  19. unsigned __int64 ac:1; // 3 : Alignment Check
  20. unsigned __int64 mfl:1; // 4 : Lower (f2 .. f31) floating-point registers written
  21. unsigned __int64 mfh:1; // 5 : Upper (f32 .. f127) floating-point registers written
  22. unsigned __int64 reserved1:7; // 6-12 : reserved
  23. unsigned __int64 ic:1; // 13 : Interruption Collection
  24. unsigned __int64 i:1; // 14 : Interrupt Bit
  25. unsigned __int64 pk:1; // 15 : Protection Key enable
  26. unsigned __int64 reserved2:1; // 16 : reserved
  27. unsigned __int64 dt:1; // 17 : Data Address Translation
  28. unsigned __int64 dfl:1; // 18 : Disabled Floating-point Low register set
  29. unsigned __int64 dfh:1; // 19 : Disabled Floating-point High register set
  30. unsigned __int64 sp:1; // 20 : Secure Performance monitors
  31. unsigned __int64 pp:1; // 21 : Privileged Performance monitor enable
  32. unsigned __int64 di:1; // 22 : Disable Instruction set transition
  33. unsigned __int64 si:1; // 23 : Secure Interval timer
  34. unsigned __int64 db:1; // 24 : Debug Breakpoint fault
  35. unsigned __int64 lp:1; // 25 : Lower Privilege transfer trap
  36. unsigned __int64 tb:1; // 26 : Taken Branch trap
  37. unsigned __int64 rt:1; // 27 : Register stack translation
  38. unsigned __int64 reserved3:4; // 28-31 : reserved
  39. unsigned __int64 cpl:2; // 32;33 : Current Privilege Level
  40. unsigned __int64 is:1; // 34 : Instruction Set
  41. unsigned __int64 mc:1; // 35 : Machine Abort Mask
  42. unsigned __int64 it:1; // 36 : Instruction address Translation
  43. unsigned __int64 id:1; // 37 : Instruction Debug fault disable
  44. unsigned __int64 da:1; // 38 : Disable Data Access and Dirty-bit faults
  45. unsigned __int64 dd:1; // 39 : Data Debug fault disable
  46. unsigned __int64 ss:1; // 40 : Single Step enable
  47. unsigned __int64 ri:2; // 41;42 : Restart Instruction
  48. unsigned __int64 ed:1; // 43 : Exception Deferral
  49. unsigned __int64 bn:1; // 44 : register Bank
  50. unsigned __int64 ia:1; // 45 : Disable Instruction Access-bit faults
  51. unsigned __int64 reserved4:18; // 46-63 : reserved
  52. } EM_PSR, *PEM_PSR;
  53. typedef EM_PSR EM_IPSR;
  54. typedef EM_IPSR *PEM_IPSR;
  55. typedef unsigned __int64 EM_REG;
  56. typedef EM_REG *PEM_REG;
  57. #define EM_REG_BITS (sizeof(EM_REG) * 8)
  58. // IA64 only
  59. typedef enum _DISPLAY_MODE {
  60. DISPLAY_MIN = 0,
  61. DISPLAY_DEFAULT = DISPLAY_MIN,
  62. DISPLAY_MED = 1,
  63. DISPLAY_MAX = 2,
  64. DISPLAY_FULL = DISPLAY_MAX
  65. } DISPLAY_MODE;
  66. typedef struct _EM_REG_FIELD {
  67. const char *SubName;
  68. const char *Name;
  69. unsigned long Length;
  70. unsigned long Shift;
  71. } EM_REG_FIELD, *PEM_REG_FIELD;
  72. //
  73. // EmPsrFields: EM register fields for the Processor Status Register.
  74. //
  75. EM_REG_FIELD EmPsrFields[] = {
  76. { "rv", "reserved0" , 0x1, 0 }, // 0
  77. { "be", "Big-Endian" , 0x1, 1 }, // 1
  78. { "up", "User Performance monitor enable", 0x1, 2 }, // 2
  79. { "ac", "Alignment Check", 0x1, 3 }, // 3
  80. { "mfl", "Lower floating-point registers written", 0x1, 4 }, // 4
  81. { "mfh", "Upper floating-point registers written", 0x1, 5 }, // 5
  82. { "rv", "reserved1", 0x7, 6 }, // 6-12
  83. { "ic", "Interruption Collection", 0x1, 13 }, // 13
  84. { "i", "Interrupt enable", 0x1, 14 }, // 14
  85. { "pk", "Protection Key enable", 0x1, 15 }, // 15
  86. { "rv", "reserved2", 0x1, 16 }, // 16
  87. { "dt", "Data Address Translation enable", 0x1, 17 }, // 17
  88. { "dfl", "Disabled Floating-point Low register set", 0x1, 18 }, // 18
  89. { "dfh", "Disabled Floating-point High register set", 0x1, 19 }, // 19
  90. { "sp", "Secure Performance monitors", 0x1, 20 }, // 20
  91. { "pp", "Privileged Performance monitor enable", 0x1, 21 }, // 21
  92. { "di", "Disable Instruction set transition", 0x1, 22 }, // 22
  93. { "si", "Secure Interval timer", 0x1, 23 }, // 23
  94. { "db", "Debug Breakpoint fault enable", 0x1, 24 }, // 24
  95. { "lp", "Lower Privilege transfer trap enable", 0x1, 25 }, // 25
  96. { "tb", "Taken Branch trap enable", 0x1, 26 }, // 26
  97. { "rt", "Register stack translation enable", 0x1, 27 }, // 27
  98. { "rv", "reserved3", 0x4, 28 }, // 28-31
  99. { "cpl", "Current Privilege Level", 0x2, 32 }, // 32-33
  100. { "is", "Instruction Set", 0x1, 34 }, // 34
  101. { "mc", "Machine Abort Mask delivery disable", 0x1, 35 }, // 35
  102. { "it", "Instruction address Translation enable", 0x1, 36 }, // 36
  103. { "id", "Instruction Debug fault disable", 0x1, 37 }, // 37
  104. { "da", "Disable Data Access and Dirty-bit faults", 0x1, 38 }, // 38
  105. { "dd", "Data Debug fault disable", 0x1, 39 }, // 39
  106. { "ss", "Single Step enable", 0x1, 40 }, // 40
  107. { "ri", "Restart Instruction", 0x2, 41 }, // 41-42
  108. { "ed", "Exception Deferral", 0x1, 43 }, // 43
  109. { "bn", "register Bank", 0x1, 44 }, // 44
  110. { "ia", "Disable Instruction Access-bit faults", 0x1, 45 }, // 45
  111. { "rv", "reserved4", 0x12, 46 } // 46-63
  112. };
  113. VOID
  114. DisplayFullEmRegField(
  115. ULONG64 EmRegValue,
  116. EM_REG_FIELD EmRegFields[],
  117. ULONG Field
  118. )
  119. {
  120. dprintf( "\n %3.3s : %I64x : %-s",
  121. EmRegFields[Field].SubName,
  122. (EmRegValue >> EmRegFields[Field].Shift) & ((1 << EmRegFields[Field].Length) - 1),
  123. EmRegFields[Field].Name
  124. );
  125. return;
  126. } // DisplayFullEmRegField()
  127. VOID
  128. DisplayFullEmReg(
  129. IN ULONG64 Val,
  130. IN EM_REG_FIELD EmRegFields[],
  131. IN DISPLAY_MODE DisplayMode
  132. )
  133. {
  134. ULONG i, j;
  135. i = j = 0;
  136. if ( DisplayMode >= DISPLAY_MAX ) {
  137. while( j < EM_REG_BITS ) {
  138. DisplayFullEmRegField( Val, EmRegFields, i );
  139. j += EmRegFields[i].Length;
  140. i++;
  141. }
  142. }
  143. else {
  144. while( j < EM_REG_BITS ) {
  145. if ( !strstr(EmRegFields[i].Name, "reserved" ) &&
  146. !strstr(EmRegFields[i].Name, "ignored" ) ) {
  147. DisplayFullEmRegField( Val, EmRegFields, i );
  148. }
  149. j += EmRegFields[i].Length;
  150. i++;
  151. }
  152. }
  153. dprintf("\n");
  154. return;
  155. } // DisplayFullEmReg()
  156. VOID
  157. DisplayPsrIA64(
  158. IN const PCHAR Header,
  159. IN EM_PSR EmPsr,
  160. IN DISPLAY_MODE DisplayMode
  161. )
  162. {
  163. dprintf("%s", Header ? Header : "" );
  164. if ( DisplayMode >= DISPLAY_MED ) {
  165. DisplayFullEmReg( *((PULONG64) &EmPsr), EmPsrFields, DisplayMode );
  166. }
  167. else {
  168. dprintf(
  169. "ia bn ed ri ss dd da id it mc is cpl rt tb lp db\n\t\t "
  170. "%1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x\n\t\t"
  171. "si di pp sp dfh dfl dt pk i ic | mfh mfl ac up be\n\t\t "
  172. "%1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x %1I64x | %1I64x %1I64x %1I64x %1I64x %1I64x\n",
  173. EmPsr.ia,
  174. EmPsr.bn,
  175. EmPsr.ed,
  176. EmPsr.ri,
  177. EmPsr.ss,
  178. EmPsr.dd,
  179. EmPsr.da,
  180. EmPsr.id,
  181. EmPsr.it,
  182. EmPsr.mc,
  183. EmPsr.is,
  184. EmPsr.cpl,
  185. EmPsr.rt,
  186. EmPsr.tb,
  187. EmPsr.lp,
  188. EmPsr.db,
  189. EmPsr.si,
  190. EmPsr.di,
  191. EmPsr.pp,
  192. EmPsr.sp,
  193. EmPsr.dfh,
  194. EmPsr.dfl,
  195. EmPsr.dt,
  196. EmPsr.pk,
  197. EmPsr.i,
  198. EmPsr.ic,
  199. EmPsr.mfh,
  200. EmPsr.mfl,
  201. EmPsr.ac,
  202. EmPsr.up,
  203. EmPsr.be
  204. );
  205. }
  206. return;
  207. } // DisplayPsrIA64()
  208. DECLARE_API( psr )
  209. /*++
  210. Routine Description:
  211. Dumps an IA64 Processor Status Word
  212. Arguments:
  213. args - Supplies the address in hex.
  214. Return Value:
  215. None
  216. --*/
  217. {
  218. ULONG64 psrValue;
  219. ULONG result;
  220. ULONG flags = 0;
  221. char *header;
  222. result = sscanf(args,"%X %lx", &psrValue, &flags);
  223. psrValue = GetExpression(args);
  224. if ((result != 1) && (result != 2)) {
  225. //
  226. // If user specified "@ipsr"...
  227. //
  228. char ipsrStr[16];
  229. result = sscanf(args, "%s %lx", ipsrStr, &flags);
  230. if ( ((result != 1) && (result != 2)) || strcmp(ipsrStr,"@ipsr") ) {
  231. dprintf("USAGE: !psr 0xValue [display_mode:0,1,2]\n");
  232. dprintf("USAGE: !psr @ipsr [display_mode:0,1,2]\n");
  233. return E_INVALIDARG;
  234. }
  235. psrValue = GetExpression("@ipsr");
  236. }
  237. header = (flags > DISPLAY_MIN) ? NULL : "\tpsr:\t";
  238. if (TargetMachine != IMAGE_FILE_MACHINE_IA64)
  239. {
  240. dprintf("!psr not implemented for this architecture.\n");
  241. }
  242. else
  243. {
  244. DisplayPsrIA64( header, *((EM_PSR *) &psrValue), flags );
  245. }
  246. return S_OK;
  247. } // !psr