diff --git a/qemu/target/mips/cpu.c b/qemu/target/mips/cpu.c index 43f55687..e29c44f1 100644 --- a/qemu/target/mips/cpu.c +++ b/qemu/target/mips/cpu.c @@ -150,28 +150,29 @@ static void mips_cpu_class_init(CPUClass *c) cc->tlb_fill = mips_cpu_tlb_fill; } -MIPSCPU *cpu_mips_init(struct uc_struct *uc, const char *cpu_model) +MIPSCPU *cpu_mips_init(struct uc_struct *uc) { MIPSCPU *cpu; CPUState *cs; CPUClass *cc; CPUMIPSState *env; - int i; - - if (cpu_model == NULL) { -#ifdef TARGET_MIPS64 - cpu_model = "R4000"; -#else - // Add UC_MODE_ flag to select model? - cpu_model = "74Kf"; -#endif - } cpu = calloc(1, sizeof(*cpu)); if (cpu == NULL) { return NULL; } + if (uc->cpu_model == INT_MAX) { +#ifdef TARGET_MIPS64 + uc->cpu_model = 17; // R4000 +#else + uc->cpu_model = 10; // 74kf +#endif + } else if (uc->cpu_model >= mips_defs_number) { + free(cpu); + return NULL; + } + cs = (CPUState *)cpu; cc = (CPUClass *)&cpu->cc; cs->cc = cc; @@ -187,12 +188,8 @@ MIPSCPU *cpu_mips_init(struct uc_struct *uc, const char *cpu_model) mips_cpu_initfn(uc, cs); env = &cpu->env; - for (i = 0; i < mips_defs_number; i++) { - if (strcasecmp(cpu_model, mips_defs[i].name) == 0) { - env->cpu_model = &(mips_defs[i]); - break; - } - } + env->cpu_model = &(mips_defs[uc->cpu_model]); + if (env->cpu_model == NULL) { free(cpu); return NULL; diff --git a/qemu/target/mips/unicorn.c b/qemu/target/mips/unicorn.c index c2840828..00e1c26a 100644 --- a/qemu/target/mips/unicorn.c +++ b/qemu/target/mips/unicorn.c @@ -15,7 +15,7 @@ typedef uint64_t mipsreg_t; typedef uint32_t mipsreg_t; #endif -MIPSCPU *cpu_mips_init(struct uc_struct *uc, const char *cpu_model); +MIPSCPU *cpu_mips_init(struct uc_struct *uc); static uint64_t mips_mem_redirect(uint64_t address) { @@ -226,7 +226,7 @@ static int mips_cpus_init(struct uc_struct *uc, const char *cpu_model) { MIPSCPU *cpu; - cpu = cpu_mips_init(uc, NULL); + cpu = cpu_mips_init(uc); if (cpu == NULL) { return -1; }