1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "qemu/osdep.h"
22#include "cpu.h"
23#include "exec/helper-proto.h"
24#include "exec/exec-all.h"
25#include "exec/cpu_ldst.h"
26#include "tcg/helper-tcg.h"
27#include "tcg/seg_helper.h"
28
29#ifdef TARGET_X86_64
30void helper_syscall(CPUX86State *env, int next_eip_addend)
31{
32 CPUState *cs = env_cpu(env);
33
34 cs->exception_index = EXCP_SYSCALL;
35 env->exception_is_int = 0;
36 env->exception_next_eip = env->eip + next_eip_addend;
37 cpu_loop_exit(cs);
38}
39#endif
40
41
42
43
44
45
46
47static void do_interrupt_user(CPUX86State *env, int intno, int is_int,
48 int error_code, target_ulong next_eip)
49{
50 if (is_int) {
51 SegmentCache *dt;
52 target_ulong ptr;
53 int dpl, cpl, shift;
54 uint32_t e2;
55
56 dt = &env->idt;
57 if (env->hflags & HF_LMA_MASK) {
58 shift = 4;
59 } else {
60 shift = 3;
61 }
62 ptr = dt->base + (intno << shift);
63 e2 = cpu_ldl_kernel(env, ptr + 4);
64
65 dpl = (e2 >> DESC_DPL_SHIFT) & 3;
66 cpl = env->hflags & HF_CPL_MASK;
67
68 if (dpl < cpl) {
69 raise_exception_err(env, EXCP0D_GPF, (intno << shift) + 2);
70 }
71 }
72
73
74
75
76 if (is_int || intno == EXCP_SYSCALL) {
77 env->eip = next_eip;
78 }
79}
80
81void x86_cpu_do_interrupt(CPUState *cs)
82{
83 X86CPU *cpu = X86_CPU(cs);
84 CPUX86State *env = &cpu->env;
85
86
87
88
89 do_interrupt_user(env, cs->exception_index,
90 env->exception_is_int,
91 env->error_code,
92 env->exception_next_eip);
93
94 env->old_exception = -1;
95}
96
97void cpu_x86_load_seg(CPUX86State *env, X86Seg seg_reg, int selector)
98{
99 if (!(env->cr[0] & CR0_PE_MASK) || (env->eflags & VM_MASK)) {
100 int dpl = (env->eflags & VM_MASK) ? 3 : 0;
101 selector &= 0xffff;
102 cpu_x86_load_seg_cache(env, seg_reg, selector,
103 (selector << 4), 0xffff,
104 DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |
105 DESC_A_MASK | (dpl << DESC_DPL_SHIFT));
106 } else {
107 helper_load_seg(env, seg_reg, selector);
108 }
109}
110