From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "open list:PowerPC" <qemu-ppc@nongnu.org>,
"Andreas Färber" <afaerber@suse.de>,
"Alexander Graf" <agraf@suse.de>
Subject: [Qemu-devel] [PATCH v4] target-ppc: Introduce unrealizefn for PowerPCCPU
Date: Sun, 9 Jun 2013 22:11:49 +0200 [thread overview]
Message-ID: <1370808709-12856-1-git-send-email-afaerber@suse.de> (raw)
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 <afaerber@suse.de>
---
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 finalizefn.
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 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;
- 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);
@@ -7916,6 +7916,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;
@@ -8303,6 +8316,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;
--
1.8.1.4
next reply other threads:[~2013-06-09 20:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-09 20:11 Andreas Färber [this message]
2013-06-20 22:56 ` [Qemu-devel] [PATCH v4] target-ppc: Introduce unrealizefn for PowerPCCPU Alexander Graf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1370808709-12856-1-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).