qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC 10/20] cpu: introduce generic_cpu_init() & generic_cpu


From: Eduardo Habkost
Subject: [Qemu-devel] [RFC 10/20] cpu: introduce generic_cpu_init() & generic_cpu_create() functions
Date: Tue, 18 Dec 2012 18:04:03 -0200

Useful for architectures where cpu_init() is just creation of a CPU
object and a call to cpu_realize().

All the functions should need is the base CPU class name and cpu_model
string. Any target-specific behavior/information can later be provided
by the target-specific CPU class, if necessary.

Signed-off-by: Eduardo Habkost <address@hidden>
---
 include/qemu/cpu.h | 24 ++++++++++++++++++++++++
 qom/cpu.c          | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 90bb27d..7461319 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -151,4 +151,28 @@ bool cpu_is_stopped(CPUState *cpu);
 void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
 
 
+/* generic_cpu_create:
+ * @base_class_name: The name of the base CPU class
+ * @cpu_model: full CPU model string to be parsed
+ * @errp: pointer to Error pointer, where error information can be returned
+ *
+ * Generic target-independent function to create a CPU object. Caller
+ * should call cpu_realize() later.
+ *
+ * Any target-specific behavior can be set as CPUClass fields in the base 
class.
+ */
+CPUState *generic_cpu_create(const char *base_class_name,
+                             const char *cpu_model,
+                             Error **errp);
+
+/* generic_cpu_init:
+ * @base_class_name: The name of the base CPU class
+ * @cpu_model: full CPU model string to be parsed
+ *
+ * Generic target-independent cpu_init implementation. Any target-specific
+ * behavior can be set as CPUClass fields in the base class.
+ */
+CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model);
+
+
 #endif
diff --git a/qom/cpu.c b/qom/cpu.c
index a96f6ee..42cbe42 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/cpu.h"
+#include "qemu-error.h"
 #include "qemu-common.h"
 
 void cpu_reset(CPUState *cpu)
@@ -65,4 +66,41 @@ static void cpu_register_types(void)
     type_register_static(&cpu_type_info);
 }
 
+CPUState *generic_cpu_create(const char *base_class_name,
+                             const char *cpu_model,
+                             Error **errp)
+{
+    CPUState *cpu;
+
+    if (!object_class_by_name(cpu_model)) {
+        error_setg(errp, "Can't find CPU class for model: %s", cpu_model);
+        return NULL;
+    }
+
+    cpu = CPU(object_new(cpu_model));
+    cpu->cpu_model_str = cpu_model;
+    return cpu;
+}
+
+CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model)
+{
+    CPUState *cpu;
+    Error *err = NULL;
+
+    cpu = generic_cpu_create(base_class_name, cpu_model, &err);
+    if (err) {
+        goto error;
+    }
+
+    cpu_realize(cpu, &err);
+    if (err) {
+        goto error;
+    }
+
+    return cpu;
+error:
+    error_report("cpu_init: %s", error_get_pretty(err));
+    return NULL;
+}
+
 type_init(cpu_register_types)
-- 
1.7.11.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]