ReactOS  0.4.14-dev-114-gc8cbd56
debug.c File Reference
#include <windef.h>
#include <debug.h>
#include <fast486.h>
#include "common.h"
#include "opcodes.h"
#include "fpu.h"
Include dependency graph for debug.c:

Go to the source code of this file.

Enumerations

enum  FAST486_EXEC_CMD { FAST486_STEP_INTO, FAST486_STEP_OVER, FAST486_STEP_OUT, FAST486_CONTINUE }
 

Functions

FORCEINLINE VOID FASTCALL Fast486ExecutionControl (PFAST486_STATE State, FAST486_EXEC_CMD Command)
 
VOID NTAPI Fast486DumpState (PFAST486_STATE State)
 
VOID NTAPI Fast486Continue (PFAST486_STATE State)
 
VOID NTAPI Fast486StepInto (PFAST486_STATE State)
 
VOID NTAPI Fast486StepOver (PFAST486_STATE State)
 
VOID NTAPI Fast486StepOut (PFAST486_STATE State)
 

Enumeration Type Documentation

◆ FAST486_EXEC_CMD

Enumerator
FAST486_STEP_INTO 
FAST486_STEP_OVER 
FAST486_STEP_OUT 
FAST486_CONTINUE 

Definition at line 36 of file debug.c.

Function Documentation

◆ Fast486Continue()

VOID NTAPI Fast486Continue ( PFAST486_STATE  State)

Definition at line 240 of file debug.c.

241 {
242  /* Call the internal function */
244 }
FORCEINLINE VOID FASTCALL Fast486ExecutionControl(PFAST486_STATE State, FAST486_EXEC_CMD Command)
Definition: debug.c:49

◆ Fast486DumpState()

VOID NTAPI Fast486DumpState ( PFAST486_STATE  State)

Definition at line 127 of file debug.c.

128 {
129  DbgPrint("\nFast486DumpState -->\n");
130  DbgPrint("\nCPU currently executing in %s mode at %04X:%08X\n",
131  (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE) ? "protected" : "real",
132  State->SegmentRegs[FAST486_REG_CS].Selector,
133  State->InstPtr.Long);
134  DbgPrint("\nGeneral purpose registers:\n"
135  "EAX = %08X\tECX = %08X\tEDX = %08X\tEBX = %08X\n"
136  "ESP = %08X\tEBP = %08X\tESI = %08X\tEDI = %08X\n",
137  State->GeneralRegs[FAST486_REG_EAX].Long,
138  State->GeneralRegs[FAST486_REG_ECX].Long,
139  State->GeneralRegs[FAST486_REG_EDX].Long,
140  State->GeneralRegs[FAST486_REG_EBX].Long,
141  State->GeneralRegs[FAST486_REG_ESP].Long,
142  State->GeneralRegs[FAST486_REG_EBP].Long,
143  State->GeneralRegs[FAST486_REG_ESI].Long,
144  State->GeneralRegs[FAST486_REG_EDI].Long);
145  DbgPrint("\nSegment registers:\n"
146  "ES = %04X (Base: %08X, Limit: %08X, Dpl: %u)\n"
147  "CS = %04X (Base: %08X, Limit: %08X, Dpl: %u)\n"
148  "SS = %04X (Base: %08X, Limit: %08X, Dpl: %u)\n"
149  "DS = %04X (Base: %08X, Limit: %08X, Dpl: %u)\n"
150  "FS = %04X (Base: %08X, Limit: %08X, Dpl: %u)\n"
151  "GS = %04X (Base: %08X, Limit: %08X, Dpl: %u)\n",
152  State->SegmentRegs[FAST486_REG_ES].Selector,
153  State->SegmentRegs[FAST486_REG_ES].Base,
154  State->SegmentRegs[FAST486_REG_ES].Limit,
155  State->SegmentRegs[FAST486_REG_ES].Dpl,
156  State->SegmentRegs[FAST486_REG_CS].Selector,
157  State->SegmentRegs[FAST486_REG_CS].Base,
158  State->SegmentRegs[FAST486_REG_CS].Limit,
159  State->SegmentRegs[FAST486_REG_CS].Dpl,
160  State->SegmentRegs[FAST486_REG_SS].Selector,
161  State->SegmentRegs[FAST486_REG_SS].Base,
162  State->SegmentRegs[FAST486_REG_SS].Limit,
163  State->SegmentRegs[FAST486_REG_SS].Dpl,
164  State->SegmentRegs[FAST486_REG_DS].Selector,
165  State->SegmentRegs[FAST486_REG_DS].Base,
166  State->SegmentRegs[FAST486_REG_DS].Limit,
167  State->SegmentRegs[FAST486_REG_DS].Dpl,
168  State->SegmentRegs[FAST486_REG_FS].Selector,
169  State->SegmentRegs[FAST486_REG_FS].Base,
170  State->SegmentRegs[FAST486_REG_FS].Limit,
171  State->SegmentRegs[FAST486_REG_FS].Dpl,
172  State->SegmentRegs[FAST486_REG_GS].Selector,
173  State->SegmentRegs[FAST486_REG_GS].Base,
174  State->SegmentRegs[FAST486_REG_GS].Limit,
175  State->SegmentRegs[FAST486_REG_GS].Dpl);
176  DbgPrint("\nFlags: %08X (%s %s %s %s %s %s %s %s %s %s %s %s %s) Iopl: %u\n",
177  State->Flags.Long,
178  State->Flags.Cf ? "CF" : "cf",
179  State->Flags.Pf ? "PF" : "pf",
180  State->Flags.Af ? "AF" : "af",
181  State->Flags.Zf ? "ZF" : "zf",
182  State->Flags.Sf ? "SF" : "sf",
183  State->Flags.Tf ? "TF" : "tf",
184  State->Flags.If ? "IF" : "if",
185  State->Flags.Df ? "DF" : "df",
186  State->Flags.Of ? "OF" : "of",
187  State->Flags.Nt ? "NT" : "nt",
188  State->Flags.Rf ? "RF" : "rf",
189  State->Flags.Vm ? "VM" : "vm",
190  State->Flags.Ac ? "AC" : "ac",
191  State->Flags.Iopl);
192  DbgPrint("\nControl Registers:\n"
193  "CR0 = %08X\tCR2 = %08X\tCR3 = %08X\n",
194  State->ControlRegisters[FAST486_REG_CR0],
195  State->ControlRegisters[FAST486_REG_CR2],
196  State->ControlRegisters[FAST486_REG_CR3]);
197  DbgPrint("\nDebug Registers:\n"
198  "DR0 = %08X\tDR1 = %08X\tDR2 = %08X\n"
199  "DR3 = %08X\tDR4 = %08X\tDR5 = %08X\n",
200  State->DebugRegisters[FAST486_REG_DR0],
201  State->DebugRegisters[FAST486_REG_DR1],
202  State->DebugRegisters[FAST486_REG_DR2],
203  State->DebugRegisters[FAST486_REG_DR3],
204  State->DebugRegisters[FAST486_REG_DR4],
205  State->DebugRegisters[FAST486_REG_DR5]);
206 
207 #ifndef FAST486_NO_FPU
208  DbgPrint("\nFPU Registers:\n"
209  "ST0 = %04X%016llX\tST1 = %04X%016llX\n"
210  "ST2 = %04X%016llX\tST3 = %04X%016llX\n"
211  "ST4 = %04X%016llX\tST5 = %04X%016llX\n"
212  "ST6 = %04X%016llX\tST7 = %04X%016llX\n"
213  "Status: %04X\tControl: %04X\tTag: %04X\n",
214  FPU_ST(0).Exponent | ((USHORT)FPU_ST(0).Sign << 15),
215  FPU_ST(0).Mantissa,
216  FPU_ST(1).Exponent | ((USHORT)FPU_ST(1).Sign << 15),
217  FPU_ST(1).Mantissa,
218  FPU_ST(2).Exponent | ((USHORT)FPU_ST(2).Sign << 15),
219  FPU_ST(2).Mantissa,
220  FPU_ST(3).Exponent | ((USHORT)FPU_ST(3).Sign << 15),
221  FPU_ST(3).Mantissa,
222  FPU_ST(4).Exponent | ((USHORT)FPU_ST(4).Sign << 15),
223  FPU_ST(4).Mantissa,
224  FPU_ST(5).Exponent | ((USHORT)FPU_ST(5).Sign << 15),
225  FPU_ST(5).Mantissa,
226  FPU_ST(6).Exponent | ((USHORT)FPU_ST(6).Sign << 15),
227  FPU_ST(6).Mantissa,
228  FPU_ST(7).Exponent | ((USHORT)FPU_ST(7).Sign << 15),
229  FPU_ST(7).Mantissa,
230  State->FpuStatus,
231  State->FpuControl,
232  State->FpuTag);
233 #endif
234 
235  DbgPrint("\n<-- Fast486DumpState\n\n");
236 }
ULONG DbgPrint(PCCH Format,...)
Definition: debug.c:416
#define FPU_ST(i)
Definition: fpu.h:37
#define FAST486_CR0_PE
Definition: fast486.h:46
Definition: msg.c:1064
unsigned short USHORT
Definition: pedump.c:61

Referenced by EmulatorException().

◆ Fast486ExecutionControl()

FORCEINLINE VOID FASTCALL Fast486ExecutionControl ( PFAST486_STATE  State,
FAST486_EXEC_CMD  Command 
)

Definition at line 49 of file debug.c.

50 {
51  UCHAR Opcode;
52  FAST486_OPCODE_HANDLER_PROC CurrentHandler;
53  INT ProcedureCallCount = 0;
54  BOOLEAN Trap;
55 
56  /* Main execution loop */
57  do
58  {
59  Trap = State->Flags.Tf;
60 
61  if (!State->Halted)
62  {
63 NextInst:
64  /* Check if this is a new instruction */
65  if (State->PrefixFlags == 0)
66  {
67  State->SavedInstPtr = State->InstPtr;
68  State->SavedStackPtr = State->GeneralRegs[FAST486_REG_ESP];
69  }
70 
71  /* Perform an instruction fetch */
72  if (!Fast486FetchByte(State, &Opcode))
73  {
74  /* Exception occurred */
75  State->PrefixFlags = 0;
76  continue;
77  }
78 
79  // TODO: Check for CALL/RET to update ProcedureCallCount.
80 
81  /* Call the opcode handler */
82  CurrentHandler = Fast486OpcodeHandlers[Opcode];
83  CurrentHandler(State, Opcode);
84 
85  /* If this is a prefix, go to the next instruction immediately */
86  if (CurrentHandler == Fast486OpcodePrefix) goto NextInst;
87 
88  /* A non-prefix opcode has been executed, reset the prefix flags */
89  State->PrefixFlags = 0;
90  }
91 
92  /*
93  * Check if there is an interrupt to execute, or a hardware interrupt signal
94  * while interrupts are enabled.
95  */
96  if (State->DoNotInterrupt)
97  {
98  /* Clear the interrupt delay flag */
99  State->DoNotInterrupt = FALSE;
100  }
101  else if (Trap && !State->Halted)
102  {
103  /* Perform the interrupt */
104  Fast486PerformInterrupt(State, FAST486_EXCEPTION_DB);
105  }
106  else if (State->Flags.If && State->IntSignaled)
107  {
108  /* No longer halted */
109  State->Halted = FALSE;
110 
111  /* Acknowledge the interrupt and perform it */
112  Fast486PerformInterrupt(State, State->IntAckCallback(State));
113 
114  /* Clear the interrupt status */
115  State->IntSignaled = FALSE;
116  }
117  }
118  while ((Command == FAST486_CONTINUE) ||
119  (Command == FAST486_STEP_OVER && ProcedureCallCount > 0) ||
120  (Command == FAST486_STEP_OUT && ProcedureCallCount >= 0));
121 }
_In_ PVOID _In_ ULONG Opcode
Definition: hubbusif.h:330
FAST486_OPCODE_HANDLER_PROC Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS]
Definition: opcodes.c:39
Definition: shell.h:41
int32_t INT
Definition: typedefs.h:56
unsigned char BOOLEAN
BOOLEAN FASTCALL Fast486PerformInterrupt(PFAST486_STATE State, UCHAR Number)
Definition: common.c:533
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID(FASTCALL * FAST486_OPCODE_HANDLER_PROC)(PFAST486_STATE, UCHAR)
Definition: opcodes.h:34

Referenced by Fast486Continue(), Fast486StepInto(), Fast486StepOut(), and Fast486StepOver().

◆ Fast486StepInto()

VOID NTAPI Fast486StepInto ( PFAST486_STATE  State)

Definition at line 248 of file debug.c.

249 {
250  /* Call the internal function */
252 }
FORCEINLINE VOID FASTCALL Fast486ExecutionControl(PFAST486_STATE State, FAST486_EXEC_CMD Command)
Definition: debug.c:49

Referenced by CpuStep(), and x86BiosCall().

◆ Fast486StepOut()

VOID NTAPI Fast486StepOut ( PFAST486_STATE  State)

Definition at line 264 of file debug.c.

265 {
266  /* Call the internal function */
268 }
FORCEINLINE VOID FASTCALL Fast486ExecutionControl(PFAST486_STATE State, FAST486_EXEC_CMD Command)
Definition: debug.c:49

◆ Fast486StepOver()

VOID NTAPI Fast486StepOver ( PFAST486_STATE  State)

Definition at line 256 of file debug.c.

257 {
258  /* Call the internal function */
260 }
FORCEINLINE VOID FASTCALL Fast486ExecutionControl(PFAST486_STATE State, FAST486_EXEC_CMD Command)
Definition: debug.c:49