ReactOS  0.4.13-dev-982-g9853eab
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 /* 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))
21 
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.
27 
28 #define SEG_OFF_TO_PTR(seg, off) \
29  (PVOID)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), (off)))
30 
31 #define FAR_POINTER(x) SEG_OFF_TO_PTR(HIWORD(x), LOWORD(x))
32 
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)
35 
36 #define ARRAY_INDEX(ptr, array) ((ULONG)(((ULONG_PTR)(ptr) - (ULONG_PTR)(array)) / sizeof(*array)))
37 
38 /* BCD-Binary conversion */
39 
41 USHORT
43 {
44  USHORT Result;
45 
46  Result = (Value / 1000) << 12;
47  Value %= 1000;
48  Result |= (Value / 100) << 8;
49  Value %= 100;
50  Result |= (Value / 10) << 4;
51  Value %= 10;
52  Result |= Value;
53 
54  return Result;
55 }
56 
58 USHORT
60 {
61  USHORT Result;
62 
63  Result = Value & 0xF;
64  Value >>= 4;
65  Result += (Value & 0xF) * 10;
66  Value >>= 4;
67  Result += (Value & 0xF) * 100;
68  Value >>= 4;
69  Result += Value * 1000;
70 
71  return Result;
72 }
73 
74 enum
75 {
91 };
92 
93 extern FAST486_STATE EmulatorContext;
94 extern LPVOID BaseAddress;
95 extern BOOLEAN VdmRunning;
96 
97 /* FUNCTIONS ******************************************************************/
98 
99 VOID DumpMemory(BOOLEAN TextFormat);
100 
101 VOID MountFloppy(IN ULONG DiskNumber);
102 VOID EjectFloppy(IN ULONG DiskNumber);
103 
105 (
106  PFAST486_STATE State
107 );
108 
110 (
111  PFAST486_STATE State
112 );
113 
115 VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack);
116 
120 
123 
124 #endif // _EMULATOR_H_
125 
126 /* EOF */
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define IN
Definition: typedefs.h:38
FORCEINLINE USHORT BINARY_TO_BCD(USHORT Value)
Definition: emulator.h:42
BOOLEAN VdmRunning
Definition: emulator.c:49
FAST486_STATE EmulatorContext
Definition: cpu.c:39
#define FASTCALL
Definition: nt_native.h:50
C_ASSERT(0x100000<=MAX_ADDRESS)
VOID EjectFloppy(IN ULONG DiskNumber)
Definition: emulator.c:467
VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack)
Definition: emulator.c:85
unsigned char BOOLEAN
#define FORCEINLINE
Definition: ntbasedef.h:221
_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:426
FORCEINLINE USHORT BCD_TO_BINARY(USHORT Value)
Definition: emulator.h:59
BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput)
Definition: emulator.c:510
unsigned char UCHAR
Definition: xmlstorage.h:181
unsigned char BYTE
Definition: mem.h:68
UCHAR FASTCALL EmulatorIntAcknowledge(PFAST486_STATE State)
Definition: emulator.c:71
uint16_t * LPWORD
Definition: typedefs.h:54
VOID MountFloppy(IN ULONG DiskNumber)
Definition: emulator.c:413
VOID EmulatorCleanup(VOID)
Definition: emulator.c:639
unsigned short USHORT
Definition: pedump.c:61
VOID EmulatorPause(VOID)
Definition: emulator.c:487
LPVOID BaseAddress
Definition: mmfuncs.h:404
VOID DumpMemory(BOOLEAN TextFormat)
Definition: emulator.c:369
static HANDLE ConsoleOutput
Definition: console.c:17
VOID EmulatorInterruptSignal(VOID)
Definition: emulator.c:120
unsigned int ULONG
Definition: retypes.h:1
VOID EmulatorResume(VOID)
Definition: emulator.c:495
VOID FASTCALL EmulatorFpu(PFAST486_STATE State)
Definition: emulator.c:79
VOID EmulatorTerminate(VOID)
Definition: emulator.c:503
#define MAX_ADDRESS
Definition: emulator.h:25