Patchwork [qom-cpu,for-1.4] target-m68k: Rename CPU types

login
register
mail settings
Submitter Andreas Färber
Date Jan. 27, 2013, 7:18 p.m.
Message ID <1359314286-8305-1-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/216031/
State New
Headers show

Comments

Andreas Färber - Jan. 27, 2013, 7:18 p.m.
In the initial conversion of CPU models to QOM types, model names were
mapped 1:1 to type names. As a side effect this gained us a type "any",
which is now a device.

To avoid "-device any" silliness and to pave the way for compiling
multiple targets into one executable, adopt a <name>-<arch>-cpu scheme.

No functional changes for -cpu arguments or -cpu ? output.

Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 target-m68k/cpu.c    |    8 ++++++--
 target-m68k/helper.c |   11 ++++++++---
 2 Dateien geändert, 14 Zeilen hinzugefügt(+), 5 Zeilen entfernt(-)
Andreas Färber - Jan. 29, 2013, 10:44 p.m.
Am 27.01.2013 20:18, schrieb Andreas Färber:
> In the initial conversion of CPU models to QOM types, model names were
> mapped 1:1 to type names. As a side effect this gained us a type "any",
> which is now a device.
> 
> To avoid "-device any" silliness and to pave the way for compiling
> multiple targets into one executable, adopt a <name>-<arch>-cpu scheme.
> 
> No functional changes for -cpu arguments or -cpu ? output.
> 
> Signed-off-by: Andreas Färber <afaerber@suse.de>

Applied to qom-cpu (after verifying that env->cpu_model_str is correct):
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Andreas

Patch

diff --git a/target-m68k/cpu.c b/target-m68k/cpu.c
index 5c78031..32aaea3 100644
--- a/target-m68k/cpu.c
+++ b/target-m68k/cpu.c
@@ -58,12 +58,15 @@  static void m68k_cpu_reset(CPUState *s)
 static ObjectClass *m68k_cpu_class_by_name(const char *cpu_model)
 {
     ObjectClass *oc;
+    char *typename;
 
     if (cpu_model == NULL) {
         return NULL;
     }
 
-    oc = object_class_by_name(cpu_model);
+    typename = g_strdup_printf("%s-" TYPE_M68K_CPU, cpu_model);
+    oc = object_class_by_name(typename);
+    g_free(typename);
     if (oc != NULL && (object_class_dynamic_cast(oc, TYPE_M68K_CPU) == NULL ||
                        object_class_is_abstract(oc))) {
         return NULL;
@@ -157,12 +160,13 @@  static void m68k_cpu_class_init(ObjectClass *c, void *data)
 static void register_cpu_type(const M68kCPUInfo *info)
 {
     TypeInfo type_info = {
-        .name = info->name,
         .parent = TYPE_M68K_CPU,
         .instance_init = info->instance_init,
     };
 
+    type_info.name = g_strdup_printf("%s-" TYPE_M68K_CPU, info->name);
     type_register(&type_info);
+    g_free((void *)type_info.name);
 }
 
 static const TypeInfo m68k_cpu_type_info = {
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index f66e12b..5ddcd70 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -34,9 +34,9 @@  static gint m68k_cpu_list_compare(gconstpointer a, gconstpointer b)
 
     name_a = object_class_get_name(class_a);
     name_b = object_class_get_name(class_b);
-    if (strcmp(name_a, "any") == 0) {
+    if (strcmp(name_a, "any-" TYPE_M68K_CPU) == 0) {
         return 1;
-    } else if (strcmp(name_b, "any") == 0) {
+    } else if (strcmp(name_b, "any-" TYPE_M68K_CPU) == 0) {
         return -1;
     } else {
         return strcasecmp(name_a, name_b);
@@ -47,9 +47,14 @@  static void m68k_cpu_list_entry(gpointer data, gpointer user_data)
 {
     ObjectClass *c = data;
     CPUListState *s = user_data;
+    const char *typename;
+    char *name;
 
+    typename = object_class_get_name(c);
+    name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_M68K_CPU));
     (*s->cpu_fprintf)(s->file, "%s\n",
-                      object_class_get_name(c));
+                      name);
+    g_free(name);
 }
 
 void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf)