]>
Commit | Line | Data |
---|---|---|
eaa728ee | 1 | /* |
10774999 BS |
2 | * x86 segmentation related helpers: |
3 | * TSS, interrupts, system calls, jumps and call/task gates, descriptors | |
eaa728ee FB |
4 | * |
5 | * Copyright (c) 2003 Fabrice Bellard | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
8167ee88 | 18 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
eaa728ee | 19 | */ |
83dae095 | 20 | |
3e457172 | 21 | #include "cpu.h" |
1de7afc9 | 22 | #include "qemu/log.h" |
3e457172 | 23 | #include "helper.h" |
eaa728ee | 24 | |
3e457172 | 25 | //#define DEBUG_PCALL |
d12d51d5 | 26 | |
92fc4b58 | 27 | #if !defined(CONFIG_USER_ONLY) |
022c62cb | 28 | #include "exec/softmmu_exec.h" |
92fc4b58 BS |
29 | #endif /* !defined(CONFIG_USER_ONLY) */ |
30 | ||
d12d51d5 | 31 | #ifdef DEBUG_PCALL |
20054ef0 | 32 | # define LOG_PCALL(...) qemu_log_mask(CPU_LOG_PCALL, ## __VA_ARGS__) |
8995b7a0 AF |
33 | # define LOG_PCALL_STATE(cpu) \ |
34 | log_cpu_state_mask(CPU_LOG_PCALL, (cpu), CPU_DUMP_CCOP) | |
d12d51d5 | 35 | #else |
20054ef0 | 36 | # define LOG_PCALL(...) do { } while (0) |
8995b7a0 | 37 | # define LOG_PCALL_STATE(cpu) do { } while (0) |
d12d51d5 AL |
38 | #endif |
39 | ||
eaa728ee | 40 | /* return non zero if error */ |
2999a0b2 BS |
41 | static inline int load_segment(CPUX86State *env, uint32_t *e1_ptr, |
42 | uint32_t *e2_ptr, int selector) | |
eaa728ee FB |
43 | { |
44 | SegmentCache *dt; | |
45 | int index; | |
46 | target_ulong ptr; | |
47 | ||
20054ef0 | 48 | if (selector & 0x4) { |
eaa728ee | 49 | dt = &env->ldt; |
20054ef0 | 50 | } else { |
eaa728ee | 51 | dt = &env->gdt; |
20054ef0 | 52 | } |
eaa728ee | 53 | index = selector & ~7; |
20054ef0 | 54 | if ((index + 7) > dt->limit) { |
eaa728ee | 55 | return -1; |
20054ef0 | 56 | } |
eaa728ee | 57 | ptr = dt->base + index; |
329e607d BS |
58 | *e1_ptr = cpu_ldl_kernel(env, ptr); |
59 | *e2_ptr = cpu_ldl_kernel(env, ptr + 4); | |
eaa728ee FB |
60 | return 0; |
61 | } | |
62 | ||
63 | static inline unsigned int get_seg_limit(uint32_t e1, uint32_t e2) | |
64 | { | |
65 | unsigned int limit; | |
20054ef0 | 66 | |
eaa728ee | 67 | limit = (e1 & 0xffff) | (e2 & 0x000f0000); |
20054ef0 | 68 | if (e2 & DESC_G_MASK) { |
eaa728ee | 69 | limit = (limit << 12) | 0xfff; |
20054ef0 | 70 | } |
eaa728ee FB |
71 | return limit; |
72 | } | |
73 | ||
74 | static inline uint32_t get_seg_base(uint32_t e1, uint32_t e2) | |
75 | { | |
20054ef0 | 76 | return (e1 >> 16) | ((e2 & 0xff) << 16) | (e2 & 0xff000000); |
eaa728ee FB |
77 | } |
78 | ||
20054ef0 BS |
79 | static inline void load_seg_cache_raw_dt(SegmentCache *sc, uint32_t e1, |
80 | uint32_t e2) | |
eaa728ee FB |
81 | { |
82 | sc->base = get_seg_base(e1, e2); | |
83 | sc->limit = get_seg_limit(e1, e2); | |
84 | sc->flags = e2; | |
85 | } | |
86 | ||
87 | /* init the segment cache in vm86 mode. */ | |
2999a0b2 | 88 | static inline void load_seg_vm(CPUX86State *env, int seg, int selector) |
eaa728ee FB |
89 | { |
90 | selector &= 0xffff; | |
91 | cpu_x86_load_seg_cache(env, seg, selector, | |
92 | (selector << 4), 0xffff, 0); | |
93 | } | |
94 | ||
2999a0b2 | 95 | static inline void get_ss_esp_from_tss(CPUX86State *env, uint32_t *ss_ptr, |
eaa728ee FB |
96 | uint32_t *esp_ptr, int dpl) |
97 | { | |
a47dddd7 | 98 | X86CPU *cpu = x86_env_get_cpu(env); |
eaa728ee FB |
99 | int type, index, shift; |
100 | ||
101 | #if 0 | |
102 | { | |
103 | int i; | |
104 | printf("TR: base=%p limit=%x\n", env->tr.base, env->tr.limit); | |
20054ef0 | 105 | for (i = 0; i < env->tr.limit; i++) { |
eaa728ee | 106 | printf("%02x ", env->tr.base[i]); |
20054ef0 BS |
107 | if ((i & 7) == 7) { |
108 | printf("\n"); | |
109 | } | |
eaa728ee FB |
110 | } |
111 | printf("\n"); | |
112 | } | |
113 | #endif | |
114 | ||
20054ef0 | 115 | if (!(env->tr.flags & DESC_P_MASK)) { |
a47dddd7 | 116 | cpu_abort(CPU(cpu), "invalid tss"); |
20054ef0 | 117 | } |
eaa728ee | 118 | type = (env->tr.flags >> DESC_TYPE_SHIFT) & 0xf; |
20054ef0 | 119 | if ((type & 7) != 1) { |
a47dddd7 | 120 | cpu_abort(CPU(cpu), "invalid tss type"); |
20054ef0 | 121 | } |
eaa728ee FB |
122 | shift = type >> 3; |
123 | index = (dpl * 4 + 2) << shift; | |
20054ef0 | 124 | if (index + (4 << shift) - 1 > env->tr.limit) { |
77b2bc2c | 125 | raise_exception_err(env, EXCP0A_TSS, env->tr.selector & 0xfffc); |
20054ef0 | 126 | } |
eaa728ee | 127 | if (shift == 0) { |
329e607d BS |
128 | *esp_ptr = cpu_lduw_kernel(env, env->tr.base + index); |
129 | *ss_ptr = cpu_lduw_kernel(env, env->tr.base + index + 2); | |
eaa728ee | 130 | } else { |
329e607d BS |
131 | *esp_ptr = cpu_ldl_kernel(env, env->tr.base + index); |
132 | *ss_ptr = cpu_lduw_kernel(env, env->tr.base + index + 4); | |
eaa728ee FB |
133 | } |
134 | } | |
135 | ||
136 | /* XXX: merge with load_seg() */ | |
2999a0b2 | 137 | static void tss_load_seg(CPUX86State *env, int seg_reg, int selector) |
eaa728ee FB |
138 | { |
139 | uint32_t e1, e2; | |
140 | int rpl, dpl, cpl; | |
141 | ||
142 | if ((selector & 0xfffc) != 0) { | |
2999a0b2 | 143 | if (load_segment(env, &e1, &e2, selector) != 0) { |
77b2bc2c | 144 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 BS |
145 | } |
146 | if (!(e2 & DESC_S_MASK)) { | |
77b2bc2c | 147 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 | 148 | } |
eaa728ee FB |
149 | rpl = selector & 3; |
150 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
151 | cpl = env->hflags & HF_CPL_MASK; | |
152 | if (seg_reg == R_CS) { | |
20054ef0 | 153 | if (!(e2 & DESC_CS_MASK)) { |
77b2bc2c | 154 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 BS |
155 | } |
156 | /* XXX: is it correct? */ | |
157 | if (dpl != rpl) { | |
77b2bc2c | 158 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 BS |
159 | } |
160 | if ((e2 & DESC_C_MASK) && dpl > rpl) { | |
77b2bc2c | 161 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 | 162 | } |
eaa728ee FB |
163 | } else if (seg_reg == R_SS) { |
164 | /* SS must be writable data */ | |
20054ef0 | 165 | if ((e2 & DESC_CS_MASK) || !(e2 & DESC_W_MASK)) { |
77b2bc2c | 166 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 BS |
167 | } |
168 | if (dpl != cpl || dpl != rpl) { | |
77b2bc2c | 169 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 | 170 | } |
eaa728ee FB |
171 | } else { |
172 | /* not readable code */ | |
20054ef0 | 173 | if ((e2 & DESC_CS_MASK) && !(e2 & DESC_R_MASK)) { |
77b2bc2c | 174 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 | 175 | } |
eaa728ee FB |
176 | /* if data or non conforming code, checks the rights */ |
177 | if (((e2 >> DESC_TYPE_SHIFT) & 0xf) < 12) { | |
20054ef0 | 178 | if (dpl < cpl || dpl < rpl) { |
77b2bc2c | 179 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 | 180 | } |
eaa728ee FB |
181 | } |
182 | } | |
20054ef0 | 183 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 184 | raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc); |
20054ef0 | 185 | } |
eaa728ee | 186 | cpu_x86_load_seg_cache(env, seg_reg, selector, |
20054ef0 BS |
187 | get_seg_base(e1, e2), |
188 | get_seg_limit(e1, e2), | |
189 | e2); | |
eaa728ee | 190 | } else { |
20054ef0 | 191 | if (seg_reg == R_SS || seg_reg == R_CS) { |
77b2bc2c | 192 | raise_exception_err(env, EXCP0A_TSS, selector & 0xfffc); |
20054ef0 | 193 | } |
eaa728ee FB |
194 | } |
195 | } | |
196 | ||
197 | #define SWITCH_TSS_JMP 0 | |
198 | #define SWITCH_TSS_IRET 1 | |
199 | #define SWITCH_TSS_CALL 2 | |
200 | ||
201 | /* XXX: restore CPU state in registers (PowerPC case) */ | |
2999a0b2 | 202 | static void switch_tss(CPUX86State *env, int tss_selector, |
eaa728ee FB |
203 | uint32_t e1, uint32_t e2, int source, |
204 | uint32_t next_eip) | |
205 | { | |
206 | int tss_limit, tss_limit_max, type, old_tss_limit_max, old_type, v1, v2, i; | |
207 | target_ulong tss_base; | |
208 | uint32_t new_regs[8], new_segs[6]; | |
209 | uint32_t new_eflags, new_eip, new_cr3, new_ldt, new_trap; | |
210 | uint32_t old_eflags, eflags_mask; | |
211 | SegmentCache *dt; | |
212 | int index; | |
213 | target_ulong ptr; | |
214 | ||
215 | type = (e2 >> DESC_TYPE_SHIFT) & 0xf; | |
20054ef0 BS |
216 | LOG_PCALL("switch_tss: sel=0x%04x type=%d src=%d\n", tss_selector, type, |
217 | source); | |
eaa728ee FB |
218 | |
219 | /* if task gate, we read the TSS segment and we load it */ | |
220 | if (type == 5) { | |
20054ef0 | 221 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 222 | raise_exception_err(env, EXCP0B_NOSEG, tss_selector & 0xfffc); |
20054ef0 | 223 | } |
eaa728ee | 224 | tss_selector = e1 >> 16; |
20054ef0 | 225 | if (tss_selector & 4) { |
77b2bc2c | 226 | raise_exception_err(env, EXCP0A_TSS, tss_selector & 0xfffc); |
20054ef0 | 227 | } |
2999a0b2 | 228 | if (load_segment(env, &e1, &e2, tss_selector) != 0) { |
77b2bc2c | 229 | raise_exception_err(env, EXCP0D_GPF, tss_selector & 0xfffc); |
20054ef0 BS |
230 | } |
231 | if (e2 & DESC_S_MASK) { | |
77b2bc2c | 232 | raise_exception_err(env, EXCP0D_GPF, tss_selector & 0xfffc); |
20054ef0 | 233 | } |
eaa728ee | 234 | type = (e2 >> DESC_TYPE_SHIFT) & 0xf; |
20054ef0 | 235 | if ((type & 7) != 1) { |
77b2bc2c | 236 | raise_exception_err(env, EXCP0D_GPF, tss_selector & 0xfffc); |
20054ef0 | 237 | } |
eaa728ee FB |
238 | } |
239 | ||
20054ef0 | 240 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 241 | raise_exception_err(env, EXCP0B_NOSEG, tss_selector & 0xfffc); |
20054ef0 | 242 | } |
eaa728ee | 243 | |
20054ef0 | 244 | if (type & 8) { |
eaa728ee | 245 | tss_limit_max = 103; |
20054ef0 | 246 | } else { |
eaa728ee | 247 | tss_limit_max = 43; |
20054ef0 | 248 | } |
eaa728ee FB |
249 | tss_limit = get_seg_limit(e1, e2); |
250 | tss_base = get_seg_base(e1, e2); | |
251 | if ((tss_selector & 4) != 0 || | |
20054ef0 | 252 | tss_limit < tss_limit_max) { |
77b2bc2c | 253 | raise_exception_err(env, EXCP0A_TSS, tss_selector & 0xfffc); |
20054ef0 | 254 | } |
eaa728ee | 255 | old_type = (env->tr.flags >> DESC_TYPE_SHIFT) & 0xf; |
20054ef0 | 256 | if (old_type & 8) { |
eaa728ee | 257 | old_tss_limit_max = 103; |
20054ef0 | 258 | } else { |
eaa728ee | 259 | old_tss_limit_max = 43; |
20054ef0 | 260 | } |
eaa728ee FB |
261 | |
262 | /* read all the registers from the new TSS */ | |
263 | if (type & 8) { | |
264 | /* 32 bit */ | |
329e607d BS |
265 | new_cr3 = cpu_ldl_kernel(env, tss_base + 0x1c); |
266 | new_eip = cpu_ldl_kernel(env, tss_base + 0x20); | |
267 | new_eflags = cpu_ldl_kernel(env, tss_base + 0x24); | |
20054ef0 | 268 | for (i = 0; i < 8; i++) { |
329e607d | 269 | new_regs[i] = cpu_ldl_kernel(env, tss_base + (0x28 + i * 4)); |
20054ef0 BS |
270 | } |
271 | for (i = 0; i < 6; i++) { | |
329e607d | 272 | new_segs[i] = cpu_lduw_kernel(env, tss_base + (0x48 + i * 4)); |
20054ef0 | 273 | } |
329e607d BS |
274 | new_ldt = cpu_lduw_kernel(env, tss_base + 0x60); |
275 | new_trap = cpu_ldl_kernel(env, tss_base + 0x64); | |
eaa728ee FB |
276 | } else { |
277 | /* 16 bit */ | |
278 | new_cr3 = 0; | |
329e607d BS |
279 | new_eip = cpu_lduw_kernel(env, tss_base + 0x0e); |
280 | new_eflags = cpu_lduw_kernel(env, tss_base + 0x10); | |
20054ef0 | 281 | for (i = 0; i < 8; i++) { |
329e607d BS |
282 | new_regs[i] = cpu_lduw_kernel(env, tss_base + (0x12 + i * 2)) | |
283 | 0xffff0000; | |
20054ef0 BS |
284 | } |
285 | for (i = 0; i < 4; i++) { | |
329e607d | 286 | new_segs[i] = cpu_lduw_kernel(env, tss_base + (0x22 + i * 4)); |
20054ef0 | 287 | } |
329e607d | 288 | new_ldt = cpu_lduw_kernel(env, tss_base + 0x2a); |
eaa728ee FB |
289 | new_segs[R_FS] = 0; |
290 | new_segs[R_GS] = 0; | |
291 | new_trap = 0; | |
292 | } | |
4581cbcd BS |
293 | /* XXX: avoid a compiler warning, see |
294 | http://support.amd.com/us/Processor_TechDocs/24593.pdf | |
295 | chapters 12.2.5 and 13.2.4 on how to implement TSS Trap bit */ | |
296 | (void)new_trap; | |
eaa728ee FB |
297 | |
298 | /* NOTE: we must avoid memory exceptions during the task switch, | |
299 | so we make dummy accesses before */ | |
300 | /* XXX: it can still fail in some cases, so a bigger hack is | |
301 | necessary to valid the TLB after having done the accesses */ | |
302 | ||
329e607d BS |
303 | v1 = cpu_ldub_kernel(env, env->tr.base); |
304 | v2 = cpu_ldub_kernel(env, env->tr.base + old_tss_limit_max); | |
305 | cpu_stb_kernel(env, env->tr.base, v1); | |
306 | cpu_stb_kernel(env, env->tr.base + old_tss_limit_max, v2); | |
eaa728ee FB |
307 | |
308 | /* clear busy bit (it is restartable) */ | |
309 | if (source == SWITCH_TSS_JMP || source == SWITCH_TSS_IRET) { | |
310 | target_ulong ptr; | |
311 | uint32_t e2; | |
20054ef0 | 312 | |
eaa728ee | 313 | ptr = env->gdt.base + (env->tr.selector & ~7); |
329e607d | 314 | e2 = cpu_ldl_kernel(env, ptr + 4); |
eaa728ee | 315 | e2 &= ~DESC_TSS_BUSY_MASK; |
329e607d | 316 | cpu_stl_kernel(env, ptr + 4, e2); |
eaa728ee | 317 | } |
997ff0d9 | 318 | old_eflags = cpu_compute_eflags(env); |
20054ef0 | 319 | if (source == SWITCH_TSS_IRET) { |
eaa728ee | 320 | old_eflags &= ~NT_MASK; |
20054ef0 | 321 | } |
eaa728ee FB |
322 | |
323 | /* save the current state in the old TSS */ | |
324 | if (type & 8) { | |
325 | /* 32 bit */ | |
329e607d BS |
326 | cpu_stl_kernel(env, env->tr.base + 0x20, next_eip); |
327 | cpu_stl_kernel(env, env->tr.base + 0x24, old_eflags); | |
4b34e3ad | 328 | cpu_stl_kernel(env, env->tr.base + (0x28 + 0 * 4), env->regs[R_EAX]); |
a4165610 | 329 | cpu_stl_kernel(env, env->tr.base + (0x28 + 1 * 4), env->regs[R_ECX]); |
00f5e6f2 | 330 | cpu_stl_kernel(env, env->tr.base + (0x28 + 2 * 4), env->regs[R_EDX]); |
70b51365 | 331 | cpu_stl_kernel(env, env->tr.base + (0x28 + 3 * 4), env->regs[R_EBX]); |
08b3ded6 | 332 | cpu_stl_kernel(env, env->tr.base + (0x28 + 4 * 4), env->regs[R_ESP]); |
c12dddd7 | 333 | cpu_stl_kernel(env, env->tr.base + (0x28 + 5 * 4), env->regs[R_EBP]); |
78c3c6d3 | 334 | cpu_stl_kernel(env, env->tr.base + (0x28 + 6 * 4), env->regs[R_ESI]); |
cf75c597 | 335 | cpu_stl_kernel(env, env->tr.base + (0x28 + 7 * 4), env->regs[R_EDI]); |
20054ef0 | 336 | for (i = 0; i < 6; i++) { |
329e607d BS |
337 | cpu_stw_kernel(env, env->tr.base + (0x48 + i * 4), |
338 | env->segs[i].selector); | |
20054ef0 | 339 | } |
eaa728ee FB |
340 | } else { |
341 | /* 16 bit */ | |
329e607d BS |
342 | cpu_stw_kernel(env, env->tr.base + 0x0e, next_eip); |
343 | cpu_stw_kernel(env, env->tr.base + 0x10, old_eflags); | |
4b34e3ad | 344 | cpu_stw_kernel(env, env->tr.base + (0x12 + 0 * 2), env->regs[R_EAX]); |
a4165610 | 345 | cpu_stw_kernel(env, env->tr.base + (0x12 + 1 * 2), env->regs[R_ECX]); |
00f5e6f2 | 346 | cpu_stw_kernel(env, env->tr.base + (0x12 + 2 * 2), env->regs[R_EDX]); |
70b51365 | 347 | cpu_stw_kernel(env, env->tr.base + (0x12 + 3 * 2), env->regs[R_EBX]); |
08b3ded6 | 348 | cpu_stw_kernel(env, env->tr.base + (0x12 + 4 * 2), env->regs[R_ESP]); |
c12dddd7 | 349 | cpu_stw_kernel(env, env->tr.base + (0x12 + 5 * 2), env->regs[R_EBP]); |
78c3c6d3 | 350 | cpu_stw_kernel(env, env->tr.base + (0x12 + 6 * 2), env->regs[R_ESI]); |
cf75c597 | 351 | cpu_stw_kernel(env, env->tr.base + (0x12 + 7 * 2), env->regs[R_EDI]); |
20054ef0 | 352 | for (i = 0; i < 4; i++) { |
329e607d BS |
353 | cpu_stw_kernel(env, env->tr.base + (0x22 + i * 4), |
354 | env->segs[i].selector); | |
20054ef0 | 355 | } |
eaa728ee FB |
356 | } |
357 | ||
358 | /* now if an exception occurs, it will occurs in the next task | |
359 | context */ | |
360 | ||
361 | if (source == SWITCH_TSS_CALL) { | |
329e607d | 362 | cpu_stw_kernel(env, tss_base, env->tr.selector); |
eaa728ee FB |
363 | new_eflags |= NT_MASK; |
364 | } | |
365 | ||
366 | /* set busy bit */ | |
367 | if (source == SWITCH_TSS_JMP || source == SWITCH_TSS_CALL) { | |
368 | target_ulong ptr; | |
369 | uint32_t e2; | |
20054ef0 | 370 | |
eaa728ee | 371 | ptr = env->gdt.base + (tss_selector & ~7); |
329e607d | 372 | e2 = cpu_ldl_kernel(env, ptr + 4); |
eaa728ee | 373 | e2 |= DESC_TSS_BUSY_MASK; |
329e607d | 374 | cpu_stl_kernel(env, ptr + 4, e2); |
eaa728ee FB |
375 | } |
376 | ||
377 | /* set the new CPU state */ | |
378 | /* from this point, any exception which occurs can give problems */ | |
379 | env->cr[0] |= CR0_TS_MASK; | |
380 | env->hflags |= HF_TS_MASK; | |
381 | env->tr.selector = tss_selector; | |
382 | env->tr.base = tss_base; | |
383 | env->tr.limit = tss_limit; | |
384 | env->tr.flags = e2 & ~DESC_TSS_BUSY_MASK; | |
385 | ||
386 | if ((type & 8) && (env->cr[0] & CR0_PG_MASK)) { | |
387 | cpu_x86_update_cr3(env, new_cr3); | |
388 | } | |
389 | ||
390 | /* load all registers without an exception, then reload them with | |
391 | possible exception */ | |
392 | env->eip = new_eip; | |
393 | eflags_mask = TF_MASK | AC_MASK | ID_MASK | | |
394 | IF_MASK | IOPL_MASK | VM_MASK | RF_MASK | NT_MASK; | |
20054ef0 | 395 | if (!(type & 8)) { |
eaa728ee | 396 | eflags_mask &= 0xffff; |
20054ef0 | 397 | } |
997ff0d9 | 398 | cpu_load_eflags(env, new_eflags, eflags_mask); |
20054ef0 | 399 | /* XXX: what to do in 16 bit case? */ |
4b34e3ad | 400 | env->regs[R_EAX] = new_regs[0]; |
a4165610 | 401 | env->regs[R_ECX] = new_regs[1]; |
00f5e6f2 | 402 | env->regs[R_EDX] = new_regs[2]; |
70b51365 | 403 | env->regs[R_EBX] = new_regs[3]; |
08b3ded6 | 404 | env->regs[R_ESP] = new_regs[4]; |
c12dddd7 | 405 | env->regs[R_EBP] = new_regs[5]; |
78c3c6d3 | 406 | env->regs[R_ESI] = new_regs[6]; |
cf75c597 | 407 | env->regs[R_EDI] = new_regs[7]; |
eaa728ee | 408 | if (new_eflags & VM_MASK) { |
20054ef0 | 409 | for (i = 0; i < 6; i++) { |
2999a0b2 | 410 | load_seg_vm(env, i, new_segs[i]); |
20054ef0 | 411 | } |
eaa728ee FB |
412 | /* in vm86, CPL is always 3 */ |
413 | cpu_x86_set_cpl(env, 3); | |
414 | } else { | |
415 | /* CPL is set the RPL of CS */ | |
416 | cpu_x86_set_cpl(env, new_segs[R_CS] & 3); | |
417 | /* first just selectors as the rest may trigger exceptions */ | |
20054ef0 | 418 | for (i = 0; i < 6; i++) { |
eaa728ee | 419 | cpu_x86_load_seg_cache(env, i, new_segs[i], 0, 0, 0); |
20054ef0 | 420 | } |
eaa728ee FB |
421 | } |
422 | ||
423 | env->ldt.selector = new_ldt & ~4; | |
424 | env->ldt.base = 0; | |
425 | env->ldt.limit = 0; | |
426 | env->ldt.flags = 0; | |
427 | ||
428 | /* load the LDT */ | |
20054ef0 | 429 | if (new_ldt & 4) { |
77b2bc2c | 430 | raise_exception_err(env, EXCP0A_TSS, new_ldt & 0xfffc); |
20054ef0 | 431 | } |
eaa728ee FB |
432 | |
433 | if ((new_ldt & 0xfffc) != 0) { | |
434 | dt = &env->gdt; | |
435 | index = new_ldt & ~7; | |
20054ef0 | 436 | if ((index + 7) > dt->limit) { |
77b2bc2c | 437 | raise_exception_err(env, EXCP0A_TSS, new_ldt & 0xfffc); |
20054ef0 | 438 | } |
eaa728ee | 439 | ptr = dt->base + index; |
329e607d BS |
440 | e1 = cpu_ldl_kernel(env, ptr); |
441 | e2 = cpu_ldl_kernel(env, ptr + 4); | |
20054ef0 | 442 | if ((e2 & DESC_S_MASK) || ((e2 >> DESC_TYPE_SHIFT) & 0xf) != 2) { |
77b2bc2c | 443 | raise_exception_err(env, EXCP0A_TSS, new_ldt & 0xfffc); |
20054ef0 BS |
444 | } |
445 | if (!(e2 & DESC_P_MASK)) { | |
77b2bc2c | 446 | raise_exception_err(env, EXCP0A_TSS, new_ldt & 0xfffc); |
20054ef0 | 447 | } |
eaa728ee FB |
448 | load_seg_cache_raw_dt(&env->ldt, e1, e2); |
449 | } | |
450 | ||
451 | /* load the segments */ | |
452 | if (!(new_eflags & VM_MASK)) { | |
2999a0b2 BS |
453 | tss_load_seg(env, R_CS, new_segs[R_CS]); |
454 | tss_load_seg(env, R_SS, new_segs[R_SS]); | |
455 | tss_load_seg(env, R_ES, new_segs[R_ES]); | |
456 | tss_load_seg(env, R_DS, new_segs[R_DS]); | |
457 | tss_load_seg(env, R_FS, new_segs[R_FS]); | |
458 | tss_load_seg(env, R_GS, new_segs[R_GS]); | |
eaa728ee FB |
459 | } |
460 | ||
a78d0eab | 461 | /* check that env->eip is in the CS segment limits */ |
eaa728ee | 462 | if (new_eip > env->segs[R_CS].limit) { |
20054ef0 | 463 | /* XXX: different exception if CALL? */ |
77b2bc2c | 464 | raise_exception_err(env, EXCP0D_GPF, 0); |
eaa728ee | 465 | } |
01df040b AL |
466 | |
467 | #ifndef CONFIG_USER_ONLY | |
468 | /* reset local breakpoints */ | |
428065ce LG |
469 | if (env->dr[7] & DR7_LOCAL_BP_MASK) { |
470 | for (i = 0; i < DR7_MAX_BP; i++) { | |
5902564a LG |
471 | if (hw_local_breakpoint_enabled(env->dr[7], i) && |
472 | !hw_global_breakpoint_enabled(env->dr[7], i)) { | |
01df040b | 473 | hw_breakpoint_remove(env, i); |
20054ef0 | 474 | } |
01df040b | 475 | } |
428065ce | 476 | env->dr[7] &= ~DR7_LOCAL_BP_MASK; |
01df040b AL |
477 | } |
478 | #endif | |
eaa728ee FB |
479 | } |
480 | ||
eaa728ee FB |
481 | static inline unsigned int get_sp_mask(unsigned int e2) |
482 | { | |
20054ef0 | 483 | if (e2 & DESC_B_MASK) { |
eaa728ee | 484 | return 0xffffffff; |
20054ef0 | 485 | } else { |
eaa728ee | 486 | return 0xffff; |
20054ef0 | 487 | } |
eaa728ee FB |
488 | } |
489 | ||
20054ef0 | 490 | static int exception_has_error_code(int intno) |
2ed51f5b | 491 | { |
20054ef0 BS |
492 | switch (intno) { |
493 | case 8: | |
494 | case 10: | |
495 | case 11: | |
496 | case 12: | |
497 | case 13: | |
498 | case 14: | |
499 | case 17: | |
500 | return 1; | |
501 | } | |
502 | return 0; | |
2ed51f5b AL |
503 | } |
504 | ||
eaa728ee | 505 | #ifdef TARGET_X86_64 |
08b3ded6 LG |
506 | #define SET_ESP(val, sp_mask) \ |
507 | do { \ | |
508 | if ((sp_mask) == 0xffff) { \ | |
509 | env->regs[R_ESP] = (env->regs[R_ESP] & ~0xffff) | \ | |
510 | ((val) & 0xffff); \ | |
511 | } else if ((sp_mask) == 0xffffffffLL) { \ | |
512 | env->regs[R_ESP] = (uint32_t)(val); \ | |
513 | } else { \ | |
514 | env->regs[R_ESP] = (val); \ | |
515 | } \ | |
20054ef0 | 516 | } while (0) |
eaa728ee | 517 | #else |
08b3ded6 LG |
518 | #define SET_ESP(val, sp_mask) \ |
519 | do { \ | |
520 | env->regs[R_ESP] = (env->regs[R_ESP] & ~(sp_mask)) | \ | |
521 | ((val) & (sp_mask)); \ | |
20054ef0 | 522 | } while (0) |
eaa728ee FB |
523 | #endif |
524 | ||
c0a04f0e AL |
525 | /* in 64-bit machines, this can overflow. So this segment addition macro |
526 | * can be used to trim the value to 32-bit whenever needed */ | |
527 | #define SEG_ADDL(ssp, sp, sp_mask) ((uint32_t)((ssp) + (sp & (sp_mask)))) | |
528 | ||
eaa728ee | 529 | /* XXX: add a is_user flag to have proper security support */ |
329e607d BS |
530 | #define PUSHW(ssp, sp, sp_mask, val) \ |
531 | { \ | |
532 | sp -= 2; \ | |
533 | cpu_stw_kernel(env, (ssp) + (sp & (sp_mask)), (val)); \ | |
20054ef0 | 534 | } |
eaa728ee | 535 | |
20054ef0 BS |
536 | #define PUSHL(ssp, sp, sp_mask, val) \ |
537 | { \ | |
538 | sp -= 4; \ | |
329e607d | 539 | cpu_stl_kernel(env, SEG_ADDL(ssp, sp, sp_mask), (uint32_t)(val)); \ |
20054ef0 | 540 | } |
eaa728ee | 541 | |
329e607d BS |
542 | #define POPW(ssp, sp, sp_mask, val) \ |
543 | { \ | |
544 | val = cpu_lduw_kernel(env, (ssp) + (sp & (sp_mask))); \ | |
545 | sp += 2; \ | |
20054ef0 | 546 | } |
eaa728ee | 547 | |
329e607d BS |
548 | #define POPL(ssp, sp, sp_mask, val) \ |
549 | { \ | |
550 | val = (uint32_t)cpu_ldl_kernel(env, SEG_ADDL(ssp, sp, sp_mask)); \ | |
551 | sp += 4; \ | |
20054ef0 | 552 | } |
eaa728ee FB |
553 | |
554 | /* protected mode interrupt */ | |
2999a0b2 BS |
555 | static void do_interrupt_protected(CPUX86State *env, int intno, int is_int, |
556 | int error_code, unsigned int next_eip, | |
557 | int is_hw) | |
eaa728ee FB |
558 | { |
559 | SegmentCache *dt; | |
560 | target_ulong ptr, ssp; | |
561 | int type, dpl, selector, ss_dpl, cpl; | |
562 | int has_error_code, new_stack, shift; | |
1c918eba | 563 | uint32_t e1, e2, offset, ss = 0, esp, ss_e1 = 0, ss_e2 = 0; |
eaa728ee | 564 | uint32_t old_eip, sp_mask; |
eaa728ee | 565 | |
eaa728ee | 566 | has_error_code = 0; |
20054ef0 BS |
567 | if (!is_int && !is_hw) { |
568 | has_error_code = exception_has_error_code(intno); | |
569 | } | |
570 | if (is_int) { | |
eaa728ee | 571 | old_eip = next_eip; |
20054ef0 | 572 | } else { |
eaa728ee | 573 | old_eip = env->eip; |
20054ef0 | 574 | } |
eaa728ee FB |
575 | |
576 | dt = &env->idt; | |
20054ef0 | 577 | if (intno * 8 + 7 > dt->limit) { |
77b2bc2c | 578 | raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2); |
20054ef0 | 579 | } |
eaa728ee | 580 | ptr = dt->base + intno * 8; |
329e607d BS |
581 | e1 = cpu_ldl_kernel(env, ptr); |
582 | e2 = cpu_ldl_kernel(env, ptr + 4); | |
eaa728ee FB |
583 | /* check gate type */ |
584 | type = (e2 >> DESC_TYPE_SHIFT) & 0x1f; | |
20054ef0 | 585 | switch (type) { |
eaa728ee FB |
586 | case 5: /* task gate */ |
587 | /* must do that check here to return the correct error code */ | |
20054ef0 | 588 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 589 | raise_exception_err(env, EXCP0B_NOSEG, intno * 8 + 2); |
20054ef0 | 590 | } |
2999a0b2 | 591 | switch_tss(env, intno * 8, e1, e2, SWITCH_TSS_CALL, old_eip); |
eaa728ee FB |
592 | if (has_error_code) { |
593 | int type; | |
594 | uint32_t mask; | |
20054ef0 | 595 | |
eaa728ee FB |
596 | /* push the error code */ |
597 | type = (env->tr.flags >> DESC_TYPE_SHIFT) & 0xf; | |
598 | shift = type >> 3; | |
20054ef0 | 599 | if (env->segs[R_SS].flags & DESC_B_MASK) { |
eaa728ee | 600 | mask = 0xffffffff; |
20054ef0 | 601 | } else { |
eaa728ee | 602 | mask = 0xffff; |
20054ef0 | 603 | } |
08b3ded6 | 604 | esp = (env->regs[R_ESP] - (2 << shift)) & mask; |
eaa728ee | 605 | ssp = env->segs[R_SS].base + esp; |
20054ef0 | 606 | if (shift) { |
329e607d | 607 | cpu_stl_kernel(env, ssp, error_code); |
20054ef0 | 608 | } else { |
329e607d | 609 | cpu_stw_kernel(env, ssp, error_code); |
20054ef0 | 610 | } |
eaa728ee FB |
611 | SET_ESP(esp, mask); |
612 | } | |
613 | return; | |
614 | case 6: /* 286 interrupt gate */ | |
615 | case 7: /* 286 trap gate */ | |
616 | case 14: /* 386 interrupt gate */ | |
617 | case 15: /* 386 trap gate */ | |
618 | break; | |
619 | default: | |
77b2bc2c | 620 | raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2); |
eaa728ee FB |
621 | break; |
622 | } | |
623 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
624 | cpl = env->hflags & HF_CPL_MASK; | |
1235fc06 | 625 | /* check privilege if software int */ |
20054ef0 | 626 | if (is_int && dpl < cpl) { |
77b2bc2c | 627 | raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2); |
20054ef0 | 628 | } |
eaa728ee | 629 | /* check valid bit */ |
20054ef0 | 630 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 631 | raise_exception_err(env, EXCP0B_NOSEG, intno * 8 + 2); |
20054ef0 | 632 | } |
eaa728ee FB |
633 | selector = e1 >> 16; |
634 | offset = (e2 & 0xffff0000) | (e1 & 0x0000ffff); | |
20054ef0 | 635 | if ((selector & 0xfffc) == 0) { |
77b2bc2c | 636 | raise_exception_err(env, EXCP0D_GPF, 0); |
20054ef0 | 637 | } |
2999a0b2 | 638 | if (load_segment(env, &e1, &e2, selector) != 0) { |
77b2bc2c | 639 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 BS |
640 | } |
641 | if (!(e2 & DESC_S_MASK) || !(e2 & (DESC_CS_MASK))) { | |
77b2bc2c | 642 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 643 | } |
eaa728ee | 644 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; |
20054ef0 | 645 | if (dpl > cpl) { |
77b2bc2c | 646 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 BS |
647 | } |
648 | if (!(e2 & DESC_P_MASK)) { | |
77b2bc2c | 649 | raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc); |
20054ef0 | 650 | } |
eaa728ee FB |
651 | if (!(e2 & DESC_C_MASK) && dpl < cpl) { |
652 | /* to inner privilege */ | |
2999a0b2 | 653 | get_ss_esp_from_tss(env, &ss, &esp, dpl); |
20054ef0 | 654 | if ((ss & 0xfffc) == 0) { |
77b2bc2c | 655 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 BS |
656 | } |
657 | if ((ss & 3) != dpl) { | |
77b2bc2c | 658 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 | 659 | } |
2999a0b2 | 660 | if (load_segment(env, &ss_e1, &ss_e2, ss) != 0) { |
77b2bc2c | 661 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 | 662 | } |
eaa728ee | 663 | ss_dpl = (ss_e2 >> DESC_DPL_SHIFT) & 3; |
20054ef0 | 664 | if (ss_dpl != dpl) { |
77b2bc2c | 665 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 | 666 | } |
eaa728ee FB |
667 | if (!(ss_e2 & DESC_S_MASK) || |
668 | (ss_e2 & DESC_CS_MASK) || | |
20054ef0 | 669 | !(ss_e2 & DESC_W_MASK)) { |
77b2bc2c | 670 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 BS |
671 | } |
672 | if (!(ss_e2 & DESC_P_MASK)) { | |
77b2bc2c | 673 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 | 674 | } |
eaa728ee FB |
675 | new_stack = 1; |
676 | sp_mask = get_sp_mask(ss_e2); | |
677 | ssp = get_seg_base(ss_e1, ss_e2); | |
678 | } else if ((e2 & DESC_C_MASK) || dpl == cpl) { | |
679 | /* to same privilege */ | |
20054ef0 | 680 | if (env->eflags & VM_MASK) { |
77b2bc2c | 681 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 682 | } |
eaa728ee FB |
683 | new_stack = 0; |
684 | sp_mask = get_sp_mask(env->segs[R_SS].flags); | |
685 | ssp = env->segs[R_SS].base; | |
08b3ded6 | 686 | esp = env->regs[R_ESP]; |
eaa728ee FB |
687 | dpl = cpl; |
688 | } else { | |
77b2bc2c | 689 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
eaa728ee FB |
690 | new_stack = 0; /* avoid warning */ |
691 | sp_mask = 0; /* avoid warning */ | |
692 | ssp = 0; /* avoid warning */ | |
693 | esp = 0; /* avoid warning */ | |
694 | } | |
695 | ||
696 | shift = type >> 3; | |
697 | ||
698 | #if 0 | |
699 | /* XXX: check that enough room is available */ | |
700 | push_size = 6 + (new_stack << 2) + (has_error_code << 1); | |
20054ef0 | 701 | if (env->eflags & VM_MASK) { |
eaa728ee | 702 | push_size += 8; |
20054ef0 | 703 | } |
eaa728ee FB |
704 | push_size <<= shift; |
705 | #endif | |
706 | if (shift == 1) { | |
707 | if (new_stack) { | |
708 | if (env->eflags & VM_MASK) { | |
709 | PUSHL(ssp, esp, sp_mask, env->segs[R_GS].selector); | |
710 | PUSHL(ssp, esp, sp_mask, env->segs[R_FS].selector); | |
711 | PUSHL(ssp, esp, sp_mask, env->segs[R_DS].selector); | |
712 | PUSHL(ssp, esp, sp_mask, env->segs[R_ES].selector); | |
713 | } | |
714 | PUSHL(ssp, esp, sp_mask, env->segs[R_SS].selector); | |
08b3ded6 | 715 | PUSHL(ssp, esp, sp_mask, env->regs[R_ESP]); |
eaa728ee | 716 | } |
997ff0d9 | 717 | PUSHL(ssp, esp, sp_mask, cpu_compute_eflags(env)); |
eaa728ee FB |
718 | PUSHL(ssp, esp, sp_mask, env->segs[R_CS].selector); |
719 | PUSHL(ssp, esp, sp_mask, old_eip); | |
720 | if (has_error_code) { | |
721 | PUSHL(ssp, esp, sp_mask, error_code); | |
722 | } | |
723 | } else { | |
724 | if (new_stack) { | |
725 | if (env->eflags & VM_MASK) { | |
726 | PUSHW(ssp, esp, sp_mask, env->segs[R_GS].selector); | |
727 | PUSHW(ssp, esp, sp_mask, env->segs[R_FS].selector); | |
728 | PUSHW(ssp, esp, sp_mask, env->segs[R_DS].selector); | |
729 | PUSHW(ssp, esp, sp_mask, env->segs[R_ES].selector); | |
730 | } | |
731 | PUSHW(ssp, esp, sp_mask, env->segs[R_SS].selector); | |
08b3ded6 | 732 | PUSHW(ssp, esp, sp_mask, env->regs[R_ESP]); |
eaa728ee | 733 | } |
997ff0d9 | 734 | PUSHW(ssp, esp, sp_mask, cpu_compute_eflags(env)); |
eaa728ee FB |
735 | PUSHW(ssp, esp, sp_mask, env->segs[R_CS].selector); |
736 | PUSHW(ssp, esp, sp_mask, old_eip); | |
737 | if (has_error_code) { | |
738 | PUSHW(ssp, esp, sp_mask, error_code); | |
739 | } | |
740 | } | |
741 | ||
742 | if (new_stack) { | |
743 | if (env->eflags & VM_MASK) { | |
744 | cpu_x86_load_seg_cache(env, R_ES, 0, 0, 0, 0); | |
745 | cpu_x86_load_seg_cache(env, R_DS, 0, 0, 0, 0); | |
746 | cpu_x86_load_seg_cache(env, R_FS, 0, 0, 0, 0); | |
747 | cpu_x86_load_seg_cache(env, R_GS, 0, 0, 0, 0); | |
748 | } | |
749 | ss = (ss & ~3) | dpl; | |
750 | cpu_x86_load_seg_cache(env, R_SS, ss, | |
751 | ssp, get_seg_limit(ss_e1, ss_e2), ss_e2); | |
752 | } | |
753 | SET_ESP(esp, sp_mask); | |
754 | ||
755 | selector = (selector & ~3) | dpl; | |
756 | cpu_x86_load_seg_cache(env, R_CS, selector, | |
757 | get_seg_base(e1, e2), | |
758 | get_seg_limit(e1, e2), | |
759 | e2); | |
760 | cpu_x86_set_cpl(env, dpl); | |
761 | env->eip = offset; | |
762 | ||
763 | /* interrupt gate clear IF mask */ | |
764 | if ((type & 1) == 0) { | |
765 | env->eflags &= ~IF_MASK; | |
766 | } | |
767 | env->eflags &= ~(TF_MASK | VM_MASK | RF_MASK | NT_MASK); | |
768 | } | |
769 | ||
770 | #ifdef TARGET_X86_64 | |
771 | ||
20054ef0 BS |
772 | #define PUSHQ(sp, val) \ |
773 | { \ | |
774 | sp -= 8; \ | |
329e607d | 775 | cpu_stq_kernel(env, sp, (val)); \ |
20054ef0 | 776 | } |
eaa728ee | 777 | |
20054ef0 BS |
778 | #define POPQ(sp, val) \ |
779 | { \ | |
329e607d | 780 | val = cpu_ldq_kernel(env, sp); \ |
20054ef0 BS |
781 | sp += 8; \ |
782 | } | |
eaa728ee | 783 | |
2999a0b2 | 784 | static inline target_ulong get_rsp_from_tss(CPUX86State *env, int level) |
eaa728ee | 785 | { |
a47dddd7 | 786 | X86CPU *cpu = x86_env_get_cpu(env); |
eaa728ee FB |
787 | int index; |
788 | ||
789 | #if 0 | |
790 | printf("TR: base=" TARGET_FMT_lx " limit=%x\n", | |
791 | env->tr.base, env->tr.limit); | |
792 | #endif | |
793 | ||
20054ef0 | 794 | if (!(env->tr.flags & DESC_P_MASK)) { |
a47dddd7 | 795 | cpu_abort(CPU(cpu), "invalid tss"); |
20054ef0 | 796 | } |
eaa728ee | 797 | index = 8 * level + 4; |
20054ef0 | 798 | if ((index + 7) > env->tr.limit) { |
77b2bc2c | 799 | raise_exception_err(env, EXCP0A_TSS, env->tr.selector & 0xfffc); |
20054ef0 | 800 | } |
329e607d | 801 | return cpu_ldq_kernel(env, env->tr.base + index); |
eaa728ee FB |
802 | } |
803 | ||
804 | /* 64 bit interrupt */ | |
2999a0b2 BS |
805 | static void do_interrupt64(CPUX86State *env, int intno, int is_int, |
806 | int error_code, target_ulong next_eip, int is_hw) | |
eaa728ee FB |
807 | { |
808 | SegmentCache *dt; | |
809 | target_ulong ptr; | |
810 | int type, dpl, selector, cpl, ist; | |
811 | int has_error_code, new_stack; | |
812 | uint32_t e1, e2, e3, ss; | |
813 | target_ulong old_eip, esp, offset; | |
eaa728ee | 814 | |
eaa728ee | 815 | has_error_code = 0; |
20054ef0 BS |
816 | if (!is_int && !is_hw) { |
817 | has_error_code = exception_has_error_code(intno); | |
818 | } | |
819 | if (is_int) { | |
eaa728ee | 820 | old_eip = next_eip; |
20054ef0 | 821 | } else { |
eaa728ee | 822 | old_eip = env->eip; |
20054ef0 | 823 | } |
eaa728ee FB |
824 | |
825 | dt = &env->idt; | |
20054ef0 | 826 | if (intno * 16 + 15 > dt->limit) { |
77b2bc2c | 827 | raise_exception_err(env, EXCP0D_GPF, intno * 16 + 2); |
20054ef0 | 828 | } |
eaa728ee | 829 | ptr = dt->base + intno * 16; |
329e607d BS |
830 | e1 = cpu_ldl_kernel(env, ptr); |
831 | e2 = cpu_ldl_kernel(env, ptr + 4); | |
832 | e3 = cpu_ldl_kernel(env, ptr + 8); | |
eaa728ee FB |
833 | /* check gate type */ |
834 | type = (e2 >> DESC_TYPE_SHIFT) & 0x1f; | |
20054ef0 | 835 | switch (type) { |
eaa728ee FB |
836 | case 14: /* 386 interrupt gate */ |
837 | case 15: /* 386 trap gate */ | |
838 | break; | |
839 | default: | |
77b2bc2c | 840 | raise_exception_err(env, EXCP0D_GPF, intno * 16 + 2); |
eaa728ee FB |
841 | break; |
842 | } | |
843 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
844 | cpl = env->hflags & HF_CPL_MASK; | |
1235fc06 | 845 | /* check privilege if software int */ |
20054ef0 | 846 | if (is_int && dpl < cpl) { |
77b2bc2c | 847 | raise_exception_err(env, EXCP0D_GPF, intno * 16 + 2); |
20054ef0 | 848 | } |
eaa728ee | 849 | /* check valid bit */ |
20054ef0 | 850 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 851 | raise_exception_err(env, EXCP0B_NOSEG, intno * 16 + 2); |
20054ef0 | 852 | } |
eaa728ee FB |
853 | selector = e1 >> 16; |
854 | offset = ((target_ulong)e3 << 32) | (e2 & 0xffff0000) | (e1 & 0x0000ffff); | |
855 | ist = e2 & 7; | |
20054ef0 | 856 | if ((selector & 0xfffc) == 0) { |
77b2bc2c | 857 | raise_exception_err(env, EXCP0D_GPF, 0); |
20054ef0 | 858 | } |
eaa728ee | 859 | |
2999a0b2 | 860 | if (load_segment(env, &e1, &e2, selector) != 0) { |
77b2bc2c | 861 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 BS |
862 | } |
863 | if (!(e2 & DESC_S_MASK) || !(e2 & (DESC_CS_MASK))) { | |
77b2bc2c | 864 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 865 | } |
eaa728ee | 866 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; |
20054ef0 | 867 | if (dpl > cpl) { |
77b2bc2c | 868 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 BS |
869 | } |
870 | if (!(e2 & DESC_P_MASK)) { | |
77b2bc2c | 871 | raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc); |
20054ef0 BS |
872 | } |
873 | if (!(e2 & DESC_L_MASK) || (e2 & DESC_B_MASK)) { | |
77b2bc2c | 874 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 875 | } |
eaa728ee FB |
876 | if ((!(e2 & DESC_C_MASK) && dpl < cpl) || ist != 0) { |
877 | /* to inner privilege */ | |
20054ef0 | 878 | if (ist != 0) { |
2999a0b2 | 879 | esp = get_rsp_from_tss(env, ist + 3); |
20054ef0 | 880 | } else { |
2999a0b2 | 881 | esp = get_rsp_from_tss(env, dpl); |
20054ef0 | 882 | } |
eaa728ee FB |
883 | esp &= ~0xfLL; /* align stack */ |
884 | ss = 0; | |
885 | new_stack = 1; | |
886 | } else if ((e2 & DESC_C_MASK) || dpl == cpl) { | |
887 | /* to same privilege */ | |
20054ef0 | 888 | if (env->eflags & VM_MASK) { |
77b2bc2c | 889 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 890 | } |
eaa728ee | 891 | new_stack = 0; |
20054ef0 | 892 | if (ist != 0) { |
2999a0b2 | 893 | esp = get_rsp_from_tss(env, ist + 3); |
20054ef0 | 894 | } else { |
08b3ded6 | 895 | esp = env->regs[R_ESP]; |
20054ef0 | 896 | } |
eaa728ee FB |
897 | esp &= ~0xfLL; /* align stack */ |
898 | dpl = cpl; | |
899 | } else { | |
77b2bc2c | 900 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
eaa728ee FB |
901 | new_stack = 0; /* avoid warning */ |
902 | esp = 0; /* avoid warning */ | |
903 | } | |
904 | ||
905 | PUSHQ(esp, env->segs[R_SS].selector); | |
08b3ded6 | 906 | PUSHQ(esp, env->regs[R_ESP]); |
997ff0d9 | 907 | PUSHQ(esp, cpu_compute_eflags(env)); |
eaa728ee FB |
908 | PUSHQ(esp, env->segs[R_CS].selector); |
909 | PUSHQ(esp, old_eip); | |
910 | if (has_error_code) { | |
911 | PUSHQ(esp, error_code); | |
912 | } | |
913 | ||
914 | if (new_stack) { | |
915 | ss = 0 | dpl; | |
916 | cpu_x86_load_seg_cache(env, R_SS, ss, 0, 0, 0); | |
917 | } | |
08b3ded6 | 918 | env->regs[R_ESP] = esp; |
eaa728ee FB |
919 | |
920 | selector = (selector & ~3) | dpl; | |
921 | cpu_x86_load_seg_cache(env, R_CS, selector, | |
922 | get_seg_base(e1, e2), | |
923 | get_seg_limit(e1, e2), | |
924 | e2); | |
925 | cpu_x86_set_cpl(env, dpl); | |
926 | env->eip = offset; | |
927 | ||
928 | /* interrupt gate clear IF mask */ | |
929 | if ((type & 1) == 0) { | |
930 | env->eflags &= ~IF_MASK; | |
931 | } | |
932 | env->eflags &= ~(TF_MASK | VM_MASK | RF_MASK | NT_MASK); | |
933 | } | |
934 | #endif | |
935 | ||
d9957a8b | 936 | #ifdef TARGET_X86_64 |
eaa728ee | 937 | #if defined(CONFIG_USER_ONLY) |
2999a0b2 | 938 | void helper_syscall(CPUX86State *env, int next_eip_addend) |
eaa728ee | 939 | { |
27103424 AF |
940 | CPUState *cs = CPU(x86_env_get_cpu(env)); |
941 | ||
942 | cs->exception_index = EXCP_SYSCALL; | |
eaa728ee | 943 | env->exception_next_eip = env->eip + next_eip_addend; |
5638d180 | 944 | cpu_loop_exit(cs); |
eaa728ee FB |
945 | } |
946 | #else | |
2999a0b2 | 947 | void helper_syscall(CPUX86State *env, int next_eip_addend) |
eaa728ee FB |
948 | { |
949 | int selector; | |
950 | ||
951 | if (!(env->efer & MSR_EFER_SCE)) { | |
77b2bc2c | 952 | raise_exception_err(env, EXCP06_ILLOP, 0); |
eaa728ee FB |
953 | } |
954 | selector = (env->star >> 32) & 0xffff; | |
eaa728ee FB |
955 | if (env->hflags & HF_LMA_MASK) { |
956 | int code64; | |
957 | ||
a4165610 | 958 | env->regs[R_ECX] = env->eip + next_eip_addend; |
997ff0d9 | 959 | env->regs[11] = cpu_compute_eflags(env); |
eaa728ee FB |
960 | |
961 | code64 = env->hflags & HF_CS64_MASK; | |
962 | ||
963 | cpu_x86_set_cpl(env, 0); | |
964 | cpu_x86_load_seg_cache(env, R_CS, selector & 0xfffc, | |
965 | 0, 0xffffffff, | |
966 | DESC_G_MASK | DESC_P_MASK | | |
967 | DESC_S_MASK | | |
20054ef0 BS |
968 | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK | |
969 | DESC_L_MASK); | |
eaa728ee FB |
970 | cpu_x86_load_seg_cache(env, R_SS, (selector + 8) & 0xfffc, |
971 | 0, 0xffffffff, | |
972 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
973 | DESC_S_MASK | | |
974 | DESC_W_MASK | DESC_A_MASK); | |
975 | env->eflags &= ~env->fmask; | |
997ff0d9 | 976 | cpu_load_eflags(env, env->eflags, 0); |
20054ef0 | 977 | if (code64) { |
eaa728ee | 978 | env->eip = env->lstar; |
20054ef0 | 979 | } else { |
eaa728ee | 980 | env->eip = env->cstar; |
20054ef0 | 981 | } |
d9957a8b | 982 | } else { |
a4165610 | 983 | env->regs[R_ECX] = (uint32_t)(env->eip + next_eip_addend); |
eaa728ee FB |
984 | |
985 | cpu_x86_set_cpl(env, 0); | |
986 | cpu_x86_load_seg_cache(env, R_CS, selector & 0xfffc, | |
987 | 0, 0xffffffff, | |
988 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
989 | DESC_S_MASK | | |
990 | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK); | |
991 | cpu_x86_load_seg_cache(env, R_SS, (selector + 8) & 0xfffc, | |
992 | 0, 0xffffffff, | |
993 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
994 | DESC_S_MASK | | |
995 | DESC_W_MASK | DESC_A_MASK); | |
996 | env->eflags &= ~(IF_MASK | RF_MASK | VM_MASK); | |
997 | env->eip = (uint32_t)env->star; | |
998 | } | |
999 | } | |
1000 | #endif | |
d9957a8b | 1001 | #endif |
eaa728ee | 1002 | |
d9957a8b | 1003 | #ifdef TARGET_X86_64 |
2999a0b2 | 1004 | void helper_sysret(CPUX86State *env, int dflag) |
eaa728ee FB |
1005 | { |
1006 | int cpl, selector; | |
1007 | ||
1008 | if (!(env->efer & MSR_EFER_SCE)) { | |
77b2bc2c | 1009 | raise_exception_err(env, EXCP06_ILLOP, 0); |
eaa728ee FB |
1010 | } |
1011 | cpl = env->hflags & HF_CPL_MASK; | |
1012 | if (!(env->cr[0] & CR0_PE_MASK) || cpl != 0) { | |
77b2bc2c | 1013 | raise_exception_err(env, EXCP0D_GPF, 0); |
eaa728ee FB |
1014 | } |
1015 | selector = (env->star >> 48) & 0xffff; | |
eaa728ee FB |
1016 | if (env->hflags & HF_LMA_MASK) { |
1017 | if (dflag == 2) { | |
1018 | cpu_x86_load_seg_cache(env, R_CS, (selector + 16) | 3, | |
1019 | 0, 0xffffffff, | |
1020 | DESC_G_MASK | DESC_P_MASK | | |
1021 | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | | |
1022 | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK | | |
1023 | DESC_L_MASK); | |
a4165610 | 1024 | env->eip = env->regs[R_ECX]; |
eaa728ee FB |
1025 | } else { |
1026 | cpu_x86_load_seg_cache(env, R_CS, selector | 3, | |
1027 | 0, 0xffffffff, | |
1028 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
1029 | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | | |
1030 | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK); | |
a4165610 | 1031 | env->eip = (uint32_t)env->regs[R_ECX]; |
eaa728ee FB |
1032 | } |
1033 | cpu_x86_load_seg_cache(env, R_SS, selector + 8, | |
1034 | 0, 0xffffffff, | |
1035 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
1036 | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | | |
1037 | DESC_W_MASK | DESC_A_MASK); | |
997ff0d9 BS |
1038 | cpu_load_eflags(env, (uint32_t)(env->regs[11]), TF_MASK | AC_MASK |
1039 | | ID_MASK | IF_MASK | IOPL_MASK | VM_MASK | RF_MASK | | |
1040 | NT_MASK); | |
eaa728ee | 1041 | cpu_x86_set_cpl(env, 3); |
d9957a8b | 1042 | } else { |
eaa728ee FB |
1043 | cpu_x86_load_seg_cache(env, R_CS, selector | 3, |
1044 | 0, 0xffffffff, | |
1045 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
1046 | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | | |
1047 | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK); | |
a4165610 | 1048 | env->eip = (uint32_t)env->regs[R_ECX]; |
eaa728ee FB |
1049 | cpu_x86_load_seg_cache(env, R_SS, selector + 8, |
1050 | 0, 0xffffffff, | |
1051 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
1052 | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | | |
1053 | DESC_W_MASK | DESC_A_MASK); | |
1054 | env->eflags |= IF_MASK; | |
1055 | cpu_x86_set_cpl(env, 3); | |
1056 | } | |
eaa728ee | 1057 | } |
d9957a8b | 1058 | #endif |
eaa728ee FB |
1059 | |
1060 | /* real mode interrupt */ | |
2999a0b2 BS |
1061 | static void do_interrupt_real(CPUX86State *env, int intno, int is_int, |
1062 | int error_code, unsigned int next_eip) | |
eaa728ee FB |
1063 | { |
1064 | SegmentCache *dt; | |
1065 | target_ulong ptr, ssp; | |
1066 | int selector; | |
1067 | uint32_t offset, esp; | |
1068 | uint32_t old_cs, old_eip; | |
eaa728ee | 1069 | |
20054ef0 | 1070 | /* real mode (simpler!) */ |
eaa728ee | 1071 | dt = &env->idt; |
20054ef0 | 1072 | if (intno * 4 + 3 > dt->limit) { |
77b2bc2c | 1073 | raise_exception_err(env, EXCP0D_GPF, intno * 8 + 2); |
20054ef0 | 1074 | } |
eaa728ee | 1075 | ptr = dt->base + intno * 4; |
329e607d BS |
1076 | offset = cpu_lduw_kernel(env, ptr); |
1077 | selector = cpu_lduw_kernel(env, ptr + 2); | |
08b3ded6 | 1078 | esp = env->regs[R_ESP]; |
eaa728ee | 1079 | ssp = env->segs[R_SS].base; |
20054ef0 | 1080 | if (is_int) { |
eaa728ee | 1081 | old_eip = next_eip; |
20054ef0 | 1082 | } else { |
eaa728ee | 1083 | old_eip = env->eip; |
20054ef0 | 1084 | } |
eaa728ee | 1085 | old_cs = env->segs[R_CS].selector; |
20054ef0 | 1086 | /* XXX: use SS segment size? */ |
997ff0d9 | 1087 | PUSHW(ssp, esp, 0xffff, cpu_compute_eflags(env)); |
eaa728ee FB |
1088 | PUSHW(ssp, esp, 0xffff, old_cs); |
1089 | PUSHW(ssp, esp, 0xffff, old_eip); | |
1090 | ||
1091 | /* update processor state */ | |
08b3ded6 | 1092 | env->regs[R_ESP] = (env->regs[R_ESP] & ~0xffff) | (esp & 0xffff); |
eaa728ee FB |
1093 | env->eip = offset; |
1094 | env->segs[R_CS].selector = selector; | |
1095 | env->segs[R_CS].base = (selector << 4); | |
1096 | env->eflags &= ~(IF_MASK | TF_MASK | AC_MASK | RF_MASK); | |
1097 | } | |
1098 | ||
e694d4e2 | 1099 | #if defined(CONFIG_USER_ONLY) |
eaa728ee | 1100 | /* fake user mode interrupt */ |
2999a0b2 BS |
1101 | static void do_interrupt_user(CPUX86State *env, int intno, int is_int, |
1102 | int error_code, target_ulong next_eip) | |
eaa728ee FB |
1103 | { |
1104 | SegmentCache *dt; | |
1105 | target_ulong ptr; | |
1106 | int dpl, cpl, shift; | |
1107 | uint32_t e2; | |
1108 | ||
1109 | dt = &env->idt; | |
1110 | if (env->hflags & HF_LMA_MASK) { | |
1111 | shift = 4; | |
1112 | } else { | |
1113 | shift = 3; | |
1114 | } | |
1115 | ptr = dt->base + (intno << shift); | |
329e607d | 1116 | e2 = cpu_ldl_kernel(env, ptr + 4); |
eaa728ee FB |
1117 | |
1118 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
1119 | cpl = env->hflags & HF_CPL_MASK; | |
1235fc06 | 1120 | /* check privilege if software int */ |
20054ef0 | 1121 | if (is_int && dpl < cpl) { |
77b2bc2c | 1122 | raise_exception_err(env, EXCP0D_GPF, (intno << shift) + 2); |
20054ef0 | 1123 | } |
eaa728ee FB |
1124 | |
1125 | /* Since we emulate only user space, we cannot do more than | |
1126 | exiting the emulation with the suitable exception and error | |
1127 | code */ | |
20054ef0 | 1128 | if (is_int) { |
a78d0eab | 1129 | env->eip = next_eip; |
20054ef0 | 1130 | } |
eaa728ee FB |
1131 | } |
1132 | ||
e694d4e2 BS |
1133 | #else |
1134 | ||
2999a0b2 BS |
1135 | static void handle_even_inj(CPUX86State *env, int intno, int is_int, |
1136 | int error_code, int is_hw, int rm) | |
2ed51f5b | 1137 | { |
19d6ca16 | 1138 | CPUState *cs = CPU(x86_env_get_cpu(env)); |
fdfba1a2 | 1139 | uint32_t event_inj = ldl_phys(cs->as, env->vm_vmcb + offsetof(struct vmcb, |
20054ef0 BS |
1140 | control.event_inj)); |
1141 | ||
2ed51f5b | 1142 | if (!(event_inj & SVM_EVTINJ_VALID)) { |
20054ef0 BS |
1143 | int type; |
1144 | ||
1145 | if (is_int) { | |
1146 | type = SVM_EVTINJ_TYPE_SOFT; | |
1147 | } else { | |
1148 | type = SVM_EVTINJ_TYPE_EXEPT; | |
1149 | } | |
1150 | event_inj = intno | type | SVM_EVTINJ_VALID; | |
1151 | if (!rm && exception_has_error_code(intno)) { | |
1152 | event_inj |= SVM_EVTINJ_VALID_ERR; | |
ab1da857 | 1153 | stl_phys(cs->as, env->vm_vmcb + offsetof(struct vmcb, |
20054ef0 BS |
1154 | control.event_inj_err), |
1155 | error_code); | |
1156 | } | |
ab1da857 EI |
1157 | stl_phys(cs->as, |
1158 | env->vm_vmcb + offsetof(struct vmcb, control.event_inj), | |
20054ef0 | 1159 | event_inj); |
2ed51f5b AL |
1160 | } |
1161 | } | |
00ea18d1 | 1162 | #endif |
2ed51f5b | 1163 | |
eaa728ee FB |
1164 | /* |
1165 | * Begin execution of an interruption. is_int is TRUE if coming from | |
a78d0eab | 1166 | * the int instruction. next_eip is the env->eip value AFTER the interrupt |
eaa728ee FB |
1167 | * instruction. It is only relevant if is_int is TRUE. |
1168 | */ | |
ca4c810a | 1169 | static void do_interrupt_all(X86CPU *cpu, int intno, int is_int, |
2999a0b2 | 1170 | int error_code, target_ulong next_eip, int is_hw) |
eaa728ee | 1171 | { |
ca4c810a AF |
1172 | CPUX86State *env = &cpu->env; |
1173 | ||
8fec2b8c | 1174 | if (qemu_loglevel_mask(CPU_LOG_INT)) { |
eaa728ee FB |
1175 | if ((env->cr[0] & CR0_PE_MASK)) { |
1176 | static int count; | |
20054ef0 BS |
1177 | |
1178 | qemu_log("%6d: v=%02x e=%04x i=%d cpl=%d IP=%04x:" TARGET_FMT_lx | |
1179 | " pc=" TARGET_FMT_lx " SP=%04x:" TARGET_FMT_lx, | |
1180 | count, intno, error_code, is_int, | |
1181 | env->hflags & HF_CPL_MASK, | |
a78d0eab LG |
1182 | env->segs[R_CS].selector, env->eip, |
1183 | (int)env->segs[R_CS].base + env->eip, | |
08b3ded6 | 1184 | env->segs[R_SS].selector, env->regs[R_ESP]); |
eaa728ee | 1185 | if (intno == 0x0e) { |
93fcfe39 | 1186 | qemu_log(" CR2=" TARGET_FMT_lx, env->cr[2]); |
eaa728ee | 1187 | } else { |
4b34e3ad | 1188 | qemu_log(" env->regs[R_EAX]=" TARGET_FMT_lx, env->regs[R_EAX]); |
eaa728ee | 1189 | } |
93fcfe39 | 1190 | qemu_log("\n"); |
a0762859 | 1191 | log_cpu_state(CPU(cpu), CPU_DUMP_CCOP); |
eaa728ee FB |
1192 | #if 0 |
1193 | { | |
1194 | int i; | |
9bd5494e | 1195 | target_ulong ptr; |
20054ef0 | 1196 | |
93fcfe39 | 1197 | qemu_log(" code="); |
eaa728ee | 1198 | ptr = env->segs[R_CS].base + env->eip; |
20054ef0 | 1199 | for (i = 0; i < 16; i++) { |
93fcfe39 | 1200 | qemu_log(" %02x", ldub(ptr + i)); |
eaa728ee | 1201 | } |
93fcfe39 | 1202 | qemu_log("\n"); |
eaa728ee FB |
1203 | } |
1204 | #endif | |
1205 | count++; | |
1206 | } | |
1207 | } | |
1208 | if (env->cr[0] & CR0_PE_MASK) { | |
00ea18d1 | 1209 | #if !defined(CONFIG_USER_ONLY) |
20054ef0 | 1210 | if (env->hflags & HF_SVMI_MASK) { |
2999a0b2 | 1211 | handle_even_inj(env, intno, is_int, error_code, is_hw, 0); |
20054ef0 | 1212 | } |
00ea18d1 | 1213 | #endif |
eb38c52c | 1214 | #ifdef TARGET_X86_64 |
eaa728ee | 1215 | if (env->hflags & HF_LMA_MASK) { |
2999a0b2 | 1216 | do_interrupt64(env, intno, is_int, error_code, next_eip, is_hw); |
eaa728ee FB |
1217 | } else |
1218 | #endif | |
1219 | { | |
2999a0b2 BS |
1220 | do_interrupt_protected(env, intno, is_int, error_code, next_eip, |
1221 | is_hw); | |
eaa728ee FB |
1222 | } |
1223 | } else { | |
00ea18d1 | 1224 | #if !defined(CONFIG_USER_ONLY) |
20054ef0 | 1225 | if (env->hflags & HF_SVMI_MASK) { |
2999a0b2 | 1226 | handle_even_inj(env, intno, is_int, error_code, is_hw, 1); |
20054ef0 | 1227 | } |
00ea18d1 | 1228 | #endif |
2999a0b2 | 1229 | do_interrupt_real(env, intno, is_int, error_code, next_eip); |
eaa728ee | 1230 | } |
2ed51f5b | 1231 | |
00ea18d1 | 1232 | #if !defined(CONFIG_USER_ONLY) |
2ed51f5b | 1233 | if (env->hflags & HF_SVMI_MASK) { |
fdfba1a2 EI |
1234 | CPUState *cs = CPU(cpu); |
1235 | uint32_t event_inj = ldl_phys(cs->as, env->vm_vmcb + | |
20054ef0 BS |
1236 | offsetof(struct vmcb, |
1237 | control.event_inj)); | |
1238 | ||
ab1da857 EI |
1239 | stl_phys(cs->as, |
1240 | env->vm_vmcb + offsetof(struct vmcb, control.event_inj), | |
20054ef0 | 1241 | event_inj & ~SVM_EVTINJ_VALID); |
2ed51f5b | 1242 | } |
00ea18d1 | 1243 | #endif |
eaa728ee FB |
1244 | } |
1245 | ||
97a8ea5a | 1246 | void x86_cpu_do_interrupt(CPUState *cs) |
e694d4e2 | 1247 | { |
97a8ea5a AF |
1248 | X86CPU *cpu = X86_CPU(cs); |
1249 | CPUX86State *env = &cpu->env; | |
1250 | ||
e694d4e2 BS |
1251 | #if defined(CONFIG_USER_ONLY) |
1252 | /* if user mode only, we simulate a fake exception | |
1253 | which will be handled outside the cpu execution | |
1254 | loop */ | |
27103424 | 1255 | do_interrupt_user(env, cs->exception_index, |
e694d4e2 BS |
1256 | env->exception_is_int, |
1257 | env->error_code, | |
1258 | env->exception_next_eip); | |
1259 | /* successfully delivered */ | |
1260 | env->old_exception = -1; | |
1261 | #else | |
1262 | /* simulate a real cpu exception. On i386, it can | |
1263 | trigger new exceptions, but we do not handle | |
1264 | double or triple faults yet. */ | |
27103424 | 1265 | do_interrupt_all(cpu, cs->exception_index, |
e694d4e2 BS |
1266 | env->exception_is_int, |
1267 | env->error_code, | |
1268 | env->exception_next_eip, 0); | |
1269 | /* successfully delivered */ | |
1270 | env->old_exception = -1; | |
1271 | #endif | |
e694d4e2 BS |
1272 | } |
1273 | ||
2999a0b2 | 1274 | void do_interrupt_x86_hardirq(CPUX86State *env, int intno, int is_hw) |
e694d4e2 | 1275 | { |
ca4c810a | 1276 | do_interrupt_all(x86_env_get_cpu(env), intno, 0, 0, 0, is_hw); |
e694d4e2 BS |
1277 | } |
1278 | ||
2999a0b2 BS |
1279 | void helper_enter_level(CPUX86State *env, int level, int data32, |
1280 | target_ulong t1) | |
eaa728ee FB |
1281 | { |
1282 | target_ulong ssp; | |
1283 | uint32_t esp_mask, esp, ebp; | |
1284 | ||
1285 | esp_mask = get_sp_mask(env->segs[R_SS].flags); | |
1286 | ssp = env->segs[R_SS].base; | |
c12dddd7 | 1287 | ebp = env->regs[R_EBP]; |
08b3ded6 | 1288 | esp = env->regs[R_ESP]; |
eaa728ee FB |
1289 | if (data32) { |
1290 | /* 32 bit */ | |
1291 | esp -= 4; | |
1292 | while (--level) { | |
1293 | esp -= 4; | |
1294 | ebp -= 4; | |
329e607d BS |
1295 | cpu_stl_data(env, ssp + (esp & esp_mask), |
1296 | cpu_ldl_data(env, ssp + (ebp & esp_mask))); | |
eaa728ee FB |
1297 | } |
1298 | esp -= 4; | |
329e607d | 1299 | cpu_stl_data(env, ssp + (esp & esp_mask), t1); |
eaa728ee FB |
1300 | } else { |
1301 | /* 16 bit */ | |
1302 | esp -= 2; | |
1303 | while (--level) { | |
1304 | esp -= 2; | |
1305 | ebp -= 2; | |
329e607d BS |
1306 | cpu_stw_data(env, ssp + (esp & esp_mask), |
1307 | cpu_lduw_data(env, ssp + (ebp & esp_mask))); | |
eaa728ee FB |
1308 | } |
1309 | esp -= 2; | |
329e607d | 1310 | cpu_stw_data(env, ssp + (esp & esp_mask), t1); |
eaa728ee FB |
1311 | } |
1312 | } | |
1313 | ||
1314 | #ifdef TARGET_X86_64 | |
2999a0b2 BS |
1315 | void helper_enter64_level(CPUX86State *env, int level, int data64, |
1316 | target_ulong t1) | |
eaa728ee FB |
1317 | { |
1318 | target_ulong esp, ebp; | |
20054ef0 | 1319 | |
c12dddd7 | 1320 | ebp = env->regs[R_EBP]; |
08b3ded6 | 1321 | esp = env->regs[R_ESP]; |
eaa728ee FB |
1322 | |
1323 | if (data64) { | |
1324 | /* 64 bit */ | |
1325 | esp -= 8; | |
1326 | while (--level) { | |
1327 | esp -= 8; | |
1328 | ebp -= 8; | |
329e607d | 1329 | cpu_stq_data(env, esp, cpu_ldq_data(env, ebp)); |
eaa728ee FB |
1330 | } |
1331 | esp -= 8; | |
329e607d | 1332 | cpu_stq_data(env, esp, t1); |
eaa728ee FB |
1333 | } else { |
1334 | /* 16 bit */ | |
1335 | esp -= 2; | |
1336 | while (--level) { | |
1337 | esp -= 2; | |
1338 | ebp -= 2; | |
329e607d | 1339 | cpu_stw_data(env, esp, cpu_lduw_data(env, ebp)); |
eaa728ee FB |
1340 | } |
1341 | esp -= 2; | |
329e607d | 1342 | cpu_stw_data(env, esp, t1); |
eaa728ee FB |
1343 | } |
1344 | } | |
1345 | #endif | |
1346 | ||
2999a0b2 | 1347 | void helper_lldt(CPUX86State *env, int selector) |
eaa728ee FB |
1348 | { |
1349 | SegmentCache *dt; | |
1350 | uint32_t e1, e2; | |
1351 | int index, entry_limit; | |
1352 | target_ulong ptr; | |
1353 | ||
1354 | selector &= 0xffff; | |
1355 | if ((selector & 0xfffc) == 0) { | |
1356 | /* XXX: NULL selector case: invalid LDT */ | |
1357 | env->ldt.base = 0; | |
1358 | env->ldt.limit = 0; | |
1359 | } else { | |
20054ef0 | 1360 | if (selector & 0x4) { |
77b2bc2c | 1361 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1362 | } |
eaa728ee FB |
1363 | dt = &env->gdt; |
1364 | index = selector & ~7; | |
1365 | #ifdef TARGET_X86_64 | |
20054ef0 | 1366 | if (env->hflags & HF_LMA_MASK) { |
eaa728ee | 1367 | entry_limit = 15; |
20054ef0 | 1368 | } else |
eaa728ee | 1369 | #endif |
20054ef0 | 1370 | { |
eaa728ee | 1371 | entry_limit = 7; |
20054ef0 BS |
1372 | } |
1373 | if ((index + entry_limit) > dt->limit) { | |
77b2bc2c | 1374 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1375 | } |
eaa728ee | 1376 | ptr = dt->base + index; |
329e607d BS |
1377 | e1 = cpu_ldl_kernel(env, ptr); |
1378 | e2 = cpu_ldl_kernel(env, ptr + 4); | |
20054ef0 | 1379 | if ((e2 & DESC_S_MASK) || ((e2 >> DESC_TYPE_SHIFT) & 0xf) != 2) { |
77b2bc2c | 1380 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 BS |
1381 | } |
1382 | if (!(e2 & DESC_P_MASK)) { | |
77b2bc2c | 1383 | raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc); |
20054ef0 | 1384 | } |
eaa728ee FB |
1385 | #ifdef TARGET_X86_64 |
1386 | if (env->hflags & HF_LMA_MASK) { | |
1387 | uint32_t e3; | |
20054ef0 | 1388 | |
329e607d | 1389 | e3 = cpu_ldl_kernel(env, ptr + 8); |
eaa728ee FB |
1390 | load_seg_cache_raw_dt(&env->ldt, e1, e2); |
1391 | env->ldt.base |= (target_ulong)e3 << 32; | |
1392 | } else | |
1393 | #endif | |
1394 | { | |
1395 | load_seg_cache_raw_dt(&env->ldt, e1, e2); | |
1396 | } | |
1397 | } | |
1398 | env->ldt.selector = selector; | |
1399 | } | |
1400 | ||
2999a0b2 | 1401 | void helper_ltr(CPUX86State *env, int selector) |
eaa728ee FB |
1402 | { |
1403 | SegmentCache *dt; | |
1404 | uint32_t e1, e2; | |
1405 | int index, type, entry_limit; | |
1406 | target_ulong ptr; | |
1407 | ||
1408 | selector &= 0xffff; | |
1409 | if ((selector & 0xfffc) == 0) { | |
1410 | /* NULL selector case: invalid TR */ | |
1411 | env->tr.base = 0; | |
1412 | env->tr.limit = 0; | |
1413 | env->tr.flags = 0; | |
1414 | } else { | |
20054ef0 | 1415 | if (selector & 0x4) { |
77b2bc2c | 1416 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1417 | } |
eaa728ee FB |
1418 | dt = &env->gdt; |
1419 | index = selector & ~7; | |
1420 | #ifdef TARGET_X86_64 | |
20054ef0 | 1421 | if (env->hflags & HF_LMA_MASK) { |
eaa728ee | 1422 | entry_limit = 15; |
20054ef0 | 1423 | } else |
eaa728ee | 1424 | #endif |
20054ef0 | 1425 | { |
eaa728ee | 1426 | entry_limit = 7; |
20054ef0 BS |
1427 | } |
1428 | if ((index + entry_limit) > dt->limit) { | |
77b2bc2c | 1429 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1430 | } |
eaa728ee | 1431 | ptr = dt->base + index; |
329e607d BS |
1432 | e1 = cpu_ldl_kernel(env, ptr); |
1433 | e2 = cpu_ldl_kernel(env, ptr + 4); | |
eaa728ee FB |
1434 | type = (e2 >> DESC_TYPE_SHIFT) & 0xf; |
1435 | if ((e2 & DESC_S_MASK) || | |
20054ef0 | 1436 | (type != 1 && type != 9)) { |
77b2bc2c | 1437 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 BS |
1438 | } |
1439 | if (!(e2 & DESC_P_MASK)) { | |
77b2bc2c | 1440 | raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc); |
20054ef0 | 1441 | } |
eaa728ee FB |
1442 | #ifdef TARGET_X86_64 |
1443 | if (env->hflags & HF_LMA_MASK) { | |
1444 | uint32_t e3, e4; | |
20054ef0 | 1445 | |
329e607d BS |
1446 | e3 = cpu_ldl_kernel(env, ptr + 8); |
1447 | e4 = cpu_ldl_kernel(env, ptr + 12); | |
20054ef0 | 1448 | if ((e4 >> DESC_TYPE_SHIFT) & 0xf) { |
77b2bc2c | 1449 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1450 | } |
eaa728ee FB |
1451 | load_seg_cache_raw_dt(&env->tr, e1, e2); |
1452 | env->tr.base |= (target_ulong)e3 << 32; | |
1453 | } else | |
1454 | #endif | |
1455 | { | |
1456 | load_seg_cache_raw_dt(&env->tr, e1, e2); | |
1457 | } | |
1458 | e2 |= DESC_TSS_BUSY_MASK; | |
329e607d | 1459 | cpu_stl_kernel(env, ptr + 4, e2); |
eaa728ee FB |
1460 | } |
1461 | env->tr.selector = selector; | |
1462 | } | |
1463 | ||
1464 | /* only works if protected mode and not VM86. seg_reg must be != R_CS */ | |
2999a0b2 | 1465 | void helper_load_seg(CPUX86State *env, int seg_reg, int selector) |
eaa728ee FB |
1466 | { |
1467 | uint32_t e1, e2; | |
1468 | int cpl, dpl, rpl; | |
1469 | SegmentCache *dt; | |
1470 | int index; | |
1471 | target_ulong ptr; | |
1472 | ||
1473 | selector &= 0xffff; | |
1474 | cpl = env->hflags & HF_CPL_MASK; | |
1475 | if ((selector & 0xfffc) == 0) { | |
1476 | /* null selector case */ | |
1477 | if (seg_reg == R_SS | |
1478 | #ifdef TARGET_X86_64 | |
1479 | && (!(env->hflags & HF_CS64_MASK) || cpl == 3) | |
1480 | #endif | |
20054ef0 | 1481 | ) { |
77b2bc2c | 1482 | raise_exception_err(env, EXCP0D_GPF, 0); |
20054ef0 | 1483 | } |
eaa728ee FB |
1484 | cpu_x86_load_seg_cache(env, seg_reg, selector, 0, 0, 0); |
1485 | } else { | |
1486 | ||
20054ef0 | 1487 | if (selector & 0x4) { |
eaa728ee | 1488 | dt = &env->ldt; |
20054ef0 | 1489 | } else { |
eaa728ee | 1490 | dt = &env->gdt; |
20054ef0 | 1491 | } |
eaa728ee | 1492 | index = selector & ~7; |
20054ef0 | 1493 | if ((index + 7) > dt->limit) { |
77b2bc2c | 1494 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1495 | } |
eaa728ee | 1496 | ptr = dt->base + index; |
329e607d BS |
1497 | e1 = cpu_ldl_kernel(env, ptr); |
1498 | e2 = cpu_ldl_kernel(env, ptr + 4); | |
eaa728ee | 1499 | |
20054ef0 | 1500 | if (!(e2 & DESC_S_MASK)) { |
77b2bc2c | 1501 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1502 | } |
eaa728ee FB |
1503 | rpl = selector & 3; |
1504 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
1505 | if (seg_reg == R_SS) { | |
1506 | /* must be writable segment */ | |
20054ef0 | 1507 | if ((e2 & DESC_CS_MASK) || !(e2 & DESC_W_MASK)) { |
77b2bc2c | 1508 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 BS |
1509 | } |
1510 | if (rpl != cpl || dpl != cpl) { | |
77b2bc2c | 1511 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1512 | } |
eaa728ee FB |
1513 | } else { |
1514 | /* must be readable segment */ | |
20054ef0 | 1515 | if ((e2 & (DESC_CS_MASK | DESC_R_MASK)) == DESC_CS_MASK) { |
77b2bc2c | 1516 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1517 | } |
eaa728ee FB |
1518 | |
1519 | if (!(e2 & DESC_CS_MASK) || !(e2 & DESC_C_MASK)) { | |
1520 | /* if not conforming code, test rights */ | |
20054ef0 | 1521 | if (dpl < cpl || dpl < rpl) { |
77b2bc2c | 1522 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1523 | } |
eaa728ee FB |
1524 | } |
1525 | } | |
1526 | ||
1527 | if (!(e2 & DESC_P_MASK)) { | |
20054ef0 | 1528 | if (seg_reg == R_SS) { |
77b2bc2c | 1529 | raise_exception_err(env, EXCP0C_STACK, selector & 0xfffc); |
20054ef0 | 1530 | } else { |
77b2bc2c | 1531 | raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc); |
20054ef0 | 1532 | } |
eaa728ee FB |
1533 | } |
1534 | ||
1535 | /* set the access bit if not already set */ | |
1536 | if (!(e2 & DESC_A_MASK)) { | |
1537 | e2 |= DESC_A_MASK; | |
329e607d | 1538 | cpu_stl_kernel(env, ptr + 4, e2); |
eaa728ee FB |
1539 | } |
1540 | ||
1541 | cpu_x86_load_seg_cache(env, seg_reg, selector, | |
1542 | get_seg_base(e1, e2), | |
1543 | get_seg_limit(e1, e2), | |
1544 | e2); | |
1545 | #if 0 | |
93fcfe39 | 1546 | qemu_log("load_seg: sel=0x%04x base=0x%08lx limit=0x%08lx flags=%08x\n", |
eaa728ee FB |
1547 | selector, (unsigned long)sc->base, sc->limit, sc->flags); |
1548 | #endif | |
1549 | } | |
1550 | } | |
1551 | ||
1552 | /* protected mode jump */ | |
2999a0b2 | 1553 | void helper_ljmp_protected(CPUX86State *env, int new_cs, target_ulong new_eip, |
eaa728ee FB |
1554 | int next_eip_addend) |
1555 | { | |
1556 | int gate_cs, type; | |
1557 | uint32_t e1, e2, cpl, dpl, rpl, limit; | |
1558 | target_ulong next_eip; | |
1559 | ||
20054ef0 | 1560 | if ((new_cs & 0xfffc) == 0) { |
77b2bc2c | 1561 | raise_exception_err(env, EXCP0D_GPF, 0); |
20054ef0 | 1562 | } |
2999a0b2 | 1563 | if (load_segment(env, &e1, &e2, new_cs) != 0) { |
77b2bc2c | 1564 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1565 | } |
eaa728ee FB |
1566 | cpl = env->hflags & HF_CPL_MASK; |
1567 | if (e2 & DESC_S_MASK) { | |
20054ef0 | 1568 | if (!(e2 & DESC_CS_MASK)) { |
77b2bc2c | 1569 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1570 | } |
eaa728ee FB |
1571 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; |
1572 | if (e2 & DESC_C_MASK) { | |
1573 | /* conforming code segment */ | |
20054ef0 | 1574 | if (dpl > cpl) { |
77b2bc2c | 1575 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1576 | } |
eaa728ee FB |
1577 | } else { |
1578 | /* non conforming code segment */ | |
1579 | rpl = new_cs & 3; | |
20054ef0 | 1580 | if (rpl > cpl) { |
77b2bc2c | 1581 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 BS |
1582 | } |
1583 | if (dpl != cpl) { | |
77b2bc2c | 1584 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1585 | } |
eaa728ee | 1586 | } |
20054ef0 | 1587 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 1588 | raise_exception_err(env, EXCP0B_NOSEG, new_cs & 0xfffc); |
20054ef0 | 1589 | } |
eaa728ee FB |
1590 | limit = get_seg_limit(e1, e2); |
1591 | if (new_eip > limit && | |
20054ef0 | 1592 | !(env->hflags & HF_LMA_MASK) && !(e2 & DESC_L_MASK)) { |
77b2bc2c | 1593 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1594 | } |
eaa728ee FB |
1595 | cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl, |
1596 | get_seg_base(e1, e2), limit, e2); | |
a78d0eab | 1597 | env->eip = new_eip; |
eaa728ee FB |
1598 | } else { |
1599 | /* jump to call or task gate */ | |
1600 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
1601 | rpl = new_cs & 3; | |
1602 | cpl = env->hflags & HF_CPL_MASK; | |
1603 | type = (e2 >> DESC_TYPE_SHIFT) & 0xf; | |
20054ef0 | 1604 | switch (type) { |
eaa728ee FB |
1605 | case 1: /* 286 TSS */ |
1606 | case 9: /* 386 TSS */ | |
1607 | case 5: /* task gate */ | |
20054ef0 | 1608 | if (dpl < cpl || dpl < rpl) { |
77b2bc2c | 1609 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1610 | } |
eaa728ee | 1611 | next_eip = env->eip + next_eip_addend; |
2999a0b2 | 1612 | switch_tss(env, new_cs, e1, e2, SWITCH_TSS_JMP, next_eip); |
eaa728ee FB |
1613 | CC_OP = CC_OP_EFLAGS; |
1614 | break; | |
1615 | case 4: /* 286 call gate */ | |
1616 | case 12: /* 386 call gate */ | |
20054ef0 | 1617 | if ((dpl < cpl) || (dpl < rpl)) { |
77b2bc2c | 1618 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 BS |
1619 | } |
1620 | if (!(e2 & DESC_P_MASK)) { | |
77b2bc2c | 1621 | raise_exception_err(env, EXCP0B_NOSEG, new_cs & 0xfffc); |
20054ef0 | 1622 | } |
eaa728ee FB |
1623 | gate_cs = e1 >> 16; |
1624 | new_eip = (e1 & 0xffff); | |
20054ef0 | 1625 | if (type == 12) { |
eaa728ee | 1626 | new_eip |= (e2 & 0xffff0000); |
20054ef0 | 1627 | } |
2999a0b2 | 1628 | if (load_segment(env, &e1, &e2, gate_cs) != 0) { |
77b2bc2c | 1629 | raise_exception_err(env, EXCP0D_GPF, gate_cs & 0xfffc); |
20054ef0 | 1630 | } |
eaa728ee FB |
1631 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; |
1632 | /* must be code segment */ | |
1633 | if (((e2 & (DESC_S_MASK | DESC_CS_MASK)) != | |
20054ef0 | 1634 | (DESC_S_MASK | DESC_CS_MASK))) { |
77b2bc2c | 1635 | raise_exception_err(env, EXCP0D_GPF, gate_cs & 0xfffc); |
20054ef0 | 1636 | } |
eaa728ee | 1637 | if (((e2 & DESC_C_MASK) && (dpl > cpl)) || |
20054ef0 | 1638 | (!(e2 & DESC_C_MASK) && (dpl != cpl))) { |
77b2bc2c | 1639 | raise_exception_err(env, EXCP0D_GPF, gate_cs & 0xfffc); |
20054ef0 BS |
1640 | } |
1641 | if (!(e2 & DESC_P_MASK)) { | |
77b2bc2c | 1642 | raise_exception_err(env, EXCP0D_GPF, gate_cs & 0xfffc); |
20054ef0 | 1643 | } |
eaa728ee | 1644 | limit = get_seg_limit(e1, e2); |
20054ef0 | 1645 | if (new_eip > limit) { |
77b2bc2c | 1646 | raise_exception_err(env, EXCP0D_GPF, 0); |
20054ef0 | 1647 | } |
eaa728ee FB |
1648 | cpu_x86_load_seg_cache(env, R_CS, (gate_cs & 0xfffc) | cpl, |
1649 | get_seg_base(e1, e2), limit, e2); | |
a78d0eab | 1650 | env->eip = new_eip; |
eaa728ee FB |
1651 | break; |
1652 | default: | |
77b2bc2c | 1653 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
eaa728ee FB |
1654 | break; |
1655 | } | |
1656 | } | |
1657 | } | |
1658 | ||
1659 | /* real mode call */ | |
2999a0b2 | 1660 | void helper_lcall_real(CPUX86State *env, int new_cs, target_ulong new_eip1, |
eaa728ee FB |
1661 | int shift, int next_eip) |
1662 | { | |
1663 | int new_eip; | |
1664 | uint32_t esp, esp_mask; | |
1665 | target_ulong ssp; | |
1666 | ||
1667 | new_eip = new_eip1; | |
08b3ded6 | 1668 | esp = env->regs[R_ESP]; |
eaa728ee FB |
1669 | esp_mask = get_sp_mask(env->segs[R_SS].flags); |
1670 | ssp = env->segs[R_SS].base; | |
1671 | if (shift) { | |
1672 | PUSHL(ssp, esp, esp_mask, env->segs[R_CS].selector); | |
1673 | PUSHL(ssp, esp, esp_mask, next_eip); | |
1674 | } else { | |
1675 | PUSHW(ssp, esp, esp_mask, env->segs[R_CS].selector); | |
1676 | PUSHW(ssp, esp, esp_mask, next_eip); | |
1677 | } | |
1678 | ||
1679 | SET_ESP(esp, esp_mask); | |
1680 | env->eip = new_eip; | |
1681 | env->segs[R_CS].selector = new_cs; | |
1682 | env->segs[R_CS].base = (new_cs << 4); | |
1683 | } | |
1684 | ||
1685 | /* protected mode call */ | |
2999a0b2 | 1686 | void helper_lcall_protected(CPUX86State *env, int new_cs, target_ulong new_eip, |
eaa728ee FB |
1687 | int shift, int next_eip_addend) |
1688 | { | |
1689 | int new_stack, i; | |
1690 | uint32_t e1, e2, cpl, dpl, rpl, selector, offset, param_count; | |
1c918eba | 1691 | uint32_t ss = 0, ss_e1 = 0, ss_e2 = 0, sp, type, ss_dpl, sp_mask; |
eaa728ee FB |
1692 | uint32_t val, limit, old_sp_mask; |
1693 | target_ulong ssp, old_ssp, next_eip; | |
1694 | ||
1695 | next_eip = env->eip + next_eip_addend; | |
d12d51d5 | 1696 | LOG_PCALL("lcall %04x:%08x s=%d\n", new_cs, (uint32_t)new_eip, shift); |
8995b7a0 | 1697 | LOG_PCALL_STATE(CPU(x86_env_get_cpu(env))); |
20054ef0 | 1698 | if ((new_cs & 0xfffc) == 0) { |
77b2bc2c | 1699 | raise_exception_err(env, EXCP0D_GPF, 0); |
20054ef0 | 1700 | } |
2999a0b2 | 1701 | if (load_segment(env, &e1, &e2, new_cs) != 0) { |
77b2bc2c | 1702 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1703 | } |
eaa728ee | 1704 | cpl = env->hflags & HF_CPL_MASK; |
d12d51d5 | 1705 | LOG_PCALL("desc=%08x:%08x\n", e1, e2); |
eaa728ee | 1706 | if (e2 & DESC_S_MASK) { |
20054ef0 | 1707 | if (!(e2 & DESC_CS_MASK)) { |
77b2bc2c | 1708 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1709 | } |
eaa728ee FB |
1710 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; |
1711 | if (e2 & DESC_C_MASK) { | |
1712 | /* conforming code segment */ | |
20054ef0 | 1713 | if (dpl > cpl) { |
77b2bc2c | 1714 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1715 | } |
eaa728ee FB |
1716 | } else { |
1717 | /* non conforming code segment */ | |
1718 | rpl = new_cs & 3; | |
20054ef0 | 1719 | if (rpl > cpl) { |
77b2bc2c | 1720 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 BS |
1721 | } |
1722 | if (dpl != cpl) { | |
77b2bc2c | 1723 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1724 | } |
eaa728ee | 1725 | } |
20054ef0 | 1726 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 1727 | raise_exception_err(env, EXCP0B_NOSEG, new_cs & 0xfffc); |
20054ef0 | 1728 | } |
eaa728ee FB |
1729 | |
1730 | #ifdef TARGET_X86_64 | |
1731 | /* XXX: check 16/32 bit cases in long mode */ | |
1732 | if (shift == 2) { | |
1733 | target_ulong rsp; | |
20054ef0 | 1734 | |
eaa728ee | 1735 | /* 64 bit case */ |
08b3ded6 | 1736 | rsp = env->regs[R_ESP]; |
eaa728ee FB |
1737 | PUSHQ(rsp, env->segs[R_CS].selector); |
1738 | PUSHQ(rsp, next_eip); | |
1739 | /* from this point, not restartable */ | |
08b3ded6 | 1740 | env->regs[R_ESP] = rsp; |
eaa728ee FB |
1741 | cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl, |
1742 | get_seg_base(e1, e2), | |
1743 | get_seg_limit(e1, e2), e2); | |
a78d0eab | 1744 | env->eip = new_eip; |
eaa728ee FB |
1745 | } else |
1746 | #endif | |
1747 | { | |
08b3ded6 | 1748 | sp = env->regs[R_ESP]; |
eaa728ee FB |
1749 | sp_mask = get_sp_mask(env->segs[R_SS].flags); |
1750 | ssp = env->segs[R_SS].base; | |
1751 | if (shift) { | |
1752 | PUSHL(ssp, sp, sp_mask, env->segs[R_CS].selector); | |
1753 | PUSHL(ssp, sp, sp_mask, next_eip); | |
1754 | } else { | |
1755 | PUSHW(ssp, sp, sp_mask, env->segs[R_CS].selector); | |
1756 | PUSHW(ssp, sp, sp_mask, next_eip); | |
1757 | } | |
1758 | ||
1759 | limit = get_seg_limit(e1, e2); | |
20054ef0 | 1760 | if (new_eip > limit) { |
77b2bc2c | 1761 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1762 | } |
eaa728ee FB |
1763 | /* from this point, not restartable */ |
1764 | SET_ESP(sp, sp_mask); | |
1765 | cpu_x86_load_seg_cache(env, R_CS, (new_cs & 0xfffc) | cpl, | |
1766 | get_seg_base(e1, e2), limit, e2); | |
a78d0eab | 1767 | env->eip = new_eip; |
eaa728ee FB |
1768 | } |
1769 | } else { | |
1770 | /* check gate type */ | |
1771 | type = (e2 >> DESC_TYPE_SHIFT) & 0x1f; | |
1772 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
1773 | rpl = new_cs & 3; | |
20054ef0 | 1774 | switch (type) { |
eaa728ee FB |
1775 | case 1: /* available 286 TSS */ |
1776 | case 9: /* available 386 TSS */ | |
1777 | case 5: /* task gate */ | |
20054ef0 | 1778 | if (dpl < cpl || dpl < rpl) { |
77b2bc2c | 1779 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1780 | } |
2999a0b2 | 1781 | switch_tss(env, new_cs, e1, e2, SWITCH_TSS_CALL, next_eip); |
eaa728ee FB |
1782 | CC_OP = CC_OP_EFLAGS; |
1783 | return; | |
1784 | case 4: /* 286 call gate */ | |
1785 | case 12: /* 386 call gate */ | |
1786 | break; | |
1787 | default: | |
77b2bc2c | 1788 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
eaa728ee FB |
1789 | break; |
1790 | } | |
1791 | shift = type >> 3; | |
1792 | ||
20054ef0 | 1793 | if (dpl < cpl || dpl < rpl) { |
77b2bc2c | 1794 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 1795 | } |
eaa728ee | 1796 | /* check valid bit */ |
20054ef0 | 1797 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 1798 | raise_exception_err(env, EXCP0B_NOSEG, new_cs & 0xfffc); |
20054ef0 | 1799 | } |
eaa728ee FB |
1800 | selector = e1 >> 16; |
1801 | offset = (e2 & 0xffff0000) | (e1 & 0x0000ffff); | |
1802 | param_count = e2 & 0x1f; | |
20054ef0 | 1803 | if ((selector & 0xfffc) == 0) { |
77b2bc2c | 1804 | raise_exception_err(env, EXCP0D_GPF, 0); |
20054ef0 | 1805 | } |
eaa728ee | 1806 | |
2999a0b2 | 1807 | if (load_segment(env, &e1, &e2, selector) != 0) { |
77b2bc2c | 1808 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 BS |
1809 | } |
1810 | if (!(e2 & DESC_S_MASK) || !(e2 & (DESC_CS_MASK))) { | |
77b2bc2c | 1811 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 | 1812 | } |
eaa728ee | 1813 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; |
20054ef0 | 1814 | if (dpl > cpl) { |
77b2bc2c | 1815 | raise_exception_err(env, EXCP0D_GPF, selector & 0xfffc); |
20054ef0 BS |
1816 | } |
1817 | if (!(e2 & DESC_P_MASK)) { | |
77b2bc2c | 1818 | raise_exception_err(env, EXCP0B_NOSEG, selector & 0xfffc); |
20054ef0 | 1819 | } |
eaa728ee FB |
1820 | |
1821 | if (!(e2 & DESC_C_MASK) && dpl < cpl) { | |
1822 | /* to inner privilege */ | |
2999a0b2 | 1823 | get_ss_esp_from_tss(env, &ss, &sp, dpl); |
90a2541b LG |
1824 | LOG_PCALL("new ss:esp=%04x:%08x param_count=%d env->regs[R_ESP]=" |
1825 | TARGET_FMT_lx "\n", ss, sp, param_count, | |
1826 | env->regs[R_ESP]); | |
20054ef0 | 1827 | if ((ss & 0xfffc) == 0) { |
77b2bc2c | 1828 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 BS |
1829 | } |
1830 | if ((ss & 3) != dpl) { | |
77b2bc2c | 1831 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 | 1832 | } |
2999a0b2 | 1833 | if (load_segment(env, &ss_e1, &ss_e2, ss) != 0) { |
77b2bc2c | 1834 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 | 1835 | } |
eaa728ee | 1836 | ss_dpl = (ss_e2 >> DESC_DPL_SHIFT) & 3; |
20054ef0 | 1837 | if (ss_dpl != dpl) { |
77b2bc2c | 1838 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 | 1839 | } |
eaa728ee FB |
1840 | if (!(ss_e2 & DESC_S_MASK) || |
1841 | (ss_e2 & DESC_CS_MASK) || | |
20054ef0 | 1842 | !(ss_e2 & DESC_W_MASK)) { |
77b2bc2c | 1843 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 BS |
1844 | } |
1845 | if (!(ss_e2 & DESC_P_MASK)) { | |
77b2bc2c | 1846 | raise_exception_err(env, EXCP0A_TSS, ss & 0xfffc); |
20054ef0 | 1847 | } |
eaa728ee | 1848 | |
20054ef0 | 1849 | /* push_size = ((param_count * 2) + 8) << shift; */ |
eaa728ee FB |
1850 | |
1851 | old_sp_mask = get_sp_mask(env->segs[R_SS].flags); | |
1852 | old_ssp = env->segs[R_SS].base; | |
1853 | ||
1854 | sp_mask = get_sp_mask(ss_e2); | |
1855 | ssp = get_seg_base(ss_e1, ss_e2); | |
1856 | if (shift) { | |
1857 | PUSHL(ssp, sp, sp_mask, env->segs[R_SS].selector); | |
08b3ded6 | 1858 | PUSHL(ssp, sp, sp_mask, env->regs[R_ESP]); |
20054ef0 | 1859 | for (i = param_count - 1; i >= 0; i--) { |
90a2541b LG |
1860 | val = cpu_ldl_kernel(env, old_ssp + |
1861 | ((env->regs[R_ESP] + i * 4) & | |
1862 | old_sp_mask)); | |
eaa728ee FB |
1863 | PUSHL(ssp, sp, sp_mask, val); |
1864 | } | |
1865 | } else { | |
1866 | PUSHW(ssp, sp, sp_mask, env->segs[R_SS].selector); | |
08b3ded6 | 1867 | PUSHW(ssp, sp, sp_mask, env->regs[R_ESP]); |
20054ef0 | 1868 | for (i = param_count - 1; i >= 0; i--) { |
90a2541b LG |
1869 | val = cpu_lduw_kernel(env, old_ssp + |
1870 | ((env->regs[R_ESP] + i * 2) & | |
1871 | old_sp_mask)); | |
eaa728ee FB |
1872 | PUSHW(ssp, sp, sp_mask, val); |
1873 | } | |
1874 | } | |
1875 | new_stack = 1; | |
1876 | } else { | |
1877 | /* to same privilege */ | |
08b3ded6 | 1878 | sp = env->regs[R_ESP]; |
eaa728ee FB |
1879 | sp_mask = get_sp_mask(env->segs[R_SS].flags); |
1880 | ssp = env->segs[R_SS].base; | |
20054ef0 | 1881 | /* push_size = (4 << shift); */ |
eaa728ee FB |
1882 | new_stack = 0; |
1883 | } | |
1884 | ||
1885 | if (shift) { | |
1886 | PUSHL(ssp, sp, sp_mask, env->segs[R_CS].selector); | |
1887 | PUSHL(ssp, sp, sp_mask, next_eip); | |
1888 | } else { | |
1889 | PUSHW(ssp, sp, sp_mask, env->segs[R_CS].selector); | |
1890 | PUSHW(ssp, sp, sp_mask, next_eip); | |
1891 | } | |
1892 | ||
1893 | /* from this point, not restartable */ | |
1894 | ||
1895 | if (new_stack) { | |
1896 | ss = (ss & ~3) | dpl; | |
1897 | cpu_x86_load_seg_cache(env, R_SS, ss, | |
1898 | ssp, | |
1899 | get_seg_limit(ss_e1, ss_e2), | |
1900 | ss_e2); | |
1901 | } | |
1902 | ||
1903 | selector = (selector & ~3) | dpl; | |
1904 | cpu_x86_load_seg_cache(env, R_CS, selector, | |
1905 | get_seg_base(e1, e2), | |
1906 | get_seg_limit(e1, e2), | |
1907 | e2); | |
1908 | cpu_x86_set_cpl(env, dpl); | |
1909 | SET_ESP(sp, sp_mask); | |
a78d0eab | 1910 | env->eip = offset; |
eaa728ee | 1911 | } |
eaa728ee FB |
1912 | } |
1913 | ||
1914 | /* real and vm86 mode iret */ | |
2999a0b2 | 1915 | void helper_iret_real(CPUX86State *env, int shift) |
eaa728ee FB |
1916 | { |
1917 | uint32_t sp, new_cs, new_eip, new_eflags, sp_mask; | |
1918 | target_ulong ssp; | |
1919 | int eflags_mask; | |
1920 | ||
20054ef0 | 1921 | sp_mask = 0xffff; /* XXXX: use SS segment size? */ |
08b3ded6 | 1922 | sp = env->regs[R_ESP]; |
eaa728ee FB |
1923 | ssp = env->segs[R_SS].base; |
1924 | if (shift == 1) { | |
1925 | /* 32 bits */ | |
1926 | POPL(ssp, sp, sp_mask, new_eip); | |
1927 | POPL(ssp, sp, sp_mask, new_cs); | |
1928 | new_cs &= 0xffff; | |
1929 | POPL(ssp, sp, sp_mask, new_eflags); | |
1930 | } else { | |
1931 | /* 16 bits */ | |
1932 | POPW(ssp, sp, sp_mask, new_eip); | |
1933 | POPW(ssp, sp, sp_mask, new_cs); | |
1934 | POPW(ssp, sp, sp_mask, new_eflags); | |
1935 | } | |
08b3ded6 | 1936 | env->regs[R_ESP] = (env->regs[R_ESP] & ~sp_mask) | (sp & sp_mask); |
bdadc0b5 | 1937 | env->segs[R_CS].selector = new_cs; |
1938 | env->segs[R_CS].base = (new_cs << 4); | |
eaa728ee | 1939 | env->eip = new_eip; |
20054ef0 BS |
1940 | if (env->eflags & VM_MASK) { |
1941 | eflags_mask = TF_MASK | AC_MASK | ID_MASK | IF_MASK | RF_MASK | | |
1942 | NT_MASK; | |
1943 | } else { | |
1944 | eflags_mask = TF_MASK | AC_MASK | ID_MASK | IF_MASK | IOPL_MASK | | |
1945 | RF_MASK | NT_MASK; | |
1946 | } | |
1947 | if (shift == 0) { | |
eaa728ee | 1948 | eflags_mask &= 0xffff; |
20054ef0 | 1949 | } |
997ff0d9 | 1950 | cpu_load_eflags(env, new_eflags, eflags_mask); |
db620f46 | 1951 | env->hflags2 &= ~HF2_NMI_MASK; |
eaa728ee FB |
1952 | } |
1953 | ||
2999a0b2 | 1954 | static inline void validate_seg(CPUX86State *env, int seg_reg, int cpl) |
eaa728ee FB |
1955 | { |
1956 | int dpl; | |
1957 | uint32_t e2; | |
1958 | ||
1959 | /* XXX: on x86_64, we do not want to nullify FS and GS because | |
1960 | they may still contain a valid base. I would be interested to | |
1961 | know how a real x86_64 CPU behaves */ | |
1962 | if ((seg_reg == R_FS || seg_reg == R_GS) && | |
20054ef0 | 1963 | (env->segs[seg_reg].selector & 0xfffc) == 0) { |
eaa728ee | 1964 | return; |
20054ef0 | 1965 | } |
eaa728ee FB |
1966 | |
1967 | e2 = env->segs[seg_reg].flags; | |
1968 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
1969 | if (!(e2 & DESC_CS_MASK) || !(e2 & DESC_C_MASK)) { | |
1970 | /* data or non conforming code segment */ | |
1971 | if (dpl < cpl) { | |
1972 | cpu_x86_load_seg_cache(env, seg_reg, 0, 0, 0, 0); | |
1973 | } | |
1974 | } | |
1975 | } | |
1976 | ||
1977 | /* protected mode iret */ | |
2999a0b2 BS |
1978 | static inline void helper_ret_protected(CPUX86State *env, int shift, |
1979 | int is_iret, int addend) | |
eaa728ee FB |
1980 | { |
1981 | uint32_t new_cs, new_eflags, new_ss; | |
1982 | uint32_t new_es, new_ds, new_fs, new_gs; | |
1983 | uint32_t e1, e2, ss_e1, ss_e2; | |
1984 | int cpl, dpl, rpl, eflags_mask, iopl; | |
1985 | target_ulong ssp, sp, new_eip, new_esp, sp_mask; | |
1986 | ||
1987 | #ifdef TARGET_X86_64 | |
20054ef0 | 1988 | if (shift == 2) { |
eaa728ee | 1989 | sp_mask = -1; |
20054ef0 | 1990 | } else |
eaa728ee | 1991 | #endif |
20054ef0 | 1992 | { |
eaa728ee | 1993 | sp_mask = get_sp_mask(env->segs[R_SS].flags); |
20054ef0 | 1994 | } |
08b3ded6 | 1995 | sp = env->regs[R_ESP]; |
eaa728ee FB |
1996 | ssp = env->segs[R_SS].base; |
1997 | new_eflags = 0; /* avoid warning */ | |
1998 | #ifdef TARGET_X86_64 | |
1999 | if (shift == 2) { | |
2000 | POPQ(sp, new_eip); | |
2001 | POPQ(sp, new_cs); | |
2002 | new_cs &= 0xffff; | |
2003 | if (is_iret) { | |
2004 | POPQ(sp, new_eflags); | |
2005 | } | |
2006 | } else | |
2007 | #endif | |
20054ef0 BS |
2008 | { |
2009 | if (shift == 1) { | |
2010 | /* 32 bits */ | |
2011 | POPL(ssp, sp, sp_mask, new_eip); | |
2012 | POPL(ssp, sp, sp_mask, new_cs); | |
2013 | new_cs &= 0xffff; | |
2014 | if (is_iret) { | |
2015 | POPL(ssp, sp, sp_mask, new_eflags); | |
2016 | if (new_eflags & VM_MASK) { | |
2017 | goto return_to_vm86; | |
2018 | } | |
2019 | } | |
2020 | } else { | |
2021 | /* 16 bits */ | |
2022 | POPW(ssp, sp, sp_mask, new_eip); | |
2023 | POPW(ssp, sp, sp_mask, new_cs); | |
2024 | if (is_iret) { | |
2025 | POPW(ssp, sp, sp_mask, new_eflags); | |
2026 | } | |
eaa728ee | 2027 | } |
eaa728ee | 2028 | } |
d12d51d5 AL |
2029 | LOG_PCALL("lret new %04x:" TARGET_FMT_lx " s=%d addend=0x%x\n", |
2030 | new_cs, new_eip, shift, addend); | |
8995b7a0 | 2031 | LOG_PCALL_STATE(CPU(x86_env_get_cpu(env))); |
20054ef0 | 2032 | if ((new_cs & 0xfffc) == 0) { |
77b2bc2c | 2033 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 2034 | } |
2999a0b2 | 2035 | if (load_segment(env, &e1, &e2, new_cs) != 0) { |
77b2bc2c | 2036 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 2037 | } |
eaa728ee | 2038 | if (!(e2 & DESC_S_MASK) || |
20054ef0 | 2039 | !(e2 & DESC_CS_MASK)) { |
77b2bc2c | 2040 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 2041 | } |
eaa728ee FB |
2042 | cpl = env->hflags & HF_CPL_MASK; |
2043 | rpl = new_cs & 3; | |
20054ef0 | 2044 | if (rpl < cpl) { |
77b2bc2c | 2045 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 2046 | } |
eaa728ee FB |
2047 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; |
2048 | if (e2 & DESC_C_MASK) { | |
20054ef0 | 2049 | if (dpl > rpl) { |
77b2bc2c | 2050 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 2051 | } |
eaa728ee | 2052 | } else { |
20054ef0 | 2053 | if (dpl != rpl) { |
77b2bc2c | 2054 | raise_exception_err(env, EXCP0D_GPF, new_cs & 0xfffc); |
20054ef0 | 2055 | } |
eaa728ee | 2056 | } |
20054ef0 | 2057 | if (!(e2 & DESC_P_MASK)) { |
77b2bc2c | 2058 | raise_exception_err(env, EXCP0B_NOSEG, new_cs & 0xfffc); |
20054ef0 | 2059 | } |
eaa728ee FB |
2060 | |
2061 | sp += addend; | |
2062 | if (rpl == cpl && (!(env->hflags & HF_CS64_MASK) || | |
2063 | ((env->hflags & HF_CS64_MASK) && !is_iret))) { | |
1235fc06 | 2064 | /* return to same privilege level */ |
eaa728ee FB |
2065 | cpu_x86_load_seg_cache(env, R_CS, new_cs, |
2066 | get_seg_base(e1, e2), | |
2067 | get_seg_limit(e1, e2), | |
2068 | e2); | |
2069 | } else { | |
2070 | /* return to different privilege level */ | |
2071 | #ifdef TARGET_X86_64 | |
2072 | if (shift == 2) { | |
2073 | POPQ(sp, new_esp); | |
2074 | POPQ(sp, new_ss); | |
2075 | new_ss &= 0xffff; | |
2076 | } else | |
2077 | #endif | |
20054ef0 BS |
2078 | { |
2079 | if (shift == 1) { | |
2080 | /* 32 bits */ | |
2081 | POPL(ssp, sp, sp_mask, new_esp); | |
2082 | POPL(ssp, sp, sp_mask, new_ss); | |
2083 | new_ss &= 0xffff; | |
2084 | } else { | |
2085 | /* 16 bits */ | |
2086 | POPW(ssp, sp, sp_mask, new_esp); | |
2087 | POPW(ssp, sp, sp_mask, new_ss); | |
2088 | } | |
eaa728ee | 2089 | } |
d12d51d5 | 2090 | LOG_PCALL("new ss:esp=%04x:" TARGET_FMT_lx "\n", |
20054ef0 | 2091 | new_ss, new_esp); |
eaa728ee FB |
2092 | if ((new_ss & 0xfffc) == 0) { |
2093 | #ifdef TARGET_X86_64 | |
20054ef0 BS |
2094 | /* NULL ss is allowed in long mode if cpl != 3 */ |
2095 | /* XXX: test CS64? */ | |
eaa728ee FB |
2096 | if ((env->hflags & HF_LMA_MASK) && rpl != 3) { |
2097 | cpu_x86_load_seg_cache(env, R_SS, new_ss, | |
2098 | 0, 0xffffffff, | |
2099 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
2100 | DESC_S_MASK | (rpl << DESC_DPL_SHIFT) | | |
2101 | DESC_W_MASK | DESC_A_MASK); | |
20054ef0 | 2102 | ss_e2 = DESC_B_MASK; /* XXX: should not be needed? */ |
eaa728ee FB |
2103 | } else |
2104 | #endif | |
2105 | { | |
77b2bc2c | 2106 | raise_exception_err(env, EXCP0D_GPF, 0); |
eaa728ee FB |
2107 | } |
2108 | } else { | |
20054ef0 | 2109 | if ((new_ss & 3) != rpl) { |
77b2bc2c | 2110 | raise_exception_err(env, EXCP0D_GPF, new_ss & 0xfffc); |
20054ef0 | 2111 | } |
2999a0b2 | 2112 | if (load_segment(env, &ss_e1, &ss_e2, new_ss) != 0) { |
77b2bc2c | 2113 | raise_exception_err(env, EXCP0D_GPF, new_ss & 0xfffc); |
20054ef0 | 2114 | } |
eaa728ee FB |
2115 | if (!(ss_e2 & DESC_S_MASK) || |
2116 | (ss_e2 & DESC_CS_MASK) || | |
20054ef0 | 2117 | !(ss_e2 & DESC_W_MASK)) { |
77b2bc2c | 2118 | raise_exception_err(env, EXCP0D_GPF, new_ss & 0xfffc); |
20054ef0 | 2119 | } |
eaa728ee | 2120 | dpl = (ss_e2 >> DESC_DPL_SHIFT) & 3; |
20054ef0 | 2121 | if (dpl != rpl) { |
77b2bc2c | 2122 | raise_exception_err(env, EXCP0D_GPF, new_ss & 0xfffc); |
20054ef0 BS |
2123 | } |
2124 | if (!(ss_e2 & DESC_P_MASK)) { | |
77b2bc2c | 2125 | raise_exception_err(env, EXCP0B_NOSEG, new_ss & 0xfffc); |
20054ef0 | 2126 | } |
eaa728ee FB |
2127 | cpu_x86_load_seg_cache(env, R_SS, new_ss, |
2128 | get_seg_base(ss_e1, ss_e2), | |
2129 | get_seg_limit(ss_e1, ss_e2), | |
2130 | ss_e2); | |
2131 | } | |
2132 | ||
2133 | cpu_x86_load_seg_cache(env, R_CS, new_cs, | |
2134 | get_seg_base(e1, e2), | |
2135 | get_seg_limit(e1, e2), | |
2136 | e2); | |
2137 | cpu_x86_set_cpl(env, rpl); | |
2138 | sp = new_esp; | |
2139 | #ifdef TARGET_X86_64 | |
20054ef0 | 2140 | if (env->hflags & HF_CS64_MASK) { |
eaa728ee | 2141 | sp_mask = -1; |
20054ef0 | 2142 | } else |
eaa728ee | 2143 | #endif |
20054ef0 | 2144 | { |
eaa728ee | 2145 | sp_mask = get_sp_mask(ss_e2); |
20054ef0 | 2146 | } |
eaa728ee FB |
2147 | |
2148 | /* validate data segments */ | |
2999a0b2 BS |
2149 | validate_seg(env, R_ES, rpl); |
2150 | validate_seg(env, R_DS, rpl); | |
2151 | validate_seg(env, R_FS, rpl); | |
2152 | validate_seg(env, R_GS, rpl); | |
eaa728ee FB |
2153 | |
2154 | sp += addend; | |
2155 | } | |
2156 | SET_ESP(sp, sp_mask); | |
2157 | env->eip = new_eip; | |
2158 | if (is_iret) { | |
2159 | /* NOTE: 'cpl' is the _old_ CPL */ | |
2160 | eflags_mask = TF_MASK | AC_MASK | ID_MASK | RF_MASK | NT_MASK; | |
20054ef0 | 2161 | if (cpl == 0) { |
eaa728ee | 2162 | eflags_mask |= IOPL_MASK; |
20054ef0 | 2163 | } |
eaa728ee | 2164 | iopl = (env->eflags >> IOPL_SHIFT) & 3; |
20054ef0 | 2165 | if (cpl <= iopl) { |
eaa728ee | 2166 | eflags_mask |= IF_MASK; |
20054ef0 BS |
2167 | } |
2168 | if (shift == 0) { | |
eaa728ee | 2169 | eflags_mask &= 0xffff; |
20054ef0 | 2170 | } |
997ff0d9 | 2171 | cpu_load_eflags(env, new_eflags, eflags_mask); |
eaa728ee FB |
2172 | } |
2173 | return; | |
2174 | ||
2175 | return_to_vm86: | |
2176 | POPL(ssp, sp, sp_mask, new_esp); | |
2177 | POPL(ssp, sp, sp_mask, new_ss); | |
2178 | POPL(ssp, sp, sp_mask, new_es); | |
2179 | POPL(ssp, sp, sp_mask, new_ds); | |
2180 | POPL(ssp, sp, sp_mask, new_fs); | |
2181 | POPL(ssp, sp, sp_mask, new_gs); | |
2182 | ||
2183 | /* modify processor state */ | |
997ff0d9 BS |
2184 | cpu_load_eflags(env, new_eflags, TF_MASK | AC_MASK | ID_MASK | |
2185 | IF_MASK | IOPL_MASK | VM_MASK | NT_MASK | VIF_MASK | | |
2186 | VIP_MASK); | |
2999a0b2 | 2187 | load_seg_vm(env, R_CS, new_cs & 0xffff); |
eaa728ee | 2188 | cpu_x86_set_cpl(env, 3); |
2999a0b2 BS |
2189 | load_seg_vm(env, R_SS, new_ss & 0xffff); |
2190 | load_seg_vm(env, R_ES, new_es & 0xffff); | |
2191 | load_seg_vm(env, R_DS, new_ds & 0xffff); | |
2192 | load_seg_vm(env, R_FS, new_fs & 0xffff); | |
2193 | load_seg_vm(env, R_GS, new_gs & 0xffff); | |
eaa728ee FB |
2194 | |
2195 | env->eip = new_eip & 0xffff; | |
08b3ded6 | 2196 | env->regs[R_ESP] = new_esp; |
eaa728ee FB |
2197 | } |
2198 | ||
2999a0b2 | 2199 | void helper_iret_protected(CPUX86State *env, int shift, int next_eip) |
eaa728ee FB |
2200 | { |
2201 | int tss_selector, type; | |
2202 | uint32_t e1, e2; | |
2203 | ||
2204 | /* specific case for TSS */ | |
2205 | if (env->eflags & NT_MASK) { | |
2206 | #ifdef TARGET_X86_64 | |
20054ef0 | 2207 | if (env->hflags & HF_LMA_MASK) { |
77b2bc2c | 2208 | raise_exception_err(env, EXCP0D_GPF, 0); |
20054ef0 | 2209 | } |
eaa728ee | 2210 | #endif |
329e607d | 2211 | tss_selector = cpu_lduw_kernel(env, env->tr.base + 0); |
20054ef0 | 2212 | if (tss_selector & 4) { |
77b2bc2c | 2213 | raise_exception_err(env, EXCP0A_TSS, tss_selector & 0xfffc); |
20054ef0 | 2214 | } |
2999a0b2 | 2215 | if (load_segment(env, &e1, &e2, tss_selector) != 0) { |
77b2bc2c | 2216 | raise_exception_err(env, EXCP0A_TSS, tss_selector & 0xfffc); |
20054ef0 | 2217 | } |
eaa728ee FB |
2218 | type = (e2 >> DESC_TYPE_SHIFT) & 0x17; |
2219 | /* NOTE: we check both segment and busy TSS */ | |
20054ef0 | 2220 | if (type != 3) { |
77b2bc2c | 2221 | raise_exception_err(env, EXCP0A_TSS, tss_selector & 0xfffc); |
20054ef0 | 2222 | } |
2999a0b2 | 2223 | switch_tss(env, tss_selector, e1, e2, SWITCH_TSS_IRET, next_eip); |
eaa728ee | 2224 | } else { |
2999a0b2 | 2225 | helper_ret_protected(env, shift, 1, 0); |
eaa728ee | 2226 | } |
db620f46 | 2227 | env->hflags2 &= ~HF2_NMI_MASK; |
eaa728ee FB |
2228 | } |
2229 | ||
2999a0b2 | 2230 | void helper_lret_protected(CPUX86State *env, int shift, int addend) |
eaa728ee | 2231 | { |
2999a0b2 | 2232 | helper_ret_protected(env, shift, 0, addend); |
eaa728ee FB |
2233 | } |
2234 | ||
2999a0b2 | 2235 | void helper_sysenter(CPUX86State *env) |
eaa728ee FB |
2236 | { |
2237 | if (env->sysenter_cs == 0) { | |
77b2bc2c | 2238 | raise_exception_err(env, EXCP0D_GPF, 0); |
eaa728ee FB |
2239 | } |
2240 | env->eflags &= ~(VM_MASK | IF_MASK | RF_MASK); | |
2241 | cpu_x86_set_cpl(env, 0); | |
2436b61a AZ |
2242 | |
2243 | #ifdef TARGET_X86_64 | |
2244 | if (env->hflags & HF_LMA_MASK) { | |
2245 | cpu_x86_load_seg_cache(env, R_CS, env->sysenter_cs & 0xfffc, | |
2246 | 0, 0xffffffff, | |
2247 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
2248 | DESC_S_MASK | | |
20054ef0 BS |
2249 | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK | |
2250 | DESC_L_MASK); | |
2436b61a AZ |
2251 | } else |
2252 | #endif | |
2253 | { | |
2254 | cpu_x86_load_seg_cache(env, R_CS, env->sysenter_cs & 0xfffc, | |
2255 | 0, 0xffffffff, | |
2256 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
2257 | DESC_S_MASK | | |
2258 | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK); | |
2259 | } | |
eaa728ee FB |
2260 | cpu_x86_load_seg_cache(env, R_SS, (env->sysenter_cs + 8) & 0xfffc, |
2261 | 0, 0xffffffff, | |
2262 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | | |
2263 | DESC_S_MASK | | |
2264 | DESC_W_MASK | DESC_A_MASK); | |
08b3ded6 | 2265 | env->regs[R_ESP] = env->sysenter_esp; |
a78d0eab | 2266 | env->eip = env->sysenter_eip; |
eaa728ee FB |
2267 | } |
2268 | ||
2999a0b2 | 2269 | void helper_sysexit(CPUX86State *env, int dflag) |
eaa728ee FB |
2270 | { |
2271 | int cpl; | |
2272 | ||
2273 | cpl = env->hflags & HF_CPL_MASK; | |
2274 | if (env->sysenter_cs == 0 || cpl != 0) { | |
77b2bc2c | 2275 | raise_exception_err(env, EXCP0D_GPF, 0); |
eaa728ee FB |
2276 | } |
2277 | cpu_x86_set_cpl(env, 3); | |
2436b61a AZ |
2278 | #ifdef TARGET_X86_64 |
2279 | if (dflag == 2) { | |
20054ef0 BS |
2280 | cpu_x86_load_seg_cache(env, R_CS, ((env->sysenter_cs + 32) & 0xfffc) | |
2281 | 3, 0, 0xffffffff, | |
2436b61a AZ |
2282 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | |
2283 | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | | |
20054ef0 BS |
2284 | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK | |
2285 | DESC_L_MASK); | |
2286 | cpu_x86_load_seg_cache(env, R_SS, ((env->sysenter_cs + 40) & 0xfffc) | | |
2287 | 3, 0, 0xffffffff, | |
2436b61a AZ |
2288 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | |
2289 | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | | |
2290 | DESC_W_MASK | DESC_A_MASK); | |
2291 | } else | |
2292 | #endif | |
2293 | { | |
20054ef0 BS |
2294 | cpu_x86_load_seg_cache(env, R_CS, ((env->sysenter_cs + 16) & 0xfffc) | |
2295 | 3, 0, 0xffffffff, | |
2436b61a AZ |
2296 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | |
2297 | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | | |
2298 | DESC_CS_MASK | DESC_R_MASK | DESC_A_MASK); | |
20054ef0 BS |
2299 | cpu_x86_load_seg_cache(env, R_SS, ((env->sysenter_cs + 24) & 0xfffc) | |
2300 | 3, 0, 0xffffffff, | |
2436b61a AZ |
2301 | DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | |
2302 | DESC_S_MASK | (3 << DESC_DPL_SHIFT) | | |
2303 | DESC_W_MASK | DESC_A_MASK); | |
2304 | } | |
08b3ded6 | 2305 | env->regs[R_ESP] = env->regs[R_ECX]; |
a78d0eab | 2306 | env->eip = env->regs[R_EDX]; |
eaa728ee FB |
2307 | } |
2308 | ||
2999a0b2 | 2309 | target_ulong helper_lsl(CPUX86State *env, target_ulong selector1) |
eaa728ee FB |
2310 | { |
2311 | unsigned int limit; | |
2312 | uint32_t e1, e2, eflags, selector; | |
2313 | int rpl, dpl, cpl, type; | |
2314 | ||
2315 | selector = selector1 & 0xffff; | |
f0967a1a | 2316 | eflags = cpu_cc_compute_all(env, CC_OP); |
20054ef0 | 2317 | if ((selector & 0xfffc) == 0) { |
dc1ded53 | 2318 | goto fail; |
20054ef0 | 2319 | } |
2999a0b2 | 2320 | if (load_segment(env, &e1, &e2, selector) != 0) { |
eaa728ee | 2321 | goto fail; |
20054ef0 | 2322 | } |
eaa728ee FB |
2323 | rpl = selector & 3; |
2324 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
2325 | cpl = env->hflags & HF_CPL_MASK; | |
2326 | if (e2 & DESC_S_MASK) { | |
2327 | if ((e2 & DESC_CS_MASK) && (e2 & DESC_C_MASK)) { | |
2328 | /* conforming */ | |
2329 | } else { | |
20054ef0 | 2330 | if (dpl < cpl || dpl < rpl) { |
eaa728ee | 2331 | goto fail; |
20054ef0 | 2332 | } |
eaa728ee FB |
2333 | } |
2334 | } else { | |
2335 | type = (e2 >> DESC_TYPE_SHIFT) & 0xf; | |
20054ef0 | 2336 | switch (type) { |
eaa728ee FB |
2337 | case 1: |
2338 | case 2: | |
2339 | case 3: | |
2340 | case 9: | |
2341 | case 11: | |
2342 | break; | |
2343 | default: | |
2344 | goto fail; | |
2345 | } | |
2346 | if (dpl < cpl || dpl < rpl) { | |
2347 | fail: | |
2348 | CC_SRC = eflags & ~CC_Z; | |
2349 | return 0; | |
2350 | } | |
2351 | } | |
2352 | limit = get_seg_limit(e1, e2); | |
2353 | CC_SRC = eflags | CC_Z; | |
2354 | return limit; | |
2355 | } | |
2356 | ||
2999a0b2 | 2357 | target_ulong helper_lar(CPUX86State *env, target_ulong selector1) |
eaa728ee FB |
2358 | { |
2359 | uint32_t e1, e2, eflags, selector; | |
2360 | int rpl, dpl, cpl, type; | |
2361 | ||
2362 | selector = selector1 & 0xffff; | |
f0967a1a | 2363 | eflags = cpu_cc_compute_all(env, CC_OP); |
20054ef0 | 2364 | if ((selector & 0xfffc) == 0) { |
eaa728ee | 2365 | goto fail; |
20054ef0 | 2366 | } |
2999a0b2 | 2367 | if (load_segment(env, &e1, &e2, selector) != 0) { |
eaa728ee | 2368 | goto fail; |
20054ef0 | 2369 | } |
eaa728ee FB |
2370 | rpl = selector & 3; |
2371 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
2372 | cpl = env->hflags & HF_CPL_MASK; | |
2373 | if (e2 & DESC_S_MASK) { | |
2374 | if ((e2 & DESC_CS_MASK) && (e2 & DESC_C_MASK)) { | |
2375 | /* conforming */ | |
2376 | } else { | |
20054ef0 | 2377 | if (dpl < cpl || dpl < rpl) { |
eaa728ee | 2378 | goto fail; |
20054ef0 | 2379 | } |
eaa728ee FB |
2380 | } |
2381 | } else { | |
2382 | type = (e2 >> DESC_TYPE_SHIFT) & 0xf; | |
20054ef0 | 2383 | switch (type) { |
eaa728ee FB |
2384 | case 1: |
2385 | case 2: | |
2386 | case 3: | |
2387 | case 4: | |
2388 | case 5: | |
2389 | case 9: | |
2390 | case 11: | |
2391 | case 12: | |
2392 | break; | |
2393 | default: | |
2394 | goto fail; | |
2395 | } | |
2396 | if (dpl < cpl || dpl < rpl) { | |
2397 | fail: | |
2398 | CC_SRC = eflags & ~CC_Z; | |
2399 | return 0; | |
2400 | } | |
2401 | } | |
2402 | CC_SRC = eflags | CC_Z; | |
2403 | return e2 & 0x00f0ff00; | |
2404 | } | |
2405 | ||
2999a0b2 | 2406 | void helper_verr(CPUX86State *env, target_ulong selector1) |
eaa728ee FB |
2407 | { |
2408 | uint32_t e1, e2, eflags, selector; | |
2409 | int rpl, dpl, cpl; | |
2410 | ||
2411 | selector = selector1 & 0xffff; | |
f0967a1a | 2412 | eflags = cpu_cc_compute_all(env, CC_OP); |
20054ef0 | 2413 | if ((selector & 0xfffc) == 0) { |
eaa728ee | 2414 | goto fail; |
20054ef0 | 2415 | } |
2999a0b2 | 2416 | if (load_segment(env, &e1, &e2, selector) != 0) { |
eaa728ee | 2417 | goto fail; |
20054ef0 BS |
2418 | } |
2419 | if (!(e2 & DESC_S_MASK)) { | |
eaa728ee | 2420 | goto fail; |
20054ef0 | 2421 | } |
eaa728ee FB |
2422 | rpl = selector & 3; |
2423 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
2424 | cpl = env->hflags & HF_CPL_MASK; | |
2425 | if (e2 & DESC_CS_MASK) { | |
20054ef0 | 2426 | if (!(e2 & DESC_R_MASK)) { |
eaa728ee | 2427 | goto fail; |
20054ef0 | 2428 | } |
eaa728ee | 2429 | if (!(e2 & DESC_C_MASK)) { |
20054ef0 | 2430 | if (dpl < cpl || dpl < rpl) { |
eaa728ee | 2431 | goto fail; |
20054ef0 | 2432 | } |
eaa728ee FB |
2433 | } |
2434 | } else { | |
2435 | if (dpl < cpl || dpl < rpl) { | |
2436 | fail: | |
2437 | CC_SRC = eflags & ~CC_Z; | |
2438 | return; | |
2439 | } | |
2440 | } | |
2441 | CC_SRC = eflags | CC_Z; | |
2442 | } | |
2443 | ||
2999a0b2 | 2444 | void helper_verw(CPUX86State *env, target_ulong selector1) |
eaa728ee FB |
2445 | { |
2446 | uint32_t e1, e2, eflags, selector; | |
2447 | int rpl, dpl, cpl; | |
2448 | ||
2449 | selector = selector1 & 0xffff; | |
f0967a1a | 2450 | eflags = cpu_cc_compute_all(env, CC_OP); |
20054ef0 | 2451 | if ((selector & 0xfffc) == 0) { |
eaa728ee | 2452 | goto fail; |
20054ef0 | 2453 | } |
2999a0b2 | 2454 | if (load_segment(env, &e1, &e2, selector) != 0) { |
eaa728ee | 2455 | goto fail; |
20054ef0 BS |
2456 | } |
2457 | if (!(e2 & DESC_S_MASK)) { | |
eaa728ee | 2458 | goto fail; |
20054ef0 | 2459 | } |
eaa728ee FB |
2460 | rpl = selector & 3; |
2461 | dpl = (e2 >> DESC_DPL_SHIFT) & 3; | |
2462 | cpl = env->hflags & HF_CPL_MASK; | |
2463 | if (e2 & DESC_CS_MASK) { | |
2464 | goto fail; | |
2465 | } else { | |
20054ef0 | 2466 | if (dpl < cpl || dpl < rpl) { |
eaa728ee | 2467 | goto fail; |
20054ef0 | 2468 | } |
eaa728ee FB |
2469 | if (!(e2 & DESC_W_MASK)) { |
2470 | fail: | |
2471 | CC_SRC = eflags & ~CC_Z; | |
2472 | return; | |
2473 | } | |
2474 | } | |
2475 | CC_SRC = eflags | CC_Z; | |
2476 | } | |
2477 | ||
f299f437 | 2478 | #if defined(CONFIG_USER_ONLY) |
2999a0b2 | 2479 | void cpu_x86_load_seg(CPUX86State *env, int seg_reg, int selector) |
eaa728ee | 2480 | { |
f299f437 BS |
2481 | if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) { |
2482 | selector &= 0xffff; | |
2483 | cpu_x86_load_seg_cache(env, seg_reg, selector, | |
2484 | (selector << 4), 0xffff, 0); | |
2485 | } else { | |
2999a0b2 | 2486 | helper_load_seg(env, seg_reg, selector); |
13822781 | 2487 | } |
eaa728ee | 2488 | } |
eaa728ee | 2489 | #endif |