From patchwork Sat Feb 2 00:37:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 217631 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 824032C0094 for ; Sat, 2 Feb 2013 11:38:31 +1100 (EST) Received: from localhost ([::1]:44609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1R7l-00016y-GB for incoming@patchwork.ozlabs.org; Fri, 01 Feb 2013 19:38:29 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1R7N-000110-SB for qemu-devel@nongnu.org; Fri, 01 Feb 2013 19:38:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1R7L-0007rX-PE for qemu-devel@nongnu.org; Fri, 01 Feb 2013 19:38:05 -0500 Received: from cantor2.suse.de ([195.135.220.15]:51150 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1R7L-0007UY-GI for qemu-devel@nongnu.org; Fri, 01 Feb 2013 19:38:03 -0500 Received: from relay2.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 7C5F3A3A49; Sat, 2 Feb 2013 01:37:22 +0100 (CET) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: qemu-devel@nongnu.org Date: Sat, 2 Feb 2013 01:37:06 +0100 Message-Id: <1359765428-27805-3-git-send-email-afaerber@suse.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1359765428-27805-1-git-send-email-afaerber@suse.de> References: <1359765428-27805-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 195.135.220.15 Cc: blauwirbel@gmail.com, imammedo@redhat.com, ehabkost@redhat.com, anthony@codemonkey.ws, =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH qom-cpu-next v3 2/4] target-i386: Split command line parsing out of cpu_x86_register() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In order to instantiate a CPU subtype we will need to know which type, so move the cpu_model splitting into cpu_x86_init(). Parameters need to be set on the X86CPU instance, so move cpu_x86_parse_featurestr() into cpu_x86_init() as well. This leaves cpu_x86_register() operating on the model name only. Signed-off-by: Andreas Färber --- target-i386/cpu.c | 50 +++++++++++++++++++++++++++++++------------------- 1 Datei geändert, 31 Zeilen hinzugefügt(+), 19 Zeilen entfernt(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index e74802b..ee2fd6b 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1516,24 +1516,14 @@ static void filter_features_for_kvm(X86CPU *cpu) } #endif -static int cpu_x86_register(X86CPU *cpu, const char *cpu_model) +static int cpu_x86_register(X86CPU *cpu, const char *name) { CPUX86State *env = &cpu->env; x86_def_t def1, *def = &def1; Error *error = NULL; - char *name, *features; - gchar **model_pieces; memset(def, 0, sizeof(*def)); - model_pieces = g_strsplit(cpu_model, ",", 2); - if (!model_pieces[0]) { - error_setg(&error, "Invalid/empty CPU model name"); - goto out; - } - name = model_pieces[0]; - features = model_pieces[1]; - if (cpu_x86_find_by_name(def, name) < 0) { error_setg(&error, "Unable to find CPU definition: %s", name); goto out; @@ -1565,9 +1555,7 @@ static int cpu_x86_register(X86CPU *cpu, const char *cpu_model) goto out; } - cpu_x86_parse_featurestr(cpu, features, &error); out: - g_strfreev(model_pieces); if (error) { fprintf(stderr, "%s\n", error_get_pretty(error)); error_free(error); @@ -1578,26 +1566,50 @@ out: X86CPU *cpu_x86_init(const char *cpu_model) { - X86CPU *cpu; + X86CPU *cpu = NULL; CPUX86State *env; + gchar **model_pieces; + char *name, *features; Error *error = NULL; + model_pieces = g_strsplit(cpu_model, ",", 2); + if (!model_pieces[0]) { + error_setg(&error, "Invalid/empty CPU model name"); + goto error; + } + name = model_pieces[0]; + features = model_pieces[1]; + cpu = X86_CPU(object_new(TYPE_X86_CPU)); env = &cpu->env; env->cpu_model_str = cpu_model; - if (cpu_x86_register(cpu, cpu_model) < 0) { - object_delete(OBJECT(cpu)); - return NULL; + if (cpu_x86_register(cpu, name) < 0) { + goto error; + } + + cpu_x86_parse_featurestr(cpu, features, &error); + if (error) { + goto error; } object_property_set_bool(OBJECT(cpu), true, "realized", &error); if (error) { + goto error; + } + g_strfreev(model_pieces); + return cpu; + +error: + g_strfreev(model_pieces); + if (error) { + fprintf(stderr, "%s\n", error_get_pretty(error)); error_free(error); + } + if (cpu != NULL) { object_delete(OBJECT(cpu)); - return NULL; } - return cpu; + return NULL; } #if !defined(CONFIG_USER_ONLY)