generic_cpu_init() and generic_cpu_create() functions
cover generic_cpu_init() and generic_cpu_create() functions
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(). 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.
Eduardo Habkost (20):
qemu-common.h: "use" env parameter in no-op version of
qemu_init_vcpu()
cpu: introduce CPU_GET_ENV macros
cpu: make cpu_init return CPUState QOM object
cpu: replace trivial old_cpu_init functions
alpha: convert cpu_init to QOM
m68k: convert cpu_init to QOM
target-unicore32: convert cpu_init to QOM
cpu: move cpu_model_str to CPUState
cpu: introduce cpu_realize()
cpu: introduce generic_cpu_init() & generic_cpu_create() functions
target-openrisc: implement CPU realize() method hw/openrisc_sim.c: coding style/indentation fix
target-openrisc: replace cpu_openrisc_init() with generic_cpu_init()
target-arm: move final steps of cpu_arm_init() to realize function
target-arm: replace cpu_arm_init() with generic_cpu_init()
target-m68k: move final steps of cpu_m68k_init() to realize function
target-m68k: replace cpu_m68k_init() with generic_cpu_init()
target-unicore32: move final steps of uc32_cpu_init() to realize
function
target-unicore32: replace uc32_cpu_init() with generic_cpu_init()
cpu: convert cpu_copy() to QOM
bsd-user/main.c | 2 +- cpu-all.h | 1 - cpu-defs.h | 1 - exec.c | 8 +++-- hw/alpha_dp264.c | 2 +- hw/an5206.c | 2 +- hw/dummy_m68k.c | 2 +- hw/mcf5208.c | 2 +- hw/openrisc_sim.c | 4 +-- hw/puv3.c | 2 +- hw/shix.c | 2 +- include/qemu/cpu.h | 42 ++++++++++++++++++++++ linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- qemu-common.h | 2 +- qom/cpu.c | 48 +++++++++++++++++++++++++ target-alpha/cpu-qom.h | 7 ++++ target-alpha/cpu.h | 2 +- target-alpha/translate.c | 6 ++-- target-arm/cpu-qom.h | 8 ++++- target-arm/cpu.c | 76 ++++++++++++++++++++++++++++++++++++++- target-arm/cpu.h | 13 +++---- target-arm/helper.c | 87 --------------------------------------------- target-cris/cpu-qom.h | 7 ++++ target-cris/cpu.h | 9 +---- target-i386/cpu-qom.h | 7 ++++ target-i386/cpu.h | 9 +---- target-i386/helper.c | 4 +-- target-lm32/cpu-qom.h | 7 ++++ target-lm32/cpu.h | 9 +---- target-m68k/cpu-qom.h | 7 ++++ target-m68k/cpu.c | 52 ++++++++++++++++++++++++++- target-m68k/cpu.h | 3 +- target-m68k/helper.c | 59 ------------------------------ target-microblaze/cpu-qom.h | 7 ++++ target-microblaze/cpu.h | 9 +---- target-mips/cpu-qom.h | 7 ++++ target-mips/cpu.h | 9 +---- target-mips/translate.c | 2 +- target-openrisc/cpu.c | 25 ++++--------- target-openrisc/cpu.h | 17 ++++----- target-ppc/cpu-qom.h | 7 ++++ target-ppc/cpu.h | 9 +---- target-ppc/helper.c | 2 +- target-s390x/cpu-qom.h | 7 ++++ target-s390x/cpu.h | 2 +- target-s390x/helper.c | 2 +- target-sh4/cpu-qom.h | 7 ++++ target-sh4/cpu.h | 9 +---- target-sh4/translate.c | 2 +- target-sparc/cpu-qom.h | 7 ++++ target-sparc/cpu.c | 2 +- target-sparc/cpu.h | 9 +---- target-unicore32/cpu-qom.h | 7 ++++ target-unicore32/cpu.c | 23 +++++++++++- target-unicore32/cpu.h | 5 +-- target-unicore32/helper.c | 21 ----------- target-xtensa/cpu-qom.h | 7 ++++ target-xtensa/cpu.h | 9 +---- 59 files changed, 394 insertions(+), 315 deletions(-)
Signature · 1 line
1.7.11.7
RFC 1/20 qemu-common.h: "use" env parameter in no-op version of qemu_init_vcpu()
This will avoid warnings about unused variables when compiling code that calls qemu_init_vcpu().
--- qemu-common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
qemu-common.h +1 -1
@@ -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
Signature · 1 line
1.7.11.7
RFC 2/20 cpu: introduce CPU_GET_ENV macros
In reply to Eduardo HabkostThis 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.
--- 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(+)
target-alpha/cpu-qom.h +7 -0
@@ -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
target-arm/cpu-qom.h +7 -0
@@ -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);
target-cris/cpu-qom.h +7 -0
@@ -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
target-i386/cpu-qom.h +7 -0
@@ -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);
target-lm32/cpu-qom.h +7 -0
@@ -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
target-m68k/cpu-qom.h +7 -0
@@ -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
target-microblaze/cpu-qom.h +7 -0
@@ -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
target-mips/cpu-qom.h +7 -0
@@ -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
target-openrisc/cpu.h +7 -0
@@ -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);
target-ppc/cpu-qom.h +7 -0
@@ -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
target-s390x/cpu-qom.h +7 -0
@@ -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
target-sh4/cpu-qom.h +7 -0
@@ -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
target-sparc/cpu-qom.h +7 -0
@@ -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
target-unicore32/cpu-qom.h +7 -0
@@ -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
target-xtensa/cpu-qom.h +7 -0
@@ -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
Signature · 1 line
1.7.11.7
RFC 3/20 cpu: make cpu_init return CPUState QOM object
In reply to Eduardo HabkostThis 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.
--- 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(-)
bsd-user/main.c +1 -1
@@ -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 );
exec.c +1 -1
@@ -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 )
hw/alpha_dp264.c +1 -1
@@ -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;
hw/an5206.c +1 -1
@@ -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" ); }
hw/dummy_m68k.c +1 -1
@@ -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 );
hw/mcf5208.c +1 -1
@@ -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 );
hw/puv3.c +1 -1
@@ -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" ); }
hw/shix.c +1 -1
@@ -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" );
linux-user/main.c +1 -1
@@ -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 );
target-alpha/cpu.h +2 -1
@@ -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
target-arm/cpu.h +2 -1
@@ -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) {
target-cris/cpu.h +2 -1
@@ -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 ) {
target-i386/cpu.h +2 -1
@@ -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 ) {
target-lm32/cpu.h +2 -1
@@ -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 ) {
target-m68k/cpu.h +2 -1
@@ -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
target-microblaze/cpu.h +2 -1
@@ -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 ) {
target-mips/cpu.h +2 -1
@@ -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 ) {
target-openrisc/cpu.h +2 -1
@@ -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) {
target-ppc/cpu.h +2 -1
@@ -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 ) {
target-s390x/cpu.h +2 -1
@@ -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
target-sh4/cpu.h +2 -1
@@ -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 ) {
target-sparc/cpu.h +2 -1
@@ -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 ) {
target-unicore32/cpu.h +2 -1
@@ -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
target-xtensa/cpu.h +2 -1
@@ -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 ) {
Signature · 1 line
1.7.11.7
RFC 4/20 cpu: replace trivial old_cpu_init functions
In reply to Eduardo HabkostMost 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).
--- 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(-)
target-arm/cpu.h +1 -9
@@ -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
target-cris/cpu.h +1 -9
@@ -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
target-i386/cpu.h +1 -9
@@ -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
target-lm32/cpu.h +1 -9
@@ -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
target-microblaze/cpu.h +1 -9
@@ -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
target-mips/cpu.h +1 -9
@@ -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);
target-openrisc/cpu.h +1 -9
@@ -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)
target-ppc/cpu.h +1 -9
@@ -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
target-s390x/cpu.h +1 -2
@@ -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
target-sh4/cpu.h +1 -9
@@ -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
target-sparc/cpu.h +1 -9
@@ -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
target-xtensa/cpu.h +1 -9
@@ -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);
Signature · 1 line
1.7.11.7
RFC 5/20 alpha: convert cpu_init to QOM
In reply to Eduardo Habkost--- target-alpha/cpu.h | 5 ++--- target-alpha/translate.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-)
target-alpha/cpu.h +2 -3
@@ -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
target-alpha/translate.c +2 -2
@@ -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)
Signature · 1 line
1.7.11.7
RFC 6/20 m68k: convert cpu_init to QOM
In reply to Eduardo Habkost--- target-m68k/cpu.h | 5 ++--- target-m68k/helper.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-)
target-m68k/cpu.h +2 -3
@@ -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
target-m68k/helper.c +2 -2
@@ -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)
Signature · 1 line
1.7.11.7
RFC 7/20 target-unicore32: convert cpu_init to QOM
In reply to Eduardo Habkost--- target-unicore32/cpu.h | 6 +++--- target-unicore32/helper.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
target-unicore32/cpu.h +3 -3
@@ -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;
target-unicore32/helper.c +2 -2
@@ -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)
Signature · 1 line
1.7.11.7
RFC 8/20 cpu: move cpu_model_str to CPUState
In reply to Eduardo Habkost--- 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(-)
cpu-defs.h +0 -1
@@ -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; \
exec.c +2 -1
@@ -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 )
include/qemu/cpu.h +1 -0
@@ -77,6 +77,7 @@ struct CPUState {bool stop;bool stopped; +const char *cpu_model_str; \/* TODO Move common fields from CPUArchState here. */ };
target-alpha/translate.c +1 -1
@@ -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);
target-arm/helper.c +1 -1
@@ -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) {
target-i386/helper.c +1 -3
@@ -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));
target-m68k/helper.c +1 -1
@@ -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 )) {
target-mips/translate.c +1 -1
@@ -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);
target-openrisc/cpu.c +1 -1
@@ -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 );
target-ppc/helper.c +1 -1
@@ -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);
target-s390x/helper.c +1 -1
@@ -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; }
target-sh4/translate.c +1 -1
@@ -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);
target-sparc/cpu.c +1 -1
@@ -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;
target-unicore32/cpu.c +1 -1
@@ -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 ;
Signature · 1 line
1.7.11.7
RFC 9/20 cpu: introduce cpu_realize()
In reply to Eduardo HabkostThis is just for testing/demonstration purposes. Probably this will be replaced by the more generic DeviceState realize() method, later.
--- include/qemu/cpu.h | 13 +++++++++++++ qom/cpu.c | 10 ++++++++++ 2 files changed, 23 insertions(+)
include/qemu/cpu.h +13 -0
@@ -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.
qom/cpu.c +10 -0
@@ -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) { }
Signature · 1 line
1.7.11.7
Re: [Qemu-devel] [RFC 09/20] cpu: introduce cpu_realize()
Am 18.12.2012 21:04, schrieb Eduardo Habkost:
Quoted 4 lines
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 <[email protected]>
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
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
RFC 10/20 cpu: introduce generic_cpu_init() & generic_cpu_create() functions
In reply to Eduardo HabkostUseful 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.
--- include/qemu/cpu.h | 24 ++++++++++++++++++++++++ qom/cpu.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+)
include/qemu/cpu.h +24 -0
@@ -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
qom/cpu.c +38 -0
@@ -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)
Signature · 1 line
1.7.11.7
RFC 11/20 target-openrisc: implement CPU realize() method
In reply to Eduardo Habkost--- target-openrisc/cpu.c | 19 ++++++++++++++----- target-openrisc/cpu.h | 1 - 2 files changed, 14 insertions(+), 6 deletions(-)
target-openrisc/cpu.c +14 -5
@@ -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 {
target-openrisc/cpu.h +0 -1
@@ -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);
Signature · 1 line
1.7.11.7
RFC 12/20 hw/openrisc_sim.c: coding style/indentation fix
In reply to Eduardo Habkost--- hw/openrisc_sim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/openrisc_sim.c +1 -1
@@ -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;
Signature · 1 line
1.7.11.7
RFC 13/20 target-openrisc: replace cpu_openrisc_init() with generic_cpu_init()
In reply to Eduardo Habkost--- hw/openrisc_sim.c | 2 +- target-openrisc/cpu.c | 22 ---------------------- target-openrisc/cpu.h | 4 +--- 3 files changed, 2 insertions(+), 26 deletions(-)
hw/openrisc_sim.c +1 -1
@@ -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 );
target-openrisc/cpu.c +0 -22
@@ -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;
target-openrisc/cpu.h +1 -3
@@ -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)
Signature · 1 line
1.7.11.7
RFC 14/20 target-arm: move final steps of cpu_arm_init() to realize function
In reply to Eduardo HabkostThis way we will be able to replace cpu_arm_init() with generic_cpu_init().
--- target-arm/cpu-qom.h | 1 - target-arm/cpu.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++- target-arm/helper.c | 76 +--------------------------------------------------- 3 files changed, 76 insertions(+), 77 deletions(-)
target-arm/cpu-qom.h +0 -1
@@ -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
target-arm/cpu.c +75 -1
107 lines not on this page · raw message
target-arm/helper.c +1 -75
98 lines not on this page · raw message
Signature · 1 line
1.7.11.7
RFC 15/20 target-arm: replace cpu_arm_init() with generic_cpu_init()
In reply to Eduardo Habkost--- target-arm/cpu.h | 6 ++++-- target-arm/helper.c | 13 ------------- 2 files changed, 4 insertions(+), 15 deletions(-)
target-arm/cpu.h +4 -2
@@ -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
target-arm/helper.c +0 -13
@@ -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;
Signature · 1 line
1.7.11.7
RFC 16/20 target-m68k: move final steps of cpu_m68k_init() to realize function
In reply to Eduardo Habkost--- target-m68k/cpu.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- target-m68k/helper.c | 47 +---------------------------------------------- 2 files changed, 52 insertions(+), 47 deletions(-)
target-m68k/cpu.c +51 -1
@@ -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)
target-m68k/helper.c +1 -46
69 lines not on this page · raw message
Signature · 1 line
1.7.11.7
RFC 17/20 target-m68k: replace cpu_m68k_init() with generic_cpu_init()
In reply to Eduardo Habkost--- target-m68k/cpu.h | 3 +-- target-m68k/helper.c | 14 -------------- 2 files changed, 1 insertion(+), 16 deletions(-)
target-m68k/cpu.h +1 -2
@@ -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
target-m68k/helper.c +0 -14
@@ -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;
Signature · 1 line
1.7.11.7
RFC 18/20 target-unicore32: move final steps of uc32_cpu_init() to realize function
In reply to Eduardo Habkost--- target-unicore32/cpu.c | 21 +++++++++++++++++++++ target-unicore32/helper.c | 11 +---------- 2 files changed, 22 insertions(+), 10 deletions(-)
target-unicore32/cpu.c +21 -0
@@ -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);
target-unicore32/helper.c +1 -10
@@ -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); }
Signature · 1 line
1.7.11.7
RFC 19/20 target-unicore32: replace uc32_cpu_init() with generic_cpu_init()
In reply to Eduardo Habkost--- target-unicore32/cpu.h | 2 +- target-unicore32/helper.c | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-)
target-unicore32/cpu.h +1 -1
@@ -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
target-unicore32/helper.c +0 -12
@@ -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);
Signature · 1 line
1.7.11.7
RFC 20/20 cpu: convert cpu_copy() to QOM
In reply to Eduardo HabkostInstead 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().
--- cpu-all.h | 1 - exec.c | 9 +++++---- include/qemu/cpu.h | 4 ++++ linux-user/syscall.c | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-)
cpu-all.h +0 -1
@@ -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
exec.c +5 -4
@@ -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 )
include/qemu/cpu.h +4 -0
@@ -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
linux-user/syscall.c +1 -1
@@ -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
Signature · 1 line
1.7.11.7
Am 18.12.2012 21:03, schrieb Eduardo Habkost:
Quoted 6 lines
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.
Quoted 7 lines
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
Quoted 7 lines
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.
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 21 lines · Andreas Färber
Am 18.12.2012 21:03, schrieb Eduardo Habkost:
Quoted 6 lines
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.Quoted 7 lines
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.
Quoted 9 lines
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 ofcpu_copy(). realize would in my mind allow us to register a realizefn in CPUclass_init, automatically invoked byobject_new, the targetted recursive realization allowing to drop any realize call fromcpu_init()and with a couple explicit realization calls in *-user allowing us to repurposecpu_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).
Quoted 14 lines
Andreas
Quoted 7 lines
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.
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Signature · 1 line
Eduardo