From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVOnX-0005Qy-C0 for qemu-devel@nongnu.org; Tue, 10 Mar 2015 14:22:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVOnQ-0002ff-Dy for qemu-devel@nongnu.org; Tue, 10 Mar 2015 14:22:31 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Tue, 10 Mar 2015 19:22:20 +0100 Message-Id: <1426011740-17688-7-git-send-email-afaerber@suse.de> In-Reply-To: <1426011740-17688-1-git-send-email-afaerber@suse.de> References: <1426011740-17688-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 6/6] cpu: Make cpu_init() return QOM CPUState object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Eduardo Habkost , Jia Liu , Anthony Green , Riku Voipio , Alexander Graf , Bastian Koppelmann , Blue Swirl , Max Filippov , Michael Walle , "open list:PowerPC" , Paolo Bonzini , "Edgar E. Iglesias" , Guan Xuetao , Leon Alrae , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Aurelien Jarno , Richard Henderson From: Eduardo Habkost Instead of making cpu_init() return CPUArchState, return CPUState. Changes were made using the Coccinelle semantic patch below. @@ typedef CPUState; identifier e; expression args; type CPUArchState; @@ - e =3D + cpu =3D cpu_init(args); - if (!e) { + if (!cpu) { ... } - cpu =3D ENV_GET_CPU(env); + e =3D cpu->env_ptr; @@ identifier new_env, new_cpu, env, cpu; type CPUArchState; expression args; @@ -{ - CPUState *cpu =3D ENV_GET_CPU(env); - CPUArchState *new_env =3D cpu_init(args); - CPUState *new_cpu =3D ENV_GET_CPU(new_env); +{ + CPUState *cpu =3D ENV_GET_CPU(env); + CPUState *new_cpu =3D cpu_init(args); + CPUArchState *new_env =3D new_cpu->env_ptr; ... } @@ identifier c, cpu_init_func, cpu_model; type StateType, CPUType; @@ -static inline StateType* cpu_init(const char *cpu_model) -{ - CPUType *c =3D cpu_init_func(cpu_model); ( - if (c =3D=3D NULL) { - return NULL; - } - return &c->env; | - if (c) { - return &c->env; - } - return NULL; ) -} +#define cpu_init(cpu_model) CPU(cpu_init_func(cpu_model)) @@ identifier cpu_init_func; identifier model; @@ -#define cpu_init(model) (&cpu_init_func(model)->env) +#define cpu_init(model) CPU(cpu_init_func(model)) Signed-off-by: Eduardo Habkost Cc: Blue Swirl Cc: Guan Xuetao Cc: Riku Voipio Cc: Richard Henderson Cc: Peter Maydell Cc: "Edgar E. Iglesias" Cc: Paolo Bonzini Cc: Michael Walle Cc: Aurelien Jarno Cc: Leon Alrae Cc: Anthony Green Cc: Jia Liu Cc: Alexander Graf Cc: Bastian Koppelmann Cc: Max Filippov [AF: Fixed up cpu_copy() manually] Signed-off-by: Andreas F=C3=A4rber --- bsd-user/main.c | 6 +++--- linux-user/main.c | 10 +++++----- target-alpha/cpu.h | 9 +-------- target-arm/cpu.h | 9 +-------- target-cris/cpu.h | 9 +-------- target-i386/cpu.h | 9 +-------- target-lm32/cpu.h | 9 +-------- target-m68k/cpu.h | 9 +-------- target-microblaze/cpu.h | 9 +-------- target-mips/cpu.h | 9 +-------- target-moxie/cpu.h | 9 +-------- target-openrisc/cpu.h | 9 +-------- target-ppc/cpu.h | 9 +-------- target-s390x/cpu.h | 2 +- target-sh4/cpu.h | 9 +-------- target-sparc/cpu.h | 9 +-------- target-tricore/cpu.h | 10 +--------- target-unicore32/cpu.h | 10 +--------- target-xtensa/cpu.h | 9 +-------- 19 files changed, 25 insertions(+), 139 deletions(-) diff --git a/bsd-user/main.c b/bsd-user/main.c index 0e8c26c..1bb2754 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -908,12 +908,12 @@ 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 =3D cpu_init(cpu_model); - if (!env) { + cpu =3D cpu_init(cpu_model); + if (!cpu) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } - cpu =3D ENV_GET_CPU(env); + env =3D cpu->env_ptr; #if defined(TARGET_SPARC) || defined(TARGET_PPC) cpu_reset(cpu); #endif diff --git a/linux-user/main.c b/linux-user/main.c index d92702a..6bd23af 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -3452,8 +3452,8 @@ void init_task_state(TaskState *ts) CPUArchState *cpu_copy(CPUArchState *env) { CPUState *cpu =3D ENV_GET_CPU(env); - CPUArchState *new_env =3D cpu_init(cpu_model); - CPUState *new_cpu =3D ENV_GET_CPU(new_env); + CPUState *new_cpu =3D cpu_init(cpu_model); + CPUArchState *new_env =3D cpu->env_ptr; CPUBreakpoint *bp; CPUWatchpoint *wp; =20 @@ -3939,12 +3939,12 @@ 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 =3D cpu_init(cpu_model); - if (!env) { + cpu =3D cpu_init(cpu_model); + if (!cpu) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } - cpu =3D ENV_GET_CPU(env); + env =3D cpu->env_ptr; cpu_reset(cpu); =20 thread_cpu =3D cpu; diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h index e276dbf..9538f19 100644 --- a/target-alpha/cpu.h +++ b/target-alpha/cpu.h @@ -429,14 +429,7 @@ void alpha_translate_init(void); =20 AlphaCPU *cpu_alpha_init(const char *cpu_model); =20 -static inline CPUAlphaState *cpu_init(const char *cpu_model) -{ - AlphaCPU *cpu =3D cpu_alpha_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_alpha_init(cpu_model)) =20 void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf); int cpu_alpha_exec(CPUAlphaState *s); diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 11845a6..083211c 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -1569,14 +1569,7 @@ static inline bool arm_excp_unmasked(CPUState *cs,= unsigned int excp_idx) return unmasked || pstate_unmasked; } =20 -static inline CPUARMState *cpu_init(const char *cpu_model) -{ - ARMCPU *cpu =3D cpu_arm_init(cpu_model); - if (cpu) { - return &cpu->env; - } - return NULL; -} +#define cpu_init(cpu_model) CPU(cpu_arm_init(cpu_model)) =20 #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 eea14b6..677b38c 100644 --- a/target-cris/cpu.h +++ b/target-cris/cpu.h @@ -221,14 +221,7 @@ enum { #define TARGET_PHYS_ADDR_SPACE_BITS 32 #define TARGET_VIRT_ADDR_SPACE_BITS 32 =20 -static inline CPUCRISState *cpu_init(const char *cpu_model) -{ - CRISCPU *cpu =3D cpu_cris_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_cris_init(cpu_model)) =20 #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 478450c..4255803 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -1171,14 +1171,7 @@ uint64_t cpu_get_tsc(CPUX86State *env); # define PHYS_ADDR_MASK 0xfffffffffLL # endif =20 -static inline CPUX86State *cpu_init(const char *cpu_model) -{ - X86CPU *cpu =3D cpu_x86_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_x86_init(cpu_model)) =20 #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 e558c59..11ae68d 100644 --- a/target-lm32/cpu.h +++ b/target-lm32/cpu.h @@ -217,14 +217,7 @@ void lm32_watchpoint_insert(CPULM32State *env, int i= ndex, target_ulong address, void lm32_watchpoint_remove(CPULM32State *env, int index); bool lm32_cpu_do_semihosting(CPUState *cs); =20 -static inline CPULM32State *cpu_init(const char *cpu_model) -{ - LM32CPU *cpu =3D cpu_lm32_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_lm32_init(cpu_model)) =20 #define cpu_list lm32_cpu_list #define cpu_exec cpu_lm32_exec diff --git a/target-m68k/cpu.h b/target-m68k/cpu.h index 3a1b9ab..5f165da 100644 --- a/target-m68k/cpu.h +++ b/target-m68k/cpu.h @@ -212,14 +212,7 @@ void register_m68k_insns (CPUM68KState *env); #define TARGET_PHYS_ADDR_SPACE_BITS 32 #define TARGET_VIRT_ADDR_SPACE_BITS 32 =20 -static inline CPUM68KState *cpu_init(const char *cpu_model) -{ - M68kCPU *cpu =3D cpu_m68k_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_m68k_init(cpu_model)) =20 #define cpu_exec cpu_m68k_exec #define cpu_gen_code cpu_m68k_gen_code diff --git a/target-microblaze/cpu.h b/target-microblaze/cpu.h index 5794f89..7d06227 100644 --- a/target-microblaze/cpu.h +++ b/target-microblaze/cpu.h @@ -297,14 +297,7 @@ enum { #define TARGET_PHYS_ADDR_SPACE_BITS 32 #define TARGET_VIRT_ADDR_SPACE_BITS 32 =20 -static inline CPUMBState *cpu_init(const char *cpu_model) -{ - MicroBlazeCPU *cpu =3D cpu_mb_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_mb_init(cpu_model)) =20 #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 5ea61bc..f44c814 100644 --- a/target-mips/cpu.h +++ b/target-mips/cpu.h @@ -739,14 +739,7 @@ void mips_tcg_init(void); MIPSCPU *cpu_mips_init(const char *cpu_model); int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc); =20 -static inline CPUMIPSState *cpu_init(const char *cpu_model) -{ - MIPSCPU *cpu =3D cpu_mips_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_mips_init(cpu_model)) =20 /* TODO QOM'ify CPU reset and remove */ void cpu_state_reset(CPUMIPSState *s); diff --git a/target-moxie/cpu.h b/target-moxie/cpu.h index d809393..c2733a2 100644 --- a/target-moxie/cpu.h +++ b/target-moxie/cpu.h @@ -121,14 +121,7 @@ void moxie_translate_init(void); int cpu_moxie_signal_handler(int host_signum, void *pinfo, void *puc); =20 -static inline CPUMoxieState *cpu_init(const char *cpu_model) -{ - MoxieCPU *cpu =3D cpu_moxie_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_moxie_init(cpu_model)) =20 #define cpu_exec cpu_moxie_exec #define cpu_gen_code cpu_moxie_gen_code diff --git a/target-openrisc/cpu.h b/target-openrisc/cpu.h index 69b96c6..b25324b 100644 --- a/target-openrisc/cpu.h +++ b/target-openrisc/cpu.h @@ -389,14 +389,7 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu, int *prot, target_ulong address, int rw); #endif =20 -static inline CPUOpenRISCState *cpu_init(const char *cpu_model) -{ - OpenRISCCPU *cpu =3D cpu_openrisc_init(cpu_model); - if (cpu) { - return &cpu->env; - } - return NULL; -} +#define cpu_init(cpu_model) CPU(cpu_openrisc_init(cpu_model)) =20 #include "exec/cpu-all.h" =20 diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h index abc3545..f15815f 100644 --- a/target-ppc/cpu.h +++ b/target-ppc/cpu.h @@ -1238,14 +1238,7 @@ static inline uint64_t ppc_dump_gpr(CPUPPCState *e= nv, 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); =20 -static inline CPUPPCState *cpu_init(const char *cpu_model) -{ - PowerPCCPU *cpu =3D cpu_ppc_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_ppc_init(cpu_model)) =20 #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 b6b4632..67fc53c 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -466,7 +466,7 @@ int css_do_rchp(uint8_t cssid, uint8_t chpid); bool css_present(uint8_t cssid); #endif =20 -#define cpu_init(model) (&cpu_s390x_init(model)->env) +#define cpu_init(model) CPU(cpu_s390x_init(model)) #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 b2fb199..c8dea6c 100644 --- a/target-sh4/cpu.h +++ b/target-sh4/cpu.h @@ -221,14 +221,7 @@ int cpu_sh4_is_cached(CPUSH4State * env, target_ulon= g addr); =20 void cpu_load_tlb(CPUSH4State * env); =20 -static inline CPUSH4State *cpu_init(const char *cpu_model) -{ - SuperHCPU *cpu =3D cpu_sh4_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_sh4_init(cpu_model)) =20 #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 0a50e5d..f5c9006 100644 --- a/target-sparc/cpu.h +++ b/target-sparc/cpu.h @@ -594,14 +594,7 @@ hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env,= target_ulong addr, int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc); =20 #ifndef NO_CPU_IO_DEFS -static inline CPUSPARCState *cpu_init(const char *cpu_model) -{ - SPARCCPU *cpu =3D cpu_sparc_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_sparc_init(cpu_model)) #endif =20 #define cpu_exec cpu_sparc_exec diff --git a/target-tricore/cpu.h b/target-tricore/cpu.h index e5409e4..b473426 100644 --- a/target-tricore/cpu.h +++ b/target-tricore/cpu.h @@ -378,15 +378,7 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreSt= ate *env, target_ulong *pc, =20 TriCoreCPU *cpu_tricore_init(const char *cpu_model); =20 -static inline CPUTriCoreState *cpu_init(const char *cpu_model) -{ - TriCoreCPU *cpu =3D cpu_tricore_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; - -} +#define cpu_init(cpu_model) CPU(cpu_tricore_init(cpu_model)) =20 =20 /* helpers.c */ diff --git a/target-unicore32/cpu.h b/target-unicore32/cpu.h index 11d76dc..14dc862 100644 --- a/target-unicore32/cpu.h +++ b/target-unicore32/cpu.h @@ -143,15 +143,7 @@ static inline int cpu_mmu_index(CPUUniCore32State *e= nv) =20 UniCore32CPU *uc32_cpu_init(const char *cpu_model); =20 -static inline CPUUniCore32State *cpu_init(const char *cpu_model) -{ - UniCore32CPU *cpu =3D uc32_cpu_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; - -} +#define cpu_init(cpu_model) CPU(uc32_cpu_init(cpu_model)) =20 static inline void cpu_get_tb_cpu_state(CPUUniCore32State *env, target_u= long *pc, target_ulong *cs_base, int *flag= s) diff --git a/target-xtensa/cpu.h b/target-xtensa/cpu.h index 60ee563..dfd0d1c 100644 --- a/target-xtensa/cpu.h +++ b/target-xtensa/cpu.h @@ -379,14 +379,7 @@ typedef struct CPUXtensaState { =20 XtensaCPU *cpu_xtensa_init(const char *cpu_model); =20 -static inline CPUXtensaState *cpu_init(const char *cpu_model) -{ - XtensaCPU *cpu =3D cpu_xtensa_init(cpu_model); - if (cpu =3D=3D NULL) { - return NULL; - } - return &cpu->env; -} +#define cpu_init(cpu_model) CPU(cpu_xtensa_init(cpu_model)) =20 void xtensa_translate_init(void); void xtensa_breakpoint_handler(CPUState *cs); --=20 2.1.4