ReactOS 0.4.15-dev-8348-gc1b9bb5
cpu.c File Reference
#include "ntvdm.h"
#include <debug.h>
#include "emulator.h"
#include "cpu.h"
#include "memory.h"
#include "callback.h"
#include "bop.h"
#include <isvbop.h>
#include "clock.h"
#include "bios/rom.h"
#include "hardware/cmos.h"
#include "hardware/keyboard.h"
#include "hardware/mouse.h"
#include "hardware/pic.h"
#include "hardware/ps2.h"
#include "hardware/sound/speaker.h"
#include "hardware/pit.h"
#include "hardware/video/svga.h"
#include "io.h"
Include dependency graph for cpu.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID CpuExecute (WORD Segment, WORD Offset)
 
VOID CpuStep (VOID)
 
LONG CpuExceptionFilter (IN PEXCEPTION_POINTERS ExceptionInfo)
 
VOID CpuSimulate (VOID)
 
VOID CpuUnsimulate (VOID)
 
static VOID WINAPI CpuUnsimulateBop (LPWORD Stack)
 
BOOLEAN CpuInitialize (VOID)
 
VOID CpuCleanup (VOID)
 

Variables

FAST486_STATE EmulatorContext
 
BOOLEAN CpuRunning = FALSE
 
static const INT MaxCpuCallLevel = 32
 
static INT CpuCallLevel = 0
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file cpu.c.

Function Documentation

◆ CpuCleanup()

VOID CpuCleanup ( VOID  )

Definition at line 243 of file cpu.c.

244{
245 // Fast486Cleanup();
246}

Referenced by EmulatorCleanup().

◆ CpuExceptionFilter()

LONG CpuExceptionFilter ( IN PEXCEPTION_POINTERS  ExceptionInfo)

Definition at line 117 of file cpu.c.

118{
119 /* Get the exception record */
120 PEXCEPTION_RECORD ExceptionRecord = ExceptionInfo->ExceptionRecord;
121
122 switch (ExceptionRecord->ExceptionCode)
123 {
124 /* We only handle access violations so far */
126 {
127 BOOLEAN Writing = (ExceptionRecord->ExceptionInformation[0] == 1);
128
129 /* Retrieve the address to which a read or write attempt was made */
130 ULONG_PTR Address = ExceptionRecord->ExceptionInformation[1];
131
132 /*
133 * Check whether the access exception was done inside the virtual memory space
134 * (caused by an emulated app) or outside (caused by a bug in ourselves).
135 */
138 {
139 DPRINT1("NTVDM: %s access violation at 0x%p outside the virtual memory space!\n",
140 (Writing ? "Write" : "Read"), Address);
142 }
143
144 /* We are good to go, dispatch to our memory handlers */
145
146 /* Fix the CPU state */
148
149 /* Call the memory handler */
151
152 /* The execution of the CPU opcode handler MUST NOT continue */
154 }
155
156 default:
157 {
158 DPRINT1("NTVDM: Exception 0x%08lx not handled!\n", ExceptionRecord->ExceptionCode);
159 break;
160 }
161 }
162
163 /* Continue to search for a handler */
165}
unsigned char BOOLEAN
#define MAX_ADDRESS
#define DPRINT1
Definition: precomp.h:8
#define ULONG_PTR
Definition: config.h:101
#define PHYS_TO_REAL(ptr)
Definition: emulator.h:38
VOID NTAPI Fast486Rewind(PFAST486_STATE State)
Definition: fast486.c:252
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
static WCHAR Address[46]
Definition: ping.c:68
struct _EXCEPTION_RECORD * ExceptionRecord
Definition: compat.h:210
DWORD ExceptionCode
Definition: compat.h:208
ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]
Definition: compat.h:213
FAST486_STATE EmulatorContext
Definition: cpu.c:39
VOID MemExceptionHandler(ULONG FaultAddress, BOOLEAN Writing)
Definition: memory.c:286
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define EXCEPTION_ACCESS_VIOLATION
Definition: winbase.h:311

Referenced by CpuSimulate().

◆ CpuExecute()

VOID CpuExecute ( WORD  Segment,
WORD  Offset 
)

Definition at line 102 of file cpu.c.

103{
104 /* Tell Fast486 to move the instruction pointer */
106}
VOID NTAPI Fast486ExecuteAt(PFAST486_STATE State, USHORT Segment, ULONG Offset)
Definition: fast486.c:212
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Inout_ PVOID Segment
Definition: exfuncs.h:1101

Referenced by DosLoadExecutableInternal(), setEIP(), and setIP().

◆ CpuInitialize()

BOOLEAN CpuInitialize ( VOID  )

Definition at line 216 of file cpu.c.

217{
218 // /* Initialize the internal clock */
219 // if (!ClockInitialize())
220 // {
221 // wprintf(L"FATAL: Failed to initialize the clock\n");
222 // return FALSE;
223 // }
224
225 /* Initialize the CPU */
234 NULL /* TODO: Use a TLB */);
235
236 /* Initialize the software callback system and register the emulator BOPs */
237 // RegisterBop(BOP_DEBUGGER , EmulatorDebugBreakBop);
239
240 return TRUE;
241}
VOID FASTCALL EmulatorBiosOperation(PFAST486_STATE State, UCHAR BopCode)
Definition: bop.c:34
VOID RegisterBop(BYTE BopCode, EMULATOR_BOP_PROC BopHandler)
Definition: bop.c:29
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
UCHAR FASTCALL EmulatorIntAcknowledge(PFAST486_STATE State)
Definition: emulator.c:71
VOID FASTCALL EmulatorFpu(PFAST486_STATE State)
Definition: emulator.c:79
VOID NTAPI Fast486Initialize(PFAST486_STATE State, FAST486_MEM_READ_PROC MemReadCallback, FAST486_MEM_WRITE_PROC MemWriteCallback, FAST486_IO_READ_PROC IoReadCallback, FAST486_IO_WRITE_PROC IoWriteCallback, FAST486_BOP_PROC BopCallback, FAST486_INT_ACK_PROC IntAckCallback, FAST486_FPU_PROC FpuCallback, PULONG Tlb)
Definition: fast486.c:103
#define BOP_UNSIMULATE
Definition: isvbop.h:31
static VOID WINAPI CpuUnsimulateBop(LPWORD Stack)
Definition: cpu.c:209
VOID FASTCALL EmulatorReadIo(PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG DataCount, UCHAR DataSize)
Definition: io.c:349
VOID FASTCALL EmulatorWriteIo(PFAST486_STATE State, USHORT Port, PVOID Buffer, ULONG DataCount, UCHAR DataSize)
Definition: io.c:424
VOID FASTCALL EmulatorReadMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:142
VOID FASTCALL EmulatorWriteMemory(PFAST486_STATE State, ULONG Address, PVOID Buffer, ULONG Size)
Definition: memory.c:186

Referenced by EmulatorInitialize().

◆ CpuSimulate()

VOID CpuSimulate ( VOID  )

Definition at line 167 of file cpu.c.

168{
170 {
171 DisplayMessage(L"Too many CPU levels of recursion (%d, expected maximum %d)",
173
174 /* Stop the VDM */
176 return;
177 }
178 CpuCallLevel++;
179 DPRINT("CpuSimulate --> Level %d\n", CpuCallLevel);
180
182 while (VdmRunning && CpuRunning)
183 {
185 {
186 while (VdmRunning && CpuRunning) ClockUpdate();
187 }
189 {
190 DPRINT("VDM exception handler called\n");
191 }
192 _SEH2_END;
193 }
194
195 DPRINT("CpuSimulate <-- Level %d\n", CpuCallLevel);
196 CpuCallLevel--;
197 if (!VdmRunning || CpuCallLevel < 0) CpuCallLevel = 0;
198
199 /* This takes into account for reentrance */
200 if (VdmRunning && (CpuCallLevel > 0)) CpuRunning = TRUE;
201}
VOID EmulatorTerminate(VOID)
Definition: emulator.c:503
BOOLEAN VdmRunning
Definition: emulator.c:49
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define L(x)
Definition: ntvdm.h:50
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:164
void DisplayMessage(BOOL bConsole, BOOL bSilent, LPCTSTR lpMessage, LPCTSTR lpTitle, UINT uType)
Definition: regsvr32.c:239
#define DPRINT
Definition: sndvol32.h:73
VOID ClockUpdate(VOID)
Definition: clock.c:76
BOOLEAN CpuRunning
Definition: cpu.c:40
LONG CpuExceptionFilter(IN PEXCEPTION_POINTERS ExceptionInfo)
Definition: cpu.c:117
static INT CpuCallLevel
Definition: cpu.c:44
static const INT MaxCpuCallLevel
Definition: cpu.c:43

Referenced by Call16(), VDDSimulate16(), and wmain().

◆ CpuStep()

VOID CpuStep ( VOID  )

Definition at line 108 of file cpu.c.

109{
110 /* Dump the state for debugging purposes */
111 // Fast486DumpState(&EmulatorContext);
112
113 /* Execute the next instruction */
115}
VOID NTAPI Fast486StepInto(PFAST486_STATE State)
Definition: debug.c:248

Referenced by ClockUpdate().

◆ CpuUnsimulate()

VOID CpuUnsimulate ( VOID  )

Definition at line 203 of file cpu.c.

204{
205 /* Stop simulation */
207}
#define FALSE
Definition: types.h:117

Referenced by CpuUnsimulateBop(), DosTerminateProcess(), and EmulatorTerminate().

◆ CpuUnsimulateBop()

static VOID WINAPI CpuUnsimulateBop ( LPWORD  Stack)
static

Definition at line 209 of file cpu.c.

210{
212}
VOID CpuUnsimulate(VOID)
Definition: cpu.c:203

Referenced by CpuInitialize().

Variable Documentation

◆ CpuCallLevel

INT CpuCallLevel = 0
static

Definition at line 44 of file cpu.c.

Referenced by CpuSimulate().

◆ CpuRunning

BOOLEAN CpuRunning = FALSE

Definition at line 40 of file cpu.c.

Referenced by ClockUpdate(), CpuSimulate(), and CpuUnsimulate().

◆ EmulatorContext

◆ MaxCpuCallLevel

const INT MaxCpuCallLevel = 32
static

Definition at line 43 of file cpu.c.

Referenced by CpuSimulate().