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.

443 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. debug.c
  5. Abstract:
  6. This module implements utility functions.
  7. Author:
  8. David N. Cutler (davec) 21-Sep-1994
  9. Environment:
  10. Kernel mode only.
  11. Revision History:
  12. --*/
  13. #include "nthal.h"
  14. #include "emulate.h"
  15. #if defined(XM_DEBUG)
  16. //
  17. // Define counter used to control flag tracing.
  18. //
  19. ULONG XmTraceCount = 0;
  20. VOID
  21. XmTraceDestination (
  22. IN PRXM_CONTEXT P,
  23. IN ULONG Destination
  24. )
  25. /*++
  26. Routine Description:
  27. This function traces the destination value if the TRACE_OPERANDS
  28. flag is set.
  29. Arguments:
  30. P - Supplies a pointer to an emulator context structure.
  31. Result - Supplies the destination value to trace.
  32. Return Value:
  33. None.
  34. --*/
  35. {
  36. //
  37. // Trace result of operation.
  38. //
  39. if ((XmDebugFlags & TRACE_OPERANDS) != 0) {
  40. if (P->DataType == BYTE_DATA) {
  41. DEBUG_PRINT(("\n Dst - %02lx", Destination));
  42. } else if (P->DataType == WORD_DATA) {
  43. DEBUG_PRINT(("\n Dst - %04lx", Destination));
  44. } else {
  45. DEBUG_PRINT(("\n Dst - %08lx", Destination));
  46. }
  47. }
  48. return;
  49. }
  50. VOID
  51. XmTraceFlags (
  52. IN PRXM_CONTEXT P
  53. )
  54. /*++
  55. Routine Description:
  56. This function traces the condition flags if the TRACE_FLAGS flag
  57. is set.
  58. Arguments:
  59. P - Supplies a pointer to an emulator context structure.
  60. Return Value:
  61. None.
  62. --*/
  63. {
  64. //
  65. // Trace flags.
  66. //
  67. if ((XmDebugFlags & TRACE_OPERANDS) != 0) {
  68. DEBUG_PRINT(("\n OF-%lx, DF-%lx, SF-%lx, ZF-%lx, AF-%lx, PF-%lx, CF-%lx",
  69. (ULONG)P->Eflags.EFLAG_OF,
  70. (ULONG)P->Eflags.EFLAG_DF,
  71. (ULONG)P->Eflags.EFLAG_SF,
  72. (ULONG)P->Eflags.EFLAG_ZF,
  73. (ULONG)P->Eflags.EFLAG_AF,
  74. (ULONG)P->Eflags.EFLAG_PF,
  75. (ULONG)P->Eflags.EFLAG_CF));
  76. }
  77. //
  78. // Increment the trace count and if the result is even, then put
  79. // out a new line.
  80. //
  81. XmTraceCount += 1;
  82. if (((XmTraceCount & 1) == 0) && (XmDebugFlags != 0)) {
  83. DEBUG_PRINT(("\n"));
  84. }
  85. return;
  86. }
  87. VOID
  88. XmTraceJumps (
  89. IN PRXM_CONTEXT P
  90. )
  91. /*++
  92. Routine Description:
  93. This function traces jump operations if the TRACE_JUMPS flag is set.
  94. Arguments:
  95. P - Supplies a pointer to an emulator context structure.
  96. Return Value:
  97. None.
  98. --*/
  99. {
  100. //
  101. // Trace jumps.
  102. //
  103. if ((XmDebugFlags & TRACE_JUMPS) != 0) {
  104. DEBUG_PRINT(("\n Jump to %04lx:%04lx",
  105. (ULONG)P->SegmentRegister[CS],
  106. (ULONG)P->Eip));
  107. }
  108. return;
  109. }
  110. VOID
  111. XmTraceInstruction (
  112. IN XM_OPERATION_DATATYPE DataType,
  113. IN ULONG Instruction
  114. )
  115. /*++
  116. Routine Description:
  117. This function traces instructions if the TRACE_OPERANDS flag is
  118. set.
  119. Arguments:
  120. DataType - Supplies the data type of the instruction value.
  121. Instruction - Supplies the instruction value to trace.
  122. Return Value:
  123. None.
  124. --*/
  125. {
  126. //
  127. // Trace instruction stream of operation.
  128. //
  129. if ((XmDebugFlags & TRACE_OPERANDS) != 0) {
  130. if (DataType == BYTE_DATA) {
  131. DEBUG_PRINT(("%02lx ", Instruction));
  132. } else if (DataType == WORD_DATA) {
  133. DEBUG_PRINT(("%04lx ", Instruction));
  134. } else {
  135. DEBUG_PRINT(("%08lx ", Instruction));
  136. }
  137. }
  138. return;
  139. }
  140. VOID
  141. XmTraceOverride (
  142. IN PRXM_CONTEXT P
  143. )
  144. /*++
  145. Routine Description:
  146. This function traces segment override prefixes.
  147. Arguments:
  148. P - Supplies a pointer to an emulator context structure.
  149. Return Value:
  150. None.
  151. --*/
  152. {
  153. PCHAR Name = "ECSDFG";
  154. ULONG Segment;
  155. //
  156. // Trace segment override.
  157. //
  158. if ((XmDebugFlags & TRACE_OVERRIDE) != 0) {
  159. Segment = P->DataSegment;
  160. DEBUG_PRINT(("\n %cS:Selector - %04lx, Limit - %04lx",
  161. (ULONG)Name[Segment],
  162. (ULONG)P->SegmentRegister[Segment],
  163. P->SegmentLimit[Segment]));
  164. }
  165. return;
  166. }
  167. VOID
  168. XmTraceRegisters (
  169. IN PRXM_CONTEXT P
  170. )
  171. /*++
  172. Routine Description:
  173. This function traces emulator registers.
  174. Arguments:
  175. P - Supplies a pointer to an emulator context structure.
  176. Return Value:
  177. None.
  178. --*/
  179. {
  180. //
  181. // Trace general register.
  182. //
  183. if ((XmDebugFlags & TRACE_GENERAL_REGISTERS) != 0) {
  184. DEBUG_PRINT(("\n EAX-%08lx ECX-%08lx EDX-%08lx EBX-%08lx",
  185. P->Gpr[EAX].Exx,
  186. P->Gpr[ECX].Exx,
  187. P->Gpr[EDX].Exx,
  188. P->Gpr[EBX].Exx));
  189. DEBUG_PRINT(("\n ESP-%08lx EBP-%08lx ESI-%08lx EDI-%08lx",
  190. P->Gpr[ESP].Exx,
  191. P->Gpr[EBP].Exx,
  192. P->Gpr[ESI].Exx,
  193. P->Gpr[EDI].Exx));
  194. DEBUG_PRINT(("\n ES:%04lx CS:%04lx SS:%04lx DS:%04lx FS:%04lx GS:%04lx",
  195. (ULONG)P->SegmentRegister[ES],
  196. (ULONG)P->SegmentRegister[CS],
  197. (ULONG)P->SegmentRegister[SS],
  198. (ULONG)P->SegmentRegister[DS],
  199. (ULONG)P->SegmentRegister[FS],
  200. (ULONG)P->SegmentRegister[GS]));
  201. }
  202. return;
  203. }
  204. VOID
  205. XmTraceResult (
  206. IN PRXM_CONTEXT P,
  207. IN ULONG Result
  208. )
  209. /*++
  210. Routine Description:
  211. This function traces the result value if the TRACE_OPERANDS
  212. flag is set.
  213. Arguments:
  214. P - Supplies a pointer to an emulator context structure.
  215. Result - Supplies the result value to trace.
  216. Return Value:
  217. None.
  218. --*/
  219. {
  220. //
  221. // Trace result of operation.
  222. //
  223. if ((XmDebugFlags & TRACE_OPERANDS) != 0) {
  224. if (P->DataType == BYTE_DATA) {
  225. DEBUG_PRINT(("\n Rsl - %02lx", Result));
  226. } else if (P->DataType == WORD_DATA) {
  227. DEBUG_PRINT(("\n Rsl - %04lx", Result));
  228. } else {
  229. DEBUG_PRINT(("\n Rsl - %08lx", Result));
  230. }
  231. }
  232. return;
  233. }
  234. VOID
  235. XmTraceSpecifier (
  236. IN UCHAR Specifier
  237. )
  238. /*++
  239. Routine Description:
  240. This function traces the specifiern if the TRACE_OPERANDS flag is
  241. set.
  242. Arguments:
  243. Specifier - Supplies the specifier value to trace.
  244. Return Value:
  245. None.
  246. --*/
  247. {
  248. //
  249. // Trace instruction stream of operation.
  250. //
  251. if ((XmDebugFlags & TRACE_OPERANDS) != 0) {
  252. DEBUG_PRINT(("%02lx ", Specifier));
  253. if ((XmDebugFlags & TRACE_SPECIFIERS) != 0) {
  254. DEBUG_PRINT(("(mod-%01lx reg-%01lx r/m-%01lx) ",
  255. (Specifier >> 6) & 0x3,
  256. (Specifier >> 3) & 0x7,
  257. (Specifier >> 0) & 0x7));
  258. }
  259. }
  260. return;
  261. }
  262. VOID
  263. XmTraceSource (
  264. IN PRXM_CONTEXT P,
  265. IN ULONG Source
  266. )
  267. /*++
  268. Routine Description:
  269. This function traces the source value if the TRACE_OPERANDS
  270. flag is set.
  271. Arguments:
  272. P - Supplies a pointer to an emulator context structure.
  273. Source - Supplies the source value to trace.
  274. Return Value:
  275. None.
  276. --*/
  277. {
  278. //
  279. // Trace result of operation.
  280. //
  281. if ((XmDebugFlags & TRACE_OPERANDS) != 0) {
  282. if (P->DataType == BYTE_DATA) {
  283. DEBUG_PRINT(("\n Src - %02lx", Source));
  284. } else if (P->DataType == WORD_DATA) {
  285. DEBUG_PRINT(("\n Src - %04lx", Source));
  286. } else {
  287. DEBUG_PRINT(("\n Src - %08lx", Source));
  288. }
  289. }
  290. return;
  291. }
  292. #endif