2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: subsystems/mvdm/ntvdm/emulator.h
5 * PURPOSE: Minimal x86 machine emulator for the VDM
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
12 /* INCLUDES *******************************************************************/
16 /* DEFINES ********************************************************************/
18 /* Basic Memory Management */
19 #define MEM_ALIGN_DOWN(ptr, align) (PVOID)((ULONG_PTR)(ptr) & ~((align) - 1l))
20 #define MEM_ALIGN_UP(ptr, align) MEM_ALIGN_DOWN((ULONG_PTR)(ptr) + (align) - 1l, (align))
22 #define TO_LINEAR(seg, off) (((seg) << 4) + (off))
23 #define MAX_SEGMENT 0xFFFF
24 #define MAX_OFFSET 0xFFFF
25 #define MAX_ADDRESS 0x1000000 // 16 MB of RAM; see also: kernel32/client/vdm.c!BaseGetVdmConfigInfo
26 C_ASSERT(0x100000 <= MAX_ADDRESS
); // A minimum of 1 MB is required for PC emulation.
28 #define SEG_OFF_TO_PTR(seg, off) \
29 (PVOID)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), (off)))
31 #define FAR_POINTER(x) SEG_OFF_TO_PTR(HIWORD(x), LOWORD(x))
33 #define REAL_TO_PHYS(ptr) (PVOID)((ULONG_PTR)(ptr) + (ULONG_PTR)BaseAddress)
34 #define PHYS_TO_REAL(ptr) (PVOID)((ULONG_PTR)(ptr) - (ULONG_PTR)BaseAddress)
36 #define ARRAY_INDEX(ptr, array) ((ULONG)(((ULONG_PTR)(ptr) - (ULONG_PTR)(array)) / sizeof(*array)))
38 /* BCD-Binary conversion */
42 BINARY_TO_BCD(USHORT Value
)
46 Result
= (Value
/ 1000) << 12;
48 Result
|= (Value
/ 100) << 8;
50 Result
|= (Value
/ 10) << 4;
59 BCD_TO_BINARY(USHORT Value
)
65 Result
+= (Value
& 0xF) * 10;
67 Result
+= (Value
& 0xF) * 100;
69 Result
+= Value
* 1000;
76 EMULATOR_EXCEPTION_DIVISION_BY_ZERO
,
77 EMULATOR_EXCEPTION_DEBUG
,
78 EMULATOR_EXCEPTION_NMI
,
79 EMULATOR_EXCEPTION_BREAKPOINT
,
80 EMULATOR_EXCEPTION_OVERFLOW
,
81 EMULATOR_EXCEPTION_BOUND
,
82 EMULATOR_EXCEPTION_INVALID_OPCODE
,
83 EMULATOR_EXCEPTION_NO_FPU
,
84 EMULATOR_EXCEPTION_DOUBLE_FAULT
,
85 EMULATOR_EXCEPTION_FPU_SEGMENT
,
86 EMULATOR_EXCEPTION_INVALID_TSS
,
87 EMULATOR_EXCEPTION_NO_SEGMENT
,
88 EMULATOR_EXCEPTION_STACK_SEGMENT
,
89 EMULATOR_EXCEPTION_GPF
,
90 EMULATOR_EXCEPTION_PAGE_FAULT
93 extern FAST486_STATE EmulatorContext
;
94 extern LPVOID BaseAddress
;
95 extern BOOLEAN VdmRunning
;
97 /* FUNCTIONS ******************************************************************/
99 VOID
DumpMemory(BOOLEAN TextFormat
);
101 VOID
MountFloppy(IN ULONG DiskNumber
);
102 VOID
EjectFloppy(IN ULONG DiskNumber
);
104 UCHAR FASTCALL EmulatorIntAcknowledge
109 VOID FASTCALL EmulatorFpu
114 VOID
EmulatorInterruptSignal(VOID
);
115 VOID
EmulatorException(BYTE ExceptionNumber
, LPWORD Stack
);
117 VOID
EmulatorPause(VOID
);
118 VOID
EmulatorResume(VOID
);
119 VOID
EmulatorTerminate(VOID
);
121 BOOLEAN
EmulatorInitialize(HANDLE ConsoleInput
, HANDLE ConsoleOutput
);
122 VOID
EmulatorCleanup(VOID
);
124 #endif // _EMULATOR_H_