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