1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "qemu/osdep.h"
21#include "cpu.h"
22#include "qemu/log.h"
23#include "sysemu/sysemu.h"
24#include "exec/helper-proto.h"
25
26void helper_raise_interrupt(CPUX86State *env, int intno, int next_eip_addend)
27{
28 raise_interrupt(env, intno, 1, 0, next_eip_addend);
29}
30
31void helper_raise_exception(CPUX86State *env, int exception_index)
32{
33 raise_exception(env, exception_index);
34}
35
36
37
38
39
40
41static int check_exception(CPUX86State *env, int intno, int *error_code)
42{
43 int first_contributory = env->old_exception == 0 ||
44 (env->old_exception >= 10 &&
45 env->old_exception <= 13);
46 int second_contributory = intno == 0 ||
47 (intno >= 10 && intno <= 13);
48
49 qemu_log_mask(CPU_LOG_INT, "check_exception old: 0x%x new 0x%x\n",
50 env->old_exception, intno);
51
52#if !defined(CONFIG_USER_ONLY)
53 if (env->old_exception == EXCP08_DBLE) {
54 if (env->hflags & HF_SVMI_MASK) {
55 cpu_vmexit(env, SVM_EXIT_SHUTDOWN, 0);
56 }
57
58 qemu_log_mask(CPU_LOG_RESET, "Triple fault\n");
59
60 qemu_system_reset_request();
61 return EXCP_HLT;
62 }
63#endif
64
65 if ((first_contributory && second_contributory)
66 || (env->old_exception == EXCP0E_PAGE &&
67 (second_contributory || (intno == EXCP0E_PAGE)))) {
68 intno = EXCP08_DBLE;
69 *error_code = 0;
70 }
71
72 if (second_contributory || (intno == EXCP0E_PAGE) ||
73 (intno == EXCP08_DBLE)) {
74 env->old_exception = intno;
75 }
76
77 return intno;
78}
79
80
81
82
83
84
85
86static void QEMU_NORETURN raise_interrupt2(CPUX86State *env, int intno,
87 int is_int, int error_code,
88 int next_eip_addend,
89 uintptr_t retaddr)
90{
91 CPUState *cs = CPU(x86_env_get_cpu(env));
92
93 if (!is_int) {
94 cpu_svm_check_intercept_param(env, SVM_EXIT_EXCP_BASE + intno,
95 error_code);
96 intno = check_exception(env, intno, &error_code);
97 } else {
98 cpu_svm_check_intercept_param(env, SVM_EXIT_SWINT, 0);
99 }
100
101 cs->exception_index = intno;
102 env->error_code = error_code;
103 env->exception_is_int = is_int;
104 env->exception_next_eip = env->eip + next_eip_addend;
105 cpu_loop_exit_restore(cs, retaddr);
106}
107
108
109
110void QEMU_NORETURN raise_interrupt(CPUX86State *env, int intno, int is_int,
111 int error_code, int next_eip_addend)
112{
113 raise_interrupt2(env, intno, is_int, error_code, next_eip_addend, 0);
114}
115
116void raise_exception_err(CPUX86State *env, int exception_index,
117 int error_code)
118{
119 raise_interrupt2(env, exception_index, 0, error_code, 0, 0);
120}
121
122void raise_exception_err_ra(CPUX86State *env, int exception_index,
123 int error_code, uintptr_t retaddr)
124{
125 raise_interrupt2(env, exception_index, 0, error_code, 0, retaddr);
126}
127
128void raise_exception(CPUX86State *env, int exception_index)
129{
130 raise_interrupt2(env, exception_index, 0, 0, 0, 0);
131}
132
133void raise_exception_ra(CPUX86State *env, int exception_index, uintptr_t retaddr)
134{
135 raise_interrupt2(env, exception_index, 0, 0, 0, retaddr);
136}
137