Support changing cpu model for riscv
This commit is contained in:
@ -329,7 +329,7 @@ static const CPUModelInfo cpu_models[] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
RISCVCPU *cpu_riscv_init(struct uc_struct *uc, const char *cpu_model)
|
RISCVCPU *cpu_riscv_init(struct uc_struct *uc)
|
||||||
{
|
{
|
||||||
RISCVCPU *cpu;
|
RISCVCPU *cpu;
|
||||||
CPUState *cs;
|
CPUState *cs;
|
||||||
@ -342,16 +342,21 @@ RISCVCPU *cpu_riscv_init(struct uc_struct *uc, const char *cpu_model)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TARGET_RISCV32
|
#ifdef TARGET_RISCV32
|
||||||
if (!cpu_model) {
|
if (uc->cpu_model == INT_MAX) {
|
||||||
cpu_model = TYPE_RISCV_CPU_SIFIVE_U34;
|
uc->cpu_model = 3;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* TARGET_RISCV64 */
|
/* TARGET_RISCV64 */
|
||||||
if (!cpu_model) {
|
if (uc->cpu_model == INT_MAX) {
|
||||||
cpu_model = TYPE_RISCV_CPU_SIFIVE_U54;
|
uc->cpu_model = 3;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (uc->cpu_model >= ARRAY_SIZE(cpu_models)) {
|
||||||
|
free(cpu);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
cs = (CPUState *)cpu;
|
cs = (CPUState *)cpu;
|
||||||
cc = (CPUClass *)&cpu->cc;
|
cc = (CPUClass *)&cpu->cc;
|
||||||
cs->cc = cc;
|
cs->cc = cc;
|
||||||
@ -390,12 +395,7 @@ RISCVCPU *cpu_riscv_init(struct uc_struct *uc, const char *cpu_model)
|
|||||||
riscv_cpu_init(uc, cs);
|
riscv_cpu_init(uc, cs);
|
||||||
|
|
||||||
/* init specific CPU model */
|
/* init specific CPU model */
|
||||||
for (i = 0; i < ARRAY_SIZE(cpu_models); i++) {
|
cpu_models[uc->cpu_model].initfn(cs);
|
||||||
if (strcmp(cpu_model, cpu_models[i].name) == 0) {
|
|
||||||
cpu_models[i].initfn(cs);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* realize CPU */
|
/* realize CPU */
|
||||||
riscv_cpu_realize(uc, cs);
|
riscv_cpu_realize(uc, cs);
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <unicorn/riscv.h>
|
#include <unicorn/riscv.h>
|
||||||
#include "unicorn.h"
|
#include "unicorn.h"
|
||||||
|
|
||||||
RISCVCPU *cpu_riscv_init(struct uc_struct *uc, const char *cpu_model);
|
RISCVCPU *cpu_riscv_init(struct uc_struct *uc);
|
||||||
|
|
||||||
static void riscv_set_pc(struct uc_struct *uc, uint64_t address)
|
static void riscv_set_pc(struct uc_struct *uc, uint64_t address)
|
||||||
{
|
{
|
||||||
@ -326,7 +326,7 @@ static int riscv_cpus_init(struct uc_struct *uc, const char *cpu_model)
|
|||||||
|
|
||||||
RISCVCPU *cpu;
|
RISCVCPU *cpu;
|
||||||
|
|
||||||
cpu = cpu_riscv_init(uc, cpu_model);
|
cpu = cpu_riscv_init(uc);
|
||||||
if (cpu == NULL) {
|
if (cpu == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user