From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Richard Henderson" <rth@twiddle.net>,
"Andreas Färber" <afaerber@suse.de>,
"Paul Brook" <paul@codesourcery.com>
Subject: [Qemu-devel] [PATCH RFC v2 6/8] target-arm: Embed CPUARMState in QOM ARMCPU
Date: Wed, 1 Feb 2012 13:57:23 +0100 [thread overview]
Message-ID: <1328101045-10717-7-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1328101045-10717-1-git-send-email-afaerber@suse.de>
We g_malloc0()'ed CPUARMState ourself, and exec.c's cpu_copy() runs
through cpu_init() as well, so we are at liberty to supply the CPUState
any way we see fit. Having CPUARMState as field in the QOM CPU allows
both to access env from an ARMCPU object and to access the QOM Object
and its ObjectClass from an env pointer, in ARM code for now.
The goal is to convert all CPUs to QOM and to use CPU objects in central
places, especially once we have property support for Object.
This will then allow to have TCG AREG0 point to target-specific fields
where small immediate offsets are desired (as pointed out by rth) while
allowing for common fields at known offsets from the base class.
Having the CPUID in ARMCPUClass, we can set it from the instance_init
function. Same for cpu_model_str, which is now the QOM class name.
Make cpu_reset() call cpu_do_reset().
Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: Paul Brook <paul@codesourcery.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Richard Henderson <rth@twiddle.net>
---
target-arm/cpu-core.c | 13 +++++++++++++
target-arm/cpu-core.h | 11 +++++++++++
target-arm/helper.c | 15 ++++++++-------
3 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/target-arm/cpu-core.c b/target-arm/cpu-core.c
index b255741..1caf9aa 100644
--- a/target-arm/cpu-core.c
+++ b/target-arm/cpu-core.c
@@ -135,6 +135,18 @@ static const ARMCPUInfo arm_cpus[] = {
},
};
+static void arm_cpu_initfn(Object *obj)
+{
+ ARMCPU *cpu = ARM_CPU(obj);
+ ARMCPUClass *cpu_class = ARM_CPU_GET_CLASS(obj);
+
+ memset(&cpu->env, 0, sizeof(CPUARMState));
+ cpu_exec_init(&cpu->env);
+
+ cpu->env.cpu_model_str = object_get_typename(obj);
+ cpu->env.cp15.c0_cpuid = cpu_class->id;
+}
+
static void arm_cpu_class_init(ObjectClass *klass, void *data)
{
ARMCPUClass *k = ARM_CPU_CLASS(klass);
@@ -152,6 +164,7 @@ static void cpu_register(const ARMCPUInfo *info)
.name = info->name,
.parent = TYPE_ARM_CPU,
.instance_size = sizeof(ARMCPU),
+ .instance_init = arm_cpu_initfn,
.class_size = sizeof(ARMCPUClass),
.class_init = arm_cpu_class_init,
.class_data = (void *)info,
diff --git a/target-arm/cpu-core.h b/target-arm/cpu-core.h
index ccc5503..cd3af77 100644
--- a/target-arm/cpu-core.h
+++ b/target-arm/cpu-core.h
@@ -10,6 +10,7 @@
#define QEMU_ARM_CPU_CORE_H
#include "qemu/cpu.h"
+#include "cpu.h"
#define TYPE_ARM_CPU "arm-cpu"
@@ -39,7 +40,17 @@ typedef struct ARMCPUClass {
*/
typedef struct ARMCPU {
CPU parent_obj;
+
+ /* TODO Inline this and split off common state */
+ CPUARMState env;
} ARMCPU;
+static inline Object *arm_env_get_object(CPUARMState *env)
+{
+ return OBJECT((void *)(env) - offsetof(ARMCPU, env));
+}
+
+#define ENV_GET_OBJECT(e) arm_env_get_object(e)
+
#endif
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 3f34d8d..34b1d24 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -292,6 +292,8 @@ void cpu_reset(CPUARMState *env)
log_cpu_state(env, 0);
}
+ cpu_do_reset(CPU(ENV_GET_OBJECT(env)));
+
id = env->cp15.c0_cpuid;
tmp = env->cp15.c15_config_base_address;
memset(env, 0, offsetof(CPUARMState, breakpoints));
@@ -400,7 +402,7 @@ static int vfp_gdb_set_reg(CPUState *env, uint8_t *buf, int reg)
CPUARMState *cpu_arm_init(const char *cpu_model)
{
ObjectClass *klass;
- ARMCPUClass *cpu_class;
+ ARMCPU *cpu;
CPUARMState *env;
static int inited = 0;
@@ -408,16 +410,14 @@ CPUARMState *cpu_arm_init(const char *cpu_model)
if (klass == NULL) {
return NULL;
}
- cpu_class = ARM_CPU_CLASS(klass);
- env = g_malloc0(sizeof(CPUARMState));
- cpu_exec_init(env);
+ cpu = ARM_CPU(object_new_with_type(klass->type));
+ env = &cpu->env;
+
if (tcg_enabled() && !inited) {
inited = 1;
arm_translate_init();
}
- env->cpu_model_str = cpu_model;
- env->cp15.c0_cpuid = cpu_class->id;
cpu_reset(env);
if (arm_feature(env, ARM_FEATURE_NEON)) {
gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
@@ -459,7 +459,8 @@ void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf)
void cpu_arm_close(CPUARMState *env)
{
- g_free(env);
+ Object *obj = ENV_GET_OBJECT(env);
+ object_delete(obj);
}
static int bad_mode_switch(CPUState *env, int mode)
--
1.7.7
next prev parent reply other threads:[~2012-02-01 13:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-01 12:57 [Qemu-devel] [PATCH RFC v2 0/8] Introduce QOM CPU and use for ARM Andreas Färber
2012-02-01 12:57 ` [Qemu-devel] [PATCH RFC v2 1/8] qom: Allow object_class_foreach() to take additional parameters to refine search Andreas Färber
2012-02-01 12:57 ` [Qemu-devel] [PATCH RFC v2 2/8] qom: Register QOM infrastructure early Andreas Färber
2012-02-01 12:57 ` [Qemu-devel] [PATCH RFC v2 3/8] qom: Add QOM support to user emulators Andreas Färber
2012-02-01 12:57 ` [Qemu-devel] [PATCH RFC v2 4/8] qom: Introduce CPU class Andreas Färber
2012-02-01 22:25 ` Peter Maydell
2012-02-01 12:57 ` [Qemu-devel] [PATCH RFC v2 5/8] target-arm: Introduce QOM CPU and use it for CPUID lookup Andreas Färber
2012-02-01 16:16 ` Andreas Färber
2012-02-01 12:57 ` Andreas Färber [this message]
2012-02-01 12:57 ` [Qemu-devel] [PATCH RFC v2 7/8] target-arm: Prepare model-specific class_init function Andreas Färber
2012-02-01 12:57 ` [Qemu-devel] [PATCH RFC v2 8/8] target-arm: Move CPU feature flags out of CPUState Andreas Färber
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=1328101045-10717-7-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=paul@codesourcery.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).