[SOFT386]
[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
16 #ifndef NEW_EMULATOR
17 #include <softx86.h>
18 #include <softx87.h>
19 #else
20 #include <soft386.h>
21 #endif
22
23 /* DEFINES ********************************************************************/
24
25 /* FLAGS */
26 #define EMULATOR_FLAG_CF (1 << 0)
27 #define EMULATOR_FLAG_PF (1 << 2)
28 #define EMULATOR_FLAG_AF (1 << 4)
29 #define EMULATOR_FLAG_ZF (1 << 6)
30 #define EMULATOR_FLAG_SF (1 << 7)
31 #define EMULATOR_FLAG_TF (1 << 8)
32 #define EMULATOR_FLAG_IF (1 << 9)
33 #define EMULATOR_FLAG_DF (1 << 10)
34 #define EMULATOR_FLAG_OF (1 << 11)
35 #define EMULATOR_FLAG_NT (1 << 14)
36 #define EMULATOR_FLAG_RF (1 << 16)
37 #define EMULATOR_FLAG_VM (1 << 17)
38 #define EMULATOR_FLAG_AC (1 << 18)
39 #define EMULATOR_FLAG_VIF (1 << 19)
40 #define EMULATOR_FLAG_VIP (1 << 20)
41 #define EMULATOR_FLAG_ID (1 << 21)
42
43 /* Common definitions */
44 #define EMULATOR_BOP 0xC4C4
45 #define EMULATOR_INT_BOP 0xBEEF
46 #define STACK_INT_NUM 0
47 #define STACK_IP 1
48 #define STACK_CS 2
49 #define STACK_FLAGS 3
50
51 enum
52 {
53 EMULATOR_EXCEPTION_DIVISION_BY_ZERO,
54 EMULATOR_EXCEPTION_DEBUG,
55 EMULATOR_EXCEPTION_NMI,
56 EMULATOR_EXCEPTION_BREAKPOINT,
57 EMULATOR_EXCEPTION_OVERFLOW,
58 EMULATOR_EXCEPTION_BOUND,
59 EMULATOR_EXCEPTION_INVALID_OPCODE,
60 EMULATOR_EXCEPTION_NO_FPU,
61 EMULATOR_EXCEPTION_DOUBLE_FAULT,
62 EMULATOR_EXCEPTION_FPU_SEGMENT,
63 EMULATOR_EXCEPTION_INVALID_TSS,
64 EMULATOR_EXCEPTION_NO_SEGMENT,
65 EMULATOR_EXCEPTION_STACK_SEGMENT,
66 EMULATOR_EXCEPTION_GPF,
67 EMULATOR_EXCEPTION_PAGE_FAULT
68 };
69
70 enum
71 {
72 EMULATOR_REG_AX,
73 EMULATOR_REG_CX,
74 EMULATOR_REG_DX,
75 EMULATOR_REG_BX,
76 EMULATOR_REG_SP,
77 EMULATOR_REG_BP,
78 EMULATOR_REG_SI,
79 EMULATOR_REG_DI,
80 EMULATOR_REG_ES,
81 EMULATOR_REG_CS,
82 EMULATOR_REG_SS,
83 EMULATOR_REG_DS,
84 EMULATOR_REG_FS,
85 EMULATOR_REG_GS
86 };
87
88 #ifndef NEW_EMULATOR
89
90 #define NTVDMCALL __cdecl
91 extern softx86_ctx EmulatorContext;
92 extern softx87_ctx FpuEmulatorContext;
93
94 #else
95
96 #define NTVDMCALL __stdcall
97 extern SOFT386_STATE EmulatorContext;
98
99 #endif
100
101 /* FUNCTIONS ******************************************************************/
102
103 BOOLEAN EmulatorInitialize();
104 VOID EmulatorSetStack(WORD Segment, DWORD Offset);
105 VOID EmulatorExecute(WORD Segment, WORD Offset);
106 VOID EmulatorInterrupt(BYTE Number);
107 VOID EmulatorExternalInterrupt(BYTE Number);
108 ULONG EmulatorGetRegister(ULONG Register);
109 ULONG EmulatorGetProgramCounter(VOID);
110 VOID EmulatorSetRegister(ULONG Register, ULONG Value);
111 BOOLEAN EmulatorGetFlag(ULONG Flag);
112 VOID EmulatorSetFlag(ULONG Flag);
113 VOID EmulatorClearFlag(ULONG Flag);
114 VOID EmulatorStep();
115 VOID EmulatorCleanup();
116 VOID EmulatorSetA20(BOOLEAN Enabled);
117
118 #endif // _EMULATOR_H_
119
120 /* EOF */