From patchwork Sun Jun 30 01:45:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 255851 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0B5AE2C02F6 for ; Sun, 30 Jun 2013 11:58:18 +1000 (EST) Received: from localhost ([::1]:47750 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ut6u8-0008HS-7Q for incoming@patchwork.ozlabs.org; Sat, 29 Jun 2013 21:58:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ut6hh-0003d1-0R for qemu-devel@nongnu.org; Sat, 29 Jun 2013 21:45:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ut6hY-0007eQ-LY for qemu-devel@nongnu.org; Sat, 29 Jun 2013 21:45:24 -0400 Received: from cantor2.suse.de ([195.135.220.15]:37020 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ut6hY-0007cu-DL; Sat, 29 Jun 2013 21:45:16 -0400 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E4DC5A5464; Sun, 30 Jun 2013 03:45:14 +0200 (CEST) From: Alexander Graf To: qemu-ppc@nongnu.org Date: Sun, 30 Jun 2013 03:45:01 +0200 Message-Id: <1372556709-23868-25-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1372556709-23868-1-git-send-email-agraf@suse.de> References: <1372556709-23868-1-git-send-email-agraf@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: Blue Swirl , qemu-devel@nongnu.org, Aurelien Jarno , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 24/32] target-ppc: Introduce unrealizefn for PowerPCCPU 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 Use it to clean up the opcode table, resolving a former TODO from Jocelyn. Also switch from malloc() to g_malloc(). Signed-off-by: Andreas Färber Signed-off-by: Alexander Graf --- target-ppc/cpu.h | 4 +++- target-ppc/translate_init.c | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h index aa1d013..0ede077 100644 --- a/target-ppc/cpu.h +++ b/target-ppc/cpu.h @@ -886,6 +886,8 @@ struct ppc_segment_page_sizes { /* The whole PowerPC CPU context */ #define NB_MMU_MODES 3 +#define PPC_CPU_OPCODES_LEN 0x40 + struct CPUPPCState { /* First are the most commonly used resources * during translated code execution @@ -1039,7 +1041,7 @@ struct CPUPPCState { /* Those resources are used only during code translation */ /* opcode handlers */ - opc_handler_t *opcodes[0x40]; + opc_handler_t *opcodes[PPC_CPU_OPCODES_LEN]; /* Those resources are used only in QEMU core */ target_ulong hflags; /* hflags is a MSR & HFLAGS_MASK */ diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index f365ad8..f01e9e7 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -7256,7 +7256,7 @@ static int create_new_table (opc_handler_t **table, unsigned char idx) { opc_handler_t **tmp; - tmp = malloc(0x20 * sizeof(opc_handler_t)); + tmp = g_malloc(0x20 * sizeof(opc_handler_t)); fill_new_table(tmp, 0x20); table[idx] = (opc_handler_t *)((uintptr_t)tmp | PPC_INDIRECT); @@ -7864,6 +7864,19 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp) #endif } +static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp) +{ + PowerPCCPU *cpu = POWERPC_CPU(dev); + CPUPPCState *env = &cpu->env; + int i; + + for (i = 0; i < PPC_CPU_OPCODES_LEN; i++) { + if (env->opcodes[i] != &invalid_handler) { + g_free(env->opcodes[i]); + } + } +} + static gint ppc_cpu_compare_class_pvr(gconstpointer a, gconstpointer b) { ObjectClass *oc = (ObjectClass *)a; @@ -8251,6 +8264,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) pcc->parent_realize = dc->realize; dc->realize = ppc_cpu_realizefn; + dc->unrealize = ppc_cpu_unrealizefn; pcc->parent_reset = cc->reset; cc->reset = ppc_cpu_reset;