ReactOS 0.4.15-dev-7788-g1ad9096
emulator.h
Go to the documentation of this file.
1/*
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>
7 */
8
9#ifndef _EMULATOR_H_
10#define _EMULATOR_H_
11
12/* INCLUDES *******************************************************************/
13
14#include <fast486.h>
15
16/* DEFINES ********************************************************************/
17
18/*
19 * Basic Memory Management
20 */
21#define NULL32 ((ULONG)0)
22
23#define MEM_ALIGN_DOWN(ptr, align) (PVOID)((ULONG_PTR)(ptr) & ~((align) - 1l))
24#define MEM_ALIGN_UP(ptr, align) MEM_ALIGN_DOWN((ULONG_PTR)(ptr) + (align) - 1l, (align))
25
26#define TO_LINEAR(seg, off) (((seg) << 4) + (off))
27#define MAX_SEGMENT 0xFFFF
28#define MAX_OFFSET 0xFFFF
29#define MAX_ADDRESS 0x1000000 // 16 MB of RAM; see also: kernel32/client/vdm.c!BaseGetVdmConfigInfo
30C_ASSERT(0x100000 <= MAX_ADDRESS); // A minimum of 1 MB is required for PC emulation.
31
32#define SEG_OFF_TO_PTR(seg, off) \
33 (PVOID)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), (off)))
34
35#define FAR_POINTER(x) SEG_OFF_TO_PTR(HIWORD(x), LOWORD(x))
36
37#define REAL_TO_PHYS(ptr) (PVOID)((ULONG_PTR)(ptr) + (ULONG_PTR)BaseAddress)
38#define PHYS_TO_REAL(ptr) (PVOID)((ULONG_PTR)(ptr) - (ULONG_PTR)BaseAddress)
39
40#define ARRAY_INDEX(ptr, array) ((ULONG)(((ULONG_PTR)(ptr) - (ULONG_PTR)(array)) / sizeof(*array)))
41
42/*
43 * BCD-Binary conversion
44 */
45
49{
51
52 Result = (Value / 1000) << 12;
53 Value %= 1000;
54 Result |= (Value / 100) << 8;
55 Value %= 100;
56 Result |= (Value / 10) << 4;
57 Value %= 10;
58 Result |= Value;
59
60 return Result;
61}
62
66{
68
69 Result = Value & 0xF;
70 Value >>= 4;
71 Result += (Value & 0xF) * 10;
72 Value >>= 4;
73 Result += (Value & 0xF) * 100;
74 Value >>= 4;
75 Result += Value * 1000;
76
77 return Result;
78}
79
80
81/*
82 * Emulator state
83 */
84
85enum
86{
103
104extern FAST486_STATE EmulatorContext;
105extern LPVOID BaseAddress;
106extern BOOLEAN VdmRunning;
107
108
109/* FUNCTIONS ******************************************************************/
110
111VOID DumpMemory(BOOLEAN TextFormat);
112
113VOID MountFloppy(IN ULONG DiskNumber);
114VOID EjectFloppy(IN ULONG DiskNumber);
115
117(
118 PFAST486_STATE State
119);
120
122(
123 PFAST486_STATE State
124);
125
127VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack);
128
132
135
136#endif // _EMULATOR_H_
137
138/* EOF */
unsigned char BOOLEAN
VOID DumpMemory(BOOLEAN TextFormat)
Definition: emulator.c:369
VOID EmulatorInterruptSignal(VOID)
Definition: emulator.c:120
VOID EmulatorTerminate(VOID)
Definition: emulator.c:503
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
Definition: emulator.c:510
VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack)
Definition: emulator.c:85
FORCEINLINE USHORT BINARY_TO_BCD(USHORT Value)
Definition: emulator.h:48
VOID EmulatorResume(VOID)
Definition: emulator.c:495
@ EMULATOR_EXCEPTION_PAGE_FAULT
Definition: emulator.h:101
@ EMULATOR_EXCEPTION_NO_SEGMENT
Definition: emulator.h:98
@ EMULATOR_EXCEPTION_BREAKPOINT
Definition: emulator.h:90
@ EMULATOR_EXCEPTION_DEBUG
Definition: emulator.h:88
@ EMULATOR_EXCEPTION_GPF
Definition: emulator.h:100
@ EMULATOR_EXCEPTION_STACK_SEGMENT
Definition: emulator.h:99
@ EMULATOR_EXCEPTION_NMI
Definition: emulator.h:89
@ EMULATOR_EXCEPTION_NO_FPU
Definition: emulator.h:94
@ EMULATOR_EXCEPTION_DOUBLE_FAULT
Definition: emulator.h:95
@ EMULATOR_EXCEPTION_BOUND
Definition: emulator.h:92
@ EMULATOR_EXCEPTION_DIVISION_BY_ZERO
Definition: emulator.h:87
@ EMULATOR_EXCEPTION_INVALID_OPCODE
Definition: emulator.h:93
@ EMULATOR_EXCEPTION_FPU_SEGMENT
Definition: emulator.h:96
@ EMULATOR_EXCEPTION_OVERFLOW
Definition: emulator.h:91
@ EMULATOR_EXCEPTION_INVALID_TSS
Definition: emulator.h:97
#define MAX_ADDRESS
Definition: emulator.h:29
FAST486_STATE EmulatorContext
Definition: cpu.c:39
VOID EjectFloppy(IN ULONG DiskNumber)
Definition: emulator.c:467
LPVOID BaseAddress
Definition: mmfuncs.h:404
FORCEINLINE USHORT BCD_TO_BINARY(USHORT Value)
Definition: emulator.h:65
VOID EmulatorCleanup(VOID)
Definition: emulator.c:639
VOID MountFloppy(IN ULONG DiskNumber)
Definition: emulator.c:413
BOOLEAN VdmRunning
Definition: emulator.c:49
UCHAR FASTCALL EmulatorIntAcknowledge(PFAST486_STATE State)
Definition: emulator.c:71
VOID FASTCALL EmulatorFpu(PFAST486_STATE State)
Definition: emulator.c:79
VOID EmulatorPause(VOID)
Definition: emulator.c:487
#define C_ASSERT(e)
Definition: intsafe.h:73
#define FASTCALL
Definition: nt_native.h:50
unsigned short USHORT
Definition: pedump.c:61
static HANDLE ConsoleOutput
Definition: console.c:17
uint16_t * LPWORD
Definition: typedefs.h:56
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
#define FORCEINLINE
Definition: wdftypes.h:67
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned char BYTE
Definition: xxhash.c:193