2 * x86 exception helpers
4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "sysemu/sysemu.h"
23 #include "exec/helper-proto.h"
26 #define raise_exception_err(env, a, b) \
28 qemu_log("raise_exception line=%d\n", __LINE__); \
29 (raise_exception_err)(env, a, b); \
33 void helper_raise_interrupt(CPUX86State
*env
, int intno
, int next_eip_addend
)
35 raise_interrupt(env
, intno
, 1, 0, next_eip_addend
);
38 void helper_raise_exception(CPUX86State
*env
, int exception_index
)
40 raise_exception(env
, exception_index
);
44 * Check nested exceptions and change to double or triple fault if
45 * needed. It should only be called, if this is not an interrupt.
46 * Returns the new exception number.
48 static int check_exception(CPUX86State
*env
, int intno
, int *error_code
)
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);
56 qemu_log_mask(CPU_LOG_INT
, "check_exception old: 0x%x new 0x%x\n",
57 env
->old_exception
, intno
);
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); /* does not return */
65 qemu_log_mask(CPU_LOG_RESET
, "Triple fault\n");
67 qemu_system_reset_request();
72 if ((first_contributory
&& second_contributory
)
73 || (env
->old_exception
== EXCP0E_PAGE
&&
74 (second_contributory
|| (intno
== EXCP0E_PAGE
)))) {
79 if (second_contributory
|| (intno
== EXCP0E_PAGE
) ||
80 (intno
== EXCP08_DBLE
)) {
81 env
->old_exception
= intno
;
88 * Signal an interruption. It is executed in the main CPU loop.
89 * is_int is TRUE if coming from the int instruction. next_eip is the
90 * env->eip value AFTER the interrupt instruction. It is only relevant if
93 static void QEMU_NORETURN
raise_interrupt2(CPUX86State
*env
, int intno
,
94 int is_int
, int error_code
,
97 CPUState
*cs
= CPU(x86_env_get_cpu(env
));
100 cpu_svm_check_intercept_param(env
, SVM_EXIT_EXCP_BASE
+ intno
,
102 intno
= check_exception(env
, intno
, &error_code
);
104 cpu_svm_check_intercept_param(env
, SVM_EXIT_SWINT
, 0);
107 cs
->exception_index
= intno
;
108 env
->error_code
= error_code
;
109 env
->exception_is_int
= is_int
;
110 env
->exception_next_eip
= env
->eip
+ next_eip_addend
;
114 /* shortcuts to generate exceptions */
116 void QEMU_NORETURN
raise_interrupt(CPUX86State
*env
, int intno
, int is_int
,
117 int error_code
, int next_eip_addend
)
119 raise_interrupt2(env
, intno
, is_int
, error_code
, next_eip_addend
);
122 void raise_exception_err(CPUX86State
*env
, int exception_index
,
125 raise_interrupt2(env
, exception_index
, 0, error_code
, 0);
128 void raise_exception(CPUX86State
*env
, int exception_index
)
130 raise_interrupt2(env
, exception_index
, 0, 0, 0);