mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
target/riscv: add more RISCVCPUDef fields
Allow using RISCVCPUDef to replicate all the logic of custom .instance_init functions. To simulate inheritance, merge the child's RISCVCPUDef with the parent and then finally move it to the CPUState at the end of TYPE_RISCV_CPU's own instance_init function. Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
407254031e
commit
a6ba81424a
3 changed files with 51 additions and 1 deletions
|
@ -73,6 +73,13 @@ bool riscv_cpu_option_set(const char *optname)
|
|||
return g_hash_table_contains(general_user_opts, optname);
|
||||
}
|
||||
|
||||
static void riscv_cpu_cfg_merge(RISCVCPUConfig *dest, const RISCVCPUConfig *src)
|
||||
{
|
||||
#define BOOL_FIELD(x) dest->x |= src->x;
|
||||
#define TYPED_FIELD(type, x, default_) if (src->x != default_) dest->x = src->x;
|
||||
#include "cpu_cfg_fields.h.inc"
|
||||
}
|
||||
|
||||
#define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \
|
||||
{#_name, _min_ver, CPU_CFG_OFFSET(_prop)}
|
||||
|
||||
|
@ -434,7 +441,7 @@ const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit)
|
|||
}
|
||||
|
||||
static void set_satp_mode_max_supported(RISCVCPU *cpu,
|
||||
uint8_t satp_mode)
|
||||
int satp_mode)
|
||||
{
|
||||
bool rv32 = riscv_cpu_mxl(&cpu->env) == MXL_RV32;
|
||||
const bool *valid_vm = rv32 ? valid_vm_1_10_32 : valid_vm_1_10_64;
|
||||
|
@ -1479,6 +1486,16 @@ static void riscv_cpu_init(Object *obj)
|
|||
cpu->cfg.cboz_blocksize = 64;
|
||||
cpu->env.vext_ver = VEXT_VERSION_1_00_0;
|
||||
cpu->cfg.max_satp_mode = -1;
|
||||
|
||||
env->misa_ext_mask = env->misa_ext = mcc->def->misa_ext;
|
||||
riscv_cpu_cfg_merge(&cpu->cfg, &mcc->def->cfg);
|
||||
|
||||
if (mcc->def->priv_spec != RISCV_PROFILE_ATTR_UNUSED) {
|
||||
cpu->env.priv_ver = mcc->def->priv_spec;
|
||||
}
|
||||
if (mcc->def->vext_spec != RISCV_PROFILE_ATTR_UNUSED) {
|
||||
cpu->env.vext_ver = mcc->def->vext_spec;
|
||||
}
|
||||
}
|
||||
|
||||
static void riscv_bare_cpu_init(Object *obj)
|
||||
|
@ -3087,6 +3104,17 @@ static void riscv_cpu_class_base_init(ObjectClass *c, const void *data)
|
|||
assert(def->misa_mxl_max <= MXL_RV128);
|
||||
mcc->def->misa_mxl_max = def->misa_mxl_max;
|
||||
}
|
||||
if (def->priv_spec != RISCV_PROFILE_ATTR_UNUSED) {
|
||||
assert(def->priv_spec <= PRIV_VERSION_LATEST);
|
||||
mcc->def->priv_spec = def->priv_spec;
|
||||
}
|
||||
if (def->vext_spec != RISCV_PROFILE_ATTR_UNUSED) {
|
||||
assert(def->vext_spec != 0);
|
||||
mcc->def->vext_spec = def->vext_spec;
|
||||
}
|
||||
mcc->def->misa_ext |= def->misa_ext;
|
||||
|
||||
riscv_cpu_cfg_merge(&mcc->def->cfg, &def->cfg);
|
||||
}
|
||||
|
||||
if (!object_class_is_abstract(c)) {
|
||||
|
@ -3193,6 +3221,9 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename)
|
|||
.instance_init = (initfn), \
|
||||
.class_data = &(const RISCVCPUDef) { \
|
||||
.misa_mxl_max = (misa_mxl_max_), \
|
||||
.priv_spec = RISCV_PROFILE_ATTR_UNUSED, \
|
||||
.vext_spec = RISCV_PROFILE_ATTR_UNUSED, \
|
||||
.cfg.max_satp_mode = -1, \
|
||||
}, \
|
||||
}
|
||||
|
||||
|
@ -3203,6 +3234,9 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename)
|
|||
.instance_init = (initfn), \
|
||||
.class_data = &(const RISCVCPUDef) { \
|
||||
.misa_mxl_max = (misa_mxl_max_), \
|
||||
.priv_spec = RISCV_PROFILE_ATTR_UNUSED, \
|
||||
.vext_spec = RISCV_PROFILE_ATTR_UNUSED, \
|
||||
.cfg.max_satp_mode = -1, \
|
||||
}, \
|
||||
}
|
||||
|
||||
|
@ -3213,6 +3247,9 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename)
|
|||
.instance_init = (initfn), \
|
||||
.class_data = &(const RISCVCPUDef) { \
|
||||
.misa_mxl_max = (misa_mxl_max_), \
|
||||
.priv_spec = RISCV_PROFILE_ATTR_UNUSED, \
|
||||
.vext_spec = RISCV_PROFILE_ATTR_UNUSED, \
|
||||
.cfg.max_satp_mode = -1, \
|
||||
}, \
|
||||
}
|
||||
|
||||
|
@ -3223,6 +3260,9 @@ void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename)
|
|||
.instance_init = (initfn), \
|
||||
.class_data = &(const RISCVCPUDef) { \
|
||||
.misa_mxl_max = (misa_mxl_max_), \
|
||||
.priv_spec = RISCV_PROFILE_ATTR_UNUSED, \
|
||||
.vext_spec = RISCV_PROFILE_ATTR_UNUSED, \
|
||||
.cfg.max_satp_mode = -1, \
|
||||
}, \
|
||||
}
|
||||
|
||||
|
|
|
@ -540,6 +540,10 @@ struct ArchCPU {
|
|||
|
||||
typedef struct RISCVCPUDef {
|
||||
RISCVMXL misa_mxl_max; /* max mxl for this cpu */
|
||||
uint32_t misa_ext;
|
||||
int priv_spec;
|
||||
int32_t vext_spec;
|
||||
RISCVCPUConfig cfg;
|
||||
} RISCVCPUDef;
|
||||
|
||||
/**
|
||||
|
|
|
@ -2093,10 +2093,16 @@ static const TypeInfo riscv_kvm_cpu_type_infos[] = {
|
|||
#if defined(TARGET_RISCV32)
|
||||
.class_data = &(const RISCVCPUDef) {
|
||||
.misa_mxl_max = MXL_RV32,
|
||||
.priv_spec = RISCV_PROFILE_ATTR_UNUSED,
|
||||
.vext_spec = RISCV_PROFILE_ATTR_UNUSED,
|
||||
.cfg.max_satp_mode = -1,
|
||||
},
|
||||
#elif defined(TARGET_RISCV64)
|
||||
.class_data = &(const RISCVCPUDef) {
|
||||
.misa_mxl_max = MXL_RV64,
|
||||
.priv_spec = RISCV_PROFILE_ATTR_UNUSED,
|
||||
.vext_spec = RISCV_PROFILE_ATTR_UNUSED,
|
||||
.cfg.max_satp_mode = -1,
|
||||
},
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue