Received: from eggs.gnu.org ([2001:4830:134:3::10]:43345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ully2-0004Q3-RF for qemu-devel@nongnu.org; Sun, 09 Jun 2013 16:11:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ully1-0000VA-T2 for qemu-devel@nongnu.org; Sun, 09 Jun 2013 16:11:58 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 9 Jun 2013 22:11:49 +0200 Message-Id: <1370808709-12856-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 v4] target-ppc: Introduce unrealizefn for PowerPCCPU List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "open list:PowerPC" , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Alexander Graf 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=C3=A4rber --- v3 -> v4: * Introduced PPC_CPU_OPCODES_LEN constant to avoid magic 0x40 (requested= by Alex). From "QOM'ify Power Architecture CPU" v2: * Implemented unrealizefn instead of finalizefn, to address rejection by= dwg: create_new_table() is not called from the instance initializer. v1 -> v2: * Replace cpu_ppc_close() and its TODO with an implementation as a final= izefn. 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 =20 +#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 { =20 /* Those resources are used only during code translation */ /* opcode handlers */ - opc_handler_t *opcodes[0x40]; + opc_handler_t *opcodes[PPC_CPU_OPCODES_LEN]; =20 /* 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 021a31e..1db8b6c 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -7306,7 +7306,7 @@ static int create_new_table (opc_handler_t **table,= unsigned char idx) { opc_handler_t **tmp; =20 - tmp =3D malloc(0x20 * sizeof(opc_handler_t)); + tmp =3D g_malloc(0x20 * sizeof(opc_handler_t)); fill_new_table(tmp, 0x20); table[idx] =3D (opc_handler_t *)((uintptr_t)tmp | PPC_INDIRECT); =20 @@ -7916,6 +7916,19 @@ static void ppc_cpu_realizefn(DeviceState *dev, Er= ror **errp) #endif } =20 +static void ppc_cpu_unrealizefn(DeviceState *dev, Error **errp) +{ + PowerPCCPU *cpu =3D POWERPC_CPU(dev); + CPUPPCState *env =3D &cpu->env; + int i; + + for (i =3D 0; i < PPC_CPU_OPCODES_LEN; i++) { + if (env->opcodes[i] !=3D &invalid_handler) { + g_free(env->opcodes[i]); + } + } +} + static gint ppc_cpu_compare_class_pvr(gconstpointer a, gconstpointer b) { ObjectClass *oc =3D (ObjectClass *)a; @@ -8303,6 +8316,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, voi= d *data) =20 pcc->parent_realize =3D dc->realize; dc->realize =3D ppc_cpu_realizefn; + dc->unrealize =3D ppc_cpu_unrealizefn; =20 pcc->parent_reset =3D cc->reset; cc->reset =3D ppc_cpu_reset; --=20 1.8.1.4