[FAST486][NTVDM]
[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 (header file)
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 /* FLAGS */
20 #define EMULATOR_FLAG_CF (1 << 0)
21 #define EMULATOR_FLAG_PF (1 << 2)
22 #define EMULATOR_FLAG_AF (1 << 4)
23 #define EMULATOR_FLAG_ZF (1 << 6)
24 #define EMULATOR_FLAG_SF (1 << 7)
25 #define EMULATOR_FLAG_TF (1 << 8)
26 #define EMULATOR_FLAG_IF (1 << 9)
27 #define EMULATOR_FLAG_DF (1 << 10)
28 #define EMULATOR_FLAG_OF (1 << 11)
29 #define EMULATOR_FLAG_NT (1 << 14)
30 #define EMULATOR_FLAG_RF (1 << 16)
31 #define EMULATOR_FLAG_VM (1 << 17)
32 #define EMULATOR_FLAG_AC (1 << 18)
33 #define EMULATOR_FLAG_VIF (1 << 19)
34 #define EMULATOR_FLAG_VIP (1 << 20)
35 #define EMULATOR_FLAG_ID (1 << 21)
36
37 /* Common definitions */
38 #define EMULATOR_BOP 0xC4C4
39 #define EMULATOR_INT_BOP 0xFF
40
41 #define STACK_COUNTER 0
42 #define STACK_INT_NUM 1
43 #define STACK_IP 2
44 #define STACK_CS 3
45 #define STACK_FLAGS 4
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 enum
67 {
68 EMULATOR_REG_AX,
69 EMULATOR_REG_CX,
70 EMULATOR_REG_DX,
71 EMULATOR_REG_BX,
72 EMULATOR_REG_SP,
73 EMULATOR_REG_BP,
74 EMULATOR_REG_SI,
75 EMULATOR_REG_DI,
76 EMULATOR_REG_ES,
77 EMULATOR_REG_CS,
78 EMULATOR_REG_SS,
79 EMULATOR_REG_DS,
80 EMULATOR_REG_FS,
81 EMULATOR_REG_GS
82 };
83
84 extern FAST486_STATE EmulatorContext;
85
86 /* FUNCTIONS ******************************************************************/
87
88 BOOLEAN EmulatorInitialize();
89 VOID EmulatorSetStack(WORD Segment, DWORD Offset);
90 VOID EmulatorExecute(WORD Segment, WORD Offset);
91 VOID EmulatorInterrupt(BYTE Number);
92 VOID EmulatorInterruptSignal(VOID);
93 ULONG EmulatorGetRegister(ULONG Register);
94 ULONG EmulatorGetProgramCounter(VOID);
95 VOID EmulatorSetRegister(ULONG Register, ULONG Value);
96 BOOLEAN EmulatorGetFlag(ULONG Flag);
97 VOID EmulatorSetFlag(ULONG Flag);
98 VOID EmulatorClearFlag(ULONG Flag);
99 VOID EmulatorStep();
100 VOID EmulatorCleanup();
101 VOID EmulatorSetA20(BOOLEAN Enabled);
102
103 #endif // _EMULATOR_H_
104
105 /* EOF */