2012-04-28 23:53:52 +04:00
|
|
|
/*
|
|
|
|
* x86 exception helpers
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 15:28:01 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-04-28 23:53:52 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:03 +03:00
|
|
|
#include "qemu/osdep.h"
|
2012-04-28 23:53:52 +04:00
|
|
|
#include "cpu.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/log.h"
|
2019-08-12 08:23:59 +03:00
|
|
|
#include "sysemu/runstate.h"
|
2014-04-08 09:31:41 +04:00
|
|
|
#include "exec/helper-proto.h"
|
2020-12-12 18:55:14 +03:00
|
|
|
#include "helper-tcg.h"
|
2012-04-28 23:53:52 +04:00
|
|
|
|
2021-05-14 18:13:26 +03:00
|
|
|
void QEMU_NORETURN helper_raise_interrupt(CPUX86State *env, int intno,
|
|
|
|
int next_eip_addend)
|
2012-04-28 23:53:52 +04:00
|
|
|
{
|
|
|
|
raise_interrupt(env, intno, 1, 0, next_eip_addend);
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:13:26 +03:00
|
|
|
void QEMU_NORETURN helper_raise_exception(CPUX86State *env, int exception_index)
|
2012-04-28 23:53:52 +04:00
|
|
|
{
|
|
|
|
raise_exception(env, exception_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check nested exceptions and change to double or triple fault if
|
|
|
|
* needed. It should only be called, if this is not an interrupt.
|
|
|
|
* Returns the new exception number.
|
|
|
|
*/
|
2017-02-16 14:30:05 +03:00
|
|
|
static int check_exception(CPUX86State *env, int intno, int *error_code,
|
|
|
|
uintptr_t retaddr)
|
2012-04-28 23:53:52 +04:00
|
|
|
{
|
|
|
|
int first_contributory = env->old_exception == 0 ||
|
|
|
|
(env->old_exception >= 10 &&
|
|
|
|
env->old_exception <= 13);
|
|
|
|
int second_contributory = intno == 0 ||
|
|
|
|
(intno >= 10 && intno <= 13);
|
|
|
|
|
|
|
|
qemu_log_mask(CPU_LOG_INT, "check_exception old: 0x%x new 0x%x\n",
|
|
|
|
env->old_exception, intno);
|
|
|
|
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
if (env->old_exception == EXCP08_DBLE) {
|
2018-08-21 10:40:22 +03:00
|
|
|
if (env->hflags & HF_GUEST_MASK) {
|
2017-02-16 14:30:05 +03:00
|
|
|
cpu_vmexit(env, SVM_EXIT_SHUTDOWN, 0, retaddr); /* does not return */
|
2012-04-28 23:53:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
qemu_log_mask(CPU_LOG_RESET, "Triple fault\n");
|
|
|
|
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2012-04-28 23:53:52 +04:00
|
|
|
return EXCP_HLT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((first_contributory && second_contributory)
|
|
|
|
|| (env->old_exception == EXCP0E_PAGE &&
|
|
|
|
(second_contributory || (intno == EXCP0E_PAGE)))) {
|
|
|
|
intno = EXCP08_DBLE;
|
|
|
|
*error_code = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (second_contributory || (intno == EXCP0E_PAGE) ||
|
|
|
|
(intno == EXCP08_DBLE)) {
|
|
|
|
env->old_exception = intno;
|
|
|
|
}
|
|
|
|
|
|
|
|
return intno;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Signal an interruption. It is executed in the main CPU loop.
|
|
|
|
* is_int is TRUE if coming from the int instruction. next_eip is the
|
2013-05-28 12:21:07 +04:00
|
|
|
* env->eip value AFTER the interrupt instruction. It is only relevant if
|
2012-04-28 23:53:52 +04:00
|
|
|
* is_int is TRUE.
|
|
|
|
*/
|
|
|
|
static void QEMU_NORETURN raise_interrupt2(CPUX86State *env, int intno,
|
|
|
|
int is_int, int error_code,
|
2015-07-10 12:57:13 +03:00
|
|
|
int next_eip_addend,
|
|
|
|
uintptr_t retaddr)
|
2012-04-28 23:53:52 +04:00
|
|
|
{
|
2019-03-23 04:08:48 +03:00
|
|
|
CPUState *cs = env_cpu(env);
|
2013-08-26 10:31:06 +04:00
|
|
|
|
2012-04-28 23:53:52 +04:00
|
|
|
if (!is_int) {
|
|
|
|
cpu_svm_check_intercept_param(env, SVM_EXIT_EXCP_BASE + intno,
|
2017-02-16 14:30:05 +03:00
|
|
|
error_code, retaddr);
|
|
|
|
intno = check_exception(env, intno, &error_code, retaddr);
|
2012-04-28 23:53:52 +04:00
|
|
|
} else {
|
2017-02-16 14:30:05 +03:00
|
|
|
cpu_svm_check_intercept_param(env, SVM_EXIT_SWINT, 0, retaddr);
|
2012-04-28 23:53:52 +04:00
|
|
|
}
|
|
|
|
|
2013-08-26 10:31:06 +04:00
|
|
|
cs->exception_index = intno;
|
2012-04-28 23:53:52 +04:00
|
|
|
env->error_code = error_code;
|
|
|
|
env->exception_is_int = is_int;
|
|
|
|
env->exception_next_eip = env->eip + next_eip_addend;
|
2015-07-10 12:57:13 +03:00
|
|
|
cpu_loop_exit_restore(cs, retaddr);
|
2012-04-28 23:53:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* shortcuts to generate exceptions */
|
|
|
|
|
|
|
|
void QEMU_NORETURN raise_interrupt(CPUX86State *env, int intno, int is_int,
|
|
|
|
int error_code, int next_eip_addend)
|
|
|
|
{
|
2015-07-10 12:57:13 +03:00
|
|
|
raise_interrupt2(env, intno, is_int, error_code, next_eip_addend, 0);
|
2012-04-28 23:53:52 +04:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:13:26 +03:00
|
|
|
void QEMU_NORETURN raise_exception_err(CPUX86State *env, int exception_index,
|
|
|
|
int error_code)
|
2012-04-28 23:53:52 +04:00
|
|
|
{
|
2015-07-10 12:57:13 +03:00
|
|
|
raise_interrupt2(env, exception_index, 0, error_code, 0, 0);
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:13:26 +03:00
|
|
|
void QEMU_NORETURN raise_exception_err_ra(CPUX86State *env, int exception_index,
|
|
|
|
int error_code, uintptr_t retaddr)
|
2015-07-10 12:57:13 +03:00
|
|
|
{
|
|
|
|
raise_interrupt2(env, exception_index, 0, error_code, 0, retaddr);
|
2012-04-28 23:53:52 +04:00
|
|
|
}
|
|
|
|
|
2021-05-14 18:13:26 +03:00
|
|
|
void QEMU_NORETURN raise_exception(CPUX86State *env, int exception_index)
|
2012-04-28 23:53:52 +04:00
|
|
|
{
|
2015-07-10 12:57:13 +03:00
|
|
|
raise_interrupt2(env, exception_index, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2021-05-14 18:13:26 +03:00
|
|
|
void QEMU_NORETURN raise_exception_ra(CPUX86State *env, int exception_index,
|
|
|
|
uintptr_t retaddr)
|
2015-07-10 12:57:13 +03:00
|
|
|
{
|
|
|
|
raise_interrupt2(env, exception_index, 0, 0, 0, retaddr);
|
2012-04-28 23:53:52 +04:00
|
|
|
}
|