* Sync up to trunk head (r64921).
[reactos.git] / subsystems / ntvdm / emulator.h
1 /*
2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: 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 "ntvdm.h"
15 #include <fast486.h>
16
17 /* DEFINES ********************************************************************/
18
19 /* Basic Memory Management */
20 #define MEM_ALIGN_UP(ptr, align) MEM_ALIGN_DOWN((ULONG_PTR)(ptr) + (align) - 1l, (align))
21 #define MEM_ALIGN_DOWN(ptr, align) (PVOID)((ULONG_PTR)(ptr) & ~((align) - 1l))
22
23 #define TO_LINEAR(seg, off) (((seg) << 4) + (off))
24 #define MAX_SEGMENT 0xFFFF
25 #define MAX_OFFSET 0xFFFF
26 #define MAX_ADDRESS 0x1000000 // 16 MB of RAM
27
28 #define FAR_POINTER(x) \
29 (PVOID)((ULONG_PTR)BaseAddress + TO_LINEAR(HIWORD(x), LOWORD(x)))
30
31 #define SEG_OFF_TO_PTR(seg, off) \
32 (PVOID)((ULONG_PTR)BaseAddress + TO_LINEAR((seg), (off)))
33
34 #define REAL_TO_PHYS(ptr) (PVOID)((ULONG_PTR)(ptr) + (ULONG_PTR)BaseAddress)
35 #define PHYS_TO_REAL(ptr) (PVOID)((ULONG_PTR)(ptr) - (ULONG_PTR)BaseAddress)
36
37
38 /* BCD-Binary conversion */
39 #define BINARY_TO_BCD(x) ((((x) / 1000) << 12) + (((x) / 100) << 8) + (((x) / 10) << 4) + ((x) % 10))
40 #define BCD_TO_BINARY(x) (((x) >> 12) * 1000 + ((x) >> 8) * 100 + ((x) >> 4) * 10 + ((x) & 0x0F))
41
42
43 /* System I/O ports */
44 #define CONTROL_SYSTEM_PORT61H 0x61
45
46
47 enum
48 {
49 EMULATOR_EXCEPTION_DIVISION_BY_ZERO,
50 EMULATOR_EXCEPTION_DEBUG,
51 EMULATOR_EXCEPTION_NMI,
52 EMULATOR_EXCEPTION_BREAKPOINT,
53 EMULATOR_EXCEPTION_OVERFLOW,
54 EMULATOR_EXCEPTION_BOUND,
55 EMULATOR_EXCEPTION_INVALID_OPCODE,
56 EMULATOR_EXCEPTION_NO_FPU,
57 EMULATOR_EXCEPTION_DOUBLE_FAULT,
58 EMULATOR_EXCEPTION_FPU_SEGMENT,
59 EMULATOR_EXCEPTION_INVALID_TSS,
60 EMULATOR_EXCEPTION_NO_SEGMENT,
61 EMULATOR_EXCEPTION_STACK_SEGMENT,
62 EMULATOR_EXCEPTION_GPF,
63 EMULATOR_EXCEPTION_PAGE_FAULT
64 };
65
66 // extern FAST486_STATE EmulatorContext;
67 extern LPVOID BaseAddress;
68 extern BOOLEAN VdmRunning;
69
70 /* FUNCTIONS ******************************************************************/
71
72 VOID DumpMemory(BOOLEAN TextFormat);
73
74 VOID WINAPI EmulatorReadMemory
75 (
76 PFAST486_STATE State,
77 ULONG Address,
78 PVOID Buffer,
79 ULONG Size
80 );
81
82 VOID WINAPI EmulatorWriteMemory
83 (
84 PFAST486_STATE State,
85 ULONG Address,
86 PVOID Buffer,
87 ULONG Size
88 );
89
90 UCHAR WINAPI EmulatorIntAcknowledge
91 (
92 PFAST486_STATE State
93 );
94
95 VOID EmulatorException(BYTE ExceptionNumber, LPWORD Stack);
96
97 VOID EmulatorTerminate(VOID);
98
99 VOID EmulatorInterrupt(BYTE Number);
100 VOID EmulatorInterruptSignal(VOID);
101 VOID EmulatorSetA20(BOOLEAN Enabled);
102
103 BOOLEAN EmulatorInitialize(HANDLE ConsoleInput, HANDLE ConsoleOutput);
104 VOID EmulatorCleanup(VOID);
105
106 #endif // _EMULATOR_H_
107
108 /* EOF */