Skip to content

Commit

Permalink
target/riscv: add riscv_cpu_get_name()
Browse files Browse the repository at this point in the history
We'll introduce generic errors that will output a CPU type name via its
RISCVCPU pointer. Create a helper for that.

Use the helper in tcg_cpu_realizefn() instead of hardcoding the 'host'
CPU name.

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20230926183109.165878-2-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
  • Loading branch information
danielhb authored and alistair23 committed Oct 12, 2023
1 parent 3177844 commit b933720
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions target/riscv/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,17 @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model)
return oc;
}

char *riscv_cpu_get_name(RISCVCPU *cpu)
{
RISCVCPUClass *rcc = RISCV_CPU_GET_CLASS(cpu);
const char *typename = object_class_get_name(OBJECT_CLASS(rcc));

g_assert(g_str_has_suffix(typename, RISCV_CPU_TYPE_SUFFIX));

return g_strndup(typename,
strlen(typename) - strlen(RISCV_CPU_TYPE_SUFFIX));
}

static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
{
RISCVCPU *cpu = RISCV_CPU(cs);
Expand Down
1 change: 1 addition & 0 deletions target/riscv/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ typedef struct isa_ext_data {
int ext_enable_offset;
} RISCVIsaExtData;
extern const RISCVIsaExtData isa_edata_arr[];
char *riscv_cpu_get_name(RISCVCPU *cpu);

void riscv_add_satp_mode_properties(Object *obj);

Expand Down
4 changes: 3 additions & 1 deletion target/riscv/tcg/tcg-cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp)
Error *local_err = NULL;

if (object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) {
error_setg(errp, "'host' CPU is not compatible with TCG acceleration");
g_autofree char *name = riscv_cpu_get_name(cpu);
error_setg(errp, "'%s' CPU is not compatible with TCG acceleration",
name);
return false;
}

Expand Down

0 comments on commit b933720

Please sign in to comment.