2020-12-12 16:55:14 +01:00
|
|
|
/*
|
|
|
|
* i386 TCG cpu class initialization
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "helper-tcg.h"
|
2021-03-22 14:27:40 +01:00
|
|
|
#include "qemu/accel.h"
|
|
|
|
#include "hw/core/accel-cpu.h"
|
2020-12-12 16:55:14 +01:00
|
|
|
|
2021-05-06 17:20:23 +02:00
|
|
|
#include "tcg-cpu.h"
|
2020-12-12 16:55:14 +01:00
|
|
|
|
|
|
|
/* Frob eflags into and out of the CPU temporary format. */
|
|
|
|
|
|
|
|
static void x86_cpu_exec_enter(CPUState *cs)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = X86_CPU(cs);
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
|
|
|
env->df = 1 - (2 * ((env->eflags >> 10) & 1));
|
|
|
|
CC_OP = CC_OP_EFLAGS;
|
|
|
|
env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void x86_cpu_exec_exit(CPUState *cs)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = X86_CPU(cs);
|
|
|
|
CPUX86State *env = &cpu->env;
|
|
|
|
|
|
|
|
env->eflags = cpu_compute_eflags(env);
|
|
|
|
}
|
|
|
|
|
2020-10-29 20:30:01 +01:00
|
|
|
static void x86_cpu_synchronize_from_tb(CPUState *cs,
|
|
|
|
const TranslationBlock *tb)
|
2020-12-12 16:55:14 +01:00
|
|
|
{
|
|
|
|
X86CPU *cpu = X86_CPU(cs);
|
|
|
|
|
|
|
|
cpu->env.eip = tb->pc - tb->cs_base;
|
|
|
|
}
|
|
|
|
|
2021-02-04 17:39:23 +01:00
|
|
|
#include "hw/core/tcg-cpu-ops.h"
|
|
|
|
|
2021-02-28 00:21:17 +01:00
|
|
|
static const struct TCGCPUOps x86_tcg_ops = {
|
2021-02-04 17:39:23 +01:00
|
|
|
.initialize = tcg_x86_init,
|
|
|
|
.synchronize_from_tb = x86_cpu_synchronize_from_tb,
|
|
|
|
.cpu_exec_enter = x86_cpu_exec_enter,
|
|
|
|
.cpu_exec_exit = x86_cpu_exec_exit,
|
|
|
|
.cpu_exec_interrupt = x86_cpu_exec_interrupt,
|
|
|
|
.do_interrupt = x86_cpu_do_interrupt,
|
|
|
|
.tlb_fill = x86_cpu_tlb_fill,
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
.debug_excp_handler = breakpoint_handler,
|
|
|
|
#endif /* !CONFIG_USER_ONLY */
|
|
|
|
};
|
|
|
|
|
2021-03-22 14:27:59 +01:00
|
|
|
static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc)
|
2020-12-12 16:55:14 +01:00
|
|
|
{
|
2021-03-22 14:27:59 +01:00
|
|
|
/* for x86, all cpus use the same set of operations */
|
2021-02-04 17:39:23 +01:00
|
|
|
cc->tcg_ops = &x86_tcg_ops;
|
2020-12-12 16:55:14 +01:00
|
|
|
}
|
2021-03-22 14:27:40 +01:00
|
|
|
|
2021-03-22 14:27:59 +01:00
|
|
|
static void tcg_cpu_class_init(CPUClass *cc)
|
|
|
|
{
|
|
|
|
cc->init_accel_cpu = tcg_cpu_init_ops;
|
|
|
|
}
|
|
|
|
|
2021-07-05 12:46:31 +02:00
|
|
|
static void tcg_cpu_xsave_init(void)
|
|
|
|
{
|
|
|
|
#define XO(bit, field) \
|
|
|
|
x86_ext_save_areas[bit].offset = offsetof(X86XSaveArea, field);
|
|
|
|
|
|
|
|
XO(XSTATE_FP_BIT, legacy);
|
|
|
|
XO(XSTATE_SSE_BIT, legacy);
|
|
|
|
XO(XSTATE_YMM_BIT, avx_state);
|
|
|
|
XO(XSTATE_BNDREGS_BIT, bndreg_state);
|
|
|
|
XO(XSTATE_BNDCSR_BIT, bndcsr_state);
|
|
|
|
XO(XSTATE_OPMASK_BIT, opmask_state);
|
|
|
|
XO(XSTATE_ZMM_Hi256_BIT, zmm_hi256_state);
|
|
|
|
XO(XSTATE_Hi16_ZMM_BIT, hi16_zmm_state);
|
|
|
|
XO(XSTATE_PKRU_BIT, pkru_state);
|
|
|
|
|
|
|
|
#undef XO
|
|
|
|
}
|
|
|
|
|
2021-03-22 14:27:40 +01:00
|
|
|
/*
|
|
|
|
* TCG-specific defaults that override all CPU models when using TCG
|
|
|
|
*/
|
|
|
|
static PropValue tcg_default_props[] = {
|
|
|
|
{ "vme", "off" },
|
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void tcg_cpu_instance_init(CPUState *cs)
|
|
|
|
{
|
|
|
|
X86CPU *cpu = X86_CPU(cs);
|
|
|
|
/* Special cases not set in the X86CPUDefinition structs: */
|
|
|
|
x86_cpu_apply_props(cpu, tcg_default_props);
|
2021-07-05 12:46:31 +02:00
|
|
|
|
|
|
|
tcg_cpu_xsave_init();
|
2021-03-22 14:27:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
|
|
|
|
|
2021-05-06 17:20:23 +02:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2021-03-22 14:27:40 +01:00
|
|
|
acc->cpu_realizefn = tcg_cpu_realizefn;
|
2021-05-06 17:20:23 +02:00
|
|
|
#endif /* CONFIG_USER_ONLY */
|
|
|
|
|
2021-03-22 14:27:40 +01:00
|
|
|
acc->cpu_class_init = tcg_cpu_class_init;
|
|
|
|
acc->cpu_instance_init = tcg_cpu_instance_init;
|
|
|
|
}
|
|
|
|
static const TypeInfo tcg_cpu_accel_type_info = {
|
|
|
|
.name = ACCEL_CPU_NAME("tcg"),
|
|
|
|
|
|
|
|
.parent = TYPE_ACCEL_CPU,
|
|
|
|
.class_init = tcg_cpu_accel_class_init,
|
|
|
|
.abstract = true,
|
|
|
|
};
|
|
|
|
static void tcg_cpu_accel_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&tcg_cpu_accel_type_info);
|
|
|
|
}
|
|
|
|
type_init(tcg_cpu_accel_register_types);
|