summaryrefslogtreecommitdiffstats
path: root/target/loongarch
diff options
context:
space:
mode:
authorXiaojuan Yang2022-07-19 08:44:06 +0200
committerRichard Henderson2022-07-19 18:23:58 +0200
commitc254f7affe9bb7303241c23cca66eb31f5effc1f (patch)
tree4172b135c8000b808a78e4a3011f2b4e8e99b453 /target/loongarch
parenttests/docker/dockerfiles: Add debian-loongarch-cross.docker (diff)
downloadqemu-c254f7affe9bb7303241c23cca66eb31f5effc1f.tar.gz
qemu-c254f7affe9bb7303241c23cca66eb31f5effc1f.tar.xz
qemu-c254f7affe9bb7303241c23cca66eb31f5effc1f.zip
target/loongarch: Fix loongarch_cpu_class_by_name
The cpu_model argument may already have the '-loongarch-cpu' suffix, e.g. when using the default for the LS7A1000 machine. If that fails, try again with the suffix. Validate that the object created by the function is derived from the proper base class. Signed-off-by: Xiaojuan Yang <yangxiaojuan@loongson.cn> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20220715060740.1500628-2-yangxiaojuan@loongson.cn> [rth: Try without and then with the suffix, to avoid testsuite breakage.] Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'target/loongarch')
-rw-r--r--target/loongarch/cpu.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index e21715592a..5573468a7d 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -571,12 +571,22 @@ static void loongarch_cpu_init(Object *obj)
static ObjectClass *loongarch_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
- char *typename;
- typename = g_strdup_printf(LOONGARCH_CPU_TYPE_NAME("%s"), cpu_model);
- oc = object_class_by_name(typename);
- g_free(typename);
- return oc;
+ oc = object_class_by_name(cpu_model);
+ if (!oc) {
+ g_autofree char *typename
+ = g_strdup_printf(LOONGARCH_CPU_TYPE_NAME("%s"), cpu_model);
+ oc = object_class_by_name(typename);
+ if (!oc) {
+ return NULL;
+ }
+ }
+
+ if (object_class_dynamic_cast(oc, TYPE_LOONGARCH_CPU)
+ && !object_class_is_abstract(oc)) {
+ return oc;
+ }
+ return NULL;
}
void loongarch_cpu_dump_state(CPUState *cs, FILE *f, int flags)