root / linux-user / vm86.c @ 9ea37780
History | View | Annotate | Download (15.2 kB)
1 | 46ddf551 | bellard | /*
|
---|---|---|---|
2 | 46ddf551 | bellard | * vm86 linux syscall support
|
3 | 5fafdf24 | ths | *
|
4 | 46ddf551 | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 46ddf551 | bellard | *
|
6 | 46ddf551 | bellard | * This program is free software; you can redistribute it and/or modify
|
7 | 46ddf551 | bellard | * it under the terms of the GNU General Public License as published by
|
8 | 46ddf551 | bellard | * the Free Software Foundation; either version 2 of the License, or
|
9 | 46ddf551 | bellard | * (at your option) any later version.
|
10 | 46ddf551 | bellard | *
|
11 | 46ddf551 | bellard | * This program is distributed in the hope that it will be useful,
|
12 | 46ddf551 | bellard | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 46ddf551 | bellard | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 46ddf551 | bellard | * GNU General Public License for more details.
|
15 | 46ddf551 | bellard | *
|
16 | 46ddf551 | bellard | * You should have received a copy of the GNU General Public License
|
17 | 8167ee88 | Blue Swirl | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
18 | 46ddf551 | bellard | */
|
19 | 46ddf551 | bellard | #include <stdlib.h> |
20 | 46ddf551 | bellard | #include <stdio.h> |
21 | 46ddf551 | bellard | #include <stdarg.h> |
22 | 46ddf551 | bellard | #include <string.h> |
23 | 46ddf551 | bellard | #include <errno.h> |
24 | 46ddf551 | bellard | #include <unistd.h> |
25 | 46ddf551 | bellard | |
26 | 46ddf551 | bellard | #include "qemu.h" |
27 | 46ddf551 | bellard | |
28 | 46ddf551 | bellard | //#define DEBUG_VM86
|
29 | 46ddf551 | bellard | |
30 | d12d51d5 | aliguori | #ifdef DEBUG_VM86
|
31 | 93fcfe39 | aliguori | # define LOG_VM86(...) qemu_log(__VA_ARGS__);
|
32 | d12d51d5 | aliguori | #else
|
33 | d12d51d5 | aliguori | # define LOG_VM86(...) do { } while (0) |
34 | d12d51d5 | aliguori | #endif
|
35 | d12d51d5 | aliguori | |
36 | d12d51d5 | aliguori | |
37 | 46ddf551 | bellard | #define set_flags(X,new,mask) \
|
38 | 46ddf551 | bellard | ((X) = ((X) & ~(mask)) | ((new) & (mask))) |
39 | 46ddf551 | bellard | |
40 | 46ddf551 | bellard | #define SAFE_MASK (0xDD5) |
41 | 46ddf551 | bellard | #define RETURN_MASK (0xDFF) |
42 | 46ddf551 | bellard | |
43 | 46ddf551 | bellard | static inline int is_revectored(int nr, struct target_revectored_struct *bitmap) |
44 | 46ddf551 | bellard | { |
45 | b333af06 | bellard | return (((uint8_t *)bitmap)[nr >> 3] >> (nr & 7)) & 1; |
46 | 46ddf551 | bellard | } |
47 | 46ddf551 | bellard | |
48 | 1455bf48 | bellard | static inline void vm_putw(uint32_t segptr, unsigned int reg16, unsigned int val) |
49 | 46ddf551 | bellard | { |
50 | 84fa15d8 | bellard | stw(segptr + (reg16 & 0xffff), val);
|
51 | 46ddf551 | bellard | } |
52 | 46ddf551 | bellard | |
53 | 1455bf48 | bellard | static inline void vm_putl(uint32_t segptr, unsigned int reg16, unsigned int val) |
54 | 46ddf551 | bellard | { |
55 | 84fa15d8 | bellard | stl(segptr + (reg16 & 0xffff), val);
|
56 | 46ddf551 | bellard | } |
57 | 46ddf551 | bellard | |
58 | 1455bf48 | bellard | static inline unsigned int vm_getb(uint32_t segptr, unsigned int reg16) |
59 | 1455bf48 | bellard | { |
60 | 1455bf48 | bellard | return ldub(segptr + (reg16 & 0xffff)); |
61 | 1455bf48 | bellard | } |
62 | 1455bf48 | bellard | |
63 | 1455bf48 | bellard | static inline unsigned int vm_getw(uint32_t segptr, unsigned int reg16) |
64 | 46ddf551 | bellard | { |
65 | 84fa15d8 | bellard | return lduw(segptr + (reg16 & 0xffff)); |
66 | 46ddf551 | bellard | } |
67 | 46ddf551 | bellard | |
68 | 1455bf48 | bellard | static inline unsigned int vm_getl(uint32_t segptr, unsigned int reg16) |
69 | 46ddf551 | bellard | { |
70 | 84fa15d8 | bellard | return ldl(segptr + (reg16 & 0xffff)); |
71 | 46ddf551 | bellard | } |
72 | 46ddf551 | bellard | |
73 | 46ddf551 | bellard | void save_v86_state(CPUX86State *env)
|
74 | 46ddf551 | bellard | { |
75 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
76 | 53a5960a | pbrook | struct target_vm86plus_struct * target_v86;
|
77 | 46ddf551 | bellard | |
78 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_WRITE, target_v86, ts->target_v86, 0)) |
79 | 579a97f7 | bellard | /* FIXME - should return an error */
|
80 | 579a97f7 | bellard | return;
|
81 | 46ddf551 | bellard | /* put the VM86 registers in the userspace register structure */
|
82 | 53a5960a | pbrook | target_v86->regs.eax = tswap32(env->regs[R_EAX]); |
83 | 53a5960a | pbrook | target_v86->regs.ebx = tswap32(env->regs[R_EBX]); |
84 | 53a5960a | pbrook | target_v86->regs.ecx = tswap32(env->regs[R_ECX]); |
85 | 53a5960a | pbrook | target_v86->regs.edx = tswap32(env->regs[R_EDX]); |
86 | 53a5960a | pbrook | target_v86->regs.esi = tswap32(env->regs[R_ESI]); |
87 | 53a5960a | pbrook | target_v86->regs.edi = tswap32(env->regs[R_EDI]); |
88 | 53a5960a | pbrook | target_v86->regs.ebp = tswap32(env->regs[R_EBP]); |
89 | 53a5960a | pbrook | target_v86->regs.esp = tswap32(env->regs[R_ESP]); |
90 | 53a5960a | pbrook | target_v86->regs.eip = tswap32(env->eip); |
91 | 53a5960a | pbrook | target_v86->regs.cs = tswap16(env->segs[R_CS].selector); |
92 | 53a5960a | pbrook | target_v86->regs.ss = tswap16(env->segs[R_SS].selector); |
93 | 53a5960a | pbrook | target_v86->regs.ds = tswap16(env->segs[R_DS].selector); |
94 | 53a5960a | pbrook | target_v86->regs.es = tswap16(env->segs[R_ES].selector); |
95 | 53a5960a | pbrook | target_v86->regs.fs = tswap16(env->segs[R_FS].selector); |
96 | 53a5960a | pbrook | target_v86->regs.gs = tswap16(env->segs[R_GS].selector); |
97 | 46ddf551 | bellard | set_flags(env->eflags, ts->v86flags, VIF_MASK | ts->v86mask); |
98 | 53a5960a | pbrook | target_v86->regs.eflags = tswap32(env->eflags); |
99 | 53a5960a | pbrook | unlock_user_struct(target_v86, ts->target_v86, 1);
|
100 | d12d51d5 | aliguori | LOG_VM86("save_v86_state: eflags=%08x cs:ip=%04x:%04x\n",
|
101 | d12d51d5 | aliguori | env->eflags, env->segs[R_CS].selector, env->eip); |
102 | 46ddf551 | bellard | |
103 | 46ddf551 | bellard | /* restore 32 bit registers */
|
104 | 46ddf551 | bellard | env->regs[R_EAX] = ts->vm86_saved_regs.eax; |
105 | 46ddf551 | bellard | env->regs[R_EBX] = ts->vm86_saved_regs.ebx; |
106 | 46ddf551 | bellard | env->regs[R_ECX] = ts->vm86_saved_regs.ecx; |
107 | 46ddf551 | bellard | env->regs[R_EDX] = ts->vm86_saved_regs.edx; |
108 | 46ddf551 | bellard | env->regs[R_ESI] = ts->vm86_saved_regs.esi; |
109 | 46ddf551 | bellard | env->regs[R_EDI] = ts->vm86_saved_regs.edi; |
110 | 46ddf551 | bellard | env->regs[R_EBP] = ts->vm86_saved_regs.ebp; |
111 | 46ddf551 | bellard | env->regs[R_ESP] = ts->vm86_saved_regs.esp; |
112 | 46ddf551 | bellard | env->eflags = ts->vm86_saved_regs.eflags; |
113 | 46ddf551 | bellard | env->eip = ts->vm86_saved_regs.eip; |
114 | 46ddf551 | bellard | |
115 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_CS, ts->vm86_saved_regs.cs); |
116 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_SS, ts->vm86_saved_regs.ss); |
117 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_DS, ts->vm86_saved_regs.ds); |
118 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_ES, ts->vm86_saved_regs.es); |
119 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_FS, ts->vm86_saved_regs.fs); |
120 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_GS, ts->vm86_saved_regs.gs); |
121 | 46ddf551 | bellard | } |
122 | 46ddf551 | bellard | |
123 | 46ddf551 | bellard | /* return from vm86 mode to 32 bit. The vm86() syscall will return
|
124 | 46ddf551 | bellard | 'retval' */
|
125 | 46ddf551 | bellard | static inline void return_to_32bit(CPUX86State *env, int retval) |
126 | 46ddf551 | bellard | { |
127 | d12d51d5 | aliguori | LOG_VM86("return_to_32bit: ret=0x%x\n", retval);
|
128 | 46ddf551 | bellard | save_v86_state(env); |
129 | 46ddf551 | bellard | env->regs[R_EAX] = retval; |
130 | 46ddf551 | bellard | } |
131 | 46ddf551 | bellard | |
132 | 46ddf551 | bellard | static inline int set_IF(CPUX86State *env) |
133 | 46ddf551 | bellard | { |
134 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
135 | 3b46e624 | ths | |
136 | 46ddf551 | bellard | ts->v86flags |= VIF_MASK; |
137 | 46ddf551 | bellard | if (ts->v86flags & VIP_MASK) {
|
138 | 46ddf551 | bellard | return_to_32bit(env, TARGET_VM86_STI); |
139 | 46ddf551 | bellard | return 1; |
140 | 46ddf551 | bellard | } |
141 | 46ddf551 | bellard | return 0; |
142 | 46ddf551 | bellard | } |
143 | 46ddf551 | bellard | |
144 | 46ddf551 | bellard | static inline void clear_IF(CPUX86State *env) |
145 | 46ddf551 | bellard | { |
146 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
147 | 46ddf551 | bellard | |
148 | 46ddf551 | bellard | ts->v86flags &= ~VIF_MASK; |
149 | 46ddf551 | bellard | } |
150 | 46ddf551 | bellard | |
151 | 46ddf551 | bellard | static inline void clear_TF(CPUX86State *env) |
152 | 46ddf551 | bellard | { |
153 | 46ddf551 | bellard | env->eflags &= ~TF_MASK; |
154 | 46ddf551 | bellard | } |
155 | 46ddf551 | bellard | |
156 | 226c9132 | bellard | static inline void clear_AC(CPUX86State *env) |
157 | 226c9132 | bellard | { |
158 | 226c9132 | bellard | env->eflags &= ~AC_MASK; |
159 | 226c9132 | bellard | } |
160 | 226c9132 | bellard | |
161 | 46ddf551 | bellard | static inline int set_vflags_long(unsigned long eflags, CPUX86State *env) |
162 | 46ddf551 | bellard | { |
163 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
164 | 46ddf551 | bellard | |
165 | 46ddf551 | bellard | set_flags(ts->v86flags, eflags, ts->v86mask); |
166 | 46ddf551 | bellard | set_flags(env->eflags, eflags, SAFE_MASK); |
167 | 46ddf551 | bellard | if (eflags & IF_MASK)
|
168 | 46ddf551 | bellard | return set_IF(env);
|
169 | 226c9132 | bellard | else
|
170 | 226c9132 | bellard | clear_IF(env); |
171 | 46ddf551 | bellard | return 0; |
172 | 46ddf551 | bellard | } |
173 | 46ddf551 | bellard | |
174 | 46ddf551 | bellard | static inline int set_vflags_short(unsigned short flags, CPUX86State *env) |
175 | 46ddf551 | bellard | { |
176 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
177 | 46ddf551 | bellard | |
178 | 46ddf551 | bellard | set_flags(ts->v86flags, flags, ts->v86mask & 0xffff);
|
179 | 46ddf551 | bellard | set_flags(env->eflags, flags, SAFE_MASK); |
180 | 46ddf551 | bellard | if (flags & IF_MASK)
|
181 | 46ddf551 | bellard | return set_IF(env);
|
182 | 226c9132 | bellard | else
|
183 | 226c9132 | bellard | clear_IF(env); |
184 | 46ddf551 | bellard | return 0; |
185 | 46ddf551 | bellard | } |
186 | 46ddf551 | bellard | |
187 | 46ddf551 | bellard | static inline unsigned int get_vflags(CPUX86State *env) |
188 | 46ddf551 | bellard | { |
189 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
190 | 46ddf551 | bellard | unsigned int flags; |
191 | 46ddf551 | bellard | |
192 | 46ddf551 | bellard | flags = env->eflags & RETURN_MASK; |
193 | 46ddf551 | bellard | if (ts->v86flags & VIF_MASK)
|
194 | 46ddf551 | bellard | flags |= IF_MASK; |
195 | c05bab77 | bellard | flags |= IOPL_MASK; |
196 | 46ddf551 | bellard | return flags | (ts->v86flags & ts->v86mask);
|
197 | 46ddf551 | bellard | } |
198 | 46ddf551 | bellard | |
199 | 46ddf551 | bellard | #define ADD16(reg, val) reg = (reg & ~0xffff) | ((reg + (val)) & 0xffff) |
200 | 46ddf551 | bellard | |
201 | 46ddf551 | bellard | /* handle VM86 interrupt (NOTE: the CPU core currently does not
|
202 | 46ddf551 | bellard | support TSS interrupt revectoring, so this code is always executed) */
|
203 | 447db213 | bellard | static void do_int(CPUX86State *env, int intno) |
204 | 46ddf551 | bellard | { |
205 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
206 | 1455bf48 | bellard | uint32_t int_addr, segoffs, ssp; |
207 | 46ddf551 | bellard | unsigned int sp; |
208 | 46ddf551 | bellard | |
209 | c05bab77 | bellard | if (env->segs[R_CS].selector == TARGET_BIOSSEG)
|
210 | 46ddf551 | bellard | goto cannot_handle;
|
211 | b333af06 | bellard | if (is_revectored(intno, &ts->vm86plus.int_revectored))
|
212 | 46ddf551 | bellard | goto cannot_handle;
|
213 | 5fafdf24 | ths | if (intno == 0x21 && is_revectored((env->regs[R_EAX] >> 8) & 0xff, |
214 | b333af06 | bellard | &ts->vm86plus.int21_revectored)) |
215 | 46ddf551 | bellard | goto cannot_handle;
|
216 | 1455bf48 | bellard | int_addr = (intno << 2);
|
217 | 1455bf48 | bellard | segoffs = ldl(int_addr); |
218 | 46ddf551 | bellard | if ((segoffs >> 16) == TARGET_BIOSSEG) |
219 | 46ddf551 | bellard | goto cannot_handle;
|
220 | d12d51d5 | aliguori | LOG_VM86("VM86: emulating int 0x%x. CS:IP=%04x:%04x\n",
|
221 | d12d51d5 | aliguori | intno, segoffs >> 16, segoffs & 0xffff); |
222 | 46ddf551 | bellard | /* save old state */
|
223 | 1455bf48 | bellard | ssp = env->segs[R_SS].selector << 4;
|
224 | 46ddf551 | bellard | sp = env->regs[R_ESP] & 0xffff;
|
225 | 46ddf551 | bellard | vm_putw(ssp, sp - 2, get_vflags(env));
|
226 | c05bab77 | bellard | vm_putw(ssp, sp - 4, env->segs[R_CS].selector);
|
227 | 46ddf551 | bellard | vm_putw(ssp, sp - 6, env->eip);
|
228 | 46ddf551 | bellard | ADD16(env->regs[R_ESP], -6);
|
229 | 46ddf551 | bellard | /* goto interrupt handler */
|
230 | 46ddf551 | bellard | env->eip = segoffs & 0xffff;
|
231 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_CS, segoffs >> 16);
|
232 | 46ddf551 | bellard | clear_TF(env); |
233 | 46ddf551 | bellard | clear_IF(env); |
234 | 226c9132 | bellard | clear_AC(env); |
235 | 46ddf551 | bellard | return;
|
236 | 46ddf551 | bellard | cannot_handle:
|
237 | d12d51d5 | aliguori | LOG_VM86("VM86: return to 32 bits int 0x%x\n", intno);
|
238 | 46ddf551 | bellard | return_to_32bit(env, TARGET_VM86_INTx | (intno << 8));
|
239 | 46ddf551 | bellard | } |
240 | 46ddf551 | bellard | |
241 | 447db213 | bellard | void handle_vm86_trap(CPUX86State *env, int trapno) |
242 | 447db213 | bellard | { |
243 | 447db213 | bellard | if (trapno == 1 || trapno == 3) { |
244 | 447db213 | bellard | return_to_32bit(env, TARGET_VM86_TRAP + (trapno << 8));
|
245 | 447db213 | bellard | } else {
|
246 | 447db213 | bellard | do_int(env, trapno); |
247 | 447db213 | bellard | } |
248 | 447db213 | bellard | } |
249 | 447db213 | bellard | |
250 | b333af06 | bellard | #define CHECK_IF_IN_TRAP() \
|
251 | b333af06 | bellard | if ((ts->vm86plus.vm86plus.flags & TARGET_vm86dbg_active) && \
|
252 | b333af06 | bellard | (ts->vm86plus.vm86plus.flags & TARGET_vm86dbg_TFpendig)) \ |
253 | b333af06 | bellard | newflags |= TF_MASK |
254 | 46ddf551 | bellard | |
255 | 46ddf551 | bellard | #define VM86_FAULT_RETURN \
|
256 | b333af06 | bellard | if ((ts->vm86plus.vm86plus.flags & TARGET_force_return_for_pic) && \
|
257 | 46ddf551 | bellard | (ts->v86flags & (IF_MASK | VIF_MASK))) \ |
258 | 46ddf551 | bellard | return_to_32bit(env, TARGET_VM86_PICRETURN); \ |
259 | 46ddf551 | bellard | return
|
260 | 46ddf551 | bellard | |
261 | 46ddf551 | bellard | void handle_vm86_fault(CPUX86State *env)
|
262 | 46ddf551 | bellard | { |
263 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
264 | 1455bf48 | bellard | uint32_t csp, ssp; |
265 | b333af06 | bellard | unsigned int ip, sp, newflags, newip, newcs, opcode, intno; |
266 | b333af06 | bellard | int data32, pref_done;
|
267 | 46ddf551 | bellard | |
268 | 1455bf48 | bellard | csp = env->segs[R_CS].selector << 4;
|
269 | 46ddf551 | bellard | ip = env->eip & 0xffff;
|
270 | 3b46e624 | ths | |
271 | 1455bf48 | bellard | ssp = env->segs[R_SS].selector << 4;
|
272 | 46ddf551 | bellard | sp = env->regs[R_ESP] & 0xffff;
|
273 | 46ddf551 | bellard | |
274 | d12d51d5 | aliguori | LOG_VM86("VM86 exception %04x:%08x\n",
|
275 | d12d51d5 | aliguori | env->segs[R_CS].selector, env->eip); |
276 | 46ddf551 | bellard | |
277 | b333af06 | bellard | data32 = 0;
|
278 | b333af06 | bellard | pref_done = 0;
|
279 | b333af06 | bellard | do {
|
280 | 1455bf48 | bellard | opcode = vm_getb(csp, ip); |
281 | b333af06 | bellard | ADD16(ip, 1);
|
282 | b333af06 | bellard | switch (opcode) {
|
283 | b333af06 | bellard | case 0x66: /* 32-bit data */ data32=1; break; |
284 | b333af06 | bellard | case 0x67: /* 32-bit address */ break; |
285 | b333af06 | bellard | case 0x2e: /* CS */ break; |
286 | b333af06 | bellard | case 0x3e: /* DS */ break; |
287 | b333af06 | bellard | case 0x26: /* ES */ break; |
288 | b333af06 | bellard | case 0x36: /* SS */ break; |
289 | b333af06 | bellard | case 0x65: /* GS */ break; |
290 | b333af06 | bellard | case 0x64: /* FS */ break; |
291 | b333af06 | bellard | case 0xf2: /* repnz */ break; |
292 | b333af06 | bellard | case 0xf3: /* rep */ break; |
293 | b333af06 | bellard | default: pref_done = 1; |
294 | b333af06 | bellard | } |
295 | b333af06 | bellard | } while (!pref_done);
|
296 | b333af06 | bellard | |
297 | 46ddf551 | bellard | /* VM86 mode */
|
298 | b333af06 | bellard | switch(opcode) {
|
299 | b333af06 | bellard | case 0x9c: /* pushf */ |
300 | b333af06 | bellard | if (data32) {
|
301 | 46ddf551 | bellard | vm_putl(ssp, sp - 4, get_vflags(env));
|
302 | b333af06 | bellard | ADD16(env->regs[R_ESP], -4);
|
303 | b333af06 | bellard | } else {
|
304 | b333af06 | bellard | vm_putw(ssp, sp - 2, get_vflags(env));
|
305 | b333af06 | bellard | ADD16(env->regs[R_ESP], -2);
|
306 | b333af06 | bellard | } |
307 | b333af06 | bellard | env->eip = ip; |
308 | b333af06 | bellard | VM86_FAULT_RETURN; |
309 | 46ddf551 | bellard | |
310 | b333af06 | bellard | case 0x9d: /* popf */ |
311 | b333af06 | bellard | if (data32) {
|
312 | b333af06 | bellard | newflags = vm_getl(ssp, sp); |
313 | 46ddf551 | bellard | ADD16(env->regs[R_ESP], 4);
|
314 | b333af06 | bellard | } else {
|
315 | b333af06 | bellard | newflags = vm_getw(ssp, sp); |
316 | b333af06 | bellard | ADD16(env->regs[R_ESP], 2);
|
317 | b333af06 | bellard | } |
318 | b333af06 | bellard | env->eip = ip; |
319 | b333af06 | bellard | CHECK_IF_IN_TRAP(); |
320 | b333af06 | bellard | if (data32) {
|
321 | b333af06 | bellard | if (set_vflags_long(newflags, env))
|
322 | 46ddf551 | bellard | return;
|
323 | b333af06 | bellard | } else {
|
324 | b333af06 | bellard | if (set_vflags_short(newflags, env))
|
325 | 46ddf551 | bellard | return;
|
326 | 46ddf551 | bellard | } |
327 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
328 | 46ddf551 | bellard | |
329 | 46ddf551 | bellard | case 0xcd: /* int */ |
330 | 1455bf48 | bellard | intno = vm_getb(csp, ip); |
331 | b333af06 | bellard | ADD16(ip, 1);
|
332 | b333af06 | bellard | env->eip = ip; |
333 | b333af06 | bellard | if (ts->vm86plus.vm86plus.flags & TARGET_vm86dbg_active) {
|
334 | 5fafdf24 | ths | if ( (ts->vm86plus.vm86plus.vm86dbg_intxxtab[intno >> 3] >> |
335 | b333af06 | bellard | (intno &7)) & 1) { |
336 | b333af06 | bellard | return_to_32bit(env, TARGET_VM86_INTx + (intno << 8));
|
337 | b333af06 | bellard | return;
|
338 | b333af06 | bellard | } |
339 | b333af06 | bellard | } |
340 | b333af06 | bellard | do_int(env, intno); |
341 | 46ddf551 | bellard | break;
|
342 | 46ddf551 | bellard | |
343 | 46ddf551 | bellard | case 0xcf: /* iret */ |
344 | b333af06 | bellard | if (data32) {
|
345 | b333af06 | bellard | newip = vm_getl(ssp, sp) & 0xffff;
|
346 | b333af06 | bellard | newcs = vm_getl(ssp, sp + 4) & 0xffff; |
347 | b333af06 | bellard | newflags = vm_getl(ssp, sp + 8);
|
348 | b333af06 | bellard | ADD16(env->regs[R_ESP], 12);
|
349 | b333af06 | bellard | } else {
|
350 | b333af06 | bellard | newip = vm_getw(ssp, sp); |
351 | b333af06 | bellard | newcs = vm_getw(ssp, sp + 2);
|
352 | b333af06 | bellard | newflags = vm_getw(ssp, sp + 4);
|
353 | b333af06 | bellard | ADD16(env->regs[R_ESP], 6);
|
354 | b333af06 | bellard | } |
355 | b333af06 | bellard | env->eip = newip; |
356 | b333af06 | bellard | cpu_x86_load_seg(env, R_CS, newcs); |
357 | b333af06 | bellard | CHECK_IF_IN_TRAP(); |
358 | b333af06 | bellard | if (data32) {
|
359 | b333af06 | bellard | if (set_vflags_long(newflags, env))
|
360 | b333af06 | bellard | return;
|
361 | b333af06 | bellard | } else {
|
362 | b333af06 | bellard | if (set_vflags_short(newflags, env))
|
363 | b333af06 | bellard | return;
|
364 | b333af06 | bellard | } |
365 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
366 | 3b46e624 | ths | |
367 | 46ddf551 | bellard | case 0xfa: /* cli */ |
368 | b333af06 | bellard | env->eip = ip; |
369 | 46ddf551 | bellard | clear_IF(env); |
370 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
371 | 3b46e624 | ths | |
372 | 46ddf551 | bellard | case 0xfb: /* sti */ |
373 | b333af06 | bellard | env->eip = ip; |
374 | 46ddf551 | bellard | if (set_IF(env))
|
375 | 46ddf551 | bellard | return;
|
376 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
377 | 46ddf551 | bellard | |
378 | 46ddf551 | bellard | default:
|
379 | 46ddf551 | bellard | /* real VM86 GPF exception */
|
380 | 46ddf551 | bellard | return_to_32bit(env, TARGET_VM86_UNKNOWN); |
381 | 46ddf551 | bellard | break;
|
382 | 46ddf551 | bellard | } |
383 | 46ddf551 | bellard | } |
384 | 46ddf551 | bellard | |
385 | 992f48a0 | blueswir1 | int do_vm86(CPUX86State *env, long subfunction, abi_ulong vm86_addr) |
386 | 46ddf551 | bellard | { |
387 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
388 | 53a5960a | pbrook | struct target_vm86plus_struct * target_v86;
|
389 | 46ddf551 | bellard | int ret;
|
390 | 3b46e624 | ths | |
391 | 46ddf551 | bellard | switch (subfunction) {
|
392 | 46ddf551 | bellard | case TARGET_VM86_REQUEST_IRQ:
|
393 | 46ddf551 | bellard | case TARGET_VM86_FREE_IRQ:
|
394 | 46ddf551 | bellard | case TARGET_VM86_GET_IRQ_BITS:
|
395 | 46ddf551 | bellard | case TARGET_VM86_GET_AND_RESET_IRQ:
|
396 | 46ddf551 | bellard | gemu_log("qemu: unsupported vm86 subfunction (%ld)\n", subfunction);
|
397 | 6c30b07f | bellard | ret = -TARGET_EINVAL; |
398 | 46ddf551 | bellard | goto out;
|
399 | 46ddf551 | bellard | case TARGET_VM86_PLUS_INSTALL_CHECK:
|
400 | 46ddf551 | bellard | /* NOTE: on old vm86 stuff this will return the error
|
401 | 46ddf551 | bellard | from verify_area(), because the subfunction is
|
402 | 46ddf551 | bellard | interpreted as (invalid) address to vm86_struct.
|
403 | 46ddf551 | bellard | So the installation check works.
|
404 | 46ddf551 | bellard | */
|
405 | 46ddf551 | bellard | ret = 0;
|
406 | 46ddf551 | bellard | goto out;
|
407 | 46ddf551 | bellard | } |
408 | 46ddf551 | bellard | |
409 | 46ddf551 | bellard | /* save current CPU regs */
|
410 | 46ddf551 | bellard | ts->vm86_saved_regs.eax = 0; /* default vm86 syscall return code */ |
411 | 46ddf551 | bellard | ts->vm86_saved_regs.ebx = env->regs[R_EBX]; |
412 | 46ddf551 | bellard | ts->vm86_saved_regs.ecx = env->regs[R_ECX]; |
413 | 46ddf551 | bellard | ts->vm86_saved_regs.edx = env->regs[R_EDX]; |
414 | 46ddf551 | bellard | ts->vm86_saved_regs.esi = env->regs[R_ESI]; |
415 | 46ddf551 | bellard | ts->vm86_saved_regs.edi = env->regs[R_EDI]; |
416 | 46ddf551 | bellard | ts->vm86_saved_regs.ebp = env->regs[R_EBP]; |
417 | 46ddf551 | bellard | ts->vm86_saved_regs.esp = env->regs[R_ESP]; |
418 | 46ddf551 | bellard | ts->vm86_saved_regs.eflags = env->eflags; |
419 | 46ddf551 | bellard | ts->vm86_saved_regs.eip = env->eip; |
420 | c05bab77 | bellard | ts->vm86_saved_regs.cs = env->segs[R_CS].selector; |
421 | c05bab77 | bellard | ts->vm86_saved_regs.ss = env->segs[R_SS].selector; |
422 | c05bab77 | bellard | ts->vm86_saved_regs.ds = env->segs[R_DS].selector; |
423 | c05bab77 | bellard | ts->vm86_saved_regs.es = env->segs[R_ES].selector; |
424 | c05bab77 | bellard | ts->vm86_saved_regs.fs = env->segs[R_FS].selector; |
425 | c05bab77 | bellard | ts->vm86_saved_regs.gs = env->segs[R_GS].selector; |
426 | 46ddf551 | bellard | |
427 | 53a5960a | pbrook | ts->target_v86 = vm86_addr; |
428 | 579a97f7 | bellard | if (!lock_user_struct(VERIFY_READ, target_v86, vm86_addr, 1)) |
429 | 6c30b07f | bellard | return -TARGET_EFAULT;
|
430 | 46ddf551 | bellard | /* build vm86 CPU state */
|
431 | 46ddf551 | bellard | ts->v86flags = tswap32(target_v86->regs.eflags); |
432 | 5fafdf24 | ths | env->eflags = (env->eflags & ~SAFE_MASK) | |
433 | 46ddf551 | bellard | (tswap32(target_v86->regs.eflags) & SAFE_MASK) | VM_MASK; |
434 | b333af06 | bellard | |
435 | b333af06 | bellard | ts->vm86plus.cpu_type = tswapl(target_v86->cpu_type); |
436 | b333af06 | bellard | switch (ts->vm86plus.cpu_type) {
|
437 | b333af06 | bellard | case TARGET_CPU_286:
|
438 | b333af06 | bellard | ts->v86mask = 0;
|
439 | b333af06 | bellard | break;
|
440 | b333af06 | bellard | case TARGET_CPU_386:
|
441 | b333af06 | bellard | ts->v86mask = NT_MASK | IOPL_MASK; |
442 | b333af06 | bellard | break;
|
443 | b333af06 | bellard | case TARGET_CPU_486:
|
444 | b333af06 | bellard | ts->v86mask = AC_MASK | NT_MASK | IOPL_MASK; |
445 | b333af06 | bellard | break;
|
446 | b333af06 | bellard | default:
|
447 | b333af06 | bellard | ts->v86mask = ID_MASK | AC_MASK | NT_MASK | IOPL_MASK; |
448 | b333af06 | bellard | break;
|
449 | b333af06 | bellard | } |
450 | 46ddf551 | bellard | |
451 | 46ddf551 | bellard | env->regs[R_EBX] = tswap32(target_v86->regs.ebx); |
452 | 46ddf551 | bellard | env->regs[R_ECX] = tswap32(target_v86->regs.ecx); |
453 | 46ddf551 | bellard | env->regs[R_EDX] = tswap32(target_v86->regs.edx); |
454 | 46ddf551 | bellard | env->regs[R_ESI] = tswap32(target_v86->regs.esi); |
455 | 46ddf551 | bellard | env->regs[R_EDI] = tswap32(target_v86->regs.edi); |
456 | 46ddf551 | bellard | env->regs[R_EBP] = tswap32(target_v86->regs.ebp); |
457 | 46ddf551 | bellard | env->regs[R_ESP] = tswap32(target_v86->regs.esp); |
458 | 46ddf551 | bellard | env->eip = tswap32(target_v86->regs.eip); |
459 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_CS, tswap16(target_v86->regs.cs)); |
460 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_SS, tswap16(target_v86->regs.ss)); |
461 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_DS, tswap16(target_v86->regs.ds)); |
462 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_ES, tswap16(target_v86->regs.es)); |
463 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_FS, tswap16(target_v86->regs.fs)); |
464 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_GS, tswap16(target_v86->regs.gs)); |
465 | 46ddf551 | bellard | ret = tswap32(target_v86->regs.eax); /* eax will be restored at
|
466 | 46ddf551 | bellard | the end of the syscall */
|
467 | 5fafdf24 | ths | memcpy(&ts->vm86plus.int_revectored, |
468 | b333af06 | bellard | &target_v86->int_revectored, 32);
|
469 | 5fafdf24 | ths | memcpy(&ts->vm86plus.int21_revectored, |
470 | b333af06 | bellard | &target_v86->int21_revectored, 32);
|
471 | b333af06 | bellard | ts->vm86plus.vm86plus.flags = tswapl(target_v86->vm86plus.flags); |
472 | 5fafdf24 | ths | memcpy(&ts->vm86plus.vm86plus.vm86dbg_intxxtab, |
473 | b333af06 | bellard | target_v86->vm86plus.vm86dbg_intxxtab, 32);
|
474 | 53a5960a | pbrook | unlock_user_struct(target_v86, vm86_addr, 0);
|
475 | 3b46e624 | ths | |
476 | d12d51d5 | aliguori | LOG_VM86("do_vm86: cs:ip=%04x:%04x\n",
|
477 | d12d51d5 | aliguori | env->segs[R_CS].selector, env->eip); |
478 | 46ddf551 | bellard | /* now the virtual CPU is ready for vm86 execution ! */
|
479 | 46ddf551 | bellard | out:
|
480 | 46ddf551 | bellard | return ret;
|
481 | 46ddf551 | bellard | } |