[FAST486]
[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 0xBEEF
40 #define STACK_COUNTER 0
41 #define STACK_INT_NUM 1
42 #define STACK_IP 2
43 #define STACK_CS 3
44 #define STACK_FLAGS 4
45
46 enum
47 {
48 EMULATOR_EXCEPTION_DIVISION_BY_ZERO,
49 EMULATOR_EXCEPTION_DEBUG,
50 EMULATOR_EXCEPTION_NMI,
51 EMULATOR_EXCEPTION_BREAKPOINT,
52 EMULATOR_EXCEPTION_OVERFLOW,
53 EMULATOR_EXCEPTION_BOUND,
54 EMULATOR_EXCEPTION_INVALID_OPCODE,
55 EMULATOR_EXCEPTION_NO_FPU,
56 EMULATOR_EXCEPTION_DOUBLE_FAULT,
57 EMULATOR_EXCEPTION_FPU_SEGMENT,
58 EMULATOR_EXCEPTION_INVALID_TSS,
59 EMULATOR_EXCEPTION_NO_SEGMENT,
60 EMULATOR_EXCEPTION_STACK_SEGMENT,
61 EMULATOR_EXCEPTION_GPF,
62 EMULATOR_EXCEPTION_PAGE_FAULT
63 };
64
65 enum
66 {
67 EMULATOR_REG_AX,
68 EMULATOR_REG_CX,
69 EMULATOR_REG_DX,
70 EMULATOR_REG_BX,
71 EMULATOR_REG_SP,
72 EMULATOR_REG_BP,
73 EMULATOR_REG_SI,
74 EMULATOR_REG_DI,
75 EMULATOR_REG_ES,
76 EMULATOR_REG_CS,
77 EMULATOR_REG_SS,
78 EMULATOR_REG_DS,
79 EMULATOR_REG_FS,
80 EMULATOR_REG_GS
81 };
82
83 extern FAST486_STATE EmulatorContext;
84
85 /* FUNCTIONS ******************************************************************/
86
87 BOOLEAN EmulatorInitialize();
88 VOID EmulatorSetStack(WORD Segment, DWORD Offset);
89 VOID EmulatorExecute(WORD Segment, WORD Offset);
90 VOID EmulatorInterrupt(BYTE Number);
91 VOID EmulatorInterruptSignal(VOID);
92 ULONG EmulatorGetRegister(ULONG Register);
93 ULONG EmulatorGetProgramCounter(VOID);
94 VOID EmulatorSetRegister(ULONG Register, ULONG Value);
95 BOOLEAN EmulatorGetFlag(ULONG Flag);
96 VOID EmulatorSetFlag(ULONG Flag);
97 VOID EmulatorClearFlag(ULONG Flag);
98 VOID EmulatorStep();
99 VOID EmulatorCleanup();
100 VOID EmulatorSetA20(BOOLEAN Enabled);
101
102 #endif // _EMULATOR_H_
103
104 /* EOF */