OSDN Git Service

[DOC] Update gitlog.
[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         void get_debug_regs_info(_TCHAR *buffer, size_t buffer_len);
64         int debug_dasm(uint32_t pc, _TCHAR *buffer, size_t buffer_len);
65
66 protected:
67         const UINT8 *opcode_ptr;
68         const UINT8 *opcode_ptr_base;
69         int address_size;
70         int operand_size;
71         int address_prefix;
72         int operand_prefix;
73         int max_length;
74         UINT64 pc;
75         UINT8 modrm;
76         UINT32 segment;
77         offs_t dasm_flags;
78         _TCHAR modrm_string[256];
79         UINT8 rex, regex, sibex, rmex;
80         UINT8 pre0f;
81         UINT8 curmode;
82
83         INLINE UINT8 _FETCH(void);
84 #if 0
85         INLINE UINT16 _FETCH16(void);
86 #endif
87         INLINE UINT32 _FETCH32(void);
88         INLINE UINT8 _FETCHD(void);
89         INLINE UINT16 _FETCHD16(void);
90         INLINE UINT32 _FETCHD32(void);
91         _TCHAR *hexstring(UINT32 value, int digits);
92         _TCHAR *hexstring64(UINT32 lo, UINT32 hi);
93         _TCHAR *hexstringpc(UINT64 pc);
94         _TCHAR *shexstring(UINT32 value, int digits, int always);
95         _TCHAR* handle_sib_byte( _TCHAR* s, UINT8 mod );
96         void handle_modrm(_TCHAR* s);
97         _TCHAR* handle_param(_TCHAR* s, UINT32 param);
98         void handle_fpu(_TCHAR *s, UINT8 op1, UINT8 op2);
99         void decode_opcode(_TCHAR *s, const I386_OPCODE *op, UINT8 op1);
100
101         int i386_dasm_one_ex(_TCHAR *buffer, UINT64 eip, const UINT8 *oprom, int mode);
102         int i386_dasm_one(_TCHAR *buffer, offs_t eip, const UINT8 *oprom, int mode);
103         int cpu_disassemble_x86_16(_TCHAR *buffer, UINT64 eip, const UINT8 *oprom);
104         int cpu_disassemble_x86_32(_TCHAR *buffer, UINT64 eip, const UINT8 *oprom);
105         int cpu_disassemble_x86_64(_TCHAR *buffer, UINT64 eip, const UINT8 *oprom);
106 };
107
108 INLINE UINT8 I386_OPS::_FETCH(void)
109 {
110         if ((opcode_ptr - opcode_ptr_base) + 1 > max_length)
111                 return 0xff;
112         pc++;
113         return *opcode_ptr++;
114 }
115
116 #if 0
117 INLINE UINT16 I386_OPS::_FETCH16(void)
118 {
119         UINT16 d;
120         if ((opcode_ptr - opcode_ptr_base) + 2 > max_length)
121                 return 0xffff;
122         d = opcode_ptr[0] | (opcode_ptr[1] << 8);
123         opcode_ptr += 2;
124         pc += 2;
125         return d;
126 }
127 #endif
128
129 INLINE UINT32 I386_OPS::_FETCH32(void)
130 {
131         UINT32 d;
132         if ((opcode_ptr - opcode_ptr_base) + 4 > max_length)
133                 return 0xffffffff;
134         d = opcode_ptr[0] | (opcode_ptr[1] << 8) | (opcode_ptr[2] << 16) | (opcode_ptr[3] << 24);
135         opcode_ptr += 4;
136         pc += 4;
137         return d;
138 }
139
140 INLINE UINT8 I386_OPS::_FETCHD(void)
141 {
142         if ((opcode_ptr - opcode_ptr_base) + 1 > max_length)
143                 return 0xff;
144         pc++;
145         return *opcode_ptr++;
146 }
147
148 INLINE UINT16 I386_OPS::_FETCHD16(void)
149 {
150         UINT16 d;
151         if ((opcode_ptr - opcode_ptr_base) + 2 > max_length)
152                 return 0xffff;
153         d = opcode_ptr[0] | (opcode_ptr[1] << 8);
154         opcode_ptr += 2;
155         pc += 2;
156         return d;
157 }
158
159 INLINE UINT32 I386_OPS::_FETCHD32(void)
160 {
161         UINT32 d;
162         if ((opcode_ptr - opcode_ptr_base) + 4 > max_length)
163                 return 0xffffffff;
164         d = opcode_ptr[0] | (opcode_ptr[1] << 8) | (opcode_ptr[2] << 16) | (opcode_ptr[3] << 24);
165         opcode_ptr += 4;
166         pc += 4;
167         return d;
168 }
169
170
171
172 #endif
173
174