diff options
author | Andreas Färber <afaerber@suse.de> | 2014-03-04 03:17:10 +0100 |
---|---|---|
committer | Andreas Färber <afaerber@suse.de> | 2014-03-13 19:20:46 +0100 |
commit | 9262685b818512215f0829f0dc95c2363898a1ad (patch) | |
tree | a45bd8ce1dbcb4eaecbe6ad67af4f91d49c94f28 /qom/cpu.c | |
parent | 1590bbcb02921dfe8e3cf66e3a3aafd31193babf (diff) |
cpu: Factor out cpu_generic_init()
All targets using it gain the ability to set -cpu name,key=value,...
options via the default TYPE_CPU CPUClass::parse_features() implementation.
Signed-off-by: Andreas Färber <afaerber@suse.de>
Diffstat (limited to 'qom/cpu.c')
-rw-r--r-- | qom/cpu.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -23,6 +23,7 @@ #include "sysemu/kvm.h" #include "qemu/notify.h" #include "qemu/log.h" +#include "qemu/error-report.h" #include "sysemu/sysemu.h" bool cpu_exists(int64_t id) @@ -39,6 +40,46 @@ bool cpu_exists(int64_t id) return false; } +CPUState *cpu_generic_init(const char *typename, const char *cpu_model) +{ + char *str, *name, *featurestr; + CPUState *cpu; + ObjectClass *oc; + CPUClass *cc; + Error *err = NULL; + + str = g_strdup(cpu_model); + name = strtok(str, ","); + + oc = cpu_class_by_name(typename, name); + if (oc == NULL) { + g_free(str); + return NULL; + } + + cpu = CPU(object_new(object_class_get_name(oc))); + cc = CPU_GET_CLASS(cpu); + + featurestr = strtok(NULL, ","); + cc->parse_features(cpu, featurestr, &err); + g_free(str); + if (err != NULL) { + goto out; + } + + object_property_set_bool(OBJECT(cpu), true, "realized", &err); + +out: + if (err != NULL) { + error_report("%s", error_get_pretty(err)); + error_free(err); + object_unref(OBJECT(cpu)); + return NULL; + } + + return cpu; +} + bool cpu_paging_enabled(const CPUState *cpu) { CPUClass *cc = CPU_GET_CLASS(cpu); |