From patchwork Sat Apr 14 01:00:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 152465 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 3DACFB7012 for ; Sat, 14 Apr 2012 11:01:27 +1000 (EST) Received: from localhost ([::1]:47093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIrMj-0002cm-4R for incoming@patchwork.ozlabs.org; Fri, 13 Apr 2012 21:01:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:50667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIrM2-0000z6-0j for qemu-devel@nongnu.org; Fri, 13 Apr 2012 21:00:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SIrLz-0007eJ-3Y for qemu-devel@nongnu.org; Fri, 13 Apr 2012 21:00:41 -0400 Received: from mail-lpp01m010-f45.google.com ([209.85.215.45]:41237) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIrLy-0007cU-Q1 for qemu-devel@nongnu.org; Fri, 13 Apr 2012 21:00:39 -0400 Received: by mail-lpp01m010-f45.google.com with SMTP id e6so2872971lah.4 for ; Fri, 13 Apr 2012 18:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=OarsltBrP70bvRNG1LIHnmKTqvoeuXRKx1YM6cF80dg=; b=uoeWf6CAmL5pcuNNN/oqT8QOiiPmspO1DhcgBnApMCNKeEuh2oUMQHcZW3uGFZtWiH najjKg/O4c590AK1QgBi/9KDeBjKN87IXstK5RH52zBqpNDlUqdlzi4Ypg6zj0lOOj0J jyHevdVN2S3WsigMHKhcVtFmsWQ7ingopEDmxmZv07RYS1QSl8i4bgH51rZo/KGK420Z 7b47XZTx1vyys1gdD1HvmqnvF6kDSClEXhNrDgKVVxc/exLd9P0oSRKpbIzAuWbxE7O2 lYFQyXMEFGGOORN0582NalX63uT5myeX7V3i8bixu3D4ysQgfTxGKTBnSEnqPb+F/ZKp p9yw== Received: by 10.152.125.41 with SMTP id mn9mr3236971lab.30.1334365237729; Fri, 13 Apr 2012 18:00:37 -0700 (PDT) Received: from octofox.metropolis ([188.134.19.124]) by mx.google.com with ESMTPS id mk9sm11148911lab.0.2012.04.13.18.00.34 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 Apr 2012 18:00:36 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Sat, 14 Apr 2012 05:00:11 +0400 Message-Id: <1334365213-15986-4-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1334365213-15986-1-git-send-email-jcmvbkbc@gmail.com> References: <1334365213-15986-1-git-send-email-jcmvbkbc@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.215.45 Cc: Blue Swirl , Max Filippov , Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 3/5] target-xtensa: QOM'ify CPU 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 From: Andreas Färber Embed CPUXtensaState as first member of XtensaCPU. Let CPUClass::reset() call cpu_state_reset() for now. Signed-off-by: Andreas Färber Signed-off-by: Max Filippov --- Makefile.target | 1 + target-xtensa/cpu-qom.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++ target-xtensa/cpu.c | 69 ++++++++++++++++++++++++++++++++++++++++ target-xtensa/cpu.h | 1 + target-xtensa/helper.c | 4 ++- 5 files changed, 154 insertions(+), 1 deletions(-) create mode 100644 target-xtensa/cpu-qom.h create mode 100644 target-xtensa/cpu.c diff --git a/Makefile.target b/Makefile.target index e88b896..75b97ae 100644 --- a/Makefile.target +++ b/Makefile.target @@ -102,6 +102,7 @@ endif libobj-$(TARGET_SPARC) += int32_helper.o libobj-$(TARGET_SPARC64) += int64_helper.o libobj-$(TARGET_UNICORE32) += cpu.o +libobj-$(TARGET_XTENSA) += cpu.o libobj-$(TARGET_ALPHA) += int_helper.o fpu_helper.o sys_helper.o mem_helper.o libobj-y += disas.o diff --git a/target-xtensa/cpu-qom.h b/target-xtensa/cpu-qom.h new file mode 100644 index 0000000..1fd2f27 --- /dev/null +++ b/target-xtensa/cpu-qom.h @@ -0,0 +1,80 @@ +/* + * QEMU Xtensa CPU + * + * Copyright (c) 2012 SUSE LINUX Products GmbH + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Open Source and Linux Lab nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef QEMU_XTENSA_CPU_QOM_H +#define QEMU_XTENSA_CPU_QOM_H + +#include "qemu/cpu.h" +#include "cpu.h" + +#define TYPE_XTENSA_CPU "xtensa-cpu" + +#define XTENSA_CPU_CLASS(class) \ + OBJECT_CLASS_CHECK(XtensaCPUClass, (class), TYPE_XTENSA_CPU) +#define XTENSA_CPU(obj) \ + OBJECT_CHECK(XtensaCPU, (obj), TYPE_XTENSA_CPU) +#define XTENSA_CPU_GET_CLASS(obj) \ + OBJECT_GET_CLASS(XtensaCPUClass, (obj), TYPE_XTENSA_CPU) + +/** + * XtensaCPUClass: + * @parent_reset: The parent class' reset handler. + * + * An Xtensa CPU model. + */ +typedef struct XtensaCPUClass { + /*< private >*/ + CPUClass parent_class; + /*< public >*/ + + void (*parent_reset)(CPUState *cpu); +} XtensaCPUClass; + +/** + * XtensaCPU: + * @env: #CPUXtensaState + * + * An Xtensa CPU. + */ +typedef struct XtensaCPU { + /*< private >*/ + CPUState parent_obj; + /*< public >*/ + + CPUXtensaState env; +} XtensaCPU; + +static inline XtensaCPU *xtensa_env_get_cpu(const CPUXtensaState *env) +{ + return XTENSA_CPU(container_of(env, XtensaCPU, env)); +} + +#define ENV_GET_CPU(e) CPU(xtensa_env_get_cpu(e)) + + +#endif diff --git a/target-xtensa/cpu.c b/target-xtensa/cpu.c new file mode 100644 index 0000000..d68be22 --- /dev/null +++ b/target-xtensa/cpu.c @@ -0,0 +1,69 @@ +/* + * QEMU Xtensa CPU + * + * Copyright (c) 2012 SUSE LINUX Products GmbH + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Open Source and Linux Lab nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "cpu-qom.h" +#include "qemu-common.h" + + +/* CPUClass::reset() */ +static void xtensa_cpu_reset(CPUState *s) +{ + XtensaCPU *cpu = XTENSA_CPU(s); + XtensaCPUClass *xcc = XTENSA_CPU_GET_CLASS(cpu); + CPUXtensaState *env = &cpu->env; + + xcc->parent_reset(s); + + cpu_state_reset(env); +} + +static void xtensa_cpu_class_init(ObjectClass *oc, void *data) +{ + CPUClass *cc = CPU_CLASS(oc); + XtensaCPUClass *xcc = XTENSA_CPU_CLASS(cc); + + xcc->parent_reset = cc->reset; + cc->reset = xtensa_cpu_reset; +} + +static const TypeInfo xtensa_cpu_type_info = { + .name = TYPE_XTENSA_CPU, + .parent = TYPE_CPU, + .instance_size = sizeof(XtensaCPU), + .abstract = false, + .class_size = sizeof(XtensaCPUClass), + .class_init = xtensa_cpu_class_init, +}; + +static void xtensa_cpu_register_types(void) +{ + type_register_static(&xtensa_cpu_type_info); +} + +type_init(xtensa_cpu_register_types) diff --git a/target-xtensa/cpu.h b/target-xtensa/cpu.h index a7bcf52..2de5144 100644 --- a/target-xtensa/cpu.h +++ b/target-xtensa/cpu.h @@ -470,6 +470,7 @@ static inline void cpu_get_tb_cpu_state(CPUXtensaState *env, target_ulong *pc, } #include "cpu-all.h" +#include "cpu-qom.h" #include "exec-all.h" static inline int cpu_has_work(CPUXtensaState *env) diff --git a/target-xtensa/helper.c b/target-xtensa/helper.c index dab135c..20338e6 100644 --- a/target-xtensa/helper.c +++ b/target-xtensa/helper.c @@ -95,6 +95,7 @@ CPUXtensaState *cpu_xtensa_init(const char *cpu_model) { static int tcg_inited; static int debug_handler_inited; + XtensaCPU *cpu; CPUXtensaState *env; const XtensaConfig *config = NULL; XtensaConfigList *core = xtensa_cores; @@ -109,7 +110,8 @@ CPUXtensaState *cpu_xtensa_init(const char *cpu_model) return NULL; } - env = g_malloc0(sizeof(*env)); + cpu = XTENSA_CPU(object_new(TYPE_XTENSA_CPU)); + env = &cpu->env; env->config = config; cpu_exec_init(env);