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