OSDN Git Service

[VM][I386][OOPS] Fix OOPS.
[csp-qt/common_source_project-fm7.git] / source / src / vm / libcpu_newdev / libcpu_i386 / i386_real.h
1
2 #ifndef __LIB_I386_REAL_H__
3 #define __LIB_I386_REAL_H__
4
5 #include "./i386_opdef.h"
6
7 struct I386_OPCODE;
8 class I386_OPS: public I386_OPS_BASE
9 {
10 public:
11         I386_OPS(int cputypes = I386_OPS_CPUTYPE_I386) : I386_OPS_BASE(cputypes)
12         {
13         }
14
15         ~I386_OPS() {}
16
17         int cpu_translate_i386(void *cpudevice, address_spacenum space, int intention, offs_t *address);
18         int cpu_execute_i386(int cycles);
19         void i386_trap(int irq, int irq_gate, int trap_level);
20         void i386_trap_with_error(int irq, int irq_gate, int trap_level, UINT32 error);
21         void i386_call_abs16();        // Opcode 0x9a
22         void i386_call_rel16();        // Opcode 0xe8
23         void i386_groupFF_16();        // Opcode 0xff
24         void i386_decode_opcode();
25         //void build_opcode_table(UINT32 features);
26         i386_state *i386_common_init(int tlbsize);
27
28         void set_context_io_stored(DEVICE *dev) {
29 #ifdef USE_DEBUGGER
30                 cpustate->io_stored = dev;
31 #endif
32         }
33
34         void set_context_emu(EMU *p_emu) {
35 #ifdef USE_DEBUGGER
36                 cpustate->emu = p_emu;
37 #endif
38         }
39
40         void set_context_debugger(DEBUGGER *debugger) {
41 #ifdef USE_DEBUGGER
42                 cpustate->debugger = debugger;
43 #endif
44         }
45         void set_context_progmem_stored(DEVICE *dev) {
46 #ifdef USE_DEBUGGER
47                 cpustate->program_stored = dev;
48 #endif
49         }
50         void set_context_pseudo_bios(DEVICE *dev) {
51 #ifdef I386_PSEUDO_BIOS
52                 cpustate->bios = dev;
53                 d_bios = dev;
54 #endif
55         }
56         void set_context_dma(DEVICE *dev) {
57 #ifdef SINGLE_MODE_DMA
58                 cpustate->dma = dev;
59                 d_dma = dev;
60 #endif
61         }
62         bool write_debug_reg(const _TCHAR *reg, uint32_t data);
63         int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
64
65 protected:
66         const UINT8 *opcode_ptr;
67         const UINT8 *opcode_ptr_base;
68         int address_size;
69         int operand_size;
70         int address_prefix;
71         int operand_prefix;
72         int max_length;
73         UINT64 pc;
74         UINT8 modrm;
75         UINT32 segment;
76         offs_t dasm_flags;
77         _TCHAR modrm_string[256];
78         UINT8 rex, regex, sibex, rmex;
79         UINT8 pre0f;
80         UINT8 curmode;
81
82         INLINE UINT8 _FETCH(void);
83 #if 0
84         INLINE UINT16 _FETCH16(void);
85 #endif
86         INLINE UINT32 _FETCH32(void);
87         INLINE UINT8 _FETCHD(void);
88         INLINE UINT16 _FETCHD16(void);
89         INLINE UINT32 _FETCHD32(void);
90         _TCHAR *hexstring(UINT32 value, int digits);
91         _TCHAR *hexstring64(UINT32 lo, UINT32 hi);
92         _TCHAR *hexstringpc(UINT64 pc);
93         _TCHAR *shexstring(UINT32 value, int digits, int always);
94         _TCHAR* handle_sib_byte( _TCHAR* s, UINT8 mod );
95         void handle_modrm(_TCHAR* s);
96         _TCHAR* handle_param(_TCHAR* s, UINT32 param);
97         void handle_fpu(_TCHAR *s, UINT8 op1, UINT8 op2);
98         void decode_opcode(_TCHAR *s, const I386_OPCODE *op, UINT8 op1);
99
100         int i386_dasm_one_ex(_TCHAR *buffer, UINT64 eip, const UINT8 *oprom, int mode);
101         int i386_dasm_one(_TCHAR *buffer, offs_t eip, const UINT8 *oprom, int mode);
102         int cpu_disassemble_x86_16(_TCHAR *buffer, UINT64 eip, const UINT8 *oprom);
103         int cpu_disassemble_x86_32(_TCHAR *buffer, UINT64 eip, const UINT8 *oprom);
104         int cpu_disassemble_x86_64(_TCHAR *buffer, UINT64 eip, const UINT8 *oprom);
105 };
106
107 INLINE UINT8 I386_OPS::_FETCH(void)
108 {
109         if ((opcode_ptr - opcode_ptr_base) + 1 > max_length)
110                 return 0xff;
111         pc++;
112         return *opcode_ptr++;
113 }
114
115 #if 0
116 INLINE UINT16 I386_OPS::_FETCH16(void)
117 {
118         UINT16 d;
119         if ((opcode_ptr - opcode_ptr_base) + 2 > max_length)
120                 return 0xffff;
121         d = opcode_ptr[0] | (opcode_ptr[1] << 8);
122         opcode_ptr += 2;
123         pc += 2;
124         return d;
125 }
126 #endif
127
128 INLINE UINT32 I386_OPS::_FETCH32(void)
129 {
130         UINT32 d;
131         if ((opcode_ptr - opcode_ptr_base) + 4 > max_length)
132                 return 0xffffffff;
133         d = opcode_ptr[0] | (opcode_ptr[1] << 8) | (opcode_ptr[2] << 16) | (opcode_ptr[3] << 24);
134         opcode_ptr += 4;
135         pc += 4;
136         return d;
137 }
138
139 INLINE UINT8 I386_OPS::_FETCHD(void)
140 {
141         if ((opcode_ptr - opcode_ptr_base) + 1 > max_length)
142                 return 0xff;
143         pc++;
144         return *opcode_ptr++;
145 }
146
147 INLINE UINT16 I386_OPS::_FETCHD16(void)
148 {
149         UINT16 d;
150         if ((opcode_ptr - opcode_ptr_base) + 2 > max_length)
151                 return 0xffff;
152         d = opcode_ptr[0] | (opcode_ptr[1] << 8);
153         opcode_ptr += 2;
154         pc += 2;
155         return d;
156 }
157
158 INLINE UINT32 I386_OPS::_FETCHD32(void)
159 {
160         UINT32 d;
161         if ((opcode_ptr - opcode_ptr_base) + 4 > max_length)
162                 return 0xffffffff;
163         d = opcode_ptr[0] | (opcode_ptr[1] << 8) | (opcode_ptr[2] << 16) | (opcode_ptr[3] << 24);
164         opcode_ptr += 4;
165         pc += 4;
166         return d;
167 }
168
169
170
171 #endif
172
173