1 /* NOTE: this header is included in op-i386.c where global register
2 variable are used. Care must be used when including glibc headers.
41 #define TRAP_FLAG 0x0100
42 #define INTERRUPT_FLAG 0x0200
43 #define DIRECTION_FLAG 0x0400
44 #define IOPL_FLAG_MASK 0x3000
45 #define NESTED_FLAG 0x4000
46 #define BYTE_FL 0x8000 /* Intel reserved! */
47 #define RF_FLAG 0x10000
48 #define VM_FLAG 0x20000
56 #define EXCP05_BOUND 6
57 #define EXCP06_ILLOP 7
60 #define EXCP09_XERR 10
62 #define EXCP0B_NOSEG 12
63 #define EXCP0C_STACK 13
65 #define EXCP0E_PAGE 15
66 #define EXCP10_COPR 17
67 #define EXCP11_ALGN 18
68 #define EXCP12_MCHK 19
70 #define EXCP_SIGNAL 256 /* async signal */
73 CC_OP_DYNAMIC, /* must use dynamic code to get cc_op */
74 CC_OP_EFLAGS, /* all cc are explicitely computed, CC_SRC = flags */
75 CC_OP_MUL, /* modify all flags, C, O = (CC_SRC != 0) */
77 CC_OP_ADDB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
81 CC_OP_ADCB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
85 CC_OP_SUBB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
89 CC_OP_SBBB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
93 CC_OP_LOGICB, /* modify all flags, CC_DST = res */
97 CC_OP_INCB, /* modify all flags except, CC_DST = res, CC_SRC = C */
101 CC_OP_DECB, /* modify all flags except, CC_DST = res, CC_SRC = C */
105 CC_OP_SHLB, /* modify all flags, CC_DST = res, CC_SRC.lsb = C */
109 CC_OP_SARB, /* modify all flags, CC_DST = res, CC_SRC.lsb = C */
117 #define USE_X86LDOUBLE
120 #ifdef USE_X86LDOUBLE
121 typedef long double CPU86_LDouble;
123 typedef double CPU86_LDouble;
126 typedef struct SegmentCache {
132 typedef struct SegmentDescriptorTable {
135 /* this is the returned base when reading the register, just to
136 avoid that the emulated program modifies it */
137 unsigned long emu_base;
138 } SegmentDescriptorTable;
140 typedef struct CPUX86State {
141 /* standard registers */
143 uint32_t pc; /* cs_case + eip value */
146 /* emulator internal eflags handling */
150 int32_t df; /* D flag : 1 if D = 0, -1 if D = 1 */
153 unsigned int fpstt; /* top of stack index */
156 uint8_t fptags[8]; /* 0 = valid, 1 = empty */
157 CPU86_LDouble fpregs[8];
159 /* emulator internal variables */
163 uint32_t segs[6]; /* selector values */
164 SegmentCache seg_cache[6]; /* info taken from LDT/GDT */
165 SegmentDescriptorTable gdt;
166 SegmentDescriptorTable ldt;
167 SegmentDescriptorTable idt;
169 /* various CPU modes */
172 /* exception handling */
177 static inline int ldub(void *ptr)
179 return *(uint8_t *)ptr;
182 static inline int ldsb(void *ptr)
184 return *(int8_t *)ptr;
187 static inline int lduw(void *ptr)
189 return *(uint16_t *)ptr;
192 static inline int ldsw(void *ptr)
194 return *(int16_t *)ptr;
197 static inline int ldl(void *ptr)
199 return *(uint32_t *)ptr;
202 static inline uint64_t ldq(void *ptr)
204 return *(uint64_t *)ptr;
207 static inline void stb(void *ptr, int v)
212 static inline void stw(void *ptr, int v)
214 *(uint16_t *)ptr = v;
217 static inline void stl(void *ptr, int v)
219 *(uint32_t *)ptr = v;
222 static inline void stq(void *ptr, uint64_t v)
224 *(uint64_t *)ptr = v;
229 static inline float ldfl(void *ptr)
231 return *(float *)ptr;
234 static inline double ldfq(void *ptr)
236 return *(double *)ptr;
239 static inline void stfl(void *ptr, float v)
244 static inline void stfq(void *ptr, double v)
250 void cpu_x86_outb(int addr, int val);
251 void cpu_x86_outw(int addr, int val);
252 void cpu_x86_outl(int addr, int val);
253 int cpu_x86_inb(int addr);
254 int cpu_x86_inw(int addr);
255 int cpu_x86_inl(int addr);
258 CPUX86State *cpu_x86_init(void);
259 int cpu_x86_exec(CPUX86State *s);
260 void cpu_x86_close(CPUX86State *s);
262 /* needed to load some predefinied segment registers */
263 void cpu_x86_load_seg(CPUX86State *s, int seg_reg, int selector);
265 /* internal functions */
267 #define GEN_FLAG_CODE32_SHIFT 0
268 #define GEN_FLAG_ADDSEG_SHIFT 1
269 #define GEN_FLAG_ST_SHIFT 2
270 int cpu_x86_gen_code(uint8_t *gen_code_buf, int max_code_size,
271 int *gen_code_size_ptr, uint8_t *pc_start,
273 void cpu_x86_tblocks_init(void);
275 #endif /* CPU_I386_H */