mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-07-08 15:50:55 +00:00
qom: Introduce CPUClass.tcg_initialize
Move target cpu tcg initialization to common code, called from cpu_exec_realizefn. Backports commit 55c3ceef61fcf06fc98ddc752b7cce788ce7680b from qemu
This commit is contained in:
parent
4d9c8583fa
commit
28061c2e59
|
@ -572,6 +572,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
|
||||||
void cpu_exec_init(CPUState *cpu, void *opaque)
|
void cpu_exec_init(CPUState *cpu, void *opaque)
|
||||||
{
|
{
|
||||||
struct uc_struct *uc = opaque;
|
struct uc_struct *uc = opaque;
|
||||||
|
CPUClass *cc = CPU_GET_CLASS(uc, cpu);
|
||||||
CPUArchState *env = cpu->env_ptr;
|
CPUArchState *env = cpu->env_ptr;
|
||||||
|
|
||||||
cpu->as = NULL;
|
cpu->as = NULL;
|
||||||
|
@ -586,6 +587,11 @@ void cpu_exec_init(CPUState *cpu, void *opaque)
|
||||||
// Unicorn: Required to clean-slate TLB state
|
// Unicorn: Required to clean-slate TLB state
|
||||||
tlb_flush(cpu);
|
tlb_flush(cpu);
|
||||||
|
|
||||||
|
if (tcg_enabled(uc) && !cc->tcg_initialized) {
|
||||||
|
cc->tcg_initialized = true;
|
||||||
|
cc->tcg_initialize(uc);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_USER_ONLY
|
#ifndef CONFIG_USER_ONLY
|
||||||
|
|
||||||
// Unicorn: commented out
|
// Unicorn: commented out
|
||||||
|
|
|
@ -4473,7 +4473,6 @@ sparc_symbols = (
|
||||||
'cpu_sparc_init',
|
'cpu_sparc_init',
|
||||||
'cpu_sparc_set_id',
|
'cpu_sparc_set_id',
|
||||||
'dump_mmu',
|
'dump_mmu',
|
||||||
'gen_intermediate_code_init',
|
|
||||||
'helper_check_align',
|
'helper_check_align',
|
||||||
'helper_check_ieee_exceptions',
|
'helper_check_ieee_exceptions',
|
||||||
'helper_compute_C_icc',
|
'helper_compute_C_icc',
|
||||||
|
@ -4535,6 +4534,7 @@ sparc_symbols = (
|
||||||
'sparc_reg_read',
|
'sparc_reg_read',
|
||||||
'sparc_reg_reset',
|
'sparc_reg_reset',
|
||||||
'sparc_reg_write',
|
'sparc_reg_write',
|
||||||
|
'sparc_tcg_init',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,10 @@ typedef struct CPUClass {
|
||||||
void (*cpu_exec_exit)(CPUState *cpu);
|
void (*cpu_exec_exit)(CPUState *cpu);
|
||||||
bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
|
bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
|
||||||
vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
|
vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
|
||||||
|
void (*tcg_initialize)(struct uc_struct *uc);
|
||||||
|
|
||||||
|
/* Keep non-pointer data at the end to minimize holes. */
|
||||||
|
bool tcg_initialized;
|
||||||
} CPUClass;
|
} CPUClass;
|
||||||
|
|
||||||
#ifdef HOST_WORDS_BIGENDIAN
|
#ifdef HOST_WORDS_BIGENDIAN
|
||||||
|
|
|
@ -3449,7 +3449,6 @@
|
||||||
#define cpu_sparc_init cpu_sparc_init_sparc
|
#define cpu_sparc_init cpu_sparc_init_sparc
|
||||||
#define cpu_sparc_set_id cpu_sparc_set_id_sparc
|
#define cpu_sparc_set_id cpu_sparc_set_id_sparc
|
||||||
#define dump_mmu dump_mmu_sparc
|
#define dump_mmu dump_mmu_sparc
|
||||||
#define gen_intermediate_code_init gen_intermediate_code_init_sparc
|
|
||||||
#define helper_check_align helper_check_align_sparc
|
#define helper_check_align helper_check_align_sparc
|
||||||
#define helper_check_ieee_exceptions helper_check_ieee_exceptions_sparc
|
#define helper_check_ieee_exceptions helper_check_ieee_exceptions_sparc
|
||||||
#define helper_compute_C_icc helper_compute_C_icc_sparc
|
#define helper_compute_C_icc helper_compute_C_icc_sparc
|
||||||
|
@ -3511,4 +3510,5 @@
|
||||||
#define sparc_reg_read sparc_reg_read_sparc
|
#define sparc_reg_read sparc_reg_read_sparc
|
||||||
#define sparc_reg_reset sparc_reg_reset_sparc
|
#define sparc_reg_reset sparc_reg_reset_sparc
|
||||||
#define sparc_reg_write sparc_reg_write_sparc
|
#define sparc_reg_write sparc_reg_write_sparc
|
||||||
|
#define sparc_tcg_init sparc_tcg_init_sparc
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3449,7 +3449,6 @@
|
||||||
#define cpu_sparc_init cpu_sparc_init_sparc64
|
#define cpu_sparc_init cpu_sparc_init_sparc64
|
||||||
#define cpu_sparc_set_id cpu_sparc_set_id_sparc64
|
#define cpu_sparc_set_id cpu_sparc_set_id_sparc64
|
||||||
#define dump_mmu dump_mmu_sparc64
|
#define dump_mmu dump_mmu_sparc64
|
||||||
#define gen_intermediate_code_init gen_intermediate_code_init_sparc64
|
|
||||||
#define helper_check_align helper_check_align_sparc64
|
#define helper_check_align helper_check_align_sparc64
|
||||||
#define helper_check_ieee_exceptions helper_check_ieee_exceptions_sparc64
|
#define helper_check_ieee_exceptions helper_check_ieee_exceptions_sparc64
|
||||||
#define helper_compute_C_icc helper_compute_C_icc_sparc64
|
#define helper_compute_C_icc helper_compute_C_icc_sparc64
|
||||||
|
@ -3511,4 +3510,5 @@
|
||||||
#define sparc_reg_read sparc_reg_read_sparc64
|
#define sparc_reg_read sparc_reg_read_sparc64
|
||||||
#define sparc_reg_reset sparc_reg_reset_sparc64
|
#define sparc_reg_reset sparc_reg_reset_sparc64
|
||||||
#define sparc_reg_write sparc_reg_write_sparc64
|
#define sparc_reg_write sparc_reg_write_sparc64
|
||||||
|
#define sparc_tcg_init sparc_tcg_init_sparc64
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -461,7 +461,6 @@ static void arm_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque)
|
||||||
|
|
||||||
if (tcg_enabled(uc)) {
|
if (tcg_enabled(uc)) {
|
||||||
cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
|
cpu->psci_version = 2; /* TCG implements PSCI 0.2 */
|
||||||
arm_translate_init(uc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1516,6 +1515,7 @@ static void arm_cpu_class_init(struct uc_struct *uc, ObjectClass *oc, void *data
|
||||||
#if !defined(CONFIG_USER_ONLY)
|
#if !defined(CONFIG_USER_ONLY)
|
||||||
cc->adjust_watchpoint_address = arm_adjust_watchpoint_address;
|
cc->adjust_watchpoint_address = arm_adjust_watchpoint_address;
|
||||||
#endif
|
#endif
|
||||||
|
cc->tcg_initialize = arm_translate_init;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cpu_register(struct uc_struct *uc, const ARMCPUInfo *info)
|
static void cpu_register(struct uc_struct *uc, const ARMCPUInfo *info)
|
||||||
|
|
|
@ -3444,10 +3444,6 @@ static int x86_cpu_realizefn(struct uc_struct *uc, DeviceState *dev, Error **err
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tcg_enabled(env->uc)) {
|
|
||||||
tcg_x86_init(env->uc);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef CONFIG_USER_ONLY
|
#ifndef CONFIG_USER_ONLY
|
||||||
//qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
|
//qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
|
||||||
|
|
||||||
|
@ -3660,6 +3656,7 @@ static void x86_cpu_common_class_init(struct uc_struct *uc, ObjectClass *oc, voi
|
||||||
#endif
|
#endif
|
||||||
cc->cpu_exec_enter = x86_cpu_exec_enter;
|
cc->cpu_exec_enter = x86_cpu_exec_enter;
|
||||||
cc->cpu_exec_exit = x86_cpu_exec_exit;
|
cc->cpu_exec_exit = x86_cpu_exec_exit;
|
||||||
|
cc->tcg_initialize = tcg_x86_init;
|
||||||
}
|
}
|
||||||
|
|
||||||
void x86_cpu_register_types(void *opaque)
|
void x86_cpu_register_types(void *opaque)
|
||||||
|
|
|
@ -5071,7 +5071,7 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu)
|
||||||
TCGv *cpu_regs = tcg_ctx->cpu_regs;
|
TCGv *cpu_regs = tcg_ctx->cpu_regs;
|
||||||
TCGv *cpu_seg_base = tcg_ctx->cpu_seg_base;
|
TCGv *cpu_seg_base = tcg_ctx->cpu_seg_base;
|
||||||
//TCGArg* save_opparam_ptr = tcg_ctx->gen_opparam_buf + tcg_ctx->gen_op_buf[tcg_ctx->gen_op_buf[0].prev].args;
|
//TCGArg* save_opparam_ptr = tcg_ctx->gen_opparam_buf + tcg_ctx->gen_op_buf[tcg_ctx->gen_op_buf[0].prev].args;
|
||||||
bool cc_op_dirty = s->cc_op_dirty;
|
//bool cc_op_dirty = s->cc_op_dirty;
|
||||||
bool changed_cc_op = false;
|
bool changed_cc_op = false;
|
||||||
|
|
||||||
s->pc_start = s->pc = pc_start;
|
s->pc_start = s->pc = pc_start;
|
||||||
|
|
|
@ -234,10 +234,6 @@ static void m68k_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque)
|
||||||
|
|
||||||
cs->env_ptr = env;
|
cs->env_ptr = env;
|
||||||
cpu_exec_init(cs, opaque);
|
cpu_exec_init(cs, opaque);
|
||||||
|
|
||||||
if (tcg_enabled(uc)) {
|
|
||||||
m68k_tcg_init(uc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void m68k_cpu_class_init(struct uc_struct *uc, ObjectClass *c, void *data)
|
static void m68k_cpu_class_init(struct uc_struct *uc, ObjectClass *c, void *data)
|
||||||
|
@ -262,6 +258,7 @@ static void m68k_cpu_class_init(struct uc_struct *uc, ObjectClass *c, void *data
|
||||||
#else
|
#else
|
||||||
cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug;
|
cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug;
|
||||||
#endif
|
#endif
|
||||||
|
cc->tcg_initialize = m68k_tcg_init;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void register_cpu_type(void *opaque, const M68kCPUInfo *info)
|
static void register_cpu_type(void *opaque, const M68kCPUInfo *info)
|
||||||
|
|
|
@ -5779,14 +5779,17 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock *tb)
|
||||||
goto done_generating;
|
goto done_generating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unicorn: FIXME: Update to work with new TCG API
|
||||||
// Unicorn: trace this block on request
|
// Unicorn: trace this block on request
|
||||||
// Only hook this block if it is not broken from previous translation due to
|
// Only hook this block if it is not broken from previous translation due to
|
||||||
// full translation cache
|
// full translation cache
|
||||||
if (!env->uc->block_full && HOOK_EXISTS_BOUNDED(env->uc, UC_HOOK_BLOCK, pc_start)) {
|
if (!env->uc->block_full && HOOK_EXISTS_BOUNDED(env->uc, UC_HOOK_BLOCK, pc_start)) {
|
||||||
|
#if 0
|
||||||
// save block address to see if we need to patch block size later
|
// save block address to see if we need to patch block size later
|
||||||
env->uc->block_addr = pc_start;
|
env->uc->block_addr = pc_start;
|
||||||
env->uc->size_arg = tcg_ctx->gen_op_buf[tcg_ctx->gen_op_buf[0].prev].args;
|
env->uc->size_arg = tcg_ctx->gen_op_buf[tcg_ctx->gen_op_buf[0].prev].args;
|
||||||
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, UC_HOOK_BLOCK_IDX, env->uc, pc_start);
|
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, UC_HOOK_BLOCK_IDX, env->uc, pc_start);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
env->uc->size_arg = -1;
|
env->uc->size_arg = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,10 +131,6 @@ static void mips_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque)
|
||||||
cs->env_ptr = env;
|
cs->env_ptr = env;
|
||||||
env->cpu_model = mcc->cpu_def;
|
env->cpu_model = mcc->cpu_def;
|
||||||
cpu_exec_init(cs, opaque);
|
cpu_exec_init(cs, opaque);
|
||||||
|
|
||||||
if (tcg_enabled(uc)) {
|
|
||||||
mips_tcg_init(uc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *mips_cpu_type_name(const char *cpu_model)
|
static char *mips_cpu_type_name(const char *cpu_model)
|
||||||
|
@ -182,6 +178,7 @@ static void mips_cpu_class_init(struct uc_struct *uc, ObjectClass *c, void *data
|
||||||
cc->do_unaligned_access = mips_cpu_do_unaligned_access;
|
cc->do_unaligned_access = mips_cpu_do_unaligned_access;
|
||||||
cc->get_phys_page_debug = mips_cpu_get_phys_page_debug;
|
cc->get_phys_page_debug = mips_cpu_get_phys_page_debug;
|
||||||
#endif
|
#endif
|
||||||
|
cc->tcg_initialize = mips_tcg_init;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mips_cpu_cpudef_class_init(struct uc_struct *uc, ObjectClass *oc, void *data)
|
static void mips_cpu_cpudef_class_init(struct uc_struct *uc, ObjectClass *oc, void *data)
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#define SPARC_CPU_GET_CLASS(uc, obj) \
|
#define SPARC_CPU_GET_CLASS(uc, obj) \
|
||||||
OBJECT_GET_CLASS(uc, SPARCCPUClass, (obj), TYPE_SPARC_CPU)
|
OBJECT_GET_CLASS(uc, SPARCCPUClass, (obj), TYPE_SPARC_CPU)
|
||||||
|
|
||||||
|
typedef struct sparc_def_t sparc_def_t;
|
||||||
/**
|
/**
|
||||||
* SPARCCPUClass:
|
* SPARCCPUClass:
|
||||||
* @parent_realize: The parent class' realize handler.
|
* @parent_realize: The parent class' realize handler.
|
||||||
|
|
|
@ -860,10 +860,6 @@ static void sparc_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque)
|
||||||
|
|
||||||
cs->env_ptr = env;
|
cs->env_ptr = env;
|
||||||
cpu_exec_init(cs, opaque);
|
cpu_exec_init(cs, opaque);
|
||||||
|
|
||||||
if (tcg_enabled(uc)) {
|
|
||||||
gen_intermediate_code_init(env);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sparc_cpu_uninitfn(struct uc_struct *uc, Object *obj, void *opaque)
|
static void sparc_cpu_uninitfn(struct uc_struct *uc, Object *obj, void *opaque)
|
||||||
|
@ -904,6 +900,7 @@ static void sparc_cpu_class_init(struct uc_struct *uc, ObjectClass *oc, void *da
|
||||||
// Unicorn: commented out
|
// Unicorn: commented out
|
||||||
//cc->vmsd = &vmstate_sparc_cpu;
|
//cc->vmsd = &vmstate_sparc_cpu;
|
||||||
#endif
|
#endif
|
||||||
|
cc->tcg_initialize = sparc_tcg_init;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sparc_cpu_register_types(void *opaque)
|
void sparc_cpu_register_types(void *opaque)
|
||||||
|
|
|
@ -586,7 +586,7 @@ int sparc_cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
|
||||||
|
|
||||||
|
|
||||||
/* translate.c */
|
/* translate.c */
|
||||||
void gen_intermediate_code_init(CPUSPARCState *env);
|
void sparc_tcg_init(struct uc_struct *uc);
|
||||||
|
|
||||||
/* cpu-exec.c */
|
/* cpu-exec.c */
|
||||||
int cpu_sparc_exec(struct uc_struct *uc, CPUState *cpu);
|
int cpu_sparc_exec(struct uc_struct *uc, CPUState *cpu);
|
||||||
|
|
|
@ -141,9 +141,9 @@ static TCGv_i32 gen_load_fpr_F(DisasContext *dc, unsigned int src)
|
||||||
TCGContext *tcg_ctx = dc->uc->tcg_ctx;
|
TCGContext *tcg_ctx = dc->uc->tcg_ctx;
|
||||||
#if TCG_TARGET_REG_BITS == 32
|
#if TCG_TARGET_REG_BITS == 32
|
||||||
if (src & 1) {
|
if (src & 1) {
|
||||||
return TCGV_LOW(tcg_ctx->cpu_fpr[src / 2]);
|
return TCGV_LOW(tcg_ctx, tcg_ctx->cpu_fpr[src / 2]);
|
||||||
} else {
|
} else {
|
||||||
return TCGV_HIGH(tcg_ctx->cpu_fpr[src / 2]);
|
return TCGV_HIGH(tcg_ctx, tcg_ctx->cpu_fpr[src / 2]);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
TCGv_i32 ret = get_temp_i32(dc);
|
TCGv_i32 ret = get_temp_i32(dc);
|
||||||
|
@ -161,9 +161,9 @@ static void gen_store_fpr_F(DisasContext *dc, unsigned int dst, TCGv_i32 v)
|
||||||
TCGContext *tcg_ctx = dc->uc->tcg_ctx;
|
TCGContext *tcg_ctx = dc->uc->tcg_ctx;
|
||||||
#if TCG_TARGET_REG_BITS == 32
|
#if TCG_TARGET_REG_BITS == 32
|
||||||
if (dst & 1) {
|
if (dst & 1) {
|
||||||
tcg_gen_mov_i32(tcg_ctx, TCGV_LOW(tcg_ctx->cpu_fpr[dst / 2]), v);
|
tcg_gen_mov_i32(tcg_ctx, TCGV_LOW(tcg_ctx, tcg_ctx->cpu_fpr[dst / 2]), v);
|
||||||
} else {
|
} else {
|
||||||
tcg_gen_mov_i32(tcg_ctx, TCGV_HIGH(tcg_ctx->cpu_fpr[dst / 2]), v);
|
tcg_gen_mov_i32(tcg_ctx, TCGV_HIGH(tcg_ctx, tcg_ctx->cpu_fpr[dst / 2]), v);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
TCGv_i64 t = (TCGv_i64)v;
|
TCGv_i64 t = (TCGv_i64)v;
|
||||||
|
@ -5974,15 +5974,18 @@ void gen_intermediate_code(CPUState *cs, TranslationBlock * tb)
|
||||||
goto done_generating;
|
goto done_generating;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unicorn: FIXME: Amend to work with new TCG API
|
||||||
// Unicorn: trace this block on request
|
// Unicorn: trace this block on request
|
||||||
// Only hook this block if it is not broken from previous translation due to
|
// Only hook this block if it is not broken from previous translation due to
|
||||||
// full translation cache
|
// full translation cache
|
||||||
|
#if 0
|
||||||
if (!env->uc->block_full && HOOK_EXISTS_BOUNDED(env->uc, UC_HOOK_BLOCK, pc_start)) {
|
if (!env->uc->block_full && HOOK_EXISTS_BOUNDED(env->uc, UC_HOOK_BLOCK, pc_start)) {
|
||||||
// save block address to see if we need to patch block size later
|
// save block address to see if we need to patch block size later
|
||||||
env->uc->block_addr = pc_start;
|
env->uc->block_addr = pc_start;
|
||||||
env->uc->size_arg = tcg_ctx->gen_op_buf[tcg_ctx->gen_op_buf[0].prev].args;
|
env->uc->size_arg = tcg_ctx->gen_op_buf[tcg_ctx->gen_op_buf[0].prev].args;
|
||||||
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, UC_HOOK_BLOCK_IDX, env->uc, pc_start);
|
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, UC_HOOK_BLOCK_IDX, env->uc, pc_start);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
gen_tb_start(tcg_ctx, tb);
|
gen_tb_start(tcg_ctx, tb);
|
||||||
do {
|
do {
|
||||||
|
@ -6070,11 +6073,13 @@ done_generating:
|
||||||
env->uc->block_full = block_full;
|
env->uc->block_full = block_full;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gen_intermediate_code_init(CPUSPARCState *env)
|
void sparc_tcg_init(struct uc_struct *uc)
|
||||||
{
|
{
|
||||||
|
SPARCCPU *cpu = SPARC_CPU(s->uc, uc->cpu);
|
||||||
|
CPUSPARCState *env = &cpu->env;
|
||||||
TCGContext *tcg_ctx = env->uc->tcg_ctx;
|
TCGContext *tcg_ctx = env->uc->tcg_ctx;
|
||||||
struct uc_struct *uc = env->uc;
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
static const char gregnames[32][4] = {
|
static const char gregnames[32][4] = {
|
||||||
"g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
|
"g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
|
||||||
"o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
|
"o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
|
||||||
|
|
Loading…
Reference in a new issue