* [Qemu-devel] [RFC 01/20] qemu-common.h: "use" env parameter in no-op version of qemu_init_vcpu()
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
@ 2012-12-18 20:03 ` Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 02/20] cpu: introduce CPU_GET_ENV macros Eduardo Habkost
` (19 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:03 UTC (permalink / raw)
To: qemu-devel
This will avoid warnings about unused variables when compiling code that
calls qemu_init_vcpu().
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
qemu-common.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/qemu-common.h b/qemu-common.h
index e674786..bfd4c1a 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -288,7 +288,7 @@ struct qemu_work_item {
};
#ifdef CONFIG_USER_ONLY
-#define qemu_init_vcpu(env) do { } while (0)
+#define qemu_init_vcpu(env) do { (void)(env); } while (0)
#else
void qemu_init_vcpu(void *env);
#endif
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 02/20] cpu: introduce CPU_GET_ENV macros
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 01/20] qemu-common.h: "use" env parameter in no-op version of qemu_init_vcpu() Eduardo Habkost
@ 2012-12-18 20:03 ` Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 03/20] cpu: make cpu_init return CPUState QOM object Eduardo Habkost
` (18 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:03 UTC (permalink / raw)
To: qemu-devel
This will help us gradually convert code based on CPUArchState to
QOM-based code.
The macro checks for NULL cpu value, so a NULL cpu safely becomes a NULL
env pointer.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-alpha/cpu-qom.h | 7 +++++++
target-arm/cpu-qom.h | 7 +++++++
target-cris/cpu-qom.h | 7 +++++++
target-i386/cpu-qom.h | 7 +++++++
target-lm32/cpu-qom.h | 7 +++++++
target-m68k/cpu-qom.h | 7 +++++++
target-microblaze/cpu-qom.h | 7 +++++++
target-mips/cpu-qom.h | 7 +++++++
target-openrisc/cpu.h | 7 +++++++
target-ppc/cpu-qom.h | 7 +++++++
target-s390x/cpu-qom.h | 7 +++++++
target-sh4/cpu-qom.h | 7 +++++++
target-sparc/cpu-qom.h | 7 +++++++
target-unicore32/cpu-qom.h | 7 +++++++
target-xtensa/cpu-qom.h | 7 +++++++
15 files changed, 105 insertions(+)
diff --git a/target-alpha/cpu-qom.h b/target-alpha/cpu-qom.h
index 6b4ca6d..3c816a2 100644
--- a/target-alpha/cpu-qom.h
+++ b/target-alpha/cpu-qom.h
@@ -67,5 +67,12 @@ static inline AlphaCPU *alpha_env_get_cpu(CPUAlphaState *env)
#define ENV_GET_CPU(e) CPU(alpha_env_get_cpu(e))
+static inline CPUAlphaState *alpha_cpu_get_env(AlphaCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) alpha_cpu_get_env(ALPHA_CPU(cpu))
+
#endif
diff --git a/target-arm/cpu-qom.h b/target-arm/cpu-qom.h
index beabf9a..d7801f3 100644
--- a/target-arm/cpu-qom.h
+++ b/target-arm/cpu-qom.h
@@ -107,6 +107,13 @@ static inline ARMCPU *arm_env_get_cpu(CPUARMState *env)
#define ENV_GET_CPU(e) CPU(arm_env_get_cpu(e))
+static inline CPUARMState *arm_cpu_get_env(ARMCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) arm_cpu_get_env(ARM_CPU(cpu))
+
void arm_cpu_realize(ARMCPU *cpu);
void register_cp_regs_for_features(ARMCPU *cpu);
diff --git a/target-cris/cpu-qom.h b/target-cris/cpu-qom.h
index d0e5f04..042dca4 100644
--- a/target-cris/cpu-qom.h
+++ b/target-cris/cpu-qom.h
@@ -66,5 +66,12 @@ static inline CRISCPU *cris_env_get_cpu(CPUCRISState *env)
#define ENV_GET_CPU(e) CPU(cris_env_get_cpu(e))
+static inline CPUCRISState *cris_cpu_get_env(CRISCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) cris_cpu_get_env(CRIS_CPU(cpu))
+
#endif
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 5901140..19afe28 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -72,6 +72,13 @@ static inline X86CPU *x86_env_get_cpu(CPUX86State *env)
#define ENV_GET_CPU(e) CPU(x86_env_get_cpu(e))
+static inline CPUX86State *x86_cpu_get_env(X86CPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) x86_cpu_get_env(X86_CPU(cpu))
+
/* TODO Drop once ObjectClass::realize is available */
void x86_cpu_realize(Object *obj, Error **errp);
diff --git a/target-lm32/cpu-qom.h b/target-lm32/cpu-qom.h
index 4ae2edd..4b15192 100644
--- a/target-lm32/cpu-qom.h
+++ b/target-lm32/cpu-qom.h
@@ -67,5 +67,12 @@ static inline LM32CPU *lm32_env_get_cpu(CPULM32State *env)
#define ENV_GET_CPU(e) CPU(lm32_env_get_cpu(e))
+static inline CPULM32State *lm32_cpu_get_env(LM32CPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) lm32_cpu_get_env(LM32_CPU(cpu))
+
#endif
diff --git a/target-m68k/cpu-qom.h b/target-m68k/cpu-qom.h
index 805786b..fce1fe3 100644
--- a/target-m68k/cpu-qom.h
+++ b/target-m68k/cpu-qom.h
@@ -66,5 +66,12 @@ static inline M68kCPU *m68k_env_get_cpu(CPUM68KState *env)
#define ENV_GET_CPU(e) CPU(m68k_env_get_cpu(e))
+static inline CPUM68KState *m68k_cpu_get_env(M68kCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) m68k_cpu_get_env(M68K_CPU(cpu))
+
#endif
diff --git a/target-microblaze/cpu-qom.h b/target-microblaze/cpu-qom.h
index 4b23303..38baa32 100644
--- a/target-microblaze/cpu-qom.h
+++ b/target-microblaze/cpu-qom.h
@@ -66,5 +66,12 @@ static inline MicroBlazeCPU *mb_env_get_cpu(CPUMBState *env)
#define ENV_GET_CPU(e) CPU(mb_env_get_cpu(e))
+static inline CPUMBState *mb_cpu_get_env(MicroBlazeCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) mb_cpu_get_env(MICROBLAZE_CPU(cpu))
+
#endif
diff --git a/target-mips/cpu-qom.h b/target-mips/cpu-qom.h
index 6e22371..da8f187 100644
--- a/target-mips/cpu-qom.h
+++ b/target-mips/cpu-qom.h
@@ -70,5 +70,12 @@ static inline MIPSCPU *mips_env_get_cpu(CPUMIPSState *env)
#define ENV_GET_CPU(e) CPU(mips_env_get_cpu(e))
+static inline CPUMIPSState *mips_cpu_get_env(MIPSCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) mips_cpu_get_env(MIPS_CPU(cpu))
+
#endif
diff --git a/target-openrisc/cpu.h b/target-openrisc/cpu.h
index ebb5ad3..ca607b3 100644
--- a/target-openrisc/cpu.h
+++ b/target-openrisc/cpu.h
@@ -339,6 +339,13 @@ static inline OpenRISCCPU *openrisc_env_get_cpu(CPUOpenRISCState *env)
#define ENV_GET_CPU(e) CPU(openrisc_env_get_cpu(e))
+static inline CPUOpenRISCState *openrisc_cpu_get_env(OpenRISCCPU *cpu)
+{
+ return &cpu->env;;
+}
+
+#define CPU_GET_ENV(cpu) openrisc_cpu_get_env(OPENRISC_CPU(cpu))
+
OpenRISCCPU *cpu_openrisc_init(const char *cpu_model);
void openrisc_cpu_realize(Object *obj, Error **errp);
diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h
index fef6f95..d8a878e 100644
--- a/target-ppc/cpu-qom.h
+++ b/target-ppc/cpu-qom.h
@@ -73,5 +73,12 @@ static inline PowerPCCPU *ppc_env_get_cpu(CPUPPCState *env)
#define ENV_GET_CPU(e) CPU(ppc_env_get_cpu(e))
+static inline CPUPPCState *ppc_cpu_get_env(PowerPCCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) ppc_cpu_get_env(POWERPC_CPU(cpu))
+
#endif
diff --git a/target-s390x/cpu-qom.h b/target-s390x/cpu-qom.h
index 6fa55a8..7a51004 100644
--- a/target-s390x/cpu-qom.h
+++ b/target-s390x/cpu-qom.h
@@ -67,5 +67,12 @@ static inline S390CPU *s390_env_get_cpu(CPUS390XState *env)
#define ENV_GET_CPU(e) CPU(s390_env_get_cpu(e))
+static inline CPUS390XState *s390_cpu_get_env(S390CPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) s390_cpu_get_env(S390_CPU(cpu))
+
#endif
diff --git a/target-sh4/cpu-qom.h b/target-sh4/cpu-qom.h
index c41164a..b8cf70a 100644
--- a/target-sh4/cpu-qom.h
+++ b/target-sh4/cpu-qom.h
@@ -66,5 +66,12 @@ static inline SuperHCPU *sh_env_get_cpu(CPUSH4State *env)
#define ENV_GET_CPU(e) CPU(sh_env_get_cpu(e))
+static inline CPUSH4State *sh_cpu_get_env(SuperHCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) sh_cpu_get_env(SUPERH_CPU(cpu))
+
#endif
diff --git a/target-sparc/cpu-qom.h b/target-sparc/cpu-qom.h
index 3d3ac0f..1ed4e11 100644
--- a/target-sparc/cpu-qom.h
+++ b/target-sparc/cpu-qom.h
@@ -71,5 +71,12 @@ static inline SPARCCPU *sparc_env_get_cpu(CPUSPARCState *env)
#define ENV_GET_CPU(e) CPU(sparc_env_get_cpu(e))
+static inline CPUSPARCState *sparc_cpu_get_env(SPARCCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) sparc_cpu_get_env(SPARC_CPU(cpu))
+
#endif
diff --git a/target-unicore32/cpu-qom.h b/target-unicore32/cpu-qom.h
index 342d85e..0afe9b9 100644
--- a/target-unicore32/cpu-qom.h
+++ b/target-unicore32/cpu-qom.h
@@ -55,5 +55,12 @@ static inline UniCore32CPU *uc32_env_get_cpu(CPUUniCore32State *env)
#define ENV_GET_CPU(e) CPU(uc32_env_get_cpu(e))
+static inline CPUUniCore32State *uc32_cpu_get_env(UniCore32CPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) uc32_cpu_get_env(UNICORE32_CPU(cpu))
+
#endif
diff --git a/target-xtensa/cpu-qom.h b/target-xtensa/cpu-qom.h
index 1fd2f27..cfab791 100644
--- a/target-xtensa/cpu-qom.h
+++ b/target-xtensa/cpu-qom.h
@@ -76,5 +76,12 @@ static inline XtensaCPU *xtensa_env_get_cpu(const CPUXtensaState *env)
#define ENV_GET_CPU(e) CPU(xtensa_env_get_cpu(e))
+static inline CPUXtensaState *xtensa_cpu_get_env(XtensaCPU *cpu)
+{
+ return cpu ? &cpu->env : NULL;
+}
+
+#define CPU_GET_ENV(cpu) xtensa_cpu_get_env(XTENSA_CPU(cpu))
+
#endif
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 03/20] cpu: make cpu_init return CPUState QOM object
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 01/20] qemu-common.h: "use" env parameter in no-op version of qemu_init_vcpu() Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 02/20] cpu: introduce CPU_GET_ENV macros Eduardo Habkost
@ 2012-12-18 20:03 ` Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 04/20] cpu: replace trivial old_cpu_init functions Eduardo Habkost
` (17 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:03 UTC (permalink / raw)
To: qemu-devel
This will allow us to gradually change the existing
cpu_init()/cpu_copy() code to use QOM, and to gradually move CPU_COMMON
fields to CPUState.
The existing implementations were mechanically changed to be called
'old_cpu_init', and a wrapper was added to all architectures. Later the
wrappers and old implementations can be replaced by proper QOM-based
ones.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
bsd-user/main.c | 2 +-
exec.c | 2 +-
hw/alpha_dp264.c | 2 +-
hw/an5206.c | 2 +-
hw/dummy_m68k.c | 2 +-
hw/mcf5208.c | 2 +-
hw/puv3.c | 2 +-
hw/shix.c | 2 +-
linux-user/main.c | 2 +-
target-alpha/cpu.h | 3 ++-
target-arm/cpu.h | 3 ++-
target-cris/cpu.h | 3 ++-
target-i386/cpu.h | 3 ++-
target-lm32/cpu.h | 3 ++-
target-m68k/cpu.h | 3 ++-
target-microblaze/cpu.h | 3 ++-
target-mips/cpu.h | 3 ++-
target-openrisc/cpu.h | 3 ++-
target-ppc/cpu.h | 3 ++-
target-s390x/cpu.h | 3 ++-
target-sh4/cpu.h | 3 ++-
target-sparc/cpu.h | 3 ++-
target-unicore32/cpu.h | 3 ++-
target-xtensa/cpu.h | 3 ++-
24 files changed, 39 insertions(+), 24 deletions(-)
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 095ae8e..9372142 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -912,7 +912,7 @@ int main(int argc, char **argv)
cpu_exec_init_all();
/* NOTE: we need to init the CPU at this stage to get
qemu_host_page_size */
- env = cpu_init(cpu_model);
+ env = CPU_GET_ENV(cpu_init(cpu_model));
if (!env) {
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
diff --git a/exec.c b/exec.c
index 4c1246a..8e8a852 100644
--- a/exec.c
+++ b/exec.c
@@ -526,7 +526,7 @@ void cpu_abort(CPUArchState *env, const char *fmt, ...)
CPUArchState *cpu_copy(CPUArchState *env)
{
- CPUArchState *new_env = cpu_init(env->cpu_model_str);
+ CPUArchState *new_env = CPU_GET_ENV(cpu_init(env->cpu_model_str));
CPUArchState *next_cpu = new_env->next_cpu;
int cpu_index = new_env->cpu_index;
#if defined(TARGET_HAS_ICE)
diff --git a/hw/alpha_dp264.c b/hw/alpha_dp264.c
index 76d8ae8..0b3e30d 100644
--- a/hw/alpha_dp264.c
+++ b/hw/alpha_dp264.c
@@ -62,7 +62,7 @@ static void clipper_init(QEMUMachineInitArgs *args)
/* Create up to 4 cpus. */
memset(cpus, 0, sizeof(cpus));
for (i = 0; i < smp_cpus; ++i) {
- cpus[i] = cpu_init(cpu_model ? cpu_model : "ev67");
+ cpus[i] = CPU_GET_ENV(cpu_init(cpu_model ? cpu_model : "ev67"));
}
cpus[0]->trap_arg0 = ram_size;
diff --git a/hw/an5206.c b/hw/an5206.c
index d887c0e..1c13385 100644
--- a/hw/an5206.c
+++ b/hw/an5206.c
@@ -34,7 +34,7 @@ static void an5206_init(QEMUMachineInitArgs *args)
if (!cpu_model)
cpu_model = "m5206";
- env = cpu_init(cpu_model);
+ env = CPU_GET_ENV(cpu_init(cpu_model));
if (!env) {
hw_error("Unable to find m68k CPU definition\n");
}
diff --git a/hw/dummy_m68k.c b/hw/dummy_m68k.c
index 20f790b..c33f8b7 100644
--- a/hw/dummy_m68k.c
+++ b/hw/dummy_m68k.c
@@ -30,7 +30,7 @@ static void dummy_m68k_init(QEMUMachineInitArgs *args)
if (!cpu_model)
cpu_model = "cfv4e";
- env = cpu_init(cpu_model);
+ env = CPU_GET_ENV(cpu_init(cpu_model));
if (!env) {
fprintf(stderr, "Unable to find m68k CPU definition\n");
exit(1);
diff --git a/hw/mcf5208.c b/hw/mcf5208.c
index b1db549..2565275 100644
--- a/hw/mcf5208.c
+++ b/hw/mcf5208.c
@@ -203,7 +203,7 @@ static void mcf5208evb_init(QEMUMachineInitArgs *args)
if (!cpu_model)
cpu_model = "m5208";
- env = cpu_init(cpu_model);
+ env = CPU_GET_ENV(cpu_init(cpu_model));
if (!env) {
fprintf(stderr, "Unable to find m68k CPU definition\n");
exit(1);
diff --git a/hw/puv3.c b/hw/puv3.c
index 3d77349..edd0132 100644
--- a/hw/puv3.c
+++ b/hw/puv3.c
@@ -107,7 +107,7 @@ static void puv3_init(QEMUMachineInitArgs *args)
cpu_model = "UniCore-II";
}
- env = cpu_init(cpu_model);
+ env = CPU_GET_ENV(cpu_init(cpu_model));
if (!env) {
hw_error("Unable to find CPU definition\n");
}
diff --git a/hw/shix.c b/hw/shix.c
index b56dd54..436f2df 100644
--- a/hw/shix.c
+++ b/hw/shix.c
@@ -51,7 +51,7 @@ static void shix_init(QEMUMachineInitArgs *args)
cpu_model = "any";
printf("Initializing CPU\n");
- env = cpu_init(cpu_model);
+ env = CPU_GET_ENV(cpu_init(cpu_model));
/* Allocate memory space */
printf("Allocating ROM\n");
diff --git a/linux-user/main.c b/linux-user/main.c
index 25e35cd..36ebb82 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3486,7 +3486,7 @@ int main(int argc, char **argv, char **envp)
cpu_exec_init_all();
/* NOTE: we need to init the CPU at this stage to get
qemu_host_page_size */
- env = cpu_init(cpu_model);
+ env = CPU_GET_ENV(cpu_init(cpu_model));
if (!env) {
fprintf(stderr, "Unable to find CPU definition\n");
exit(1);
diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index 9939d61..c04d436 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -290,7 +290,8 @@ struct CPUAlphaState {
int implver;
};
-#define cpu_init cpu_alpha_init
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+#define old_cpu_init cpu_alpha_init
#define cpu_exec cpu_alpha_exec
#define cpu_gen_code cpu_alpha_gen_code
#define cpu_signal_handler cpu_alpha_signal_handler
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index e4ff918..8b14bfc 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -625,7 +625,8 @@ static inline bool cp_access_ok(CPUARMState *env,
#define TARGET_PHYS_ADDR_SPACE_BITS 40
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-static inline CPUARMState *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUARMState *old_cpu_init(const char *cpu_model)
{
ARMCPU *cpu = cpu_arm_init(cpu_model);
if (cpu) {
diff --git a/target-cris/cpu.h b/target-cris/cpu.h
index 2c27506..e992f06 100644
--- a/target-cris/cpu.h
+++ b/target-cris/cpu.h
@@ -218,7 +218,8 @@ enum {
#define TARGET_PHYS_ADDR_SPACE_BITS 32
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-static inline CPUCRISState *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUCRISState *old_cpu_init(const char *cpu_model)
{
CRISCPU *cpu = cpu_cris_init(cpu_model);
if (cpu == NULL) {
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 386c4f6..c381b03 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1034,7 +1034,8 @@ uint64_t cpu_get_tsc(CPUX86State *env);
#define TARGET_VIRT_ADDR_SPACE_BITS 32
#endif
-static inline CPUX86State *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUX86State *old_cpu_init(const char *cpu_model)
{
X86CPU *cpu = cpu_x86_init(cpu_model);
if (cpu == NULL) {
diff --git a/target-lm32/cpu.h b/target-lm32/cpu.h
index 7243b4f..9cfa7b1 100644
--- a/target-lm32/cpu.h
+++ b/target-lm32/cpu.h
@@ -199,7 +199,8 @@ int cpu_lm32_signal_handler(int host_signum, void *pinfo,
void lm32_translate_init(void);
void cpu_lm32_set_phys_msb_ignore(CPULM32State *env, int value);
-static inline CPULM32State *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPULM32State *old_cpu_init(const char *cpu_model)
{
LM32CPU *cpu = cpu_lm32_init(cpu_model);
if (cpu == NULL) {
diff --git a/target-m68k/cpu.h b/target-m68k/cpu.h
index f4fcdee..fbb35dc 100644
--- a/target-m68k/cpu.h
+++ b/target-m68k/cpu.h
@@ -214,7 +214,8 @@ void register_m68k_insns (CPUM68KState *env);
#define TARGET_PHYS_ADDR_SPACE_BITS 32
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#define cpu_init cpu_m68k_init
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+#define old_cpu_init cpu_m68k_init
#define cpu_exec cpu_m68k_exec
#define cpu_gen_code cpu_m68k_gen_code
#define cpu_signal_handler cpu_m68k_signal_handler
diff --git a/target-microblaze/cpu.h b/target-microblaze/cpu.h
index 585bbd6..c41354e 100644
--- a/target-microblaze/cpu.h
+++ b/target-microblaze/cpu.h
@@ -295,7 +295,8 @@ enum {
#define TARGET_PHYS_ADDR_SPACE_BITS 32
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-static inline CPUMBState *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUMBState *old_cpu_init(const char *cpu_model)
{
MicroBlazeCPU *cpu = cpu_mb_init(cpu_model);
if (cpu == NULL) {
diff --git a/target-mips/cpu.h b/target-mips/cpu.h
index aebb2d5..9162ced 100644
--- a/target-mips/cpu.h
+++ b/target-mips/cpu.h
@@ -632,7 +632,8 @@ int cpu_mips_exec(CPUMIPSState *s);
MIPSCPU *cpu_mips_init(const char *cpu_model);
int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
-static inline CPUMIPSState *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUMIPSState *old_cpu_init(const char *cpu_model)
{
MIPSCPU *cpu = cpu_mips_init(cpu_model);
if (cpu == NULL) {
diff --git a/target-openrisc/cpu.h b/target-openrisc/cpu.h
index ca607b3..13220a5 100644
--- a/target-openrisc/cpu.h
+++ b/target-openrisc/cpu.h
@@ -386,7 +386,8 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
int *prot, target_ulong address, int rw);
#endif
-static inline CPUOpenRISCState *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUOpenRISCState *old_cpu_init(const char *cpu_model)
{
OpenRISCCPU *cpu = cpu_openrisc_init(cpu_model);
if (cpu) {
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index 742d4f8..58404b8 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -1216,7 +1216,8 @@ static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn)
int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, uint32_t *valp);
int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val);
-static inline CPUPPCState *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUPPCState *old_cpu_init(const char *cpu_model)
{
PowerPCCPU *cpu = cpu_ppc_init(cpu_model);
if (cpu == NULL) {
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 0f9a1f7..2edebf1 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -345,7 +345,8 @@ static inline void cpu_set_tls(CPUS390XState *env, target_ulong newtls)
env->aregs[1] = newtls & 0xffffffffULL;
}
-#define cpu_init(model) (&cpu_s390x_init(model)->env)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+#define old_cpu_init(model) (&cpu_s390x_init(model)->env)
#define cpu_exec cpu_s390x_exec
#define cpu_gen_code cpu_s390x_gen_code
#define cpu_signal_handler cpu_s390x_signal_handler
diff --git a/target-sh4/cpu.h b/target-sh4/cpu.h
index 9a0e72b..f6ba00e 100644
--- a/target-sh4/cpu.h
+++ b/target-sh4/cpu.h
@@ -232,7 +232,8 @@ void cpu_load_tlb(CPUSH4State * env);
#include "softfloat.h"
-static inline CPUSH4State *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUSH4State *old_cpu_init(const char *cpu_model)
{
SuperHCPU *cpu = cpu_sh4_init(cpu_model);
if (cpu == NULL) {
diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index 013ecbd..ca2bdb1 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -592,7 +592,8 @@ hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env, target_ulong addr,
int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
#ifndef NO_CPU_IO_DEFS
-static inline CPUSPARCState *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUSPARCState *old_cpu_init(const char *cpu_model)
{
SPARCCPU *cpu = cpu_sparc_init(cpu_model);
if (cpu == NULL) {
diff --git a/target-unicore32/cpu.h b/target-unicore32/cpu.h
index 676c5d9..86a6959 100644
--- a/target-unicore32/cpu.h
+++ b/target-unicore32/cpu.h
@@ -122,7 +122,8 @@ void cpu_asr_write(CPUUniCore32State *env1, target_ulong val, target_ulong mask)
#define UC32_HWCAP_CMOV 4 /* 1 << 2 */
#define UC32_HWCAP_UCF64 8 /* 1 << 3 */
-#define cpu_init uc32_cpu_init
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+#define old_cpu_init uc32_cpu_init
#define cpu_exec uc32_cpu_exec
#define cpu_signal_handler uc32_cpu_signal_handler
#define cpu_handle_mmu_fault uc32_cpu_handle_mmu_fault
diff --git a/target-xtensa/cpu.h b/target-xtensa/cpu.h
index 08fd5bc..65f2af3 100644
--- a/target-xtensa/cpu.h
+++ b/target-xtensa/cpu.h
@@ -375,7 +375,8 @@ typedef struct CPUXtensaState {
XtensaCPU *cpu_xtensa_init(const char *cpu_model);
-static inline CPUXtensaState *cpu_init(const char *cpu_model)
+#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
+static inline CPUXtensaState *old_cpu_init(const char *cpu_model)
{
XtensaCPU *cpu = cpu_xtensa_init(cpu_model);
if (cpu == NULL) {
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 04/20] cpu: replace trivial old_cpu_init functions
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (2 preceding siblings ...)
2012-12-18 20:03 ` [Qemu-devel] [RFC 03/20] cpu: make cpu_init return CPUState QOM object Eduardo Habkost
@ 2012-12-18 20:03 ` Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 05/20] alpha: convert cpu_init to QOM Eduardo Habkost
` (16 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:03 UTC (permalink / raw)
To: qemu-devel
Most of the existing old_cpu_init functions were just wrappers around
QOM-ready cpu_*_init() functions, so just define cpu_init as a call to
those functions (wrapped inside CPU macro).
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-arm/cpu.h | 10 +---------
target-cris/cpu.h | 10 +---------
target-i386/cpu.h | 10 +---------
target-lm32/cpu.h | 10 +---------
target-microblaze/cpu.h | 10 +---------
target-mips/cpu.h | 10 +---------
target-openrisc/cpu.h | 10 +---------
target-ppc/cpu.h | 10 +---------
target-s390x/cpu.h | 3 +--
target-sh4/cpu.h | 10 +---------
target-sparc/cpu.h | 10 +---------
target-xtensa/cpu.h | 10 +---------
12 files changed, 12 insertions(+), 101 deletions(-)
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 8b14bfc..718f1d9 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -625,15 +625,7 @@ static inline bool cp_access_ok(CPUARMState *env,
#define TARGET_PHYS_ADDR_SPACE_BITS 40
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUARMState *old_cpu_init(const char *cpu_model)
-{
- ARMCPU *cpu = cpu_arm_init(cpu_model);
- if (cpu) {
- return &cpu->env;
- }
- return NULL;
-}
+#define cpu_init(m) CPU(cpu_arm_init(m))
#define cpu_exec cpu_arm_exec
#define cpu_gen_code cpu_arm_gen_code
diff --git a/target-cris/cpu.h b/target-cris/cpu.h
index e992f06..e1af636 100644
--- a/target-cris/cpu.h
+++ b/target-cris/cpu.h
@@ -218,15 +218,7 @@ enum {
#define TARGET_PHYS_ADDR_SPACE_BITS 32
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUCRISState *old_cpu_init(const char *cpu_model)
-{
- CRISCPU *cpu = cpu_cris_init(cpu_model);
- if (cpu == NULL) {
- return NULL;
- }
- return &cpu->env;
-}
+#define cpu_init(m) CPU(cpu_cris_init(m))
#define cpu_exec cpu_cris_exec
#define cpu_gen_code cpu_cris_gen_code
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index c381b03..8fa183b 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1034,15 +1034,7 @@ uint64_t cpu_get_tsc(CPUX86State *env);
#define TARGET_VIRT_ADDR_SPACE_BITS 32
#endif
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUX86State *old_cpu_init(const char *cpu_model)
-{
- X86CPU *cpu = cpu_x86_init(cpu_model);
- if (cpu == NULL) {
- return NULL;
- }
- return &cpu->env;
-}
+#define cpu_init(m) CPU(cpu_x86_init(m))
#define cpu_exec cpu_x86_exec
#define cpu_gen_code cpu_x86_gen_code
diff --git a/target-lm32/cpu.h b/target-lm32/cpu.h
index 9cfa7b1..1cf58c9 100644
--- a/target-lm32/cpu.h
+++ b/target-lm32/cpu.h
@@ -199,15 +199,7 @@ int cpu_lm32_signal_handler(int host_signum, void *pinfo,
void lm32_translate_init(void);
void cpu_lm32_set_phys_msb_ignore(CPULM32State *env, int value);
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPULM32State *old_cpu_init(const char *cpu_model)
-{
- LM32CPU *cpu = cpu_lm32_init(cpu_model);
- if (cpu == NULL) {
- return NULL;
- }
- return &cpu->env;
-}
+#define cpu_init(m) CPU(cpu_lm32_init(m))
#define cpu_list cpu_lm32_list
#define cpu_exec cpu_lm32_exec
diff --git a/target-microblaze/cpu.h b/target-microblaze/cpu.h
index c41354e..7bbf01c 100644
--- a/target-microblaze/cpu.h
+++ b/target-microblaze/cpu.h
@@ -295,15 +295,7 @@ enum {
#define TARGET_PHYS_ADDR_SPACE_BITS 32
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUMBState *old_cpu_init(const char *cpu_model)
-{
- MicroBlazeCPU *cpu = cpu_mb_init(cpu_model);
- if (cpu == NULL) {
- return NULL;
- }
- return &cpu->env;
-}
+#define cpu_init(m) CPU(cpu_mb_init(m))
#define cpu_exec cpu_mb_exec
#define cpu_gen_code cpu_mb_gen_code
diff --git a/target-mips/cpu.h b/target-mips/cpu.h
index 9162ced..b01f3da 100644
--- a/target-mips/cpu.h
+++ b/target-mips/cpu.h
@@ -632,15 +632,7 @@ int cpu_mips_exec(CPUMIPSState *s);
MIPSCPU *cpu_mips_init(const char *cpu_model);
int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUMIPSState *old_cpu_init(const char *cpu_model)
-{
- MIPSCPU *cpu = cpu_mips_init(cpu_model);
- if (cpu == NULL) {
- return NULL;
- }
- return &cpu->env;
-}
+#define cpu_init(m) CPU(cpu_mips_init(m))
/* TODO QOM'ify CPU reset and remove */
void cpu_state_reset(CPUMIPSState *s);
diff --git a/target-openrisc/cpu.h b/target-openrisc/cpu.h
index 13220a5..d7470a9 100644
--- a/target-openrisc/cpu.h
+++ b/target-openrisc/cpu.h
@@ -386,15 +386,7 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
int *prot, target_ulong address, int rw);
#endif
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUOpenRISCState *old_cpu_init(const char *cpu_model)
-{
- OpenRISCCPU *cpu = cpu_openrisc_init(cpu_model);
- if (cpu) {
- return &cpu->env;
- }
- return NULL;
-}
+#define cpu_init(m) CPU(cpu_openrisc_init(m))
#if defined(CONFIG_USER_ONLY)
static inline void cpu_clone_regs(CPUOpenRISCState *env, target_ulong newsp)
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index 58404b8..ec626fd 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -1216,15 +1216,7 @@ static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn)
int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, uint32_t *valp);
int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val);
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUPPCState *old_cpu_init(const char *cpu_model)
-{
- PowerPCCPU *cpu = cpu_ppc_init(cpu_model);
- if (cpu == NULL) {
- return NULL;
- }
- return &cpu->env;
-}
+#define cpu_init(m) CPU(cpu_ppc_init(m))
#define cpu_exec cpu_ppc_exec
#define cpu_gen_code cpu_ppc_gen_code
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 2edebf1..6d7b936 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -345,8 +345,7 @@ static inline void cpu_set_tls(CPUS390XState *env, target_ulong newtls)
env->aregs[1] = newtls & 0xffffffffULL;
}
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-#define old_cpu_init(model) (&cpu_s390x_init(model)->env)
+#define cpu_init(m) CPU(cpu_s390x_init(m))
#define cpu_exec cpu_s390x_exec
#define cpu_gen_code cpu_s390x_gen_code
#define cpu_signal_handler cpu_s390x_signal_handler
diff --git a/target-sh4/cpu.h b/target-sh4/cpu.h
index f6ba00e..1445533 100644
--- a/target-sh4/cpu.h
+++ b/target-sh4/cpu.h
@@ -232,15 +232,7 @@ void cpu_load_tlb(CPUSH4State * env);
#include "softfloat.h"
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUSH4State *old_cpu_init(const char *cpu_model)
-{
- SuperHCPU *cpu = cpu_sh4_init(cpu_model);
- if (cpu == NULL) {
- return NULL;
- }
- return &cpu->env;
-}
+#define cpu_init(m) CPU(cpu_sh4_init(m))
#define cpu_exec cpu_sh4_exec
#define cpu_gen_code cpu_sh4_gen_code
diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index ca2bdb1..4db26a6 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -592,15 +592,7 @@ hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env, target_ulong addr,
int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
#ifndef NO_CPU_IO_DEFS
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUSPARCState *old_cpu_init(const char *cpu_model)
-{
- SPARCCPU *cpu = cpu_sparc_init(cpu_model);
- if (cpu == NULL) {
- return NULL;
- }
- return &cpu->env;
-}
+#define cpu_init(m) CPU(cpu_sparc_init(m))
#endif
#define cpu_exec cpu_sparc_exec
diff --git a/target-xtensa/cpu.h b/target-xtensa/cpu.h
index 65f2af3..52d775d 100644
--- a/target-xtensa/cpu.h
+++ b/target-xtensa/cpu.h
@@ -375,15 +375,7 @@ typedef struct CPUXtensaState {
XtensaCPU *cpu_xtensa_init(const char *cpu_model);
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-static inline CPUXtensaState *old_cpu_init(const char *cpu_model)
-{
- XtensaCPU *cpu = cpu_xtensa_init(cpu_model);
- if (cpu == NULL) {
- return NULL;
- }
- return &cpu->env;
-}
+#define cpu_init(m) CPU(cpu_xtensa_init(m))
void xtensa_translate_init(void);
int cpu_xtensa_exec(CPUXtensaState *s);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 05/20] alpha: convert cpu_init to QOM
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (3 preceding siblings ...)
2012-12-18 20:03 ` [Qemu-devel] [RFC 04/20] cpu: replace trivial old_cpu_init functions Eduardo Habkost
@ 2012-12-18 20:03 ` Eduardo Habkost
2012-12-18 20:03 ` [Qemu-devel] [RFC 06/20] m68k: " Eduardo Habkost
` (15 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:03 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-alpha/cpu.h | 5 ++---
target-alpha/translate.c | 4 ++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index c04d436..a34cf0e 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -290,8 +290,7 @@ struct CPUAlphaState {
int implver;
};
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-#define old_cpu_init cpu_alpha_init
+#define cpu_init cpu_alpha_init
#define cpu_exec cpu_alpha_exec
#define cpu_gen_code cpu_alpha_gen_code
#define cpu_signal_handler cpu_alpha_signal_handler
@@ -428,7 +427,7 @@ enum {
IR_ZERO = 31,
};
-CPUAlphaState * cpu_alpha_init (const char *cpu_model);
+CPUState *cpu_alpha_init(const char *cpu_model);
int cpu_alpha_exec(CPUAlphaState *s);
/* you can call this signal handler from your SIGBUS and SIGSEGV
signal handlers to inform the virtual CPU of exceptions. non zero
diff --git a/target-alpha/translate.c b/target-alpha/translate.c
index 71fe1a1..ef51296 100644
--- a/target-alpha/translate.c
+++ b/target-alpha/translate.c
@@ -3517,7 +3517,7 @@ static const struct cpu_def_t cpu_defs[] = {
| AMASK_MVI | AMASK_TRAP | AMASK_PREFETCH), }
};
-CPUAlphaState * cpu_alpha_init (const char *cpu_model)
+CPUState *cpu_alpha_init(const char *cpu_model)
{
AlphaCPU *cpu;
CPUAlphaState *env;
@@ -3546,7 +3546,7 @@ CPUAlphaState * cpu_alpha_init (const char *cpu_model)
env->cpu_model_str = cpu_model;
qemu_init_vcpu(env);
- return env;
+ return CPU(cpu);
}
void restore_state_to_opc(CPUAlphaState *env, TranslationBlock *tb, int pc_pos)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 06/20] m68k: convert cpu_init to QOM
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (4 preceding siblings ...)
2012-12-18 20:03 ` [Qemu-devel] [RFC 05/20] alpha: convert cpu_init to QOM Eduardo Habkost
@ 2012-12-18 20:03 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 07/20] target-unicore32: " Eduardo Habkost
` (14 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:03 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-m68k/cpu.h | 5 ++---
target-m68k/helper.c | 4 ++--
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/target-m68k/cpu.h b/target-m68k/cpu.h
index fbb35dc..9823267 100644
--- a/target-m68k/cpu.h
+++ b/target-m68k/cpu.h
@@ -116,7 +116,7 @@ typedef struct CPUM68KState {
#include "cpu-qom.h"
void m68k_tcg_init(void);
-CPUM68KState *cpu_m68k_init(const char *cpu_model);
+CPUState *cpu_m68k_init(const char *cpu_model);
int cpu_m68k_exec(CPUM68KState *s);
void do_interrupt(CPUM68KState *env1);
void do_interrupt_m68k_hardirq(CPUM68KState *env1);
@@ -214,8 +214,7 @@ void register_m68k_insns (CPUM68KState *env);
#define TARGET_PHYS_ADDR_SPACE_BITS 32
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-#define old_cpu_init cpu_m68k_init
+#define cpu_init cpu_m68k_init
#define cpu_exec cpu_m68k_exec
#define cpu_gen_code cpu_m68k_gen_code
#define cpu_signal_handler cpu_m68k_signal_handler
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index a5d0100..6b6f5dd 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -98,7 +98,7 @@ static int fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
return 0;
}
-CPUM68KState *cpu_m68k_init(const char *cpu_model)
+CPUState *cpu_m68k_init(const char *cpu_model)
{
M68kCPU *cpu;
CPUM68KState *env;
@@ -126,7 +126,7 @@ CPUM68KState *cpu_m68k_init(const char *cpu_model)
cpu_reset(ENV_GET_CPU(env));
qemu_init_vcpu(env);
- return env;
+ return CPU(cpu);
}
void cpu_m68k_flush_flags(CPUM68KState *env, int cc_op)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 07/20] target-unicore32: convert cpu_init to QOM
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (5 preceding siblings ...)
2012-12-18 20:03 ` [Qemu-devel] [RFC 06/20] m68k: " Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 08/20] cpu: move cpu_model_str to CPUState Eduardo Habkost
` (13 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-unicore32/cpu.h | 6 +++---
target-unicore32/helper.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/target-unicore32/cpu.h b/target-unicore32/cpu.h
index 86a6959..43bdd84 100644
--- a/target-unicore32/cpu.h
+++ b/target-unicore32/cpu.h
@@ -122,13 +122,11 @@ void cpu_asr_write(CPUUniCore32State *env1, target_ulong val, target_ulong mask)
#define UC32_HWCAP_CMOV 4 /* 1 << 2 */
#define UC32_HWCAP_UCF64 8 /* 1 << 3 */
-#define cpu_init(m) ENV_GET_CPU(old_cpu_init(m))
-#define old_cpu_init uc32_cpu_init
+#define cpu_init uc32_cpu_init
#define cpu_exec uc32_cpu_exec
#define cpu_signal_handler uc32_cpu_signal_handler
#define cpu_handle_mmu_fault uc32_cpu_handle_mmu_fault
-CPUUniCore32State *uc32_cpu_init(const char *cpu_model);
int uc32_cpu_exec(CPUUniCore32State *s);
int uc32_cpu_signal_handler(int host_signum, void *pinfo, void *puc);
int uc32_cpu_handle_mmu_fault(CPUUniCore32State *env, target_ulong address, int rw,
@@ -162,6 +160,8 @@ static inline void cpu_set_tls(CPUUniCore32State *env, target_ulong newtls)
#include "cpu-qom.h"
#include "exec-all.h"
+CPUState *uc32_cpu_init(const char *cpu_model);
+
static inline void cpu_pc_from_tb(CPUUniCore32State *env, TranslationBlock *tb)
{
env->regs[31] = tb->pc;
diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index a9e226b..dc7b0b3 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -23,7 +23,7 @@
#define DPRINTF(fmt, ...) do {} while (0)
#endif
-CPUUniCore32State *uc32_cpu_init(const char *cpu_model)
+CPUState *uc32_cpu_init(const char *cpu_model)
{
UniCore32CPU *cpu;
CPUUniCore32State *env;
@@ -41,7 +41,7 @@ CPUUniCore32State *uc32_cpu_init(const char *cpu_model)
}
qemu_init_vcpu(env);
- return env;
+ return CPU(cpu);
}
uint32_t HELPER(clo)(uint32_t x)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 08/20] cpu: move cpu_model_str to CPUState
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (6 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 07/20] target-unicore32: " Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 09/20] cpu: introduce cpu_realize() Eduardo Habkost
` (12 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
cpu-defs.h | 1 -
exec.c | 3 ++-
include/qemu/cpu.h | 1 +
target-alpha/translate.c | 2 +-
target-arm/helper.c | 2 +-
target-i386/helper.c | 4 +---
target-m68k/helper.c | 2 +-
target-mips/translate.c | 2 +-
target-openrisc/cpu.c | 2 +-
target-ppc/helper.c | 2 +-
target-s390x/helper.c | 2 +-
target-sh4/translate.c | 2 +-
target-sparc/cpu.c | 2 +-
target-unicore32/cpu.c | 2 +-
14 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/cpu-defs.h b/cpu-defs.h
index 3669241..8b64a3d 100644
--- a/cpu-defs.h
+++ b/cpu-defs.h
@@ -204,7 +204,6 @@ typedef struct CPUWatchpoint {
/* user data */ \
void *opaque; \
\
- const char *cpu_model_str; \
struct KVMState *kvm_state; \
struct kvm_run *kvm_run; \
int kvm_fd; \
diff --git a/exec.c b/exec.c
index 8e8a852..3919145 100644
--- a/exec.c
+++ b/exec.c
@@ -526,7 +526,8 @@ void cpu_abort(CPUArchState *env, const char *fmt, ...)
CPUArchState *cpu_copy(CPUArchState *env)
{
- CPUArchState *new_env = CPU_GET_ENV(cpu_init(env->cpu_model_str));
+ CPUState *old_cpu = ENV_GET_CPU(env);
+ CPUArchState *new_env = CPU_GET_ENV(cpu_init(old_cpu->cpu_model_str));
CPUArchState *next_cpu = new_env->next_cpu;
int cpu_index = new_env->cpu_index;
#if defined(TARGET_HAS_ICE)
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 61b7698..b27b353 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -77,6 +77,7 @@ struct CPUState {
bool stop;
bool stopped;
+ const char *cpu_model_str; \
/* TODO Move common fields from CPUArchState here. */
};
diff --git a/target-alpha/translate.c b/target-alpha/translate.c
index ef51296..5c88f33 100644
--- a/target-alpha/translate.c
+++ b/target-alpha/translate.c
@@ -3543,7 +3543,7 @@ CPUState *cpu_alpha_init(const char *cpu_model)
}
env->implver = implver;
env->amask = amask;
- env->cpu_model_str = cpu_model;
+ CPU(cpu)->cpu_model_str = cpu_model;
qemu_init_vcpu(env);
return CPU(cpu);
diff --git a/target-arm/helper.c b/target-arm/helper.c
index ab8b734..e14bbbe 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -1268,7 +1268,7 @@ ARMCPU *cpu_arm_init(const char *cpu_model)
}
cpu = ARM_CPU(object_new(cpu_model));
env = &cpu->env;
- env->cpu_model_str = cpu_model;
+ CPU(cpu)->cpu_model_str = cpu_model;
arm_cpu_realize(cpu);
if (tcg_enabled() && !inited) {
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 00341c5..a0930be 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -1240,12 +1240,10 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
X86CPU *cpu_x86_init(const char *cpu_model)
{
X86CPU *cpu;
- CPUX86State *env;
Error *error = NULL;
cpu = X86_CPU(object_new(TYPE_X86_CPU));
- env = &cpu->env;
- env->cpu_model_str = cpu_model;
+ CPU(cpu)->cpu_model_str = cpu_model;
if (cpu_x86_register(cpu, cpu_model) < 0) {
object_delete(OBJECT(cpu));
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 6b6f5dd..4d88bb0 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -115,7 +115,7 @@ CPUState *cpu_m68k_init(const char *cpu_model)
m68k_tcg_init();
}
- env->cpu_model_str = cpu_model;
+ CPU(cpu)->cpu_model_str = cpu_model;
register_m68k_insns(env);
if (m68k_feature(env, M68K_FEATURE_CF_FPU)) {
diff --git a/target-mips/translate.c b/target-mips/translate.c
index 65e6725..1c20570 100644
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -15862,7 +15862,7 @@ MIPSCPU *cpu_mips_init(const char *cpu_model)
cpu = MIPS_CPU(object_new(TYPE_MIPS_CPU));
env = &cpu->env;
env->cpu_model = def;
- env->cpu_model_str = cpu_model;
+ CPU(cpu)->cpu_model_str = cpu_model;
#ifndef CONFIG_USER_ONLY
mmu_init(env, def);
diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c
index ba35b17..e152a3a 100644
--- a/target-openrisc/cpu.c
+++ b/target-openrisc/cpu.c
@@ -163,7 +163,7 @@ OpenRISCCPU *cpu_openrisc_init(const char *cpu_model)
return NULL;
}
cpu = OPENRISC_CPU(object_new(cpu_model));
- cpu->env.cpu_model_str = cpu_model;
+ CPU(cpu)->cpu_model_str = cpu_model;
openrisc_cpu_realize(OBJECT(cpu), NULL);
diff --git a/target-ppc/helper.c b/target-ppc/helper.c
index 48b19a7..4b80d4f 100644
--- a/target-ppc/helper.c
+++ b/target-ppc/helper.c
@@ -41,7 +41,7 @@ PowerPCCPU *cpu_ppc_init(const char *cpu_model)
ppc_translate_init();
}
- env->cpu_model_str = cpu_model;
+ CPU(cpu)->cpu_model_str = cpu_model;
cpu_ppc_register_internal(env, def);
qemu_init_vcpu(env);
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index b7b812a..80d62b9 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -84,7 +84,7 @@ S390CPU *cpu_s390x_init(const char *cpu_model)
s390x_translate_init();
}
- env->cpu_model_str = cpu_model;
+ CPU(cpu)->cpu_model_str = cpu_model;
qemu_init_vcpu(env);
return cpu;
}
diff --git a/target-sh4/translate.c b/target-sh4/translate.c
index 86493e1..6795d01 100644
--- a/target-sh4/translate.c
+++ b/target-sh4/translate.c
@@ -252,7 +252,7 @@ SuperHCPU *cpu_sh4_init(const char *cpu_model)
env = &cpu->env;
env->features = def->features;
sh4_translate_init();
- env->cpu_model_str = cpu_model;
+ CPU(cpu)->cpu_model_str = cpu_model;
cpu_reset(CPU(cpu));
cpu_register(env, def);
qemu_init_vcpu(env);
diff --git a/target-sparc/cpu.c b/target-sparc/cpu.c
index 882d306..2bbf24f 100644
--- a/target-sparc/cpu.c
+++ b/target-sparc/cpu.c
@@ -89,7 +89,7 @@ static int cpu_sparc_register(CPUSPARCState *env, const char *cpu_model)
env->def->features |= CPU_FEATURE_FLOAT128;
}
#endif
- env->cpu_model_str = cpu_model;
+ ENV_GET_CPU(env)->cpu_model_str = cpu_model;
env->version = def->iu_version;
env->fsr = def->fpu_version;
env->nwindows = def->nwindows;
diff --git a/target-unicore32/cpu.c b/target-unicore32/cpu.c
index 884c101..76750da 100644
--- a/target-unicore32/cpu.c
+++ b/target-unicore32/cpu.c
@@ -67,7 +67,7 @@ static void uc32_cpu_initfn(Object *obj)
CPUUniCore32State *env = &cpu->env;
cpu_exec_init(env);
- env->cpu_model_str = object_get_typename(obj);
+ CPU(cpu)->cpu_model_str = object_get_typename(obj);
#ifdef CONFIG_USER_ONLY
env->uncached_asr = ASR_MODE_USER;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 09/20] cpu: introduce cpu_realize()
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (7 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 08/20] cpu: move cpu_model_str to CPUState Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 23:13 ` Andreas Färber
2012-12-18 20:04 ` [Qemu-devel] [RFC 10/20] cpu: introduce generic_cpu_init() & generic_cpu_create() functions Eduardo Habkost
` (11 subsequent siblings)
20 siblings, 1 reply; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
This is just for testing/demonstration purposes. Probably this will be
replaced by the more generic DeviceState realize() method, later.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
include/qemu/cpu.h | 13 +++++++++++++
qom/cpu.c | 10 ++++++++++
2 files changed, 23 insertions(+)
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index b27b353..90bb27d 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -20,6 +20,7 @@
#ifndef QEMU_CPU_H
#define QEMU_CPU_H
+#include "error.h"
#include "qemu/object.h"
#include "qemu-thread.h"
@@ -41,6 +42,7 @@ typedef struct CPUState CPUState;
/**
* CPUClass:
* @reset: Callback to reset the #CPUState to its initial state.
+ * @realize: Realize function to finish CPU initialization.
*
* Represents a CPU family or model.
*/
@@ -50,6 +52,7 @@ typedef struct CPUClass {
/*< public >*/
void (*reset)(CPUState *cpu);
+ void (*realize)(CPUState *cpu, Error **errp);
} CPUClass;
/**
@@ -88,6 +91,16 @@ struct CPUState {
*/
void cpu_reset(CPUState *cpu);
+
+/**
+ * cpu_realize:
+ * @cpu: The CPU that is going to be "realized".
+ *
+ * Finishes initialization of the CPU object, after properties have been
+ * set.
+ */
+void cpu_realize(CPUState *cpu, Error **errp);
+
/**
* qemu_cpu_has_work:
* @cpu: The vCPU to check.
diff --git a/qom/cpu.c b/qom/cpu.c
index 5b36046..a96f6ee 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -30,6 +30,16 @@ void cpu_reset(CPUState *cpu)
}
}
+void cpu_realize(CPUState *cpu, Error **errp)
+{
+ CPUClass *klass = CPU_GET_CLASS(cpu);
+
+ if (klass->realize) {
+ (*klass->realize)(cpu, errp);
+ }
+}
+
+
static void cpu_common_reset(CPUState *cpu)
{
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [Qemu-devel] [RFC 09/20] cpu: introduce cpu_realize()
2012-12-18 20:04 ` [Qemu-devel] [RFC 09/20] cpu: introduce cpu_realize() Eduardo Habkost
@ 2012-12-18 23:13 ` Andreas Färber
0 siblings, 0 replies; 24+ messages in thread
From: Andreas Färber @ 2012-12-18 23:13 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: qemu-devel
Am 18.12.2012 21:04, schrieb Eduardo Habkost:
> This is just for testing/demonstration purposes. Probably this will be
> replaced by the more generic DeviceState realize() method, later.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Such a function was nack'ed for Object, the reason being that the goal
was to set realized = true in one central place rather than sprinkling
_realize() calls everywhere as done for qdev init.
Since CPU is close to becoming a device, I would rather not do this
differently for the CPU, but I can truely understand the utility of it
in this series... :)
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 24+ messages in thread
* [Qemu-devel] [RFC 10/20] cpu: introduce generic_cpu_init() & generic_cpu_create() functions
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (8 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 09/20] cpu: introduce cpu_realize() Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 11/20] target-openrisc: implement CPU realize() method Eduardo Habkost
` (10 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Useful for architectures where cpu_init() is just creation of a CPU
object and a call to cpu_realize().
All the functions should need is the base CPU class name and cpu_model
string. Any target-specific behavior/information can later be provided
by the target-specific CPU class, if necessary.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
include/qemu/cpu.h | 24 ++++++++++++++++++++++++
qom/cpu.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 90bb27d..7461319 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -151,4 +151,28 @@ bool cpu_is_stopped(CPUState *cpu);
void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
+/* generic_cpu_create:
+ * @base_class_name: The name of the base CPU class
+ * @cpu_model: full CPU model string to be parsed
+ * @errp: pointer to Error pointer, where error information can be returned
+ *
+ * Generic target-independent function to create a CPU object. Caller
+ * should call cpu_realize() later.
+ *
+ * Any target-specific behavior can be set as CPUClass fields in the base class.
+ */
+CPUState *generic_cpu_create(const char *base_class_name,
+ const char *cpu_model,
+ Error **errp);
+
+/* generic_cpu_init:
+ * @base_class_name: The name of the base CPU class
+ * @cpu_model: full CPU model string to be parsed
+ *
+ * Generic target-independent cpu_init implementation. Any target-specific
+ * behavior can be set as CPUClass fields in the base class.
+ */
+CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model);
+
+
#endif
diff --git a/qom/cpu.c b/qom/cpu.c
index a96f6ee..42cbe42 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -19,6 +19,7 @@
*/
#include "qemu/cpu.h"
+#include "qemu-error.h"
#include "qemu-common.h"
void cpu_reset(CPUState *cpu)
@@ -65,4 +66,41 @@ static void cpu_register_types(void)
type_register_static(&cpu_type_info);
}
+CPUState *generic_cpu_create(const char *base_class_name,
+ const char *cpu_model,
+ Error **errp)
+{
+ CPUState *cpu;
+
+ if (!object_class_by_name(cpu_model)) {
+ error_setg(errp, "Can't find CPU class for model: %s", cpu_model);
+ return NULL;
+ }
+
+ cpu = CPU(object_new(cpu_model));
+ cpu->cpu_model_str = cpu_model;
+ return cpu;
+}
+
+CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model)
+{
+ CPUState *cpu;
+ Error *err = NULL;
+
+ cpu = generic_cpu_create(base_class_name, cpu_model, &err);
+ if (err) {
+ goto error;
+ }
+
+ cpu_realize(cpu, &err);
+ if (err) {
+ goto error;
+ }
+
+ return cpu;
+error:
+ error_report("cpu_init: %s", error_get_pretty(err));
+ return NULL;
+}
+
type_init(cpu_register_types)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 11/20] target-openrisc: implement CPU realize() method
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (9 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 10/20] cpu: introduce generic_cpu_init() & generic_cpu_create() functions Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 12/20] hw/openrisc_sim.c: coding style/indentation fix Eduardo Habkost
` (9 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-openrisc/cpu.c | 19 ++++++++++++++-----
target-openrisc/cpu.h | 1 -
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c
index e152a3a..0a8253e 100644
--- a/target-openrisc/cpu.c
+++ b/target-openrisc/cpu.c
@@ -19,6 +19,7 @@
#include "cpu.h"
#include "qemu-common.h"
+#include "qemu-error.h"
/* CPUClass::reset() */
static void openrisc_cpu_reset(CPUState *s)
@@ -62,12 +63,12 @@ static inline void set_feature(OpenRISCCPU *cpu, int feature)
cpu->env.cpucfgr = cpu->feature;
}
-void openrisc_cpu_realize(Object *obj, Error **errp)
+static void openrisc_cpu_realize(CPUState *cpu, Error **errp)
{
- OpenRISCCPU *cpu = OPENRISC_CPU(obj);
+ OpenRISCCPU *oc = OPENRISC_CPU(cpu);
- qemu_init_vcpu(&cpu->env);
- cpu_reset(CPU(cpu));
+ qemu_init_vcpu(&oc->env);
+ cpu_reset(cpu);
}
static void openrisc_cpu_initfn(Object *obj)
@@ -120,6 +121,7 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
occ->parent_reset = cc->reset;
cc->reset = openrisc_cpu_reset;
+ cc->realize = openrisc_cpu_realize;
}
static void cpu_register(const OpenRISCCPUInfo *info)
@@ -158,6 +160,7 @@ static void openrisc_cpu_register_types(void)
OpenRISCCPU *cpu_openrisc_init(const char *cpu_model)
{
OpenRISCCPU *cpu;
+ Error *err = NULL;
if (!object_class_by_name(cpu_model)) {
return NULL;
@@ -165,9 +168,15 @@ OpenRISCCPU *cpu_openrisc_init(const char *cpu_model)
cpu = OPENRISC_CPU(object_new(cpu_model));
CPU(cpu)->cpu_model_str = cpu_model;
- openrisc_cpu_realize(OBJECT(cpu), NULL);
+ cpu_realize(CPU(cpu), &err);
+ if (err) {
+ goto error;
+ }
return cpu;
+error:
+ error_report("cpu_openrisc_init: %s", error_get_pretty(err));
+ return NULL;
}
typedef struct OpenRISCCPUList {
diff --git a/target-openrisc/cpu.h b/target-openrisc/cpu.h
index d7470a9..d0a2fdc 100644
--- a/target-openrisc/cpu.h
+++ b/target-openrisc/cpu.h
@@ -347,7 +347,6 @@ static inline CPUOpenRISCState *openrisc_cpu_get_env(OpenRISCCPU *cpu)
#define CPU_GET_ENV(cpu) openrisc_cpu_get_env(OPENRISC_CPU(cpu))
OpenRISCCPU *cpu_openrisc_init(const char *cpu_model);
-void openrisc_cpu_realize(Object *obj, Error **errp);
void cpu_openrisc_list(FILE *f, fprintf_function cpu_fprintf);
int cpu_openrisc_exec(CPUOpenRISCState *s);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 12/20] hw/openrisc_sim.c: coding style/indentation fix
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (10 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 11/20] target-openrisc: implement CPU realize() method Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 13/20] target-openrisc: replace cpu_openrisc_init() with generic_cpu_init() Eduardo Habkost
` (8 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
hw/openrisc_sim.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/openrisc_sim.c b/hw/openrisc_sim.c
index 23c66df..440dc9e 100644
--- a/hw/openrisc_sim.c
+++ b/hw/openrisc_sim.c
@@ -96,7 +96,7 @@ static void openrisc_sim_init(QEMUMachineInitArgs *args)
ram_addr_t ram_size = args->ram_size;
const char *cpu_model = args->cpu_model;
const char *kernel_filename = args->kernel_filename;
- OpenRISCCPU *cpu = NULL;
+ OpenRISCCPU *cpu = NULL;
MemoryRegion *ram;
int n;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 13/20] target-openrisc: replace cpu_openrisc_init() with generic_cpu_init()
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (11 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 12/20] hw/openrisc_sim.c: coding style/indentation fix Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 14/20] target-arm: move final steps of cpu_arm_init() to realize function Eduardo Habkost
` (7 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
hw/openrisc_sim.c | 2 +-
target-openrisc/cpu.c | 22 ----------------------
target-openrisc/cpu.h | 4 +---
3 files changed, 2 insertions(+), 26 deletions(-)
diff --git a/hw/openrisc_sim.c b/hw/openrisc_sim.c
index 440dc9e..1955854 100644
--- a/hw/openrisc_sim.c
+++ b/hw/openrisc_sim.c
@@ -105,7 +105,7 @@ static void openrisc_sim_init(QEMUMachineInitArgs *args)
}
for (n = 0; n < smp_cpus; n++) {
- cpu = cpu_openrisc_init(cpu_model);
+ cpu = OPENRISC_CPU(generic_cpu_init(TYPE_OPENRISC_CPU, cpu_model));
if (cpu == NULL) {
qemu_log("Unable to find CPU defineition!\n");
exit(1);
diff --git a/target-openrisc/cpu.c b/target-openrisc/cpu.c
index 0a8253e..1ec4e2a 100644
--- a/target-openrisc/cpu.c
+++ b/target-openrisc/cpu.c
@@ -157,28 +157,6 @@ static void openrisc_cpu_register_types(void)
}
}
-OpenRISCCPU *cpu_openrisc_init(const char *cpu_model)
-{
- OpenRISCCPU *cpu;
- Error *err = NULL;
-
- if (!object_class_by_name(cpu_model)) {
- return NULL;
- }
- cpu = OPENRISC_CPU(object_new(cpu_model));
- CPU(cpu)->cpu_model_str = cpu_model;
-
- cpu_realize(CPU(cpu), &err);
- if (err) {
- goto error;
- }
-
- return cpu;
-error:
- error_report("cpu_openrisc_init: %s", error_get_pretty(err));
- return NULL;
-}
-
typedef struct OpenRISCCPUList {
fprintf_function cpu_fprintf;
FILE *file;
diff --git a/target-openrisc/cpu.h b/target-openrisc/cpu.h
index d0a2fdc..e6b3bfa 100644
--- a/target-openrisc/cpu.h
+++ b/target-openrisc/cpu.h
@@ -346,8 +346,6 @@ static inline CPUOpenRISCState *openrisc_cpu_get_env(OpenRISCCPU *cpu)
#define CPU_GET_ENV(cpu) openrisc_cpu_get_env(OPENRISC_CPU(cpu))
-OpenRISCCPU *cpu_openrisc_init(const char *cpu_model);
-
void cpu_openrisc_list(FILE *f, fprintf_function cpu_fprintf);
int cpu_openrisc_exec(CPUOpenRISCState *s);
void do_interrupt(CPUOpenRISCState *env);
@@ -385,7 +383,7 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
int *prot, target_ulong address, int rw);
#endif
-#define cpu_init(m) CPU(cpu_openrisc_init(m))
+#define cpu_init(m) generic_cpu_init(TYPE_OPENRISC_CPU, m)
#if defined(CONFIG_USER_ONLY)
static inline void cpu_clone_regs(CPUOpenRISCState *env, target_ulong newsp)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 14/20] target-arm: move final steps of cpu_arm_init() to realize function
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (12 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 13/20] target-openrisc: replace cpu_openrisc_init() with generic_cpu_init() Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 15/20] target-arm: replace cpu_arm_init() with generic_cpu_init() Eduardo Habkost
` (6 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
This way we will be able to replace cpu_arm_init() with
generic_cpu_init().
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-arm/cpu-qom.h | 1 -
target-arm/cpu.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++-
target-arm/helper.c | 76 +---------------------------------------------------
3 files changed, 76 insertions(+), 77 deletions(-)
diff --git a/target-arm/cpu-qom.h b/target-arm/cpu-qom.h
index d7801f3..2cc1e61 100644
--- a/target-arm/cpu-qom.h
+++ b/target-arm/cpu-qom.h
@@ -114,7 +114,6 @@ static inline CPUARMState *arm_cpu_get_env(ARMCPU *cpu)
#define CPU_GET_ENV(cpu) arm_cpu_get_env(ARM_CPU(cpu))
-void arm_cpu_realize(ARMCPU *cpu);
void register_cp_regs_for_features(ARMCPU *cpu);
#endif
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index b00f5fa..7409d65 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -24,6 +24,7 @@
#include "hw/loader.h"
#endif
#include "sysemu.h"
+#include "gdbstub.h"
static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque)
{
@@ -147,8 +148,61 @@ static void arm_cpu_finalizefn(Object *obj)
g_hash_table_destroy(cpu->cp_regs);
}
-void arm_cpu_realize(ARMCPU *cpu)
+static int vfp_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg)
{
+ int nregs;
+
+ /* VFP data registers are always little-endian. */
+ nregs = arm_feature(env, ARM_FEATURE_VFP3) ? 32 : 16;
+ if (reg < nregs) {
+ stfq_le_p(buf, env->vfp.regs[reg]);
+ return 8;
+ }
+ if (arm_feature(env, ARM_FEATURE_NEON)) {
+ /* Aliases for Q regs. */
+ nregs += 16;
+ if (reg < nregs) {
+ stfq_le_p(buf, env->vfp.regs[(reg - 32) * 2]);
+ stfq_le_p(buf + 8, env->vfp.regs[(reg - 32) * 2 + 1]);
+ return 16;
+ }
+ }
+ switch (reg - nregs) {
+ case 0: stl_p(buf, env->vfp.xregs[ARM_VFP_FPSID]); return 4;
+ case 1: stl_p(buf, env->vfp.xregs[ARM_VFP_FPSCR]); return 4;
+ case 2: stl_p(buf, env->vfp.xregs[ARM_VFP_FPEXC]); return 4;
+ }
+ return 0;
+}
+
+static int vfp_gdb_set_reg(CPUARMState *env, uint8_t *buf, int reg)
+{
+ int nregs;
+
+ nregs = arm_feature(env, ARM_FEATURE_VFP3) ? 32 : 16;
+ if (reg < nregs) {
+ env->vfp.regs[reg] = ldfq_le_p(buf);
+ return 8;
+ }
+ if (arm_feature(env, ARM_FEATURE_NEON)) {
+ nregs += 16;
+ if (reg < nregs) {
+ env->vfp.regs[(reg - 32) * 2] = ldfq_le_p(buf);
+ env->vfp.regs[(reg - 32) * 2 + 1] = ldfq_le_p(buf + 8);
+ return 16;
+ }
+ }
+ switch (reg - nregs) {
+ case 0: env->vfp.xregs[ARM_VFP_FPSID] = ldl_p(buf); return 4;
+ case 1: env->vfp.xregs[ARM_VFP_FPSCR] = ldl_p(buf); return 4;
+ case 2: env->vfp.xregs[ARM_VFP_FPEXC] = ldl_p(buf) & (1 << 30); return 4;
+ }
+ return 0;
+}
+
+static void arm_cpu_realize(CPUState *cobj, Error **errp)
+{
+ ARMCPU *cpu = ARM_CPU(cobj);
/* This function is called by cpu_arm_init() because it
* needs to do common actions based on feature bits, etc
* that have been set by the subclass init functions.
@@ -156,6 +210,7 @@ void arm_cpu_realize(ARMCPU *cpu)
* a true realize function instead.
*/
CPUARMState *env = &cpu->env;
+ static int inited = 0;
/* Some features automatically imply others: */
if (arm_feature(env, ARM_FEATURE_V7)) {
set_feature(env, ARM_FEATURE_VAPA);
@@ -197,6 +252,24 @@ void arm_cpu_realize(ARMCPU *cpu)
}
register_cp_regs_for_features(cpu);
+
+ if (tcg_enabled() && !inited) {
+ inited = 1;
+ arm_translate_init();
+ }
+
+ cpu_reset(CPU(cpu));
+ if (arm_feature(env, ARM_FEATURE_NEON)) {
+ gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
+ 51, "arm-neon.xml", 0);
+ } else if (arm_feature(env, ARM_FEATURE_VFP3)) {
+ gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
+ 35, "arm-vfp3.xml", 0);
+ } else if (arm_feature(env, ARM_FEATURE_VFP)) {
+ gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
+ 19, "arm-vfp.xml", 0);
+ }
+ qemu_init_vcpu(env);
}
/* CPU models */
@@ -766,6 +839,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
acc->parent_reset = cc->reset;
cc->reset = arm_cpu_reset;
+ cc->realize = arm_cpu_realize;
}
static void cpu_register(const ARMCPUInfo *info)
diff --git a/target-arm/helper.c b/target-arm/helper.c
index e14bbbe..2a62a7f 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -1,5 +1,4 @@
#include "cpu.h"
-#include "gdbstub.h"
#include "helper.h"
#include "host-utils.h"
#include "sysemu.h"
@@ -12,58 +11,6 @@ static inline int get_phys_addr(CPUARMState *env, uint32_t address,
target_ulong *page_size);
#endif
-static int vfp_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg)
-{
- int nregs;
-
- /* VFP data registers are always little-endian. */
- nregs = arm_feature(env, ARM_FEATURE_VFP3) ? 32 : 16;
- if (reg < nregs) {
- stfq_le_p(buf, env->vfp.regs[reg]);
- return 8;
- }
- if (arm_feature(env, ARM_FEATURE_NEON)) {
- /* Aliases for Q regs. */
- nregs += 16;
- if (reg < nregs) {
- stfq_le_p(buf, env->vfp.regs[(reg - 32) * 2]);
- stfq_le_p(buf + 8, env->vfp.regs[(reg - 32) * 2 + 1]);
- return 16;
- }
- }
- switch (reg - nregs) {
- case 0: stl_p(buf, env->vfp.xregs[ARM_VFP_FPSID]); return 4;
- case 1: stl_p(buf, env->vfp.xregs[ARM_VFP_FPSCR]); return 4;
- case 2: stl_p(buf, env->vfp.xregs[ARM_VFP_FPEXC]); return 4;
- }
- return 0;
-}
-
-static int vfp_gdb_set_reg(CPUARMState *env, uint8_t *buf, int reg)
-{
- int nregs;
-
- nregs = arm_feature(env, ARM_FEATURE_VFP3) ? 32 : 16;
- if (reg < nregs) {
- env->vfp.regs[reg] = ldfq_le_p(buf);
- return 8;
- }
- if (arm_feature(env, ARM_FEATURE_NEON)) {
- nregs += 16;
- if (reg < nregs) {
- env->vfp.regs[(reg - 32) * 2] = ldfq_le_p(buf);
- env->vfp.regs[(reg - 32) * 2 + 1] = ldfq_le_p(buf + 8);
- return 16;
- }
- }
- switch (reg - nregs) {
- case 0: env->vfp.xregs[ARM_VFP_FPSID] = ldl_p(buf); return 4;
- case 1: env->vfp.xregs[ARM_VFP_FPSCR] = ldl_p(buf); return 4;
- case 2: env->vfp.xregs[ARM_VFP_FPEXC] = ldl_p(buf) & (1 << 30); return 4;
- }
- return 0;
-}
-
static int dacr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value)
{
env->cp15.c3 = value;
@@ -1260,34 +1207,13 @@ void register_cp_regs_for_features(ARMCPU *cpu)
ARMCPU *cpu_arm_init(const char *cpu_model)
{
ARMCPU *cpu;
- CPUARMState *env;
- static int inited = 0;
if (!object_class_by_name(cpu_model)) {
return NULL;
}
cpu = ARM_CPU(object_new(cpu_model));
- env = &cpu->env;
CPU(cpu)->cpu_model_str = cpu_model;
- arm_cpu_realize(cpu);
-
- if (tcg_enabled() && !inited) {
- inited = 1;
- arm_translate_init();
- }
-
- cpu_reset(CPU(cpu));
- if (arm_feature(env, ARM_FEATURE_NEON)) {
- gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
- 51, "arm-neon.xml", 0);
- } else if (arm_feature(env, ARM_FEATURE_VFP3)) {
- gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
- 35, "arm-vfp3.xml", 0);
- } else if (arm_feature(env, ARM_FEATURE_VFP)) {
- gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
- 19, "arm-vfp.xml", 0);
- }
- qemu_init_vcpu(env);
+ cpu_realize(CPU(cpu), NULL);
return cpu;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 15/20] target-arm: replace cpu_arm_init() with generic_cpu_init()
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (13 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 14/20] target-arm: move final steps of cpu_arm_init() to realize function Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 16/20] target-m68k: move final steps of cpu_m68k_init() to realize function Eduardo Habkost
` (5 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-arm/cpu.h | 6 ++++--
target-arm/helper.c | 13 -------------
2 files changed, 4 insertions(+), 15 deletions(-)
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 718f1d9..bf50ea1 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -232,7 +232,6 @@ typedef struct CPUARMState {
#include "cpu-qom.h"
-ARMCPU *cpu_arm_init(const char *cpu_model);
void arm_translate_init(void);
int cpu_arm_exec(CPUARMState *s);
void do_interrupt(CPUARMState *);
@@ -625,7 +624,10 @@ static inline bool cp_access_ok(CPUARMState *env,
#define TARGET_PHYS_ADDR_SPACE_BITS 40
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#define cpu_init(m) CPU(cpu_arm_init(m))
+#define cpu_init(m) generic_cpu_init(TYPE_ARM_CPU, m)
+
+/* helper for existing code easily create an ARM CPU: */
+#define cpu_arm_init(m) ARM_CPU(cpu_init(m))
#define cpu_exec cpu_arm_exec
#define cpu_gen_code cpu_arm_gen_code
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 2a62a7f..036c056 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -1204,19 +1204,6 @@ void register_cp_regs_for_features(ARMCPU *cpu)
}
}
-ARMCPU *cpu_arm_init(const char *cpu_model)
-{
- ARMCPU *cpu;
-
- if (!object_class_by_name(cpu_model)) {
- return NULL;
- }
- cpu = ARM_CPU(object_new(cpu_model));
- CPU(cpu)->cpu_model_str = cpu_model;
- cpu_realize(CPU(cpu), NULL);
- return cpu;
-}
-
typedef struct ARMCPUListState {
fprintf_function cpu_fprintf;
FILE *file;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 16/20] target-m68k: move final steps of cpu_m68k_init() to realize function
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (14 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 15/20] target-arm: replace cpu_arm_init() with generic_cpu_init() Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 17/20] target-m68k: replace cpu_m68k_init() with generic_cpu_init() Eduardo Habkost
` (4 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-m68k/cpu.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
target-m68k/helper.c | 47 +----------------------------------------------
2 files changed, 52 insertions(+), 47 deletions(-)
diff --git a/target-m68k/cpu.c b/target-m68k/cpu.c
index 3e70bb0..2e8d60e 100644
--- a/target-m68k/cpu.c
+++ b/target-m68k/cpu.c
@@ -20,7 +20,7 @@
#include "cpu.h"
#include "qemu-common.h"
-
+#include "gdbstub.h"
static void m68k_set_feature(CPUM68KState *env, int feature)
{
@@ -127,6 +127,55 @@ static void m68k_cpu_initfn(Object *obj)
cpu_exec_init(env);
}
+static int fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
+{
+ if (n < 8) {
+ stfq_p(mem_buf, env->fregs[n]);
+ return 8;
+ }
+ if (n < 11) {
+ /* FP control registers (not implemented) */
+ memset(mem_buf, 0, 4);
+ return 4;
+ }
+ return 0;
+}
+
+static int fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
+{
+ if (n < 8) {
+ env->fregs[n] = ldfq_p(mem_buf);
+ return 8;
+ }
+ if (n < 11) {
+ /* FP control registers (not implemented) */
+ return 4;
+ }
+ return 0;
+}
+
+static void cpu_m68k_realize(CPUState *cobj, Error **errp)
+{
+ M68kCPU *cpu = M68K_CPU(cobj);
+ CPUM68KState *env = &cpu->env;
+ static int inited;
+
+ if (!inited) {
+ inited = 1;
+ m68k_tcg_init();
+ }
+
+ register_m68k_insns(env);
+ if (m68k_feature(env, M68K_FEATURE_CF_FPU)) {
+ gdb_register_coprocessor(env, fpu_gdb_get_reg, fpu_gdb_set_reg,
+ 11, "cf-fp.xml", 18);
+ }
+ /* TODO: Add [E]MAC registers. */
+
+ cpu_reset(cobj);
+ qemu_init_vcpu(env);
+}
+
static void m68k_cpu_class_init(ObjectClass *c, void *data)
{
M68kCPUClass *mcc = M68K_CPU_CLASS(c);
@@ -134,6 +183,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
mcc->parent_reset = cc->reset;
cc->reset = m68k_cpu_reset;
+ cc->realize = cpu_m68k_realize;
}
static void register_cpu_type(const M68kCPUInfo *info)
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 4d88bb0..f122706 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -19,7 +19,6 @@
*/
#include "cpu.h"
-#include "gdbstub.h"
#include "helpers.h"
@@ -71,61 +70,17 @@ void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf)
g_slist_free(list);
}
-static int fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
-{
- if (n < 8) {
- stfq_p(mem_buf, env->fregs[n]);
- return 8;
- }
- if (n < 11) {
- /* FP control registers (not implemented) */
- memset(mem_buf, 0, 4);
- return 4;
- }
- return 0;
-}
-
-static int fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
-{
- if (n < 8) {
- env->fregs[n] = ldfq_p(mem_buf);
- return 8;
- }
- if (n < 11) {
- /* FP control registers (not implemented) */
- return 4;
- }
- return 0;
-}
-
CPUState *cpu_m68k_init(const char *cpu_model)
{
M68kCPU *cpu;
- CPUM68KState *env;
- static int inited;
if (object_class_by_name(cpu_model) == NULL) {
return NULL;
}
cpu = M68K_CPU(object_new(cpu_model));
- env = &cpu->env;
-
- if (!inited) {
- inited = 1;
- m68k_tcg_init();
- }
-
CPU(cpu)->cpu_model_str = cpu_model;
+ cpu_realize(CPU(cpu), NULL);
- register_m68k_insns(env);
- if (m68k_feature(env, M68K_FEATURE_CF_FPU)) {
- gdb_register_coprocessor(env, fpu_gdb_get_reg, fpu_gdb_set_reg,
- 11, "cf-fp.xml", 18);
- }
- /* TODO: Add [E]MAC registers. */
-
- cpu_reset(ENV_GET_CPU(env));
- qemu_init_vcpu(env);
return CPU(cpu);
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 17/20] target-m68k: replace cpu_m68k_init() with generic_cpu_init()
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (15 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 16/20] target-m68k: move final steps of cpu_m68k_init() to realize function Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 18/20] target-unicore32: move final steps of uc32_cpu_init() to realize function Eduardo Habkost
` (3 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-m68k/cpu.h | 3 +--
target-m68k/helper.c | 14 --------------
2 files changed, 1 insertion(+), 16 deletions(-)
diff --git a/target-m68k/cpu.h b/target-m68k/cpu.h
index 9823267..3573c05 100644
--- a/target-m68k/cpu.h
+++ b/target-m68k/cpu.h
@@ -116,7 +116,6 @@ typedef struct CPUM68KState {
#include "cpu-qom.h"
void m68k_tcg_init(void);
-CPUState *cpu_m68k_init(const char *cpu_model);
int cpu_m68k_exec(CPUM68KState *s);
void do_interrupt(CPUM68KState *env1);
void do_interrupt_m68k_hardirq(CPUM68KState *env1);
@@ -214,7 +213,7 @@ void register_m68k_insns (CPUM68KState *env);
#define TARGET_PHYS_ADDR_SPACE_BITS 32
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#define cpu_init cpu_m68k_init
+#define cpu_init(m) generic_cpu_init(TYPE_M68K_CPU, m)
#define cpu_exec cpu_m68k_exec
#define cpu_gen_code cpu_m68k_gen_code
#define cpu_signal_handler cpu_m68k_signal_handler
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index f122706..6026c09 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -70,20 +70,6 @@ void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf)
g_slist_free(list);
}
-CPUState *cpu_m68k_init(const char *cpu_model)
-{
- M68kCPU *cpu;
-
- if (object_class_by_name(cpu_model) == NULL) {
- return NULL;
- }
- cpu = M68K_CPU(object_new(cpu_model));
- CPU(cpu)->cpu_model_str = cpu_model;
- cpu_realize(CPU(cpu), NULL);
-
- return CPU(cpu);
-}
-
void cpu_m68k_flush_flags(CPUM68KState *env, int cc_op)
{
int flags;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 18/20] target-unicore32: move final steps of uc32_cpu_init() to realize function
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (16 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 17/20] target-m68k: replace cpu_m68k_init() with generic_cpu_init() Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 19/20] target-unicore32: replace uc32_cpu_init() with generic_cpu_init() Eduardo Habkost
` (2 subsequent siblings)
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-unicore32/cpu.c | 21 +++++++++++++++++++++
target-unicore32/helper.c | 11 +----------
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/target-unicore32/cpu.c b/target-unicore32/cpu.c
index 76750da..5467127 100644
--- a/target-unicore32/cpu.c
+++ b/target-unicore32/cpu.c
@@ -80,12 +80,33 @@ static void uc32_cpu_initfn(Object *obj)
tlb_flush(env, 1);
}
+static void uc32_cpu_realize(CPUState *cobj, Error **errp)
+{
+ UniCore32CPU *cpu = UNICORE32_CPU(cobj);
+ CPUUniCore32State *env = &cpu->env;
+ static int inited;
+
+ if (!inited) {
+ inited = 1;
+ uc32_translate_init();
+ }
+
+ qemu_init_vcpu(env);
+}
+
+static void uc32_class_init(ObjectClass *oc, void *data)
+{
+ CPUClass *cc = CPU_CLASS(oc);
+ cc->realize = uc32_cpu_realize;
+}
+
static void uc32_register_cpu_type(const UniCore32CPUInfo *info)
{
TypeInfo type_info = {
.name = info->name,
.parent = TYPE_UNICORE32_CPU,
.instance_init = info->instance_init,
+ .class_init = uc32_class_init,
};
type_register_static(&type_info);
diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index dc7b0b3..927e591 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -26,21 +26,12 @@
CPUState *uc32_cpu_init(const char *cpu_model)
{
UniCore32CPU *cpu;
- CPUUniCore32State *env;
- static int inited = 1;
if (object_class_by_name(cpu_model) == NULL) {
return NULL;
}
cpu = UNICORE32_CPU(object_new(cpu_model));
- env = &cpu->env;
-
- if (inited) {
- inited = 0;
- uc32_translate_init();
- }
-
- qemu_init_vcpu(env);
+ cpu_realize(CPU(cpu), NULL);
return CPU(cpu);
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 19/20] target-unicore32: replace uc32_cpu_init() with generic_cpu_init()
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (17 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 18/20] target-unicore32: move final steps of uc32_cpu_init() to realize function Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 20:04 ` [Qemu-devel] [RFC 20/20] cpu: convert cpu_copy() to QOM Eduardo Habkost
2012-12-18 22:57 ` [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Andreas Färber
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-unicore32/cpu.h | 2 +-
target-unicore32/helper.c | 12 ------------
2 files changed, 1 insertion(+), 13 deletions(-)
diff --git a/target-unicore32/cpu.h b/target-unicore32/cpu.h
index 43bdd84..ad6fee4 100644
--- a/target-unicore32/cpu.h
+++ b/target-unicore32/cpu.h
@@ -122,7 +122,7 @@ void cpu_asr_write(CPUUniCore32State *env1, target_ulong val, target_ulong mask)
#define UC32_HWCAP_CMOV 4 /* 1 << 2 */
#define UC32_HWCAP_UCF64 8 /* 1 << 3 */
-#define cpu_init uc32_cpu_init
+#define cpu_init(m) generic_cpu_init(TYPE_UNICORE32_CPU, m)
#define cpu_exec uc32_cpu_exec
#define cpu_signal_handler uc32_cpu_signal_handler
#define cpu_handle_mmu_fault uc32_cpu_handle_mmu_fault
diff --git a/target-unicore32/helper.c b/target-unicore32/helper.c
index 927e591..731bd5c 100644
--- a/target-unicore32/helper.c
+++ b/target-unicore32/helper.c
@@ -23,18 +23,6 @@
#define DPRINTF(fmt, ...) do {} while (0)
#endif
-CPUState *uc32_cpu_init(const char *cpu_model)
-{
- UniCore32CPU *cpu;
-
- if (object_class_by_name(cpu_model) == NULL) {
- return NULL;
- }
- cpu = UNICORE32_CPU(object_new(cpu_model));
- cpu_realize(CPU(cpu), NULL);
- return CPU(cpu);
-}
-
uint32_t HELPER(clo)(uint32_t x)
{
return clo32(x);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* [Qemu-devel] [RFC 20/20] cpu: convert cpu_copy() to QOM
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (18 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 19/20] target-unicore32: replace uc32_cpu_init() with generic_cpu_init() Eduardo Habkost
@ 2012-12-18 20:04 ` Eduardo Habkost
2012-12-18 22:57 ` [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Andreas Färber
20 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-18 20:04 UTC (permalink / raw)
To: qemu-devel
Instead of using CPUArchState for parameters and return value,
get/return CPUState objects.
It is still an ugly hack that should die, but at least it's an ugly hack
that can use the QOM CPU object if necessary, and allows the calling
code to be converted to QOM as well.
This also keeps the cpu_copy() hack that we need to eventually kill.
The result of this series is:
$ g grep class_by_name target-*/cpu.c
$
That means all architectures that used CPU class lookup on its cpu_init()
implementation were converted to use generic_cpu_init().
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
cpu-all.h | 1 -
exec.c | 9 +++++----
include/qemu/cpu.h | 4 ++++
linux-user/syscall.c | 2 +-
4 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/cpu-all.h b/cpu-all.h
index d6b2b19..24662ce 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -352,7 +352,6 @@ void page_set_flags(target_ulong start, target_ulong end, int flags);
int page_check_range(target_ulong start, target_ulong len, int flags);
#endif
-CPUArchState *cpu_copy(CPUArchState *env);
CPUArchState *qemu_get_cpu(int cpu);
#define CPU_DUMP_CODE 0x00010000
diff --git a/exec.c b/exec.c
index 3919145..5af5652 100644
--- a/exec.c
+++ b/exec.c
@@ -524,10 +524,11 @@ void cpu_abort(CPUArchState *env, const char *fmt, ...)
abort();
}
-CPUArchState *cpu_copy(CPUArchState *env)
+CPUState *cpu_copy(CPUState *old_cpu)
{
- CPUState *old_cpu = ENV_GET_CPU(env);
- CPUArchState *new_env = CPU_GET_ENV(cpu_init(old_cpu->cpu_model_str));
+ CPUArchState *env = CPU_GET_ENV(old_cpu);
+ CPUState *new_cpu = cpu_init(old_cpu->cpu_model_str);
+ CPUArchState *new_env = CPU_GET_ENV(new_cpu);
CPUArchState *next_cpu = new_env->next_cpu;
int cpu_index = new_env->cpu_index;
#if defined(TARGET_HAS_ICE)
@@ -556,7 +557,7 @@ CPUArchState *cpu_copy(CPUArchState *env)
}
#endif
- return new_env;
+ return new_cpu;
}
#if !defined(CONFIG_USER_ONLY)
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
index 7461319..9cfbc94 100644
--- a/include/qemu/cpu.h
+++ b/include/qemu/cpu.h
@@ -174,5 +174,9 @@ CPUState *generic_cpu_create(const char *base_class_name,
*/
CPUState *generic_cpu_init(const char *base_class_name, const char *cpu_model);
+/* Legacy hacks that should eventually die: */
+
+/* CPU clone/copy hack, that does a memcpy of the ->env field */
+CPUState *cpu_copy(CPUState *cpu);
#endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 31d5276..400cf47 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4362,7 +4362,7 @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp,
ts = g_malloc0(sizeof(TaskState));
init_task_state(ts);
/* we create a new CPU instance. */
- new_env = cpu_copy(env);
+ new_env = CPU_GET_ENV(cpu_copy(ENV_GET_CPU(env)));
#if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC)
cpu_reset(ENV_GET_CPU(new_env));
#endif
--
1.7.11.7
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions
2012-12-18 20:03 [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Eduardo Habkost
` (19 preceding siblings ...)
2012-12-18 20:04 ` [Qemu-devel] [RFC 20/20] cpu: convert cpu_copy() to QOM Eduardo Habkost
@ 2012-12-18 22:57 ` Andreas Färber
2012-12-19 0:08 ` Eduardo Habkost
20 siblings, 1 reply; 24+ messages in thread
From: Andreas Färber @ 2012-12-18 22:57 UTC (permalink / raw)
To: Eduardo Habkost
Cc: Peter Maydell, Paul Brook, Guan Xuetao, qemu-devel, Igor Mammedov
Am 18.12.2012 21:03, schrieb Eduardo Habkost:
> This is just a proof of concept, of how I think we could gradually move to
> make the architectures share CPU creation/initialization code.
>
> I have implemented a quick cpu_realize() function, just for testing, while we
> don't have qdev realizefn support implemented.
>
> I have converted the following targets to use generic_cpu_init(): openrisc, arm,
> m68k, unicore32.
>
> To support other architectures with additional CPU lookup requirements
> (automatically adding "<arch>-cpu" suffix, or CPU model aliases), we can simply
> add fields to CPUClass for the target-specific behavior, that can be used by
> generic_cpu_create().
Without having looked at the series yet, what I have been experiencing
the last three rounds of CPU subclass conversions is that a per-target
name -> ObjectClass mapping works pretty well to abstract target'isms.
Therefore I was gonna pursue a CPUClass::find_by_name() hook or so as
generalization.
That would result in a name -> class, object_new(name(class)),
env->cpu_model_str = name, realize scheme. That would leave us with the
issues of QOM/device realization and of cpu_copy(). realize would in my
mind allow us to register a realizefn in CPU class_init, automatically
invoked by object_new, the targetted recursive realization allowing to
drop any realize call from cpu_init() and with a couple explicit
realization calls in *-user allowing us to repurpose cpu_init() for
creation. But maybe I'm overlooking something or we're looking at
different time frames. :-)
Andreas
> We can also extend generic_cpu_init() later to support
> parsing of "+feature,-feature" feature strings, to set properties on the CPU
> objects, like on x86.
>
> Note that this series is completely untested except for checking if the code
> compiles. I am just using the series as a way to demonstrate what I have in
> mind.
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions
2012-12-18 22:57 ` [Qemu-devel] [RFC 00/20] generic_cpu_init() and generic_cpu_create() functions Andreas Färber
@ 2012-12-19 0:08 ` Eduardo Habkost
0 siblings, 0 replies; 24+ messages in thread
From: Eduardo Habkost @ 2012-12-19 0:08 UTC (permalink / raw)
To: Andreas Färber
Cc: Peter Maydell, Paul Brook, Guan Xuetao, qemu-devel, Igor Mammedov
On Tue, Dec 18, 2012 at 11:57:58PM +0100, Andreas Färber wrote:
> Am 18.12.2012 21:03, schrieb Eduardo Habkost:
> > This is just a proof of concept, of how I think we could gradually move to
> > make the architectures share CPU creation/initialization code.
> >
> > I have implemented a quick cpu_realize() function, just for testing, while we
> > don't have qdev realizefn support implemented.
> >
> > I have converted the following targets to use generic_cpu_init(): openrisc, arm,
> > m68k, unicore32.
> >
> > To support other architectures with additional CPU lookup requirements
> > (automatically adding "<arch>-cpu" suffix, or CPU model aliases), we can simply
> > add fields to CPUClass for the target-specific behavior, that can be used by
> > generic_cpu_create().
>
> Without having looked at the series yet, what I have been experiencing
> the last three rounds of CPU subclass conversions is that a per-target
> name -> ObjectClass mapping works pretty well to abstract target'isms.
> Therefore I was gonna pursue a CPUClass::find_by_name() hook or so as
> generalization.
>
> That would result in a name -> class, object_new(name(class)),
> env->cpu_model_str = name, realize scheme. That would leave us with the
> issues of QOM/device realization and of cpu_copy(). realize would in my
> mind allow us to register a realizefn in CPU class_init, automatically
> invoked by object_new, the targetted recursive realization allowing to
> drop any realize call from cpu_init() and with a couple explicit
> realization calls in *-user allowing us to repurpose cpu_init() for
> creation. But maybe I'm overlooking something or we're looking at
> different time frames. :-)
I don't have specific plans after the de-duplication. All I was pursuing
was to make all architectures use the same code to create/realize CPUs,
so we can easily change the existing behavior/interfaces in the future
without touching 15 or 30 different files. For example, it is much
easier to make cpu_init() not call realize() if we have only one
cpu_init() function, not 15.
Right now, I see cpu_init() as a temporary interface to be eventually
replaced by [generic_]cpu_create(), or maybe something that will stay
but only for *-user. I expect all the rest of the qemu-system-* code to
eventually just use [generic_]cpu_create() to create not-realized-yet
CPU objects, once we make device realization happen somewhere else. I
guess that's equivalent to what you suggest above, I'm just calling the
resulting function "cpu_create()" instead of "cpu_init()".
But while we don't have all we need, we can at least have a generic
create()+realize() helper that everybody can use, and a simple
create-only helper, for code that for some reason need a
not-realized-yet CPU (I expect the PC code to need it, to fix the
APIC-ID topology bug).
>
> Andreas
>
> > We can also extend generic_cpu_init() later to support
> > parsing of "+feature,-feature" feature strings, to set properties on the CPU
> > objects, like on x86.
> >
> > Note that this series is completely untested except for checking if the code
> > compiles. I am just using the series as a way to demonstrate what I have in
> > mind.
>
> --
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
--
Eduardo
^ permalink raw reply [flat|nested] 24+ messages in thread