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.

250 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. Registers.c
  5. Abstract:
  6. This module contains routines for manipulating registers.
  7. Author:
  8. Dave Hastings (daveh) 1-Apr-1992
  9. Notes:
  10. The routines in this module assume that the pointers to the ntsd
  11. routines have already been set up.
  12. Revision History:
  13. --*/
  14. #include <precomp.h>
  15. #pragma hdrstop
  16. #include <stdio.h>
  17. const char *FpuTagNames[] = {
  18. "Valid",
  19. "Zero",
  20. "Special",
  21. "Empty"
  22. };
  23. VOID
  24. PrintContext(
  25. IN PCONTEXT Context
  26. );
  27. VOID
  28. IntelRegistersp(
  29. VOID
  30. )
  31. /*++
  32. Routine Description:
  33. This routine dumps out the 16 bit register set from the vdmtib
  34. Arguments:
  35. None.
  36. Return Value:
  37. None.
  38. Notes:
  39. This routine assumes that the pointers to the ntsd routines have already
  40. been set up.
  41. --*/
  42. {
  43. BOOL Status;
  44. ULONG Address;
  45. CONTEXT IntelRegisters;
  46. //
  47. // Get the address of the VdmTib
  48. //
  49. if (sscanf(lpArgumentString, "%lx", &Address) <= 0) {
  50. Address = GetCurrentVdmTib();
  51. }
  52. if (!Address) {
  53. (*Print)("Error geting VdmTib address\n");
  54. return;
  55. }
  56. //
  57. // Read the 16 bit context
  58. //
  59. Status = READMEM(
  60. &(((PVDM_TIB)Address)->VdmContext),
  61. &IntelRegisters,
  62. sizeof(CONTEXT)
  63. );
  64. if (!Status) {
  65. GetLastError();
  66. (*Print)("Could not get VdmContext\n");
  67. } else {
  68. PrintContext(&IntelRegisters);
  69. }
  70. }
  71. VOID
  72. PrintContext(
  73. IN PCONTEXT Context
  74. )
  75. /*++
  76. Routine Description:
  77. This routine dumps out a context.
  78. Arguments:
  79. Context -- Supplies a pointer to the context to dump
  80. Return Value:
  81. None.
  82. --*/
  83. {
  84. (*Print)(
  85. "eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx esi=%08lx edi=%08lx\n",
  86. Context->Eax,
  87. Context->Ebx,
  88. Context->Ecx,
  89. Context->Edx,
  90. Context->Esi,
  91. Context->Edi
  92. );
  93. (*Print)(
  94. "eip=%08lx esp=%08lx ebp=%08lx\n",
  95. Context->Eip,
  96. Context->Esp,
  97. Context->Ebp
  98. );
  99. (*Print)(
  100. "cs=%04x ss=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n",
  101. Context->SegCs,
  102. Context->SegSs,
  103. Context->SegDs,
  104. Context->SegEs,
  105. Context->SegFs,
  106. Context->SegGs,
  107. Context->EFlags
  108. );
  109. }
  110. VOID
  111. Fpup(
  112. VOID
  113. )
  114. /*++
  115. Routine Description:
  116. This routine dumps out the x86 floating-point state.
  117. Arguments:
  118. None.
  119. Return Value:
  120. None.
  121. Notes:
  122. This routine assumes that the pointers to the ntsd routines have already
  123. been set up.
  124. --*/
  125. {
  126. CONTEXT IntelRegisters;
  127. USHORT Temp;
  128. int RegNum;
  129. //
  130. // Read the thread's context
  131. //
  132. IntelRegisters.ContextFlags = CONTEXT_FLOATING_POINT;
  133. if (GetThreadContext(hCurrentThread, &IntelRegisters) == FALSE) {
  134. GetLastError();
  135. (*Print)("Could not get 32-bit thread context\n");
  136. return;
  137. };
  138. Temp = (USHORT)IntelRegisters.FloatSave.ControlWord;
  139. (*Print)(" Control word = %X\n", Temp);
  140. (*Print)(
  141. " Infinity = %d Rounding = %d Precision = %d PM=%d UM=%d OM=%d ZM=%d DM=%d IM=%d\n",
  142. (Temp >> 11) & 1, // Infinity
  143. (Temp >> 9) & 3, // Rounding (2 bits)
  144. (Temp >> 7) & 3, // Precision (2 bits)
  145. (Temp >> 5) & 1, // Precision Exception Mask
  146. (Temp >> 4) & 1, // Underflow Exception Mask
  147. (Temp >> 3) & 1, // Overflow Exception Mask
  148. (Temp >> 2) & 1, // Zero Divide Exception Mask
  149. (Temp >> 1) & 1, // Denormalized Operand Exception Mask
  150. Temp & 1 // Invalid Operation Exception Mask
  151. );
  152. Temp = (USHORT)IntelRegisters.FloatSave.StatusWord;
  153. (*Print)(" Status word = %X\n", Temp);
  154. (*Print)(
  155. " Top=%d C3=%d C2=%d C1=%d C0=%d ES=%d SF=%d PE=%d UE=%d OE=%d ZE=%d DE=%d IE=%d\n",
  156. (Temp >> 11) & 7, // Top (3 bits)
  157. (Temp >> 7) & 1, // Error Summary
  158. (Temp >> 14) & 1, // C3
  159. (Temp >> 10) & 1, // C2
  160. (Temp >> 9) & 1, // C1
  161. (Temp >> 8) & 1, // C0
  162. (Temp >> 7) & 1, // Error Summary
  163. (Temp >> 6) & 1, // Stack Fault
  164. (Temp >> 5) & 1, // Precision Exception
  165. (Temp >> 4) & 1, // Underflow Exception
  166. (Temp >> 3) & 1, // Overflow Exception
  167. (Temp >> 2) & 1, // Zero Divide Exception
  168. (Temp >> 1) & 1, // Denormalized Operand Exception
  169. Temp & 1 // Invalid Operation Exception
  170. );
  171. (*Print)(" Last Instruction: CS:EIP=%X:%X EA=%X:%X\n",
  172. (USHORT)IntelRegisters.FloatSave.ErrorSelector,
  173. IntelRegisters.FloatSave.ErrorOffset,
  174. (USHORT)IntelRegisters.FloatSave.DataSelector,
  175. IntelRegisters.FloatSave.DataOffset
  176. );
  177. (*Print)(" Floating-point registers:\n");
  178. for (RegNum=0; RegNum<8; ++RegNum) {
  179. PBYTE r80 = (PBYTE)&IntelRegisters.FloatSave.RegisterArea[RegNum*10];
  180. Temp = (((USHORT)IntelRegisters.FloatSave.TagWord) >> (RegNum*2)) & 3;
  181. (*Print)(
  182. " %d. %s %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
  183. RegNum,
  184. FpuTagNames[Temp],
  185. r80[0], r80[1], r80[2], r80[3], r80[4], r80[5], r80[6], r80[7], r80[8], r80[9]
  186. );
  187. }
  188. }