Statistics
| Branch: | Revision:

root / cpu-i386.h @ 927f621e

History | View | Annotate | Download (3.6 kB)

1
#ifndef CPU_I386_H
2
#define CPU_I386_H
3

    
4
#define R_EAX 0
5
#define R_ECX 1
6
#define R_EDX 2
7
#define R_EBX 3
8
#define R_ESP 4
9
#define R_EBP 5
10
#define R_ESI 6
11
#define R_EDI 7
12

    
13
#define R_AL 0
14
#define R_CL 1
15
#define R_DL 2
16
#define R_BL 3
17
#define R_AH 4
18
#define R_CH 5
19
#define R_DH 6
20
#define R_BH 7
21

    
22
#define R_ES 0
23
#define R_CS 1
24
#define R_SS 2
25
#define R_DS 3
26
#define R_FS 4
27
#define R_GS 5
28

    
29
#define CC_C           0x0001
30
#define CC_P         0x0004
31
#define CC_A        0x0010
32
#define CC_Z        0x0040
33
#define CC_S    0x0080
34
#define CC_O    0x0800
35

    
36
#define TRAP_FLAG                0x0100
37
#define INTERRUPT_FLAG                0x0200
38
#define DIRECTION_FLAG                0x0400
39
#define IOPL_FLAG_MASK                0x3000
40
#define NESTED_FLAG                0x4000
41
#define BYTE_FL                        0x8000        /* Intel reserved! */
42
#define RF_FLAG                        0x10000
43
#define VM_FLAG                        0x20000
44
/* AC                                0x40000 */
45

    
46
enum {
47
    CC_OP_DYNAMIC, /* must use dynamic code to get cc_op */
48
    CC_OP_EFLAGS,  /* all cc are explicitely computed, CC_SRC = flags */
49
    CC_OP_MUL, /* modify all flags, C, O = (CC_SRC != 0) */
50

    
51
    CC_OP_ADDB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
52
    CC_OP_ADDW,
53
    CC_OP_ADDL,
54

    
55
    CC_OP_SUBB, /* modify all flags, CC_DST = res, CC_SRC = src1 */
56
    CC_OP_SUBW,
57
    CC_OP_SUBL,
58

    
59
    CC_OP_LOGICB, /* modify all flags, CC_DST = res */
60
    CC_OP_LOGICW,
61
    CC_OP_LOGICL,
62

    
63
    CC_OP_INCB, /* modify all flags except, CC_DST = res */
64
    CC_OP_INCW,
65
    CC_OP_INCL,
66

    
67
    CC_OP_DECB, /* modify all flags except, CC_DST = res */
68
    CC_OP_DECW,
69
    CC_OP_DECL,
70

    
71
    CC_OP_SHLB, /* modify all flags, CC_DST = res, CC_SRC.lsb = C */
72
    CC_OP_SHLW,
73
    CC_OP_SHLL,
74

    
75
    CC_OP_NB,
76
};
77

    
78
#ifdef __i386__
79
#define USE_X86LDOUBLE
80
#endif
81

    
82
#ifdef USE_X86LDOUBLE
83
typedef long double CPU86_LDouble;
84
#else
85
typedef double CPU86_LDouble;
86
#endif
87

    
88
typedef struct CPU86State {
89
    /* standard registers */
90
    uint32_t regs[8];
91
    uint32_t pc; /* cs_case + eip value */
92

    
93
    /* eflags handling */
94
    uint32_t eflags;
95
    uint32_t cc_src;
96
    uint32_t cc_dst;
97
    uint32_t cc_op;
98
    int32_t df; /* D flag : 1 if D = 0, -1 if D = 1 */
99
    
100
    /* segments */
101
    uint8_t *segs_base[6];
102
    uint32_t segs[6];
103

    
104
    /* FPU state */
105
    CPU86_LDouble fpregs[8];    
106
    uint8_t fptags[8];   /* 0 = valid, 1 = empty */
107
    unsigned int fpstt; /* top of stack index */
108
    unsigned int fpus;
109
    unsigned int fpuc;
110

    
111
    /* emulator internal variables */
112
    uint32_t t0; /* temporary t0 storage */
113
    uint32_t t1; /* temporary t1 storage */
114
    uint32_t a0; /* temporary a0 storage (address) */
115
    CPU86_LDouble ft0;
116
} CPU86State;
117

    
118
static inline int ldub(void *ptr)
119
{
120
    return *(uint8_t *)ptr;
121
}
122

    
123
static inline int ldsb(void *ptr)
124
{
125
    return *(int8_t *)ptr;
126
}
127

    
128
static inline int lduw(void *ptr)
129
{
130
    return *(uint16_t *)ptr;
131
}
132

    
133
static inline int ldsw(void *ptr)
134
{
135
    return *(int16_t *)ptr;
136
}
137

    
138
static inline int ldl(void *ptr)
139
{
140
    return *(uint32_t *)ptr;
141
}
142

    
143
static inline uint64_t ldq(void *ptr)
144
{
145
    return *(uint64_t *)ptr;
146
}
147

    
148
static inline void stb(void *ptr, int v)
149
{
150
    *(uint8_t *)ptr = v;
151
}
152

    
153
static inline void stw(void *ptr, int v)
154
{
155
    *(uint16_t *)ptr = v;
156
}
157

    
158
static inline void stl(void *ptr, int v)
159
{
160
    *(uint32_t *)ptr = v;
161
}
162

    
163
static inline void stq(void *ptr, int v)
164
{
165
    *(uint64_t *)ptr = v;
166
}
167

    
168
/* float access */
169

    
170
static inline float ldfl(void *ptr)
171
{
172
    return *(float *)ptr;
173
}
174

    
175
static inline double ldfq(void *ptr)
176
{
177
    return *(double *)ptr;
178
}
179

    
180
static inline void stfl(void *ptr, float v)
181
{
182
    *(float *)ptr = v;
183
}
184

    
185
static inline void stfq(void *ptr, double v)
186
{
187
    *(double *)ptr = v;
188
}
189

    
190
#ifndef IN_OP_I386
191
void port_outb(int addr, int val);
192
void port_outw(int addr, int val);
193
void port_outl(int addr, int val);
194
int port_inb(int addr);
195
int port_inw(int addr);
196
int port_inl(int addr);
197
#endif
198

    
199
#endif /* CPU_I386_H */