From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WICZQ-0002n2-Rq for qemu-devel@nongnu.org; Tue, 25 Feb 2014 02:36:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WICZJ-0004zT-9E for qemu-devel@nongnu.org; Tue, 25 Feb 2014 02:36:52 -0500 Received: from cantor2.suse.de ([195.135.220.15]:35571 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WICZJ-0004zG-2e for qemu-devel@nongnu.org; Tue, 25 Feb 2014 02:36:45 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 25 Feb 2014 08:36:26 +0100 Message-Id: <1393313787-890-2-git-send-email-afaerber@suse.de> In-Reply-To: <1393313787-890-1-git-send-email-afaerber@suse.de> References: <1393313787-890-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH qom-cpu v10 1/2] target-i386: Prepare CPUClass::class_by_name for X86CPU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Eduardo Habkost , Anthony Liguori , Igor Mammedov Signed-off-by: Eduardo Habkost Signed-off-by: Andreas F=C3=A4rber --- target-i386/cpu.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index a8b8e88..1c009bb 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -484,6 +484,15 @@ static void add_flagname_to_bitmaps(const char *flag= name, } } =20 +static ObjectClass *x86_cpu_class_by_name(const char *cpu_model) +{ + if (cpu_model =3D=3D NULL) { + return NULL; + } + + return object_class_by_name(TYPE_X86_CPU); +} + typedef struct X86CPUDefinition { const char *name; uint32_t level; @@ -1881,6 +1890,7 @@ X86CPU *cpu_x86_create(const char *cpu_model, Devic= eState *icc_bridge, Error **errp) { X86CPU *cpu =3D NULL; + ObjectClass *oc; gchar **model_pieces; char *name, *features; char *typename; @@ -1894,7 +1904,12 @@ X86CPU *cpu_x86_create(const char *cpu_model, Devi= ceState *icc_bridge, name =3D model_pieces[0]; features =3D model_pieces[1]; =20 - cpu =3D X86_CPU(object_new(TYPE_X86_CPU)); + oc =3D x86_cpu_class_by_name(name); + if (oc =3D=3D NULL) { + error_setg(&error, "Unable to find CPU definition: %s", name); + goto out; + } + cpu =3D X86_CPU(object_new(object_class_get_name(oc))); x86_cpu_load_def(cpu, name, &error); if (error) { goto out; @@ -1925,8 +1940,10 @@ X86CPU *cpu_x86_create(const char *cpu_model, Devi= ceState *icc_bridge, out: if (error !=3D NULL) { error_propagate(errp, error); - object_unref(OBJECT(cpu)); - cpu =3D NULL; + if (cpu) { + object_unref(OBJECT(cpu)); + cpu =3D NULL; + } } g_strfreev(model_pieces); return cpu; @@ -2739,6 +2756,7 @@ static void x86_cpu_common_class_init(ObjectClass *= oc, void *data) cc->reset =3D x86_cpu_reset; cc->reset_dump_flags =3D CPU_DUMP_FPU | CPU_DUMP_CCOP; =20 + cc->class_by_name =3D x86_cpu_class_by_name; cc->has_work =3D x86_cpu_has_work; cc->do_interrupt =3D x86_cpu_do_interrupt; cc->dump_state =3D x86_cpu_dump_state; --=20 1.8.4.5