poison TARGET_xxx for compile once object and header file cleanups
cover poison TARGET_xxx for compile once object and header file cleanups
This is a different way to achieve the same objective as Isamu's patch. Basically, his patch becomes the (much simpler) patch 7 of this series, and everything else is something I had had lying around for a while. :)
Patch 1 is simply Amit's patch, included here for convenience as it's not been applied yet.
Patches 2 and 3 remove some dyngen-exec.h hacks at the price of requiring qemu-common.h included in more places. I don't see this as a big price; all of these files were already including qemu-common.h indirectly, e.g. via cpu-all.h, just not early enough.
Patches 4 provides a CPUState type, albeit an opaque one, to files that are not compiled per-target. The advantage of this are apparent in patches 5 and 6: opaque pointers that are actually CPUState pointers are now type-safe, and it is even possible to define a cpu property type for the occasional device that has to be connected to a particular CPU (the PC APICs in particular).
Finally, patch 7 "redoes" Isamu's patch just by moving five lines of code into qemu-common.h.
Amit Shah (1):
rtc: Remove TARGET_I386 from qemu-config.c, enables driftfix
Paolo Bonzini (6):
include qemu-common.h when needed by the next patches include stdio.h freely, remove dyngen-exec.h hacks provide opaque CPUState to files that are compiled once add qdev property type "cpu"
replace void* uses with opaque CPUState* poison TARGET_xxx for compile once object
arm-semi.c | 2 +- bsd-user/qemu.h | 1 + cpu-common.h | 6 +--- cpu-defs.h | 1 + cpu-exec.c | 1 + cpus.c | 39 ++++++++++++++++++++++-------------- cpus.h | 2 + darwin-user/qemu.h | 1 + disas.c | 1 + disas.h | 5 +--- dyngen-exec.h | 16 -------------- exec.c | 2 +- hw/apic.c | 4 +- hw/pc.c | 4 +- hw/qdev-properties.c | 44 +++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 5 ++++ linux-user/arm/nwfpe/fpa11.h | 3 +- linux-user/main.c | 1 - linux-user/qemu.h | 1 + m68k-semi.c | 2 +- poison.h | 3 -- qemu-common.h | 19 ++++------------- qemu-config.c | 2 - target-alpha/cpu.h | 4 +-- target-alpha/exec.h | 6 +--- target-alpha/helper.c | 1 + target-alpha/op_helper.c | 1 + target-alpha/translate.c | 2 +- target-arm/cpu.h | 6 ++-- target-arm/exec.h | 5 +-- target-arm/helper.c | 2 +- target-arm/iwmmxt_helper.c | 1 + target-arm/neon_helper.c | 1 + target-arm/op_helper.c | 1 + target-arm/translate.c | 1 + target-cris/cpu.h | 6 ++-- target-cris/exec.h | 6 ++-- target-cris/helper.c | 1 + target-cris/mmu.c | 1 + target-cris/op_helper.c | 1 + target-cris/translate.c | 2 +- target-i386/cpu.h | 6 ++-- target-i386/cpuid.c | 1 + target-i386/exec.h | 7 +---- target-i386/helper.c | 2 +- target-i386/op_helper.c | 1 + target-i386/translate.c | 1 + target-m68k/cpu.h | 6 ++-- target-m68k/exec.h | 6 ++-- target-m68k/helper.c | 2 +- target-m68k/op_helper.c | 1 + target-m68k/translate.c | 1 + target-microblaze/cpu.h | 7 ++--- target-microblaze/exec.h | 6 ++-- target-microblaze/helper.c | 1 + target-microblaze/mmu.c | 1 + target-microblaze/op_helper.c | 1 + target-microblaze/translate.c | 2 +- target-mips/cpu.h | 5 +--- target-mips/exec.h | 6 +--- target-mips/helper.c | 1 + target-mips/op_helper.c | 1 + target-mips/translate.c | 2 +- target-ppc/cpu.h | 3 +- target-ppc/exec.h | 2 - target-ppc/helper.c | 2 +- target-ppc/op_helper.c | 1 + target-ppc/translate.c | 2 +- target-s390x/cpu.h | 6 ++-- target-s390x/exec.h | 7 ++--- target-s390x/helper.c | 2 +- target-s390x/op_helper.c | 1 + target-sh4/cpu.h | 6 ++-- target-sh4/exec.h | 5 +-- target-sh4/helper.c | 1 + target-sh4/op_helper.c | 2 + target-sh4/translate.c | 2 +- target-sparc/cpu.h | 6 ++-- target-sparc/exec.h | 3 ++ target-sparc/helper.c | 2 +- target-sparc/op_helper.c | 1 + target-sparc/translate.c | 1 + translate-all.c | 1 + 83 files changed, 189 insertions(+), 147 deletions(-)
PATCH 1/7 rtc: Remove TARGET_I386 from qemu-config.c, enables driftfix
From: Amit Shah <[email protected]>
qemu-config.c doesn't contain any target-specific code, and the TARGET_I386 conditional code didn't get compiled as a result. Removing this enables the driftfix parameter for rtc.
--- qemu-config.c | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-)
qemu-config.c +0 -2
@@ -247,11 +247,9 @@ QemuOptsList qemu_rtc_opts = { },{ .name = "clock", .type = QEMU_OPT_STRING, -#ifdef TARGET_I386 },{ .name = "driftfix", .type = QEMU_OPT_STRING, -#endif }, {/* end if list */ } },
Signature · 1 line
1.7.0.1
PATCH 2/7 include qemu-common.h when needed by the next patches
In reply to Paolo BonziniAll of these files were already including qemu-common.h indirectly, e.g. via cpu-all.h, just not early enough.
--- arm-semi.c | 2 +- bsd-user/qemu.h | 1 + cpu-exec.c | 1 + darwin-user/qemu.h | 1 + disas.c | 1 + exec.c | 2 +- linux-user/arm/nwfpe/fpa11.h | 3 ++- linux-user/main.c | 1 - linux-user/qemu.h | 1 + m68k-semi.c | 2 +- target-alpha/helper.c | 1 + target-alpha/op_helper.c | 1 + target-alpha/translate.c | 2 +- target-arm/helper.c | 2 +- target-arm/iwmmxt_helper.c | 1 + target-arm/neon_helper.c | 1 + target-arm/op_helper.c | 1 + target-arm/translate.c | 1 + target-cris/helper.c | 1 + target-cris/mmu.c | 1 + target-cris/op_helper.c | 1 + target-cris/translate.c | 2 +- target-i386/cpuid.c | 1 + target-i386/helper.c | 2 +- target-i386/op_helper.c | 1 + target-i386/translate.c | 1 + target-m68k/helper.c | 2 +- target-m68k/op_helper.c | 1 + target-m68k/translate.c | 1 + target-microblaze/helper.c | 1 + target-microblaze/mmu.c | 1 + target-microblaze/op_helper.c | 1 + target-microblaze/translate.c | 2 +- target-mips/helper.c | 1 + target-mips/op_helper.c | 1 + target-mips/translate.c | 2 +- target-ppc/helper.c | 2 +- target-ppc/op_helper.c | 1 + target-ppc/translate.c | 2 +- target-s390x/helper.c | 2 +- target-s390x/op_helper.c | 1 + target-sh4/helper.c | 1 + target-sh4/op_helper.c | 2 ++ target-sh4/translate.c | 2 +- target-sparc/helper.c | 2 +- target-sparc/op_helper.c | 1 + target-sparc/translate.c | 1 + translate-all.c | 1 + 48 files changed, 49 insertions(+), 17 deletions(-)
arm-semi.c +1 -1
@@ -26,7 +26,7 @@#include <stdio.h> #include <time.h> -#include "cpu.h" +#include "config.h" #ifdef CONFIG_USER_ONLY #include "qemu.h"
bsd-user/qemu.h +1 -0
@@ -4,6 +4,7 @@#include <signal.h> #include <string.h> +#include "qemu-common.h" #include "cpu.h" #undef DEBUG_REMAP
cpu-exec.c +1 -0
@@ -17,6 +17,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include "config.h" +#include "qemu-common.h" #include "exec.h" #include "disas.h" #include "tcg.h"
darwin-user/qemu.h +1 -0
@@ -4,6 +4,7 @@#include <signal.h> #include <string.h> +#include "qemu-common.h" #include "cpu.h" #include "thunk.h"
disas.c +1 -0
@@ -1,5 +1,6 @@/* General "disassemble this chunk" code. Used for debugging. */ #include "config.h" +#include "qemu-common.h" #include "dis-asm.h" #include "elf.h" #include <errno.h>
exec.c +1 -1
@@ -31,9 +31,9 @@#include <unistd.h> #include <inttypes.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" -#include "qemu-common.h" #include "tcg.h" #include "hw/hw.h" #include "osdep.h"
linux-user/arm/nwfpe/fpa11.h +2 -1
@@ -25,7 +25,8 @@#include <stdio.h> #include <errno.h> -#include <cpu.h> +#include "qemu-common.h" +#include "cpu.h" #define GET_FPA11 () (qemufpa)
linux-user/main.c +0 -1
@@ -27,7 +27,6 @@#include <sys/resource.h> #include "qemu.h" -#include "qemu-common.h" #include "cache-utils.h" /* For tb_lock */ #include "exec-all.h"
linux-user/qemu.h +1 -0
@@ -4,6 +4,7 @@#include <signal.h> #include <string.h> +#include "qemu-common.h" #include "cpu.h" #undef DEBUG_REMAP
m68k-semi.c +1 -1
@@ -27,7 +27,7 @@#include <sys/time.h> #include <time.h> -#include "cpu.h" +#include "config.h" #if defined(CONFIG_USER_ONLY )#include "qemu.h" #define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024)
target-alpha/helper.c +1 -0
@@ -21,6 +21,7 @@#include <stdlib.h> #include <stdio.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "softfloat.h"
target-alpha/op_helper.c +1 -0
@@ -17,6 +17,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu-common.h" #include "exec.h" #include "host-utils.h" #include "softfloat.h"
target-alpha/translate.c +1 -1
@@ -21,12 +21,12 @@#include <stdlib.h> #include <stdio.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h" #include "host-utils.h" #include "tcg-op.h" -#include "qemu-common.h" #include "helper.h" #define GEN_HELPER 1
target-arm/helper.c +1 -1
@@ -2,11 +2,11 @@#include <stdlib.h> #include <string.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "gdbstub.h" #include "helpers.h" -#include "qemu-common.h" #include "host-utils.h" #if !defined(CONFIG_USER_ONLY )#include "hw/loader.h"
target-arm/iwmmxt_helper.c +1 -0
@@ -22,6 +22,7 @@#include <stdlib.h> #include <stdio.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "helpers.h"
target-arm/neon_helper.c +1 -0
@@ -9,6 +9,7 @@#include <stdlib.h> #include <stdio.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "helpers.h"
target-arm/op_helper.c +1 -0
@@ -16,6 +16,7 @@* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu-common.h" #include "exec.h" #include "helpers.h"
target-arm/translate.c +1 -0
@@ -24,6 +24,7 @@#include <string.h> #include <inttypes.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h"
target-cris/helper.c +1 -0
@@ -22,6 +22,7 @@#include <string.h> #include "config.h" +#include "qemu-common.h" #include "cpu.h" #include "mmu.h" #include "exec-all.h"
target-cris/mmu.c +1 -0
@@ -25,6 +25,7 @@#include <stdlib.h> #include "config.h" +#include "qemu-common.h" #include "cpu.h" #include "mmu.h" #include "exec-all.h"
target-cris/op_helper.c +1 -0
@@ -18,6 +18,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu-common.h" #include "exec.h" #include "mmu.h" #include "helper.h"
target-cris/translate.c +1 -1
@@ -29,6 +29,7 @@#include <string.h> #include <inttypes.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h"
@@ -36,7 +37,6 @@#include "helper.h" #include "mmu.h" #include "crisv32-decode.h" -#include "qemu-common.h" #define GEN_HELPER 1#include "helper.h"
target-i386/cpuid.c +1 -0
@@ -21,6 +21,7 @@#include <string.h> #include <inttypes.h> +#include "qemu-common.h" #include "cpu.h" #include "kvm.h"
target-i386/helper.c +1 -1
@@ -23,9 +23,9 @@#include <inttypes.h> #include <signal.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" -#include "qemu-common.h" #include "kvm.h" //#define DEBUG_MMU
target-i386/op_helper.c +1 -0
@@ -17,6 +17,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #define CPU_NO_GLOBAL_REGS +#include "qemu-common.h" #include "exec.h" #include "exec-all.h" #include "host-utils.h"
target-i386/translate.c +1 -0
@@ -23,6 +23,7 @@#include <inttypes.h> #include <signal.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h"
target-m68k/helper.c +1 -1
@@ -22,9 +22,9 @@#include <string.h> #include "config.h" +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" -#include "qemu-common.h" #include "gdbstub.h" #include "helpers.h"
target-m68k/op_helper.c +1 -0
@@ -16,6 +16,7 @@* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu-common.h" #include "exec.h" #include "helpers.h"
target-m68k/translate.c +1 -0
@@ -24,6 +24,7 @@#include <inttypes.h> #include "config.h" +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h"
target-microblaze/helper.c +1 -0
@@ -22,6 +22,7 @@#include <assert.h> #include "config.h" +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "host-utils.h"
target-microblaze/mmu.c +1 -0
@@ -20,6 +20,7 @@#include <stdlib.h> #include <assert.h> +#include "qemu-common.h" #include "config.h" #include "cpu.h" #include "exec-all.h"
target-microblaze/op_helper.c +1 -0
@@ -18,6 +18,7 @@*/ #include <assert.h> +#include "qemu-common.h" #include "exec.h" #include "helper.h" #include "host-utils.h"
target-microblaze/translate.c +1 -1
@@ -24,13 +24,13 @@#include <inttypes.h> #include <assert.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h" #include "tcg-op.h" #include "helper.h" #include "microblaze-decode.h" -#include "qemu-common.h" #define GEN_HELPER 1#include "helper.h"
target-mips/helper.c +1 -0
@@ -23,6 +23,7 @@#include <inttypes.h> #include <signal.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h"
target-mips/op_helper.c +1 -0
@@ -17,6 +17,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include <stdlib.h> +#include "qemu-common.h" #include "exec.h" #include "host-utils.h"
target-mips/translate.c +1 -1
@@ -26,11 +26,11 @@#include <string.h> #include <inttypes.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h" #include "tcg-op.h" -#include "qemu-common.h" #include "helper.h" #define GEN_HELPER 1
target-ppc/helper.c +1 -1
@@ -23,10 +23,10 @@#include <inttypes.h> #include <signal.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "helper_regs.h" -#include "qemu-common.h" #include "kvm.h" //#define DEBUG_MMU
target-ppc/op_helper.c +1 -0
@@ -17,6 +17,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ #include <string.h> +#include "qemu-common.h" #include "exec.h" #include "host-utils.h" #include "helper.h"
target-ppc/translate.c +1 -1
@@ -22,11 +22,11 @@#include <string.h> #include <inttypes.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h" #include "tcg-op.h" -#include "qemu-common.h" #include "host-utils.h" #include "helper.h"
target-s390x/helper.c +1 -1
@@ -21,10 +21,10 @@#include <stdlib.h> #include <string.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "gdbstub.h" -#include "qemu-common.h" #include <linux/kvm.h> #include "kvm.h"
target-s390x/op_helper.c +1 -0
@@ -17,6 +17,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu-common.h" #include "exec.h" /*****************************************************************************/
target-sh4/helper.c +1 -0
@@ -23,6 +23,7 @@#include <inttypes.h> #include <signal.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "hw/sh_intc.h"
target-sh4/op_helper.c +2 -0
@@ -18,6 +18,8 @@*/ #include <assert.h> #include <stdlib.h> + +#include "qemu-common.h" #include "exec.h" #include "helper.h"
target-sh4/translate.c +1 -1
@@ -26,11 +26,11 @@#define SH4_DEBUG_DISAS //#define SH4_SINGLE_STEP +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h" #include "tcg-op.h" -#include "qemu-common.h" #include "helper.h" #define GEN_HELPER 1
target-sparc/helper.c +1 -1
@@ -23,9 +23,9 @@#include <inttypes.h> #include <signal.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" -#include "qemu-common.h" //#define DEBUG_MMU //#define DEBUG_FEATURES
target-sparc/op_helper.c +1 -0
@@ -1,3 +1,4 @@ +#include "qemu-common.h" #include "exec.h" #include "host-utils.h" #include "helper.h"
target-sparc/translate.c +1 -0
@@ -24,6 +24,7 @@#include <string.h> #include <inttypes.h> +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h"
translate-all.c +1 -0
@@ -25,6 +25,7 @@#include "config.h" #define NO_CPU_IO_DEFS +#include "qemu-common.h" #include "cpu.h" #include "exec-all.h" #include "disas.h"
Signature · 1 line
1.7.0.1
PATCH 3/7 include stdio.h freely, remove dyngen-exec.h hacks
In reply to Paolo Bonzini--- disas.h | 5 +---- dyngen-exec.h | 16 ---------------- qemu-common.h | 7 ------- 3 files changed, 1 insertions(+), 27 deletions(-)
disas.h +1 -4
@@ -2,17 +2,14 @@#define _QEMU_DISAS_H#include "qemu-common.h" +#include <stdio.h> #ifdef NEED_CPU_H /* Disassemble this for me please... (debugging). */ void disas (FILE *out,void *code,unsigned long size);void target_disas (FILE *out,target_ulong code,target_ulong size,int flags); - -/* The usual mess... FIXME: Remove this condition once dyngen-exec.h is gone */ -#ifndef __DYNGEN_EXEC_H__void monitor_disas (Monitor *mon,CPUState *env,target_ulong pc,int nb_insn,int is_physical,int flags); -#endif /* Look up symbol for debugging purpose. Returns "" if unknown. */ const char *lookup_symbol (target_ulong orig_addr);
dyngen-exec.h +0 -16
@@ -19,13 +19,6 @@#if !defined(__DYNGEN_EXEC_H__)#define __DYNGEN_EXEC_H__ -/* prevent Solaris from trying to typedef FILE in gcc's -include/floatingpoint.h which will conflict with the -definition down below */ -#ifdef __sun__ -#define _FILEDEFED -#endif -/* NOTE: standard headers should be used with special care at this point because host CPU registers are used as global variables. Some host headers do not allow that. */
@@ -40,15 +33,6 @@/* XXX: This may be wrong for 64-bit ILP32 hosts. */ typedef void *host_reg_t ; -#ifdef CONFIG_BSD -typedef struct __sFILE FILE ; -#else -typedef struct FILE FILE ; -#endif -extern int fprintf (FILE *,const char *, ...); -extern int fputs (const char *,FILE *); -extern int printf (const char *, ...); -#if defined(__i386__)#define AREG0 "ebp"#elif defined(__x86_64__)
qemu-common.h +0 -7
@@ -18,11 +18,6 @@ typedef struct QEMUFile QEMUFile;typedef struct QEMUBH QEMUBH ;typedef struct DeviceState DeviceState ; -/* Hack around the mess dyngen-exec.h causes: We need QEMU_NORETURN in files that -cannot include the following headers without conflicts. This condition has -to be removed once dyngen is gone. */ -#ifndef __DYNGEN_EXEC_H__ -/* we put basic includes here to avoid repeating them in device drivers */ #include <stdlib.h> #include <stdio.h>
@@ -293,6 +288,4 @@ static inline uint8_t from_bcd(uint8_t val)#include "module.h" -#endif /* dyngen-exec.h hack */ -#endif
Signature · 1 line
1.7.0.1
PATCH 4/7 provide opaque CPUState to files that are compiled once
In reply to Paolo BonziniThis patch unpoisons CPUState and env in once-compiled files. To achieve this, it defines an opaque struct CPUState in cpu-common.h. This also requires tweaking the relationship between CPUState and CPUXYZState in target files.
Unpoisoning env is needed because it is widely used as the name for CPUState arguments. To avoid having references to the global register variable creeping into target-independent files, the patch rationalizes inclusions at the head of target-*/exec.h. All exec.h files now include cpu.h explicitly and very early. Inclusions from machine-independent context will then error out in cpu-defs.h, even if env is not poisoned.
--- cpu-common.h | 3 +++ cpu-defs.h | 1 + poison.h | 3 --- target-alpha/cpu.h | 4 +--- target-alpha/exec.h | 6 ++---- target-arm/cpu.h | 6 +++--- target-arm/exec.h | 5 ++--- target-cris/cpu.h | 6 +++--- target-cris/exec.h | 6 +++--- target-i386/cpu.h | 6 +++--- target-i386/exec.h | 7 ++----- target-m68k/cpu.h | 6 +++--- target-m68k/exec.h | 6 +++--- target-microblaze/cpu.h | 7 +++---- target-microblaze/exec.h | 6 +++--- target-mips/cpu.h | 5 +---- target-mips/exec.h | 6 ++---- target-ppc/cpu.h | 3 +-- target-ppc/exec.h | 2 -- target-s390x/cpu.h | 6 +++--- target-s390x/exec.h | 7 +++---- target-sh4/cpu.h | 6 +++--- target-sh4/exec.h | 5 ++--- target-sparc/cpu.h | 6 +++--- target-sparc/exec.h | 3 +++ 25 files changed, 56 insertions(+), 71 deletions(-)
cpu-common.h +3 -0
@@ -18,6 +18,9 @@#include "bswap.h" #include "qemu-queue.h" +struct CPUState ; +typedef struct CPUState CPUState ; +#if !defined(CONFIG_USER_ONLY )/* address in the RAM (different from a physical address) */
cpu-defs.h +1 -0
@@ -30,6 +30,7 @@#include "osdep.h" #include "qemu-queue.h" #include "targphys.h" +#include "cpu-common.h" #ifndef TARGET_LONG_BITS #error TARGET_LONG_BITS must be defined before including this header
poison.h +0 -3
@@ -33,9 +33,6 @@#pragma GCC poison TARGET_PAGE_BITS#pragma GCC poison TARGET_PAGE_ALIGN -#pragma GCC poison CPUState -#pragma GCC poison env -#pragma GCC poison CPU_INTERRUPT_HARD#pragma GCC poison CPU_INTERRUPT_EXITTB#pragma GCC poison CPU_INTERRUPT_TIMER
target-alpha/cpu.h +1 -3
@@ -24,7 +24,7 @@#define TARGET_LONG_BITS 64 -#define CPUState struct CPUAlphaState +#define CPUAlphaState CPUState#include "cpu-defs.h"
@@ -317,8 +317,6 @@ enum { IPR_LAST, }; -typedef struct CPUAlphaState CPUAlphaState ; -typedef struct pal_handler_t pal_handler_t ;struct pal_handler_t {/* Reset */
target-alpha/exec.h +2 -4
@@ -21,8 +21,9 @@#define __ALPHA_EXEC_H__#include "config.h" -#include "dyngen-exec.h" +#include "cpu.h" +#include "exec-all.h" #define TARGET_LONG_BITS 64
@@ -32,9 +33,6 @@ register struct CPUAlphaState *env asm(AREG0);#define SPARAM (n) ((int32_t)PARAM##n)#define FP_STATUS (env->fp_status) -#include "cpu.h" -#include "exec-all.h" -#if !defined(CONFIG_USER_ONLY )#include "softmmu_exec.h" #endif /* !defined(CONFIG_USER_ONLY) */
target-arm/cpu.h +3 -3
@@ -23,7 +23,7 @@#define ELF_MACHINE EM_ARM -#define CPUState struct CPUARMState +#define CPUARMState CPUState#include "cpu-defs.h"
@@ -70,7 +70,7 @@ struct arm_boot_info;s<2n+1> maps to the most significant half of d<n> */ -typedef struct CPUARMState { +struct CPUARMState {/* Regs for current mode. */ uint32_t regs[16 ];/* Frequently accessed CPSR bits are stored separately for efficiently.
@@ -206,7 +206,7 @@ typedef struct CPUARMState { } cp[15 ];void *nvic;struct arm_boot_info *boot_info; -} CPUARMState; +};CPUARMState *cpu_arm_init (const char *cpu_model);void arm_translate_init (void );
target-arm/exec.h +2 -3
@@ -18,14 +18,13 @@*/ #include "config.h" #include "dyngen-exec.h" +#include "cpu.h" +#include "exec-all.h" register struct CPUARMState *env asm(AREG0);#define M0 env->iwmmxt.val -#include "cpu.h" -#include "exec-all.h" -static inline int cpu_has_work (CPUState *env) { return (env->interrupt_request &
target-cris/cpu.h +3 -3
@@ -22,7 +22,7 @@#define TARGET_LONG_BITS 32 -#define CPUState struct CPUCRISState +#define CPUCRISState CPUState#include "cpu-defs.h"
@@ -96,7 +96,7 @@#define NB_MMU_MODES 2 -typedef struct CPUCRISState { +struct CPUCRISState {uint32_t regs[16 ];/* P0 - P15 are referred to as special registers in the docs. */ uint32_t pregs[16 ];
@@ -158,7 +158,7 @@ typedef struct CPUCRISState {void *load_info; CPU_COMMON -} CPUCRISState; +};CPUCRISState *cpu_cris_init (const char *cpu_model);int cpu_cris_exec (CPUCRISState *s);
target-cris/exec.h +3 -3
@@ -17,13 +17,13 @@* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "config.h" #include "dyngen-exec.h" - -register struct CPUCRISState *env asm(AREG0); -#include "cpu.h" #include "exec-all.h" +register struct CPUCRISState *env asm(AREG0); +#if !defined(CONFIG_USER_ONLY )#include "softmmu_exec.h" #endif
target-i386/cpu.h +3 -3
@@ -41,7 +41,7 @@#define ELF_MACHINE EM_386#endif -#define CPUState struct CPUX86State +#define CPUX86State CPUState#include "cpu-defs.h"
@@ -581,7 +581,7 @@ typedef struct {#define NB_MMU_MODES 2 -typedef struct CPUX86State { +struct CPUX86State {/* standard registers */ target_ulong regs[CPU_NB_REGS ];target_ulong eip;
@@ -718,7 +718,7 @@ typedef struct CPUX86State {uint16_t fpus_vmstate;uint16_t fptag_vmstate;uint16_t fpregs_format_vmstate; -} CPUX86State; +};CPUX86State *cpu_x86_init (const char *cpu_model);int cpu_x86_exec (CPUX86State *s);
target-i386/exec.h +2 -5
@@ -18,6 +18,8 @@*/ #include "config.h" #include "dyngen-exec.h" +#include "cpu.h" +#include "exec-all.h" /* XXX: factorize this mess */ #ifdef TARGET_X86_64
@@ -26,8 +28,6 @@#define TARGET_LONG_BITS 32#endif -#include "cpu-defs.h" - register struct CPUX86State *env asm(AREG0);#include "qemu-common.h"
@@ -63,9 +63,6 @@ register struct CPUX86State *env asm(AREG0);#define ST (n) (env->fpregs[(env->fpstt + (n)) & 7].d)#define ST1 ST(1) -#include "cpu.h" -#include "exec-all.h" -/* op_helper.c */ void do_interrupt (int intno,int is_int,int error_code,target_ulong next_eip,int is_hw);
target-m68k/cpu.h +3 -3
@@ -22,7 +22,7 @@#define TARGET_LONG_BITS 32 -#define CPUState struct CPUM68KState +#define CPUM68KState CPUState#include "cpu-defs.h"
@@ -56,7 +56,7 @@#define NB_MMU_MODES 2 -typedef struct CPUM68KState { +struct CPUM68KState {uint32_t dregs[8 ];uint32_t aregs[8 ];uint32_t pc;
@@ -112,7 +112,7 @@ typedef struct CPUM68KState {CPU_COMMON uint32_t features; -} CPUM68KState; +};void m68k_tcg_init (void );CPUM68KState *cpu_m68k_init (const char *cpu_model);
target-m68k/exec.h +3 -3
@@ -17,13 +17,13 @@* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "config.h" #include "dyngen-exec.h" - -register struct CPUM68KState *env asm(AREG0); -#include "cpu.h" #include "exec-all.h" +register struct CPUM68KState *env asm(AREG0); +#if !defined(CONFIG_USER_ONLY )#include "softmmu_exec.h" #endif
target-microblaze/cpu.h +3 -4
@@ -21,10 +21,9 @@#define TARGET_LONG_BITS 32 -#define CPUState struct CPUMBState +#define CPUMBState CPUState#include "cpu-defs.h" -struct CPUMBState ;#if !defined(CONFIG_USER_ONLY )#include "mmu.h" #endif
@@ -199,7 +198,7 @@ struct CPUMBState;#define CC_EQ 0#define NB_MMU_MODES 3 -typedef struct CPUMBState { +struct CPUMBState {uint32_t debug;uint32_t btaken;uint32_t btarget;
@@ -230,7 +229,7 @@ typedef struct CPUMBState {#endif CPU_COMMON -} CPUMBState; +};CPUState *cpu_mb_init (const char *cpu_model);int cpu_mb_exec (CPUState *s);
target-microblaze/exec.h +3 -3
@@ -16,13 +16,13 @@* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "config.h" #include "dyngen-exec.h" - -register struct CPUMBState *env asm(AREG0); -#include "cpu.h" #include "exec-all.h" +register struct CPUMBState *env asm(AREG0); +#if !defined(CONFIG_USER_ONLY )#include "softmmu_exec.h" #endif
target-mips/cpu.h +1 -4
@@ -5,7 +5,7 @@#define ELF_MACHINE EM_MIPS -#define CPUState struct CPUMIPSState +#define CPUMIPSState CPUState#include "config.h" #include "mips-defs.h"
@@ -19,8 +19,6 @@ typedef unsigned char uint_fast8_t;typedef unsigned int uint_fast16_t ;#endif -struct CPUMIPSState ; -typedef struct r4k_tlb_t r4k_tlb_t ;struct r4k_tlb_t {target_ulong VPN;
@@ -172,7 +170,6 @@ struct TCState {int32_t CP0_Debug_tcstatus; }; -typedef struct CPUMIPSState CPUMIPSState ;struct CPUMIPSState {TCState active_tc;CPUMIPSFPUContext active_fpu;
target-mips/exec.h +2 -4
@@ -6,13 +6,11 @@#include "config.h" #include "mips-defs.h" #include "dyngen-exec.h" -#include "cpu-defs.h" - -register struct CPUMIPSState *env asm(AREG0); -#include "cpu.h" #include "exec-all.h" +register struct CPUMIPSState *env asm(AREG0); +#if !defined(CONFIG_USER_ONLY )#include "softmmu_exec.h" #endif /* !defined(CONFIG_USER_ONLY) */
target-ppc/cpu.h +1 -2
@@ -69,7 +69,7 @@#endif /* defined (TARGET_PPC64) */ -#define CPUState struct CPUPPCState +#define CPUPPCState CPUState#include "cpu-defs.h"
@@ -300,7 +300,6 @@ typedef struct opc_handler_t opc_handler_t;/*****************************************************************************/ /* Types used to describe some PowerPC registers */ -typedef struct CPUPPCState CPUPPCState ;typedef struct ppc_tb_t ppc_tb_t ;typedef struct ppc_spr_t ppc_spr_t ;typedef struct ppc_dcr_t ppc_dcr_t ;
target-ppc/exec.h +0 -2
@@ -20,9 +20,7 @@#define __PPC_H__#include "config.h" -#include "dyngen-exec.h" -#include "cpu.h" #include "exec-all.h"
target-s390x/cpu.h +3 -3
@@ -23,7 +23,7 @@#define ELF_MACHINE EM_S390 -#define CPUState struct CPUS390XState +#define CPUS390XState CPUState#include "cpu-defs.h"
@@ -45,7 +45,7 @@ typedef union FPReg {uint64_t i; } FPReg; -typedef struct CPUS390XState { +struct CPUS390XState {uint64_t regs[16 ];/* GP registers */ uint32_t aregs[16 ];/* access registers */
@@ -64,7 +64,7 @@ typedef struct CPUS390XState {uint64_t __excp_addr; CPU_COMMON -} CPUS390XState; +};#if defined(CONFIG_USER_ONLY )static inline void cpu_clone_regs (CPUState *env,target_ulong newsp)
target-s390x/exec.h +3 -4
@@ -17,14 +17,13 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -#include "dyngen-exec.h" - -register struct CPUS390XState *env asm(AREG0); -#include "config.h" +#include "dyngen-exec.h" #include "cpu.h" #include "exec-all.h" +register struct CPUS390XState *env asm(AREG0); +#if !defined(CONFIG_USER_ONLY )#include "softmmu_exec.h" #endif /* !defined(CONFIG_USER_ONLY) */
target-sh4/cpu.h +3 -3
@@ -36,7 +36,7 @@#define SH_CPU_SH7750_ALL (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7750R)#define SH_CPU_SH7751_ALL (SH_CPU_SH7751 | SH_CPU_SH7751R) -#define CPUState struct CPUSH4State +#define CPUSH4State CPUState#include "cpu-defs.h"
@@ -107,7 +107,7 @@ typedef struct memory_content {struct memory_content *next; } memory_content; -typedef struct CPUSH4State { +struct CPUSH4State {int id;/* CPU model */ uint32_t flags;/* general execution flags */
@@ -157,7 +157,7 @@ typedef struct CPUSH4State {int intr_at_halt;/* SR_BL ignored during sleep */ memory_content *movcal_backup;memory_content **movcal_backup_tail; -} CPUSH4State; +};CPUSH4State *cpu_sh4_init (const char *cpu_model);int cpu_sh4_exec (CPUSH4State * s);
target-sh4/exec.h +2 -3
@@ -21,12 +21,11 @@#include "config.h" #include "dyngen-exec.h" - -register struct CPUSH4State *env asm(AREG0); -#include "cpu.h" #include "exec-all.h" +register struct CPUSH4State *env asm(AREG0); +static inline int cpu_has_work (CPUState *env) {return (env->interrupt_request &CPU_INTERRUPT_HARD );
target-sparc/cpu.h +3 -3
@@ -21,7 +21,7 @@# endif #endif -#define CPUState struct CPUSPARCState +#define CPUSPARCState CPUState#include "cpu-defs.h"
@@ -318,7 +318,7 @@ struct QEMUFile;void cpu_put_timer (struct QEMUFile *f,CPUTimer *s);void cpu_get_timer (struct QEMUFile *f,CPUTimer *s); -typedef struct CPUSPARCState { +struct CPUSPARCState {target_ulong gregs[8 ];/* general registers */ target_ulong *regwptr;/* pointer to current register window */ target_ulong pc;/* program counter */
@@ -436,7 +436,7 @@ typedef struct CPUSPARCState {#define SOFTINT_REG_MASK (SOFTINT_STIMER|SOFTINT_INTRMASK|SOFTINT_TIMER)#endif sparc_def_t *def; -} CPUSPARCState; +};#ifndef NO_CPU_IO_DEFS /* helper.c */
target-sparc/exec.h +3 -0
@@ -1,7 +1,10 @@#ifndef EXEC_SPARC_H #define EXEC_SPARC_H 1 +#include "config.h" #include "dyngen-exec.h" +#include "cpu.h" +#include "exec-all.h" register struct CPUSPARCState *env asm(AREG0);
Signature · 1 line
1.7.0.1
Re: [Qemu-devel] [PATCH 4/7] provide opaque CPUState to files that are compiled once
Quoted 11 lines · Paolo Bonzini
This patch unpoisons CPUState and env in once-compiled files. To achieve this, it defines an opaque struct CPUState in
cpu-common.h. This also requires tweaking the relationship between CPUState and CPUXYZState in target files.Unpoisoning env is needed because it is widely used as the name for CPUState arguments. To avoid having references to the global register variable creeping into target-independent files, the patch rationalizes inclusions at the head of
target-*/exec.h. Allexec.hfiles now includecpu.hexplicitly and very early. Inclusions from machine-independent context will then error out incpu-defs.h, even if env is not poisoned.
I'm not comfortable with this part. Accidental use of the global register variable can cause subtle bugs. I'd rather rename 'env' to something more obvious and less likely to collide, like 'global_reg_env' and always poison that. Then we could replace 'env1' etc with just 'env'.
Quoted 631 lines
Signed-off-by Paolo Bonzini <[email protected]>---
cpu-common.h | 3 +++
cpu-defs.h | 1 +
poison.h | 3 ---
target-alpha/cpu.h | 4 +---
target-alpha/exec.h | 6 ++----target-arm/cpu.h | 6 +++--- target-arm/exec.h | 5 ++--- target-cris/cpu.h | 6 +++---target-cris/exec.h | 6 +++---
target-i386/cpu.h | 6 +++---
target-i386/exec.h | 7 ++-----
target-m68k/cpu.h | 6 +++---
target-m68k/exec.h | 6 +++---
target-microblaze/cpu.h | 7 +++----
target-microblaze/exec.h | 6 +++---
target-mips/cpu.h | 5 +----
target-mips/exec.h | 6 ++----
target-ppc/cpu.h | 3 +--
target-ppc/exec.h | 2 --
target-s390x/cpu.h | 6 +++---
target-s390x/exec.h | 7 +++----
target-sh4/cpu.h | 6 +++---
target-sh4/exec.h | 5 ++---
target-sparc/cpu.h | 6 +++---
target-sparc/exec.h | 3 +++25 files changed, 56 insertions(+), 71 deletions(-)cpu-common.h +3
-0@@ -18,6 +18,9 @@ #include "bswap.h" #include "qemu-queue.h" +struct CPUState ; +typedef struct CPUState CPUState ; + #if !defined(CONFIG_USER_ONLY) /* address in the RAM (different from a physical address) */cpu-defs.h +1
-0@@ -30,6 +30,7 @@ #include "osdep.h" #include "qemu-queue.h" #include "targphys.h" +#include "cpu-common.h" #ifndef TARGET_LONG_BITS #error TARGET_LONG_BITS must be defined before including this headerpoison.h +0
-3@@ -33,9 +33,6 @@ #pragma GCC poison TARGET_PAGE_BITS #pragma GCC poison TARGET_PAGE_ALIGN -#pragma GCC poison CPUState -#pragma GCC poison env - #pragma GCC poison CPU_INTERRUPT_HARD #pragma GCC poison CPU_INTERRUPT_EXITTB #pragma GCC poison CPU_INTERRUPT_TIMERtarget-alpha/cpu.h +1
-3@@ -24,7 +24,7 @@ #define TARGET_LONG_BITS 64 -#define CPUState struct CPUAlphaState +#define CPUAlphaState CPUState #include "cpu-defs.h"@@ -317,8 +317,6 @@ enum { IPR_LAST, }; -typedef struct CPUAlphaState CPUAlphaState ; - typedef struct pal_handler_t pal_handler_t; struct pal_handler_t { /* Reset */target-alpha/exec.h +2
-4@@ -21,8 +21,9 @@ #define __ALPHA_EXEC_H__ #include "config.h" - #include "dyngen-exec.h" +#include "cpu.h" +#include "exec-all.h" #define TARGET_LONG_BITS 64@@ -32,9 +33,6 @@ register struct CPUAlphaState *env asm(AREG0); #define SPARAM(n) ((int32_t)PARAM##n) #define FP_STATUS (env->fp_status) -#include "cpu.h" -#include "exec-all.h" - #if !defined(CONFIG_USER_ONLY) #include "softmmu_exec.h" #endif /* !defined(CONFIG_USER_ONLY) */target-arm/cpu.h +1
-1@@ -23,7 +23,7 @@ #define ELF_MACHINE EM_ARM -#define CPUState struct CPUARMState +#define CPUARMState CPUState #include "cpu-defs.h"@@ -70,7 +70,7 @@ struct arm_boot_info;s<2n+1> maps to the most significant half of d<n> */
target-arm/cpu.h +1
-1-typedef struct CPUARMState { +struct CPUARMState {/* Regs for current mode. */
uint32_tregs[16];
/* Frequently accessed CPSR bits are stored separately for efficiently.target-arm/cpu.h +1
-1@@ -206,7 +206,7 @@ typedef struct CPUARMState { } cp[15]; void *nvic; struct arm_boot_info *boot_info; -} CPUARMState; +}; CPUARMState *cpu_arm_init(const char *cpu_model); void arm_translate_init(void);target-arm/exec.h +2
-3@@ -18,14 +18,13 @@*/ #include "config.h" #include "dyngen-exec.h" +#include "cpu.h" +#include "exec-all.h" register struct CPUARMState *env asm(AREG0); #define M0 env->iwmmxt.val -#include "cpu.h" -#include "exec-all.h" - static inline int cpu_has_work(CPUState *env) {return (
env->interrupt_request&target-cris/cpu.h +2
-2@@ -22,7 +22,7 @@ #define TARGET_LONG_BITS 32 -#define CPUState struct CPUCRISState +#define CPUCRISState CPUState #include "cpu-defs.h"@@ -96,7 +96,7 @@ #define NB_MMU_MODES 2 -typedef struct CPUCRISState { +struct CPUCRISState { uint32_t regs[16]; /* P0 - P15 are referred to as special registers in the docs. */ uint32_t pregs[16];@@ -158,7 +158,7 @@ typedef struct CPUCRISState { void *load_info;CPU_COMMON
target-cris/cpu.h +1
-1-} CPUCRISState; +};CPUCRISState *cpu_cris_init(const char
*cpu_model); intcpu_cris_exec(CPUCRISState *s);target-cris/exec.h +3
-3@@ -17,13 +17,13 @@* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "config.h" #include "dyngen-exec.h" - -register struct CPUCRISState *env asm(AREG0); - #include "cpu.h" #include "exec-all.h" +register struct CPUCRISState *env asm(AREG0); + #if !defined(CONFIG_USER_ONLY) #include "softmmu_exec.h" #endiftarget-i386/cpu.h +3
-3@@ -41,7 +41,7 @@ #define ELF_MACHINE EM_386 #endif -#define CPUState struct CPUX86State +#define CPUX86State CPUState #include "cpu-defs.h"@@ -581,7 +581,7 @@ typedef struct { #define NB_MMU_MODES 2 -typedef struct CPUX86State { +struct CPUX86State { /* standard registers */ target_ulong regs[CPU_NB_REGS]; target_ulong eip;@@ -718,7 +718,7 @@ typedef struct CPUX86State { uint16_t fpus_vmstate; uint16_t fptag_vmstate; uint16_t fpregs_format_vmstate; -} CPUX86State; +}; CPUX86State *cpu_x86_init(const char *cpu_model); int cpu_x86_exec(CPUX86State *s);target-i386/exec.h +2
-5@@ -18,6 +18,8 @@*/ #include "config.h" #include "dyngen-exec.h" +#include "cpu.h" +#include "exec-all.h" /* XXX: factorize this mess */ #ifdef TARGET_X86_64@@ -26,8 +28,6 @@ #define TARGET_LONG_BITS 32 #endif -#include "cpu-defs.h" - register struct CPUX86State *env asm(AREG0); #include "qemu-common.h"@@ -63,9 +63,6 @@ register struct CPUX86State *env asm(AREG0); #define ST(n) (env->fpregs[(env->fpstt + (n)) & 7].d) #define ST1 ST(1) -#include "cpu.h" -#include "exec-all.h" - /* op_helper.c */ void do_interrupt(int intno, int is_int, int error_code, target_ulong next_eip, int is_hw);target-m68k/cpu.h +2
-2@@ -22,7 +22,7 @@ #define TARGET_LONG_BITS 32 -#define CPUState struct CPUM68KState +#define CPUM68KState CPUState #include "cpu-defs.h"@@ -56,7 +56,7 @@ #define NB_MMU_MODES 2 -typedef struct CPUM68KState { +struct CPUM68KState { uint32_t dregs[8]; uint32_t aregs[8]; uint32_t pc;@@ -112,7 +112,7 @@ typedef struct CPUM68KState {
CPU_COMMON
uint32_tfeatures;target-m68k/cpu.h +1
-1-} CPUM68KState; +};void
m68k_tcg_init(void);
CPUM68KState *cpu_m68k_init(const char*cpu_model);target-m68k/exec.h +3
-3@@ -17,13 +17,13 @@* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "config.h" #include "dyngen-exec.h" - -register struct CPUM68KState *env asm(AREG0); - #include "cpu.h" #include "exec-all.h" +register struct CPUM68KState *env asm(AREG0); + #if !defined(CONFIG_USER_ONLY) #include "softmmu_exec.h" #endiftarget-microblaze/cpu.h +2
-3@@ -21,10 +21,9 @@ #define TARGET_LONG_BITS 32 -#define CPUState struct CPUMBState +#define CPUMBState CPUState #include "cpu-defs.h" -struct CPUMBState ; #if !defined(CONFIG_USER_ONLY) #include "mmu.h" #endif@@ -199,7 +198,7 @@ struct CPUMBState; #define CC_EQ 0 #define NB_MMU_MODES 3 -typedef struct CPUMBState { +struct CPUMBState { uint32_t debug; uint32_t btaken; uint32_t btarget;@@ -230,7 +229,7 @@ typedef struct CPUMBState { #endif
CPU_COMMONtarget-microblaze/cpu.h +1
-1-} CPUMBState; +};CPUState *cpu_mb_init(const char
*cpu_model);
intcpu_mb_exec(CPUState *s);target-microblaze/exec.h +3
-3@@ -16,13 +16,13 @@* You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "config.h" #include "dyngen-exec.h" - -register struct CPUMBState *env asm(AREG0); - #include "cpu.h" #include "exec-all.h" +register struct CPUMBState *env asm(AREG0); + #if !defined(CONFIG_USER_ONLY) #include "softmmu_exec.h" #endiftarget-mips/cpu.h +1
-4@@ -5,7 +5,7 @@ #define ELF_MACHINE EM_MIPS -#define CPUState struct CPUMIPSState +#define CPUMIPSState CPUState #include "config.h" #include "mips-defs.h"@@ -19,8 +19,6 @@ typedef unsigned char uint_fast8_t; typedef unsigned int uint_fast16_t; #endif -struct CPUMIPSState ; - typedef struct r4k_tlb_t r4k_tlb_t; struct r4k_tlb_t { target_ulong VPN;@@ -172,7 +170,6 @@ struct TCState { int32_t CP0_Debug_tcstatus; }; -typedef struct CPUMIPSState CPUMIPSState ; struct CPUMIPSState { TCState active_tc; CPUMIPSFPUContext active_fpu;target-mips/exec.h +2
-4@@ -6,13 +6,11 @@ #include "config.h" #include "mips-defs.h" #include "dyngen-exec.h" -#include "cpu-defs.h" - -register struct CPUMIPSState *env asm(AREG0); - #include "cpu.h" #include "exec-all.h" +register struct CPUMIPSState *env asm(AREG0); + #if !defined(CONFIG_USER_ONLY) #include "softmmu_exec.h" #endif /* !defined(CONFIG_USER_ONLY) */target-ppc/cpu.h +1
-2@@ -69,7 +69,7 @@ #endif /* defined (TARGET_PPC64) */ -#define CPUState struct CPUPPCState +#define CPUPPCState CPUState #include "cpu-defs.h"@@ -300,7 +300,6 @@ typedef struct opc_handler_t opc_handler_t; /*****************************************************************************/ /* Types used to describe some PowerPC registers */ -typedef struct CPUPPCState CPUPPCState ; typedef struct ppc_tb_t ppc_tb_t; typedef struct ppc_spr_t ppc_spr_t; typedef struct ppc_dcr_t ppc_dcr_t;target-ppc/exec.h +0
-2@@ -20,9 +20,7 @@ #define __PPC_H__ #include "config.h" - #include "dyngen-exec.h" - #include "cpu.h" #include "exec-all.h"target-s390x/cpu.h +2
-2@@ -23,7 +23,7 @@ #define ELF_MACHINE EM_S390 -#define CPUState struct CPUS390XState +#define CPUS390XState CPUState #include "cpu-defs.h"@@ -45,7 +45,7 @@ typedef union FPReg { uint64_t i; } FPReg; -typedef struct CPUS390XState { +struct CPUS390XState {
uint64_tregs[16]; /* GP registers */
uint32_taregs[16]; /* access registers */target-s390x/cpu.h +0
-0@@ -64,7 +64,7 @@ typedef struct CPUS390XState { uint64_t __excp_addr;
CPU_COMMONtarget-s390x/cpu.h +1
-1-} CPUS390XState; +};#if
defined(CONFIG_USER_ONLY)
static inline voidcpu_clone_regs(CPUState *env, target_ulong newsp)target-s390x/exec.h +3
-4@@ -17,14 +17,13 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -#include "dyngen-exec.h" - -register struct CPUS390XState *env asm(AREG0); - #include "config.h" +#include "dyngen-exec.h" #include "cpu.h" #include "exec-all.h" +register struct CPUS390XState *env asm(AREG0); + #if !defined(CONFIG_USER_ONLY) #include "softmmu_exec.h" #endif /* !defined(CONFIG_USER_ONLY) */target-sh4/cpu.h +2
-2@@ -36,7 +36,7 @@ #define SH_CPU_SH7750_ALL (SH_CPU_SH7750 | SH_CPU_SH7750S | SH_CPU_SH7750R) #define SH_CPU_SH7751_ALL (SH_CPU_SH7751 | SH_CPU_SH7751R) -#define CPUState struct CPUSH4State +#define CPUSH4State CPUState #include "cpu-defs.h"@@ -107,7 +107,7 @@ typedef struct memory_content { struct memory_content *next; } memory_content; -typedef struct CPUSH4State { +struct CPUSH4State {int id; /* CPU model */
uint32_tflags; /* general execution flags */target-sh4/cpu.h +0
-0@@ -157,7 +157,7 @@ typedef struct CPUSH4State {int
intr_at_halt; /*SR_BLignored during sleep */memory_content*movcal_backup;
memory_content**movcal_backup_tail;target-sh4/cpu.h +1
-1-} CPUSH4State; +};CPUSH4State *cpu_sh4_init(const char
*cpu_model); intcpu_sh4_exec(CPUSH4State * s);target-sh4/exec.h +2
-3@@ -21,12 +21,11 @@ #include "config.h" #include "dyngen-exec.h" - -register struct CPUSH4State *env asm(AREG0); - #include "cpu.h" #include "exec-all.h" +register struct CPUSH4State *env asm(AREG0); + static inline int cpu_has_work(CPUState *env) { return (env->interrupt_request & CPU_INTERRUPT_HARD);target-sparc/cpu.h +2
-2@@ -21,7 +21,7 @@ # endif #endif -#define CPUState struct CPUSPARCState +#define CPUSPARCState CPUState #include "cpu-defs.h"@@ -318,7 +318,7 @@ struct QEMUFile; void cpu_put_timer(struct QEMUFile *f, CPUTimer *s); void cpu_get_timer(struct QEMUFile *f, CPUTimer *s); -typedef struct CPUSPARCState { +struct CPUSPARCState {
target_ulonggregs[8]; /* general registers */target_ulong*regwptr; /* pointer to current register window */target_ulongpc; /* program counter */target-sparc/cpu.h +1
-1@@ -436,7 +436,7 @@ typedef struct CPUSPARCState { #define SOFTINT_REG_MASK (SOFTINT_STIMER|SOFTINT_INTRMASK|SOFTINT_TIMER) #endif sparc_def_t *def; -} CPUSPARCState; +}; #ifndef NO_CPU_IO_DEFS /* helper.c */target-sparc/exec.h +3
-1@@ -1,7 +1,10 @@ #ifndef EXEC_SPARC_H #define EXEC_SPARC_H 1 + #include "config.h" #include "dyngen-exec.h" +#include "cpu.h" +#include "exec-all.h" register struct CPUSPARCState *env asm(AREG0); --1.7.0.1
Re: [Qemu-devel] [PATCH 4/7] provide opaque CPUState to files that are compiled once
Quoted 5 lines · Blue Swirl
I'm not comfortable with this part. Accidental use of the global register variable can cause subtle bugs. I'd rather rename 'env' to something more obvious and less likely to collide, like '
global_reg_env' and always poison that. Then we could replace 'env1' etc with just 'env'.
This is not very different from before thanks to the reordering of includes done in this patch.
All target-*/exec.h files now start with
#include "config.h"
#include "dyngen-exec.h"
#include "cpu.h"
#include "exec-all.h"
// sometimes a few #defines
register struct CPUAlphaState *env asm(AREG0);
And so they cannot use the global env unless NEED_CPU_H is defined. If anything, it's clearer than before because the structure of the initial #includes is the same for all targets.
It's true that a "NEED_GLOBAL_ENV" would provide even better safety, but that's something for a separate patch series. It's particularly easy to do after replacing CPU<Target>State with CPUState, so that it can be moved into exec-all.h, but this series is already big enough IMO. Let's do cleanups one thing at a time please.
Paolo
Re: [Qemu-devel] [PATCH 4/7] provide opaque CPUState to files that are compiled once
Quoted 26 lines · Paolo Bonzini
Quoted 6 lines · Blue Swirl
I'm not comfortable with this part. Accidental use of the global register variable can cause subtle bugs. I'd rather rename 'env' to something more obvious and less likely to collide, like '
global_reg_env' and always poison that. Then we could replace 'env1' etc with just 'env'.This is not very different from before thanks to the reordering of includes done in this patch.
All
target-*/exec.hfiles now start with#include "
config.h"
#include "dyngen-exec.h"
#include "cpu.h"
#include "exec-all.h"// sometimes a few #defines
register struct CPUAlphaState *env asm(AREG0);
And so they cannot use the global env unless
NEED_CPU_His defined. If anything, it's clearer than before because the structure of the initial #includes is the same for all targets.
Quoted 5 lines
It's true that a "
NEED_GLOBAL_ENV" would provide even better safety, but that's something for a separate patch series. It's particularly easy to do after replacing CPU<Target>State with CPUState, so that it can be moved intoexec-all.h, but this series is already big enough IMO. Let's do cleanups one thing at a time please.
Fine, but then let's not unpoison env with this patch set, please.
PATCH 5/7 add qdev property type "cpu"
In reply to Paolo Bonzini--- cpus.c | 16 ++++++++++++++++ cpus.h | 2 ++ hw/qdev-properties.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 5 +++++ 4 files changed, 67 insertions(+), 0 deletions(-)
cpus.c +16 -0
@@ -91,6 +91,22 @@ void cpu_synchronize_all_post_init(void) } } +CPUState *cpu_get_by_id (int id) +{ +CPUState *cpu; + +for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) +if (cpu->cpu_index == id) +return cpu; + +return NULL ; +} + +int cpu_get_id (CPUState *env) +{ +return env->cpu_index; +} +int cpu_is_stopped (CPUState *env) {return !vm_running || env->stopped;
cpus.h +2 -0
@@ -6,6 +6,8 @@ int qemu_init_main_loop(void);void qemu_main_loop_start (void );void resume_all_vcpus (void );void pause_all_vcpus (void ); +CPUState *cpu_get_by_id (int id); +int cpu_get_id (CPUState *env);/* vl.c */ extern int smp_cores;
hw/qdev-properties.c +44 -0
62 lines not on this page · raw message
hw/qdev.h +5 -0
@@ -90,6 +90,7 @@ enum PropertyType {PROP_TYPE_VLAN ,PROP_TYPE_PTR ,PROP_TYPE_BIT , + PROP_TYPE_CPU, }; struct PropertyInfo {
@@ -203,6 +204,7 @@ extern PropertyInfo qdev_prop_drive;extern PropertyInfo qdev_prop_netdev;extern PropertyInfo qdev_prop_vlan;extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_cpu;#define DEFINE_PROP (_name, _state, _field, _prop, _type) { \ .name = (_name), \
@@ -257,6 +259,8 @@ extern PropertyInfo qdev_prop_pci_devfn; DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*) #define DEFINE_PROP_MACADDR(_n, _s, _f) \DEFINE_PROP (_n, _s, _f, qdev_prop_macaddr, MACAddr) +#define DEFINE_PROP_CPU(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_cpu, CPUState*) #define DEFINE_PROP_END_OF_LIST() \ {}
@@ -276,6 +280,7 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valuvoid qdev_prop_set_netdev (DeviceState *dev,const char *name,VLANClientState *value);void qdev_prop_set_vlan (DeviceState *dev,const char *name,VLANState *value);void qdev_prop_set_drive (DeviceState *dev,const char *name,DriveInfo *value); +void qdev_prop_set_cpu (DeviceState *dev,const char *name,CPUState *value);void qdev_prop_set_macaddr (DeviceState *dev,const char *name,uint8_t *value);/* FIXME: Remove opaque pointer properties. */ void qdev_prop_set_ptr (DeviceState *dev,const char *name,void *value);
Signature · 1 line
1.7.0.1
Re: [Qemu-devel] [PATCH 5/7] add qdev property type "cpu"
Paolo Bonzini <[email protected]> writes:
[...]
Quoted 35 lines
hw/qdev-properties.c +20
-0@@ -1,6 +1,7 @@#include "net.h" #include "qdev.h" #include "qerror.h" +#include "cpus.h" void *qdev_get_prop_ptr (DeviceState *dev,Property *prop) {@@ -281,6 +282,44 @@ PropertyInfo qdev_prop_string = { .free = free_string, }; +/* --- cpu --- */ + +static int parse_cpu (DeviceState *dev,Property *prop,const char *str) +{ +CPUState **ptr =qdev_get_prop_ptr (dev, prop); +char *end; +int id; + +if (!*str) +return -ENOENT ; + + id =strtol (str, &end,0 ); +if (*end) +return -ENOENT ; + + *ptr =cpu_get_by_id (id); +if (*ptr ==NULL ) +return -ENOENT ; +return 0 ;
hw/qdev-properties.c PropertyInfo qdev_prop_string = { · line 313
Quoted 10 lines
hw/qdev-properties.c +10
-0+} + +static int print_cpu (DeviceState *dev,Property *prop,char *dest,size_t len) +{ +CPUState **ptr =qdev_get_prop_ptr (dev, prop); +if (*ptr) +return snprintf (dest, len,"CPU #%d" ,cpu_get_id (*ptr)); +else +return snprintf (dest, len,"CPU #<null>" ); +}
Hmm. Parse method doesn't accept output of the print method. Not so nice. Is the "CPU #" decoration essential?
Oh, and beware of the Secret Tab Police.
[...]
[Qemu-devel] Re: [PATCH 5/7] add qdev property type "cpu"
Quoted 2 lines
Hmm. Parse method doesn't accept output of the print method. Not so nice. Is the "CPU #" decoration essential?
I noticed the same in parse/print string:
static int parse_string(DeviceState *dev, Property *prop, const char *str)
{
char **ptr = qdev_get_prop_ptr(dev, prop);
if (*ptr)
qemu_free(*ptr);
*ptr = qemu_strdup(str);
return 0;
}static int print_string(DeviceState *dev, Property *prop, char *dest, size_t len)
{
char **ptr = qdev_get_prop_ptr(dev, prop);
if (!*ptr)
return snprintf(dest, len, "<null>");
return snprintf(dest, len, "\"%s\"", *ptr);
}It looks like printing representation is chosen "for the user", not for parsing.
Paolo
[Qemu-devel] Re: [PATCH 5/7] add qdev property type "cpu"
Quoted 24 lines · Paolo Bonzini
Quoted 2 lines
Hmm. Parse method doesn't accept output of the print method. Not so nice. Is the "CPU #" decoration essential?
I noticed the same in parse/print string:
static int
parse_string(DeviceState *dev, Property *prop, const char *str){ char **ptr = qdev_get_prop_ptr(dev, prop); if (*ptr) qemu_free(*ptr); *ptr = qemu_strdup(str); return 0; }static int
print_string(DeviceState *dev, Property *prop, char *dest, size_t len){ char **ptr = qdev_get_prop_ptr(dev, prop); if (!*ptr) return snprintf(dest, len, "<null>"); return snprintf(dest, len, "\"%s\"", *ptr); }
Quoted 2 lines
It looks like printing representation is chosen "for the user", not for parsing.
Yes, but does that mean we *should* add such decorations?
For me, the print method should be reasonably close to what the parse method accepts. A bit like Lisp's princ, whose ouput is close, but not identical to what the reader accepts (for output acceptable to the reader, use prin1).
As to "for the user":
dev-prop: cpu_env = CPU #0
dev-prop: cpu_env = 0
Both are equally intelligible, in my opinion: obvious if you know what the property is about, gibberish if you don't. The latter is slightly easier to parse with simple tools like AWK.
By the way, print_string() should escape double-quote and funny characters.
[Qemu-devel] Re: [PATCH 5/7] add qdev property type "cpu"
Quoted 8 lines · Markus Armbruster
As to "for the user":
dev-prop:
cpu_env= CPU #0
dev-prop:cpu_env= 0Both are equally intelligible, in my opinion: obvious if you know what the property is about, gibberish if you don't. The latter is slightly easier to parse with simple tools like AWK.
I'll remove the decoration (though the overall problem remains).
Paolo
Re: [Qemu-devel] [PATCH 5/7] add qdev property type "cpu"
In reply to Paolo BonziniQuoted 13 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini <[email protected]>---
cpus.c | 16 ++++++++++++++++
cpus.h | 2 ++
hw/qdev-properties.c | 44 ++++++++++++++++++++++++++++++++++++++++++++hw/qdev.h| 5 +++++4 files changed, 67 insertions(+), 0 deletions(-)cpus.c +0
-0
cpus.c void cpu_synchronize_all_post_init(void) · line 100
Quoted 10 lines
cpus.c +7
-0@@ -91,6 +91,22 @@ void cpu_synchronize_all_post_init(void) } } +CPUState *cpu_get_by_id (int id) +{ + CPUState *cpu; + + for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) + if (cpu->cpu_index == id) + return cpu;
CODING_STYLE, also below.
Quoted 137 lines
cpus.c +9
-0+ + return NULL; +} + +int cpu_get_id (CPUState *env) +{ + return env->cpu_index; +} + int cpu_is_stopped(CPUState *env) { return !vm_running || env->stopped;cpus.h +2
-0@@ -6,6 +6,8 @@ int qemu_init_main_loop(void); void qemu_main_loop_start(void); void resume_all_vcpus(void); void pause_all_vcpus(void); +CPUState *cpu_get_by_id (int id); +int cpu_get_id (CPUState *env); /* vl.c */ extern int smp_cores;hw/qdev-properties.c +44
-0@@ -1,6 +1,7 @@ #include "net.h" #include "qdev.h" #include "qerror.h" +#include "cpus.h" void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) {@@ -281,6 +282,44 @@ PropertyInfo qdev_prop_string = { .free = free_string, }; +/* --- cpu --- */ + +static int parse_cpu (DeviceState *dev,Property *prop,const char *str) +{ + CPUState **ptr = qdev_get_prop_ptr(dev, prop); + char *end; + int id; + + if (!*str) + return -ENOENT; + + id = strtol (str, &end, 0); + if (*end) + return -ENOENT; + + *ptr = cpu_get_by_id(id); + if (*ptr == NULL) + return -ENOENT; + return 0; +} + +static int print_cpu (DeviceState *dev,Property *prop,char *dest,size_t len) +{ + CPUState **ptr = qdev_get_prop_ptr(dev, prop); + if (*ptr) + return snprintf(dest, len, "CPU #%d", cpu_get_id(*ptr)); + else + return snprintf(dest, len, "CPU #<null>"); +} + +PropertyInfo qdev_prop_cpu = { + .name = "cpu", + .type = PROP_TYPE_CPU, + .size = sizeof(DriveInfo*), + .parse = parse_cpu, + .print = print_cpu, +}; + /* --- drive --- */ static int parse_drive(DeviceState *dev, Property *prop, const char *str)@@ -657,6 +696,11 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value) qdev_prop_set(dev, name, &value, PROP_TYPE_PTR); } +void qdev_prop_set_cpu (DeviceState *dev,const char *name,CPUState *value) +{ + qdev_prop_set(dev, name, &value, PROP_TYPE_CPU); +} + void qdev_prop_set_defaults(DeviceState *dev, Property *props) { if (!props)hw/qdev.h +5
-1@@ -90,6 +90,7 @@ enum PropertyType { PROP_TYPE_VLAN, PROP_TYPE_PTR, PROP_TYPE_BIT, + PROP_TYPE_CPU, }; struct PropertyInfo {@@ -203,6 +204,7 @@ extern PropertyInfo qdev_prop_drive; extern PropertyInfo qdev_prop_netdev; extern PropertyInfo qdev_prop_vlan; extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_cpu; #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ .name = (_name), \@@ -257,6 +259,8 @@ extern PropertyInfo qdev_prop_pci_devfn; DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*) #define DEFINE_PROP_MACADDR(_n, _s, _f) \ DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) +#define DEFINE_PROP_CPU (_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_cpu, CPUState*) #define DEFINE_PROP_END_OF_LIST() \ {}@@ -276,6 +280,7 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value); void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value); void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value); +void qdev_prop_set_cpu (DeviceState *dev,const char *name,CPUState *value); void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); /* FIXME: Remove opaque pointer properties. */ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); --1.7.0.1
PATCH 6/7 replace void* uses with opaque CPUState*
In reply to Paolo BonziniBecause we all love type safety, don't we?
--- cpu-common.h | 1 - cpus.c | 23 ++++++++--------------- hw/apic.c | 4 ++-- hw/pc.c | 4 ++-- qemu-common.h | 7 ++++--- 5 files changed, 16 insertions(+), 23 deletions(-)
cpu-common.h +0 -1
@@ -19,7 +19,6 @@#include "qemu-queue.h" struct CPUState ; -typedef struct CPUState CPUState ;#if !defined(CONFIG_USER_ONLY )
cpus.c +8 -15
@@ -259,10 +259,8 @@ void qemu_main_loop_start(void) { } -void qemu_init_vcpu (void *_env) +void qemu_init_vcpu (CPUState *env) { -CPUState *env = _env; - env->nr_cores = smp_cores; env->nr_threads = smp_threads;if (kvm_enabled ())
@@ -270,7 +268,7 @@ void qemu_init_vcpu(void *_env)return ; } -int qemu_cpu_self (void *env) +int qemu_cpu_self (CPUState *env) {return 1 ; }
@@ -288,7 +286,7 @@ void pause_all_vcpus(void) { } -void qemu_cpu_kick (void *env) +void qemu_cpu_kick (CPUState *env) {return ; }
@@ -524,16 +522,14 @@ static void *tcg_cpu_thread_fn(void *arg)return NULL ; } -void qemu_cpu_kick (void *_env) +void qemu_cpu_kick (CPUState *env) { -CPUState *env = _env;qemu_cond_broadcast (env->halt_cond);qemu_thread_signal (env->thread,SIG_IPI ); } -int qemu_cpu_self (void *_env) +int qemu_cpu_self (CPUState *env) { -CPUState *env = _env;QemuThread this;qemu_thread_self (&this);
@@ -666,9 +662,8 @@ void resume_all_vcpus(void) } } -static void tcg_init_vcpu (void *_env) +static void tcg_init_vcpu (CPUState *env) { -CPUState *env = _env;/* share a single thread for all cpus with TCG */ if (!tcg_cpu_thread) { env->thread =qemu_mallocz (sizeof (QemuThread));
@@ -695,10 +690,8 @@ static void kvm_start_vcpu(CPUState *env)qemu_cond_timedwait (&qemu_cpu_cond, &qemu_global_mutex,100 ); } -void qemu_init_vcpu (void *_env) +void qemu_init_vcpu (CPUState *env) { -CPUState *env = _env; - env->nr_cores = smp_cores; env->nr_threads = smp_threads;if (kvm_enabled ())
@@ -840,7 +833,7 @@ void set_cpu_log(const char *optarg)int64_t cpu_get_icount (void ) {int64_t icount; -CPUState *env = cpu_single_env;; +CPUState *env = cpu_single_env; icount = qemu_icount;if (env) {
hw/apic.c +2 -2
@@ -94,7 +94,7 @@ typedef struct APICState APICState;struct APICState {SysBusDevice busdev; -void *cpu_env; +CPUState *cpu_env;uint32_t apicbase;uint8_t id;uint8_t arb_id;
@@ -1006,7 +1006,7 @@ static SysBusDeviceInfo apic_info = { .qdev.no_user = 1, .qdev.props = (Property []) {DEFINE_PROP_UINT8 ("id" , APICState, id,-1 ), -DEFINE_PROP_PTR ("cpu_env" , APICState, cpu_env), +DEFINE_PROP_CPU ("cpu_env" , APICState, cpu_env),DEFINE_PROP_END_OF_LIST (), } };
hw/pc.c +2 -2
@@ -766,7 +766,7 @@ DeviceState *cpu_get_current_apic(void) } } -static DeviceState *apic_init (void *env,uint8_t apic_id) +static DeviceState *apic_init (CPUState *env,uint8_t apic_id) {DeviceState *dev;SysBusDevice *d;
@@ -774,7 +774,7 @@ static DeviceState *apic_init(void *env, uint8_t apic_id) dev =qdev_create (NULL ,"apic" );qdev_prop_set_uint8 (dev,"id" , apic_id); -qdev_prop_set_ptr (dev,"cpu_env" , env); +qdev_prop_set_cpu (dev,"cpu_env" , env);qdev_init_nofail (dev); d =sysbus_from_qdev (dev);
qemu-common.h +4 -3
@@ -17,6 +17,7 @@ typedef struct QEMUTimer QEMUTimer;typedef struct QEMUFile QEMUFile ;typedef struct QEMUBH QEMUBH ;typedef struct DeviceState DeviceState ; +typedef struct CPUState CPUState ;/* we put basic includes here to avoid repeating them in device drivers */ #include <stdlib.h>
@@ -239,8 +240,8 @@ void qemu_service_io(void);void qemu_notify_event (void );/* Unblock cpu */ -void qemu_cpu_kick (void *env); -int qemu_cpu_self (void *env); +void qemu_cpu_kick (CPUState *env); +int qemu_cpu_self (CPUState *env);/* work queue */ struct qemu_work_item {
@@ -253,7 +254,7 @@ struct qemu_work_item {#ifdef CONFIG_USER_ONLY #define qemu_init_vcpu (env) do { } while (0)#else -void qemu_init_vcpu (void *env); +void qemu_init_vcpu (CPUState *env);#endif typedef struct QEMUIOVector {
Signature · 1 line
1.7.0.1
Re: [Qemu-devel] [PATCH 6/7] replace void* uses with opaque CPUState*
Quoted 1 line · Paolo Bonzini
Because we all love type safety, don't we?
And incomplete types! Much better choice for an abstract data type than abusing poor old "void *".
You also get rid of a use of the DEFINE_PROP_PTR() abomination. Thanks!
PATCH 7/7 poison TARGET_xxx for compile once object
In reply to Paolo Bonziniprevents those ifdefs from creeping in again.
--- cpu-common.h | 4 ---- qemu-common.h | 5 +---- 2 files changed, 1 insertions(+), 8 deletions(-)
cpu-common.h +0 -4
@@ -11,10 +11,6 @@#include "targphys.h" #endif -#ifndef NEED_CPU_H -#include "poison.h" -#endif -#include "bswap.h" #include "qemu-queue.h"
qemu-common.h +1 -4
@@ -86,15 +86,12 @@ static inline char *realpath(const char *path, char *resolved_path)/* FIXME: Remove NEED_CPU_H. */ #ifndef NEED_CPU_H -#include <setjmp.h> #include "osdep.h" #include "bswap.h" - +#include "poison.h" #else -#include "cpu.h" -#endif /* !defined(NEED_CPU_H) */ /* bottom halves */
Signature · 1 line
1.7.0.1
Quoted 26 lines · Paolo Bonzini
This is a different way to achieve the same objective as Isamu's patch. Basically, his patch becomes the (much simpler) patch 7 of this series, and everything else is something I had had lying around for a while. :)
Patch 1 is simply Amit's patch, included here for convenience as it's not been applied yet.
Patches 2 and 3 remove some
dyngen-exec.hhacks at the price of requiringqemu-common.hincluded in more places. I don't see this as a big price; all of these files were already includingqemu-common.hindirectly, e.g. viacpu-all.h, just not early enough.Patches 4 provides a CPUState type, albeit an opaque one, to files that are not compiled per-target. The advantage of this are apparent in patches 5 and 6: opaque pointers that are actually CPUState pointers are now type-safe, and it is even possible to define a cpu property type for the occasional device that has to be connected to a particular CPU (the PC APICs in particular).
Finally, patch 7 "redoes" Isamu's patch just by moving five lines of code into
qemu-common.h.Amit Shah (1):
rtc: RemoveTARGET_I386fromqemu-config.c, enables driftfix
Quoted 7 lines
Paolo Bonzini (6):
includeqemu-common.hwhen needed by the next patches includestdio.hfreely, removedyngen-exec.hhacks provide opaque CPUState to files that are compiled once add qdev property type "cpu"
replace void* uses with opaque CPUState* poisonTARGET_xxxfor compile once object
I like this cleanup. Although I would personally prefer an additional patch that removes the define silliness that patch 4 works around. In other words I think there's no point in having CPUARMState et al; we should use CPUState universally.
r~
Quoted 2 lines · Richard Henderson
Although I would personally prefer an additional
patch that removes the define silliness that patch 4 works around.
Sure---I just wanted to avoid getting lost in conflicts until the first part is approved.
Paolo
Quoted 19 lines · Paolo Bonzini
This is a different way to achieve the same objective as Isamu's patch. Basically, his patch becomes the (much simpler) patch 7 of this series, and everything else is something I had had lying around for a while. :)
Patch 1 is simply Amit's patch, included here for convenience as it's not been applied yet.
Patches 2 and 3 remove some
dyngen-exec.hhacks at the price of requiringqemu-common.hincluded in more places. I don't see this as a big price; all of these files were already includingqemu-common.hindirectly, e.g. viacpu-all.h, just not early enough.Patches 4 provides a CPUState type, albeit an opaque one, to files that are not compiled per-target. The advantage of this are apparent in patches 5 and 6: opaque pointers that are actually CPUState pointers are now type-safe, and it is even possible to define a cpu property type for the occasional device that has to be connected to a particular CPU (the PC APICs in particular).
Quoted 2 lines
Finally, patch 7 "redoes" Isamu's patch just by moving five lines of code into
qemu-common.h.
From just clean up or type safety point of view, this is good stuff. But from architectural point of view, we should make it more difficult to use CPUState in device code, not easier. This may still be fine as a temporary measure, before all CPUState references have been removed.
I had some comments regarding individual patches.
Quoted 98 lines
Amit Shah (1):
rtc: RemoveTARGET_I386fromqemu-config.c, enables driftfixPaolo Bonzini (6):
includeqemu-common.hwhen needed by the next patches includestdio.hfreely, removedyngen-exec.hhacks provide opaque CPUState to files that are compiled once add qdev property type "cpu"
replace void* uses with opaque CPUState* poisonTARGET_xxxfor compile once objectarm-semi.c | 2 +-
bsd-user/qemu.h | 1 +
cpu-common.h | 6 +---
cpu-defs.h | 1 +
cpu-exec.c | 1 +
cpus.c | 39 ++++++++++++++++++++++--------------cpus.h| 2 +
darwin-user/qemu.h | 1 +
disas.c | 1 +
disas.h | 5 +---
dyngen-exec.h | 16 --------------
exec.c | 2 +-
hw/apic.c | 4 +-
hw/pc.c | 4 +-
hw/qdev-properties.c | 44 +++++++++++++++++++++++++++++++++++++++++hw/qdev.h| 5 ++++linux-user/arm/nwfpe/fpa11.h| 3 +-
linux-user/main.c | 1 -
linux-user/qemu.h | 1 +
m68k-semi.c | 2 +-
poison.h | 3 --
qemu-common.h | 19 ++++-------------qemu-config.c| 2 -
target-alpha/cpu.h | 4 +--
target-alpha/exec.h | 6 +---
target-alpha/helper.c | 1 +
target-alpha/op_helper.c | 1 +
target-alpha/translate.c | 2 +-
target-arm/cpu.h | 6 ++--
target-arm/exec.h | 5 +--
target-arm/helper.c | 2 +-target-arm/iwmmxt_helper.c| 1 +
target-arm/neon_helper.c | 1 +
target-arm/op_helper.c | 1 +
target-arm/translate.c | 1 +
target-cris/cpu.h | 6 ++--
target-cris/exec.h | 6 ++--
target-cris/helper.c | 1 +
target-cris/mmu.c | 1 +
target-cris/op_helper.c | 1 +
target-cris/translate.c | 2 +-
target-i386/cpu.h | 6 ++--
target-i386/cpuid.c | 1 +
target-i386/exec.h | 7 +----
target-i386/helper.c | 2 +-
target-i386/op_helper.c | 1 +
target-i386/translate.c | 1 +
target-m68k/cpu.h | 6 ++--
target-m68k/exec.h | 6 ++--
target-m68k/helper.c | 2 +-target-m68k/op_helper.c | 1 + target-m68k/translate.c | 1 + target-microblaze/cpu.h | 7 ++--- target-microblaze/exec.h | 6 ++--target-microblaze/helper.c | 1 +
target-microblaze/mmu.c | 1 +
target-microblaze/op_helper.c | 1 +
target-microblaze/translate.c | 2 +-
target-mips/cpu.h | 5 +---
target-mips/exec.h | 6 +---
target-mips/helper.c | 1 +
target-mips/op_helper.c | 1 +
target-mips/translate.c | 2 +-
target-ppc/cpu.h | 3 +-
target-ppc/exec.h | 2 -
target-ppc/helper.c | 2 +-
target-ppc/op_helper.c | 1 +
target-ppc/translate.c | 2 +-
target-s390x/cpu.h | 6 ++--
target-s390x/exec.h | 7 ++---
target-s390x/helper.c | 2 +-
target-s390x/op_helper.c | 1 +
target-sh4/cpu.h | 6 ++--
target-sh4/exec.h | 5 +--
target-sh4/helper.c | 1 +
target-sh4/op_helper.c | 2 +
target-sh4/translate.c | 2 +-
target-sparc/cpu.h | 6 ++--
target-sparc/exec.h | 3 ++
target-sparc/helper.c | 2 +-
target-sparc/op_helper.c | 1 +
target-sparc/translate.c | 1 +
translate-all.c | 1 +83 files changed, 189 insertions(+), 147 deletions(-)
Quoted 4 lines · Blue Swirl
From just clean up or type safety point of view, this is good stuff.
But from architectural point of view, we should make it more difficult to use CPUState in device code, not easier. This may still be fine as a temporary measure, before all CPUState references have been removed.
I don't see it at all as a temporary measure. In theory, only devices compiled per-target would need access to CPUState, that's true. However, there are conflicting goals which make an opaque CPUState preferrable.
First, converting devices such as APIC to qdev requires knowledge of CPUState in qdev, unless you want to keep DEFINE_PROP_PTR (whose removal is much more interesting) or sweep it under the void* blanket. PICs are likely to have CPUState members, e.g. hw/pxa2xx_pic.c (and BTW indirect access via functions to these fields is making emulation a little bit slower).
Also, for things compiled in libhw that are not part of device code, requiring knowledge of CPUState is absolutely not problematic and the only alternative loses type-safety and so it is inferior.
Paolo
Quoted 9 lines · Paolo Bonzini
Quoted 5 lines · Blue Swirl
From just clean up or type safety point of view, this is good stuff. But from architectural point of view, we should make it more difficult to use CPUState in device code, not easier. This may still be fine as a temporary measure, before all CPUState references have been removed.
I don't see it at all as a temporary measure. In theory, only devices compiled per-target would need access to CPUState, that's true.
There is no need for any device to have access to CPUState fields. All such accesses are either poor design or a shortcut taken for performance. The only device where the design calls for CPUState access is vmmouse and even there we could avoid the direct access. In all other cases, only board physical address size and CPU endianness matters but these should be fixed at some point by a better bus design.
Quoted 8 lines
However,
there are conflicting goals which make an opaque CPUState preferrable.First, converting devices such as APIC to qdev requires knowledge of CPUState in qdev, unless you want to keep
DEFINE_PROP_PTR(whose removal is much more interesting) or sweep it under the void* blanket. PICs are likely to have CPUState members, e.g.hw/pxa2xx_pic.c(and BTW indirect access via functions to these fields is making emulation a little bit slower).
One way to clean up PICs would be to use qemu_irq to signal CPU interrupts, but there are probably others.
Quoted 4 lines
Also, for things compiled in libhw that are not part of device code, requiring knowledge of CPUState is absolutely not problematic and the only alternative loses type-safety and so it is inferior.
Completely untrue. Devices (whether part of libhw etc. or not) have no need (from architectural point of view) to access CPUState contents. It's clearly problematic. It's also possible to get type safety without CPUState references in the devices.
Anyway, as I mentioned earlier, I think it's OK to apply the series (after the problems are fixed), because of the short term gains in cleanups and type safety. But the goal must be to make all devices independent of the CPU model. If we never reach that goal (for example, because of the performance issues), I guess you would not be sad.
Quoted 4 lines
Quoted 2 lines
I don't see it at all as a temporary measure. In theory, only devices compiled per-target would need access to CPUState, that's true.
There is no need for any device to have access to CPUState fields.
That's why this patch defines CPUState as opaque (i.e. incomplete). Granted, an opaque CPUState plus a bunch of accessors is not any better than a fully-visible CPUState, if the accessors are very much tied to that particular CPUState type. (But then, we also agree it is also a tiny little bit better than void*).
Quoted 8 lines
Quoted 5 lines
First, converting devices such as APIC to qdev requires knowledge of CPUState in qdev, unless you want to keep
DEFINE_PROP_PTR(whose removal is much more interesting) or sweep it under the void* blanket. PICs are likely to have CPUState members, e.g.hw/pxa2xx_pic.c(and BTW indirect access via functions to these fields is making emulation a little bit slower).One way to clean up PICs would be to use
qemu_irqto signal CPU interrupts, but there are probably others.
In the end the devices will be wired to a particular CPU and these "wires" will likely be more complex than a 1-bit IRQ, so qemu_irq only makes limited sense as it is now.
What you have to pass may be simply a 32-bit value as in hw/etraxfs_pic, or a more complicated payload as in apic_bus_deliver, but anyway at some point you'll be coupling either:
- the device to the CPU, as it happens now. As above, the CPU may be accessed via void* and functions, or via fields directly, but in any case the coupling is there.
- the CPU to the device. If you used qemu_irq that would be the most likely outcome: the CPU knows about some DeviceState, and it downcasts it to an expected device type in the IRQ handler. Again, you only have an illusion of decoupling and, given the lengthy discussion about IRQ payloads on qemu-devel only a few weeks ago, I'm not optimist it's going to go away.
Quoted 8 lines
Quoted 3 lines
Also, for things compiled in libhw that are not part of device code, requiring knowledge of CPUState is absolutely not problematic and the only alternative loses type-safety and so it is inferior.
Completely untrue. Devices (whether part of libhw etc. or not) have no need (from architectural point of view) to access CPUState contents. It's clearly problematic. It's also possible to get type safety without CPUState references in the devices.
I explicitly said "things compiled in libhw that are not part of device code", most of which you added.
Anyway, thanks for the review and the (partial) ack. I'll rework the patch series and resend.
Paolo