From 0a759bf7f33c15aa64a60797516b5dcebc733173 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 3 Sep 2018 17:23:54 -0400 Subject: [PATCH] target/sparc: Fix SPARC target initialization Brings up the SPARC target so it's able to be used for emulation purposes. --- qemu/hw/sparc/leon3.c | 6 ++---- qemu/hw/sparc64/sun4u.c | 6 ++---- qemu/target/sparc/cpu.c | 7 +++---- qemu/target/sparc/translate.c | 3 +++ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/qemu/hw/sparc/leon3.c b/qemu/hw/sparc/leon3.c index 64ff7d6c..4e1d2a2d 100644 --- a/qemu/hw/sparc/leon3.c +++ b/qemu/hw/sparc/leon3.c @@ -38,11 +38,9 @@ static int leon3_generic_hw_init(struct uc_struct *uc, MachineState *machine) { - const char *cpu_type = parse_cpu_model(uc, "LEON3"); - SPARCCPU *cpu; + uc->cpu = cpu_create(uc, machine->cpu_type); - uc->cpu = cpu_create(uc, cpu_type); - cpu = SPARC_CPU(uc, uc->cpu); + SPARCCPU *cpu = SPARC_CPU(uc, uc->cpu); if (cpu == NULL) { fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n"); return -1; diff --git a/qemu/hw/sparc64/sun4u.c b/qemu/hw/sparc64/sun4u.c index e2e68810..7eb4100b 100644 --- a/qemu/hw/sparc64/sun4u.c +++ b/qemu/hw/sparc64/sun4u.c @@ -36,11 +36,9 @@ /* Sun4u hardware initialisation */ static int sun4u_init(struct uc_struct *uc, MachineState *machine) { - const char *cpu_type = parse_cpu_model(uc, "Sun UltraSparc IV"); - SPARCCPU *cpu; + uc->cpu = cpu_create(uc, machine->cpu_type); - uc->cpu = cpu_create(uc, cpu_type); - cpu = SPARC_CPU(uc, uc->cpu); + SPARCCPU *cpu = SPARC_CPU(uc, uc->cpu); if (cpu == NULL) { fprintf(stderr, "Unable to find Sparc CPU definition\n"); return -1; diff --git a/qemu/target/sparc/cpu.c b/qemu/target/sparc/cpu.c index 61c07a97..add44f83 100644 --- a/qemu/target/sparc/cpu.c +++ b/qemu/target/sparc/cpu.c @@ -869,12 +869,12 @@ static void sparc_cpu_cpudef_class_init(struct uc_struct *uc, ObjectClass *oc, v static void sparc_register_cpudef_type(struct uc_struct *uc, const struct sparc_def_t *def) { char *typename = sparc_cpu_type_name(def->name); - TypeInfo ti = { + const TypeInfo ti = { typename, TYPE_SPARC_CPU, 0, 0, - NULL, + uc, NULL, NULL, @@ -914,8 +914,7 @@ void sparc_cpu_register_types(void *opaque) true, }; - //printf(">>> sparc_cpu_register_types\n"); - type_register_static(opaque, &sparc_cpu_type_info); + type_register(opaque, &sparc_cpu_type_info); for (i = 0; i < ARRAY_SIZE(sparc_defs); i++) { sparc_register_cpudef_type(opaque, &sparc_defs[i]); } diff --git a/qemu/target/sparc/translate.c b/qemu/target/sparc/translate.c index 07820f9f..67f2046a 100644 --- a/qemu/target/sparc/translate.c +++ b/qemu/target/sparc/translate.c @@ -5950,6 +5950,9 @@ static void sparc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) */ bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; dc->base.max_insns = MIN(dc->base.max_insns, bound); + + // Unicorn: Initialize specifics for Unicorn + dc->uc = cs->uc; } static void sparc_tr_tb_start(DisasContextBase *db, CPUState *cs)