root / linux-user / vm86.c @ 564c8f99
History | View | Annotate | Download (12.9 kB)
1 | 46ddf551 | bellard | /*
|
---|---|---|---|
2 | 46ddf551 | bellard | * vm86 linux syscall support
|
3 | 46ddf551 | bellard | *
|
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 | 46ddf551 | bellard | * along with this program; if not, write to the Free Software
|
18 | 46ddf551 | bellard | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
19 | 46ddf551 | bellard | */
|
20 | 46ddf551 | bellard | #include <stdlib.h> |
21 | 46ddf551 | bellard | #include <stdio.h> |
22 | 46ddf551 | bellard | #include <stdarg.h> |
23 | 46ddf551 | bellard | #include <string.h> |
24 | 46ddf551 | bellard | #include <errno.h> |
25 | 46ddf551 | bellard | #include <unistd.h> |
26 | 46ddf551 | bellard | |
27 | 46ddf551 | bellard | #include "qemu.h" |
28 | 46ddf551 | bellard | |
29 | 46ddf551 | bellard | //#define DEBUG_VM86
|
30 | 46ddf551 | bellard | |
31 | 46ddf551 | bellard | #define set_flags(X,new,mask) \
|
32 | 46ddf551 | bellard | ((X) = ((X) & ~(mask)) | ((new) & (mask))) |
33 | 46ddf551 | bellard | |
34 | 46ddf551 | bellard | #define SAFE_MASK (0xDD5) |
35 | 46ddf551 | bellard | #define RETURN_MASK (0xDFF) |
36 | 46ddf551 | bellard | |
37 | 46ddf551 | bellard | static inline int is_revectored(int nr, struct target_revectored_struct *bitmap) |
38 | 46ddf551 | bellard | { |
39 | 46ddf551 | bellard | return (tswap32(bitmap->__map[nr >> 5]) >> (nr & 0x1f)) & 1; |
40 | 46ddf551 | bellard | } |
41 | 46ddf551 | bellard | |
42 | 46ddf551 | bellard | static inline void vm_putw(uint8_t *segptr, unsigned int reg16, unsigned int val) |
43 | 46ddf551 | bellard | { |
44 | 46ddf551 | bellard | *(uint16_t *)(segptr + (reg16 & 0xffff)) = tswap16(val);
|
45 | 46ddf551 | bellard | } |
46 | 46ddf551 | bellard | |
47 | 46ddf551 | bellard | static inline void vm_putl(uint8_t *segptr, unsigned int reg16, unsigned int val) |
48 | 46ddf551 | bellard | { |
49 | 46ddf551 | bellard | *(uint32_t *)(segptr + (reg16 & 0xffff)) = tswap32(val);
|
50 | 46ddf551 | bellard | } |
51 | 46ddf551 | bellard | |
52 | 46ddf551 | bellard | static inline unsigned int vm_getw(uint8_t *segptr, unsigned int reg16) |
53 | 46ddf551 | bellard | { |
54 | 46ddf551 | bellard | return tswap16(*(uint16_t *)(segptr + (reg16 & 0xffff))); |
55 | 46ddf551 | bellard | } |
56 | 46ddf551 | bellard | |
57 | 46ddf551 | bellard | static inline unsigned int vm_getl(uint8_t *segptr, unsigned int reg16) |
58 | 46ddf551 | bellard | { |
59 | 46ddf551 | bellard | return tswap32(*(uint16_t *)(segptr + (reg16 & 0xffff))); |
60 | 46ddf551 | bellard | } |
61 | 46ddf551 | bellard | |
62 | 46ddf551 | bellard | void save_v86_state(CPUX86State *env)
|
63 | 46ddf551 | bellard | { |
64 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
65 | 46ddf551 | bellard | |
66 | 46ddf551 | bellard | /* put the VM86 registers in the userspace register structure */
|
67 | 46ddf551 | bellard | ts->target_v86->regs.eax = tswap32(env->regs[R_EAX]); |
68 | 46ddf551 | bellard | ts->target_v86->regs.ebx = tswap32(env->regs[R_EBX]); |
69 | 46ddf551 | bellard | ts->target_v86->regs.ecx = tswap32(env->regs[R_ECX]); |
70 | 46ddf551 | bellard | ts->target_v86->regs.edx = tswap32(env->regs[R_EDX]); |
71 | 46ddf551 | bellard | ts->target_v86->regs.esi = tswap32(env->regs[R_ESI]); |
72 | 46ddf551 | bellard | ts->target_v86->regs.edi = tswap32(env->regs[R_EDI]); |
73 | 46ddf551 | bellard | ts->target_v86->regs.ebp = tswap32(env->regs[R_EBP]); |
74 | 46ddf551 | bellard | ts->target_v86->regs.esp = tswap32(env->regs[R_ESP]); |
75 | 46ddf551 | bellard | ts->target_v86->regs.eip = tswap32(env->eip); |
76 | 46ddf551 | bellard | ts->target_v86->regs.cs = tswap16(env->segs[R_CS]); |
77 | 46ddf551 | bellard | ts->target_v86->regs.ss = tswap16(env->segs[R_SS]); |
78 | 46ddf551 | bellard | ts->target_v86->regs.ds = tswap16(env->segs[R_DS]); |
79 | 46ddf551 | bellard | ts->target_v86->regs.es = tswap16(env->segs[R_ES]); |
80 | 46ddf551 | bellard | ts->target_v86->regs.fs = tswap16(env->segs[R_FS]); |
81 | 46ddf551 | bellard | ts->target_v86->regs.gs = tswap16(env->segs[R_GS]); |
82 | 46ddf551 | bellard | set_flags(env->eflags, ts->v86flags, VIF_MASK | ts->v86mask); |
83 | 46ddf551 | bellard | ts->target_v86->regs.eflags = tswap32(env->eflags); |
84 | 46ddf551 | bellard | #ifdef DEBUG_VM86
|
85 | 46ddf551 | bellard | fprintf(logfile, "save_v86_state: eflags=%08x cs:ip=%04x:%04x\n",
|
86 | 46ddf551 | bellard | env->eflags, env->segs[R_CS], env->eip); |
87 | 46ddf551 | bellard | #endif
|
88 | 46ddf551 | bellard | |
89 | 46ddf551 | bellard | /* restore 32 bit registers */
|
90 | 46ddf551 | bellard | env->regs[R_EAX] = ts->vm86_saved_regs.eax; |
91 | 46ddf551 | bellard | env->regs[R_EBX] = ts->vm86_saved_regs.ebx; |
92 | 46ddf551 | bellard | env->regs[R_ECX] = ts->vm86_saved_regs.ecx; |
93 | 46ddf551 | bellard | env->regs[R_EDX] = ts->vm86_saved_regs.edx; |
94 | 46ddf551 | bellard | env->regs[R_ESI] = ts->vm86_saved_regs.esi; |
95 | 46ddf551 | bellard | env->regs[R_EDI] = ts->vm86_saved_regs.edi; |
96 | 46ddf551 | bellard | env->regs[R_EBP] = ts->vm86_saved_regs.ebp; |
97 | 46ddf551 | bellard | env->regs[R_ESP] = ts->vm86_saved_regs.esp; |
98 | 46ddf551 | bellard | env->eflags = ts->vm86_saved_regs.eflags; |
99 | 46ddf551 | bellard | env->eip = ts->vm86_saved_regs.eip; |
100 | 46ddf551 | bellard | |
101 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_CS, ts->vm86_saved_regs.cs); |
102 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_SS, ts->vm86_saved_regs.ss); |
103 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_DS, ts->vm86_saved_regs.ds); |
104 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_ES, ts->vm86_saved_regs.es); |
105 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_FS, ts->vm86_saved_regs.fs); |
106 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_GS, ts->vm86_saved_regs.gs); |
107 | 46ddf551 | bellard | } |
108 | 46ddf551 | bellard | |
109 | 46ddf551 | bellard | /* return from vm86 mode to 32 bit. The vm86() syscall will return
|
110 | 46ddf551 | bellard | 'retval' */
|
111 | 46ddf551 | bellard | static inline void return_to_32bit(CPUX86State *env, int retval) |
112 | 46ddf551 | bellard | { |
113 | 46ddf551 | bellard | #ifdef DEBUG_VM86
|
114 | 46ddf551 | bellard | fprintf(logfile, "return_to_32bit: ret=0x%x\n", retval);
|
115 | 46ddf551 | bellard | #endif
|
116 | 46ddf551 | bellard | save_v86_state(env); |
117 | 46ddf551 | bellard | env->regs[R_EAX] = retval; |
118 | 46ddf551 | bellard | } |
119 | 46ddf551 | bellard | |
120 | 46ddf551 | bellard | static inline int set_IF(CPUX86State *env) |
121 | 46ddf551 | bellard | { |
122 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
123 | 46ddf551 | bellard | |
124 | 46ddf551 | bellard | ts->v86flags |= VIF_MASK; |
125 | 46ddf551 | bellard | if (ts->v86flags & VIP_MASK) {
|
126 | 46ddf551 | bellard | return_to_32bit(env, TARGET_VM86_STI); |
127 | 46ddf551 | bellard | return 1; |
128 | 46ddf551 | bellard | } |
129 | 46ddf551 | bellard | return 0; |
130 | 46ddf551 | bellard | } |
131 | 46ddf551 | bellard | |
132 | 46ddf551 | bellard | static inline void clear_IF(CPUX86State *env) |
133 | 46ddf551 | bellard | { |
134 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
135 | 46ddf551 | bellard | |
136 | 46ddf551 | bellard | ts->v86flags &= ~VIF_MASK; |
137 | 46ddf551 | bellard | } |
138 | 46ddf551 | bellard | |
139 | 46ddf551 | bellard | static inline void clear_TF(CPUX86State *env) |
140 | 46ddf551 | bellard | { |
141 | 46ddf551 | bellard | env->eflags &= ~TF_MASK; |
142 | 46ddf551 | bellard | } |
143 | 46ddf551 | bellard | |
144 | 46ddf551 | bellard | static inline int set_vflags_long(unsigned long eflags, CPUX86State *env) |
145 | 46ddf551 | bellard | { |
146 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
147 | 46ddf551 | bellard | |
148 | 46ddf551 | bellard | set_flags(ts->v86flags, eflags, ts->v86mask); |
149 | 46ddf551 | bellard | set_flags(env->eflags, eflags, SAFE_MASK); |
150 | 46ddf551 | bellard | if (eflags & IF_MASK)
|
151 | 46ddf551 | bellard | return set_IF(env);
|
152 | 46ddf551 | bellard | return 0; |
153 | 46ddf551 | bellard | } |
154 | 46ddf551 | bellard | |
155 | 46ddf551 | bellard | static inline int set_vflags_short(unsigned short flags, CPUX86State *env) |
156 | 46ddf551 | bellard | { |
157 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
158 | 46ddf551 | bellard | |
159 | 46ddf551 | bellard | set_flags(ts->v86flags, flags, ts->v86mask & 0xffff);
|
160 | 46ddf551 | bellard | set_flags(env->eflags, flags, SAFE_MASK); |
161 | 46ddf551 | bellard | if (flags & IF_MASK)
|
162 | 46ddf551 | bellard | return set_IF(env);
|
163 | 46ddf551 | bellard | return 0; |
164 | 46ddf551 | bellard | } |
165 | 46ddf551 | bellard | |
166 | 46ddf551 | bellard | static inline unsigned int get_vflags(CPUX86State *env) |
167 | 46ddf551 | bellard | { |
168 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
169 | 46ddf551 | bellard | unsigned int flags; |
170 | 46ddf551 | bellard | |
171 | 46ddf551 | bellard | flags = env->eflags & RETURN_MASK; |
172 | 46ddf551 | bellard | if (ts->v86flags & VIF_MASK)
|
173 | 46ddf551 | bellard | flags |= IF_MASK; |
174 | 46ddf551 | bellard | return flags | (ts->v86flags & ts->v86mask);
|
175 | 46ddf551 | bellard | } |
176 | 46ddf551 | bellard | |
177 | 46ddf551 | bellard | #define ADD16(reg, val) reg = (reg & ~0xffff) | ((reg + (val)) & 0xffff) |
178 | 46ddf551 | bellard | |
179 | 46ddf551 | bellard | /* handle VM86 interrupt (NOTE: the CPU core currently does not
|
180 | 46ddf551 | bellard | support TSS interrupt revectoring, so this code is always executed) */
|
181 | 46ddf551 | bellard | void do_int(CPUX86State *env, int intno) |
182 | 46ddf551 | bellard | { |
183 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
184 | 46ddf551 | bellard | uint32_t *int_ptr, segoffs; |
185 | 46ddf551 | bellard | uint8_t *ssp; |
186 | 46ddf551 | bellard | unsigned int sp; |
187 | 46ddf551 | bellard | |
188 | 46ddf551 | bellard | #if 1 |
189 | 46ddf551 | bellard | if (intno == 0xe6 && (env->regs[R_EAX] & 0xffff) == 0x00c0) |
190 | 46ddf551 | bellard | loglevel = 1;
|
191 | 46ddf551 | bellard | #endif
|
192 | 46ddf551 | bellard | |
193 | 46ddf551 | bellard | if (env->segs[R_CS] == TARGET_BIOSSEG)
|
194 | 46ddf551 | bellard | goto cannot_handle;
|
195 | 46ddf551 | bellard | if (is_revectored(intno, &ts->target_v86->int_revectored))
|
196 | 46ddf551 | bellard | goto cannot_handle;
|
197 | 46ddf551 | bellard | if (intno == 0x21 && is_revectored((env->regs[R_EAX] >> 8) & 0xff, |
198 | 46ddf551 | bellard | &ts->target_v86->int21_revectored)) |
199 | 46ddf551 | bellard | goto cannot_handle;
|
200 | 46ddf551 | bellard | int_ptr = (uint32_t *)(intno << 2);
|
201 | 46ddf551 | bellard | segoffs = tswap32(*int_ptr); |
202 | 46ddf551 | bellard | if ((segoffs >> 16) == TARGET_BIOSSEG) |
203 | 46ddf551 | bellard | goto cannot_handle;
|
204 | 46ddf551 | bellard | #if defined(DEBUG_VM86)
|
205 | 46ddf551 | bellard | fprintf(logfile, "VM86: emulating int 0x%x. CS:IP=%04x:%04x\n",
|
206 | 46ddf551 | bellard | intno, segoffs >> 16, segoffs & 0xffff); |
207 | 46ddf551 | bellard | #endif
|
208 | 46ddf551 | bellard | /* save old state */
|
209 | 46ddf551 | bellard | ssp = (uint8_t *)(env->segs[R_SS] << 4);
|
210 | 46ddf551 | bellard | sp = env->regs[R_ESP] & 0xffff;
|
211 | 46ddf551 | bellard | vm_putw(ssp, sp - 2, get_vflags(env));
|
212 | 46ddf551 | bellard | vm_putw(ssp, sp - 4, env->segs[R_CS]);
|
213 | 46ddf551 | bellard | vm_putw(ssp, sp - 6, env->eip);
|
214 | 46ddf551 | bellard | ADD16(env->regs[R_ESP], -6);
|
215 | 46ddf551 | bellard | /* goto interrupt handler */
|
216 | 46ddf551 | bellard | env->eip = segoffs & 0xffff;
|
217 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_CS, segoffs >> 16);
|
218 | 46ddf551 | bellard | clear_TF(env); |
219 | 46ddf551 | bellard | clear_IF(env); |
220 | 46ddf551 | bellard | return;
|
221 | 46ddf551 | bellard | cannot_handle:
|
222 | 46ddf551 | bellard | #if defined(DEBUG_VM86)
|
223 | 46ddf551 | bellard | fprintf(logfile, "VM86: return to 32 bits int 0x%x\n", intno);
|
224 | 46ddf551 | bellard | #endif
|
225 | 46ddf551 | bellard | return_to_32bit(env, TARGET_VM86_INTx | (intno << 8));
|
226 | 46ddf551 | bellard | } |
227 | 46ddf551 | bellard | |
228 | 46ddf551 | bellard | #define CHECK_IF_IN_TRAP(disp) \
|
229 | 46ddf551 | bellard | if ((tswap32(ts->target_v86->vm86plus.flags) & TARGET_vm86dbg_active) && \
|
230 | 46ddf551 | bellard | (tswap32(ts->target_v86->vm86plus.flags) & TARGET_vm86dbg_TFpendig)) \ |
231 | 46ddf551 | bellard | vm_putw(ssp,sp + disp,vm_getw(ssp,sp + disp) | TF_MASK) |
232 | 46ddf551 | bellard | |
233 | 46ddf551 | bellard | #define VM86_FAULT_RETURN \
|
234 | 46ddf551 | bellard | if ((tswap32(ts->target_v86->vm86plus.flags) & TARGET_force_return_for_pic) && \
|
235 | 46ddf551 | bellard | (ts->v86flags & (IF_MASK | VIF_MASK))) \ |
236 | 46ddf551 | bellard | return_to_32bit(env, TARGET_VM86_PICRETURN); \ |
237 | 46ddf551 | bellard | return
|
238 | 46ddf551 | bellard | |
239 | 46ddf551 | bellard | void handle_vm86_fault(CPUX86State *env)
|
240 | 46ddf551 | bellard | { |
241 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
242 | 46ddf551 | bellard | uint8_t *csp, *pc, *ssp; |
243 | 46ddf551 | bellard | unsigned int ip, sp; |
244 | 46ddf551 | bellard | |
245 | 46ddf551 | bellard | csp = (uint8_t *)(env->segs[R_CS] << 4);
|
246 | 46ddf551 | bellard | ip = env->eip & 0xffff;
|
247 | 46ddf551 | bellard | pc = csp + ip; |
248 | 46ddf551 | bellard | |
249 | 46ddf551 | bellard | ssp = (uint8_t *)(env->segs[R_SS] << 4);
|
250 | 46ddf551 | bellard | sp = env->regs[R_ESP] & 0xffff;
|
251 | 46ddf551 | bellard | |
252 | 46ddf551 | bellard | #if defined(DEBUG_VM86)
|
253 | 46ddf551 | bellard | fprintf(logfile, "VM86 exception %04x:%08x %02x %02x\n",
|
254 | 46ddf551 | bellard | env->segs[R_CS], env->eip, pc[0], pc[1]); |
255 | 46ddf551 | bellard | #endif
|
256 | 46ddf551 | bellard | |
257 | 46ddf551 | bellard | /* VM86 mode */
|
258 | 46ddf551 | bellard | switch(pc[0]) { |
259 | 46ddf551 | bellard | case 0x66: |
260 | 46ddf551 | bellard | switch(pc[1]) { |
261 | 46ddf551 | bellard | case 0x9c: /* pushfd */ |
262 | 46ddf551 | bellard | ADD16(env->eip, 2);
|
263 | 46ddf551 | bellard | ADD16(env->regs[R_ESP], -4);
|
264 | 46ddf551 | bellard | vm_putl(ssp, sp - 4, get_vflags(env));
|
265 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
266 | 46ddf551 | bellard | |
267 | 46ddf551 | bellard | case 0x9d: /* popfd */ |
268 | 46ddf551 | bellard | ADD16(env->eip, 2);
|
269 | 46ddf551 | bellard | ADD16(env->regs[R_ESP], 4);
|
270 | 46ddf551 | bellard | CHECK_IF_IN_TRAP(0);
|
271 | 46ddf551 | bellard | if (set_vflags_long(vm_getl(ssp, sp), env))
|
272 | 46ddf551 | bellard | return;
|
273 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
274 | 46ddf551 | bellard | |
275 | 46ddf551 | bellard | case 0xcf: /* iretd */ |
276 | 46ddf551 | bellard | ADD16(env->regs[R_ESP], 12);
|
277 | 46ddf551 | bellard | env->eip = vm_getl(ssp, sp) & 0xffff;
|
278 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_CS, vm_getl(ssp, sp + 4) & 0xffff); |
279 | 46ddf551 | bellard | CHECK_IF_IN_TRAP(8);
|
280 | 46ddf551 | bellard | if (set_vflags_long(vm_getl(ssp, sp + 8), env)) |
281 | 46ddf551 | bellard | return;
|
282 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
283 | 46ddf551 | bellard | |
284 | 46ddf551 | bellard | default:
|
285 | 46ddf551 | bellard | goto vm86_gpf;
|
286 | 46ddf551 | bellard | } |
287 | 46ddf551 | bellard | break;
|
288 | 46ddf551 | bellard | case 0x9c: /* pushf */ |
289 | 46ddf551 | bellard | ADD16(env->eip, 1);
|
290 | 46ddf551 | bellard | ADD16(env->regs[R_ESP], -2);
|
291 | 46ddf551 | bellard | vm_putw(ssp, sp - 2, get_vflags(env));
|
292 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
293 | 46ddf551 | bellard | |
294 | 46ddf551 | bellard | case 0x9d: /* popf */ |
295 | 46ddf551 | bellard | ADD16(env->eip, 1);
|
296 | 46ddf551 | bellard | ADD16(env->regs[R_ESP], 2);
|
297 | 46ddf551 | bellard | CHECK_IF_IN_TRAP(0);
|
298 | 46ddf551 | bellard | if (set_vflags_short(vm_getw(ssp, sp), env))
|
299 | 46ddf551 | bellard | return;
|
300 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
301 | 46ddf551 | bellard | |
302 | 46ddf551 | bellard | case 0xcd: /* int */ |
303 | 46ddf551 | bellard | ADD16(env->eip, 2);
|
304 | 46ddf551 | bellard | do_int(env, pc[1]);
|
305 | 46ddf551 | bellard | break;
|
306 | 46ddf551 | bellard | |
307 | 46ddf551 | bellard | case 0xcf: /* iret */ |
308 | 46ddf551 | bellard | ADD16(env->regs[R_ESP], 6);
|
309 | 46ddf551 | bellard | env->eip = vm_getw(ssp, sp); |
310 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_CS, vm_getw(ssp, sp + 2));
|
311 | 46ddf551 | bellard | CHECK_IF_IN_TRAP(4);
|
312 | 46ddf551 | bellard | if (set_vflags_short(vm_getw(ssp, sp + 4), env)) |
313 | 46ddf551 | bellard | return;
|
314 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
315 | 46ddf551 | bellard | |
316 | 46ddf551 | bellard | case 0xfa: /* cli */ |
317 | 46ddf551 | bellard | ADD16(env->eip, 1);
|
318 | 46ddf551 | bellard | clear_IF(env); |
319 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
320 | 46ddf551 | bellard | |
321 | 46ddf551 | bellard | case 0xfb: /* sti */ |
322 | 46ddf551 | bellard | ADD16(env->eip, 1);
|
323 | 46ddf551 | bellard | if (set_IF(env))
|
324 | 46ddf551 | bellard | return;
|
325 | 46ddf551 | bellard | VM86_FAULT_RETURN; |
326 | 46ddf551 | bellard | |
327 | 46ddf551 | bellard | default:
|
328 | 46ddf551 | bellard | vm86_gpf:
|
329 | 46ddf551 | bellard | /* real VM86 GPF exception */
|
330 | 46ddf551 | bellard | return_to_32bit(env, TARGET_VM86_UNKNOWN); |
331 | 46ddf551 | bellard | break;
|
332 | 46ddf551 | bellard | } |
333 | 46ddf551 | bellard | } |
334 | 46ddf551 | bellard | |
335 | 46ddf551 | bellard | int do_vm86(CPUX86State *env, long subfunction, |
336 | 46ddf551 | bellard | struct target_vm86plus_struct * target_v86)
|
337 | 46ddf551 | bellard | { |
338 | 46ddf551 | bellard | TaskState *ts = env->opaque; |
339 | 46ddf551 | bellard | int ret;
|
340 | 46ddf551 | bellard | |
341 | 46ddf551 | bellard | switch (subfunction) {
|
342 | 46ddf551 | bellard | case TARGET_VM86_REQUEST_IRQ:
|
343 | 46ddf551 | bellard | case TARGET_VM86_FREE_IRQ:
|
344 | 46ddf551 | bellard | case TARGET_VM86_GET_IRQ_BITS:
|
345 | 46ddf551 | bellard | case TARGET_VM86_GET_AND_RESET_IRQ:
|
346 | 46ddf551 | bellard | gemu_log("qemu: unsupported vm86 subfunction (%ld)\n", subfunction);
|
347 | 46ddf551 | bellard | ret = -EINVAL; |
348 | 46ddf551 | bellard | goto out;
|
349 | 46ddf551 | bellard | case TARGET_VM86_PLUS_INSTALL_CHECK:
|
350 | 46ddf551 | bellard | /* NOTE: on old vm86 stuff this will return the error
|
351 | 46ddf551 | bellard | from verify_area(), because the subfunction is
|
352 | 46ddf551 | bellard | interpreted as (invalid) address to vm86_struct.
|
353 | 46ddf551 | bellard | So the installation check works.
|
354 | 46ddf551 | bellard | */
|
355 | 46ddf551 | bellard | ret = 0;
|
356 | 46ddf551 | bellard | goto out;
|
357 | 46ddf551 | bellard | } |
358 | 46ddf551 | bellard | |
359 | 46ddf551 | bellard | ts->target_v86 = target_v86; |
360 | 46ddf551 | bellard | /* save current CPU regs */
|
361 | 46ddf551 | bellard | ts->vm86_saved_regs.eax = 0; /* default vm86 syscall return code */ |
362 | 46ddf551 | bellard | ts->vm86_saved_regs.ebx = env->regs[R_EBX]; |
363 | 46ddf551 | bellard | ts->vm86_saved_regs.ecx = env->regs[R_ECX]; |
364 | 46ddf551 | bellard | ts->vm86_saved_regs.edx = env->regs[R_EDX]; |
365 | 46ddf551 | bellard | ts->vm86_saved_regs.esi = env->regs[R_ESI]; |
366 | 46ddf551 | bellard | ts->vm86_saved_regs.edi = env->regs[R_EDI]; |
367 | 46ddf551 | bellard | ts->vm86_saved_regs.ebp = env->regs[R_EBP]; |
368 | 46ddf551 | bellard | ts->vm86_saved_regs.esp = env->regs[R_ESP]; |
369 | 46ddf551 | bellard | ts->vm86_saved_regs.eflags = env->eflags; |
370 | 46ddf551 | bellard | ts->vm86_saved_regs.eip = env->eip; |
371 | 46ddf551 | bellard | ts->vm86_saved_regs.cs = env->segs[R_CS]; |
372 | 46ddf551 | bellard | ts->vm86_saved_regs.ss = env->segs[R_SS]; |
373 | 46ddf551 | bellard | ts->vm86_saved_regs.ds = env->segs[R_DS]; |
374 | 46ddf551 | bellard | ts->vm86_saved_regs.es = env->segs[R_ES]; |
375 | 46ddf551 | bellard | ts->vm86_saved_regs.fs = env->segs[R_FS]; |
376 | 46ddf551 | bellard | ts->vm86_saved_regs.gs = env->segs[R_GS]; |
377 | 46ddf551 | bellard | |
378 | 46ddf551 | bellard | /* build vm86 CPU state */
|
379 | 46ddf551 | bellard | ts->v86flags = tswap32(target_v86->regs.eflags); |
380 | 46ddf551 | bellard | env->eflags = (env->eflags & ~SAFE_MASK) | |
381 | 46ddf551 | bellard | (tswap32(target_v86->regs.eflags) & SAFE_MASK) | VM_MASK; |
382 | 46ddf551 | bellard | ts->v86mask = ID_MASK | AC_MASK | NT_MASK | IOPL_MASK; |
383 | 46ddf551 | bellard | |
384 | 46ddf551 | bellard | env->regs[R_EBX] = tswap32(target_v86->regs.ebx); |
385 | 46ddf551 | bellard | env->regs[R_ECX] = tswap32(target_v86->regs.ecx); |
386 | 46ddf551 | bellard | env->regs[R_EDX] = tswap32(target_v86->regs.edx); |
387 | 46ddf551 | bellard | env->regs[R_ESI] = tswap32(target_v86->regs.esi); |
388 | 46ddf551 | bellard | env->regs[R_EDI] = tswap32(target_v86->regs.edi); |
389 | 46ddf551 | bellard | env->regs[R_EBP] = tswap32(target_v86->regs.ebp); |
390 | 46ddf551 | bellard | env->regs[R_ESP] = tswap32(target_v86->regs.esp); |
391 | 46ddf551 | bellard | env->eip = tswap32(target_v86->regs.eip); |
392 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_CS, tswap16(target_v86->regs.cs)); |
393 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_SS, tswap16(target_v86->regs.ss)); |
394 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_DS, tswap16(target_v86->regs.ds)); |
395 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_ES, tswap16(target_v86->regs.es)); |
396 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_FS, tswap16(target_v86->regs.fs)); |
397 | 46ddf551 | bellard | cpu_x86_load_seg(env, R_GS, tswap16(target_v86->regs.gs)); |
398 | 46ddf551 | bellard | ret = tswap32(target_v86->regs.eax); /* eax will be restored at
|
399 | 46ddf551 | bellard | the end of the syscall */
|
400 | 46ddf551 | bellard | #ifdef DEBUG_VM86
|
401 | 46ddf551 | bellard | fprintf(logfile, "do_vm86: cs:ip=%04x:%04x\n", env->segs[R_CS], env->eip);
|
402 | 46ddf551 | bellard | #endif
|
403 | 46ddf551 | bellard | /* now the virtual CPU is ready for vm86 execution ! */
|
404 | 46ddf551 | bellard | out:
|
405 | 46ddf551 | bellard | return ret;
|
406 | 46ddf551 | bellard | } |