@@ -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
@@ -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)
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 <ehabkost@redhat.com> --- include/qemu/cpu.h | 24 ++++++++++++++++++++++++ qom/cpu.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)