Skip to contentSkip to conversation

exec/next for 9.1

PATCH In review Philippe Mathieu-Daudé 2 participants 35 messages Apr 17, 2024 – Apr 18, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover exec/next for 9.1

Hi,

This series contains the patches I'm going to send in a pull request once the final 9.0 tag is out. Sending now since I'll post another series based on it.

Also available here for convenience:
https://gitlab.com/philmd/qemu/-/commits/exec-next

Regards,

Phil.

Philippe Mathieu-Daudé (21):
gdbstub: Simplify #ifdef'ry in helpers.h
hw/core: Remove check on NEED_CPU_H in tcg-cpu-ops.h
exec: Rename NEED_CPU_H -> COMPILING_PER_TARGET
exec: Include 'cpu.h' before validating CPUArchState placement
exec: Expose 'target_page.h' API to user emulation
target: Define TCG_GUEST_DEFAULT_MO in 'cpu-param.h'
accel: Include missing 'exec/cpu_ldst.h' header
gdbstub: Include missing 'hw/core/cpu.h' header semihosting/uaccess: Avoid including 'cpu.h' semihosting/guestfd: Remove unused 'semihosting/uaccess.h' header exec/cpu-all: Reduce 'qemu/rcu.h' header inclusion target/ppc/excp_helper: Avoid 'abi_ptr' in system emulation accel/tcg: Un-inline retaddr helpers to 'user-retaddr.h' target/i386: Include missing 'exec/exec-all.h' header accel/tcg: Include missing 'hw/core/cpu.h' header exec/cpu-all: Remove unused 'qemu/thread.h' header exec/cpu-all: Remove unused tswapls() definitions
exec: Declare target_words_bigendian() in 'exec/tswap.h'
exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h' exec/user: Do not include 'cpu.h' in 'abitypes.h'
exec: Declare abi_ptr type in its own 'abi_ptr.h' header

 MAINTAINERS                        |  1 +
 meson.build                        |  6 ++--
 accel/tcg/user-retaddr.h           | 28 +++++++++++++++++++
 bsd-user/freebsd/target_os_elf.h   |  1 +
 bsd-user/freebsd/target_os_stack.h |  1 +
 bsd-user/netbsd/target_os_elf.h    |  1 +
 bsd-user/openbsd/target_os_elf.h   |  1 +
 include/exec/abi_ptr.h             | 33 ++++++++++++++++++++++
 include/exec/cpu-all.h             | 13 +--------
 include/exec/cpu-defs.h            |  2 +-
 include/exec/cpu_ldst.h            | 45 ++++--------------------------
 include/exec/exec-all.h            |  1 +
 include/exec/helper-head.h         |  4 +--
 include/exec/memop.h               |  4 +--
 include/exec/memory.h              |  4 +--
 include/exec/ram_addr.h            |  1 +
 include/exec/translator.h          |  5 +++-
 include/exec/tswap.h               | 16 +++++++++--
 include/exec/user/abitypes.h       |  8 +++++-
 include/gdbstub/helpers.h          |  9 +++---
 include/hw/core/cpu.h              | 15 ++--------
 include/hw/core/tcg-cpu-ops.h      |  3 --
 include/qemu/osdep.h               |  2 +-
 include/semihosting/uaccess.h      |  2 +-
 include/sysemu/hvf.h               |  8 +++---
 include/sysemu/kvm.h               |  6 ++--
 include/sysemu/nvmm.h              |  4 +--
 include/sysemu/whpx.h              |  4 +--
 include/sysemu/xen.h               |  4 +--
 include/user/tswap-target.h        | 22 +++++++++++++++
 target/alpha/cpu-param.h           |  3 ++
 target/alpha/cpu.h                 |  3 --
 target/arm/cpu-param.h             |  8 ++++--
 target/arm/cpu.h                   |  3 --
 target/arm/kvm-consts.h            |  4 +--
 target/avr/cpu-param.h             |  2 ++
 target/avr/cpu.h                   |  2 --
 target/hppa/cpu-param.h            |  8 ++++++
 target/hppa/cpu.h                  |  6 ----
 target/i386/cpu-param.h            |  3 ++
 target/i386/cpu.h                  |  3 --
 target/loongarch/cpu-param.h       |  2 ++
 target/loongarch/cpu.h             |  2 --
 target/microblaze/cpu-param.h      |  3 ++
 target/microblaze/cpu.h            |  3 --
 target/mips/cpu-param.h            |  2 ++
 target/mips/cpu.h                  |  2 --
 target/openrisc/cpu-param.h        |  2 ++
 target/openrisc/cpu.h              |  2 --
 target/ppc/cpu-param.h             |  2 ++
 target/ppc/cpu.h                   |  2 --
 target/riscv/cpu-param.h           |  2 ++
 target/riscv/cpu.h                 |  2 --
 target/s390x/cpu-param.h           |  6 ++++
 target/s390x/cpu.h                 |  3 --
 target/sparc/cpu-param.h           | 23 +++++++++++++++
 target/sparc/cpu.h                 | 23 ---------------
 target/xtensa/cpu-param.h          |  3 ++
 target/xtensa/cpu.h                |  3 --
 accel/tcg/cpu-exec.c               |  3 ++
 accel/tcg/tcg-accel-ops.c          |  2 ++
 accel/tcg/translator.c             |  1 +
 accel/tcg/user-exec.c              |  1 +
 bsd-user/signal.c                  |  1 +
 bsd-user/strace.c                  |  1 +
 cpu-target.c                       |  1 +
 disas/disas.c                      |  1 +
 gdbstub/gdbstub.c                  |  1 +
 hw/audio/virtio-snd.c              |  2 +-
 hw/core/cpu-sysemu.c               |  2 +-
 hw/core/generic-loader.c           |  2 +-
 hw/display/vga.c                   |  2 +-
 hw/virtio/virtio.c                 |  1 +
 linux-user/elfload.c               |  1 +
 linux-user/i386/signal.c           |  1 +
 linux-user/ppc/signal.c            |  1 +
 page-target.c                      | 44 +++++++++++++++++++++++++++++
 semihosting/guestfd.c              |  5 +---
 system/physmem.c                   | 30 --------------------
 target/hexagon/translate.c         |  1 +
 target/i386/tcg/fpu_helper.c       |  1 +
 target/microblaze/cpu.c            |  1 +
 target/microblaze/translate.c      |  1 +
 target/nios2/translate.c           |  1 +
 target/ppc/excp_helper.c           |  2 +-
 target/target-common.c             | 10 -------
 scripts/analyze-inclusions         |  6 ++--
 target/meson.build                 |  2 --
 88 files changed, 293 insertions(+), 221 deletions(-)
 create mode 100644 accel/tcg/user-retaddr.h
 create mode 100644 include/exec/abi_ptr.h
 create mode 100644 include/user/tswap-target.h
 create mode 100644 page-target.c
 delete mode 100644 target/target-common.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/21 gdbstub: Simplify #ifdef'ry in helpers.h

Slightly simplify by checking NEED_CPU_H definition in header.

Message-Id: <[email protected]>

---
 include/gdbstub/helpers.h | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
include/gdbstub/helpers.h +4 -5
index c573aef2dc..53e88d807c 100644
@@ -12,7 +12,10 @@
 #ifndef _GDBSTUB_HELPERS_H_
 #define _GDBSTUB_HELPERS_H_
 
-#ifdef NEED_CPU_H
+#ifndef NEED_CPU_H
+#error "gdbstub helpers should only be included by target specific code"
+#endif
+
 #include "cpu.h"
 
 /*
@@ -96,8 +99,4 @@ static inline uint8_t *gdb_get_reg_ptr(GByteArray *buf, int len)
 #define ldtul_p(addr) ldl_p(addr)
 #endif
 
-#else
-#error "gdbstub helpers should only be included by target specific code"
-#endif
-
 #endif /* _GDBSTUB_HELPERS_H_ */
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/21 hw/core: Remove check on NEED_CPU_H in tcg-cpu-ops.h

In reply to Philippe Mathieu-Daudé

Commit fd3f7d24d4 ("include/hw/core: Remove i386 conditional on fake_user_interrupt") remove the need to check on NEED_CPU_H.

Message-Id: <[email protected]>

---
 include/hw/core/tcg-cpu-ops.h | 3 ---
 1 file changed, 3 deletions(-)
include/hw/core/tcg-cpu-ops.h +0 -3
index bf8ff8e3ee..dc1f16a977 100644
@@ -49,7 +49,6 @@ struct TCGCPUOps {
     /** @debug_excp_handler: Callback for handling debug exceptions */
     void (*debug_excp_handler)(CPUState *cpu);
 
-#ifdef NEED_CPU_H
 #ifdef CONFIG_USER_ONLY
     /**
      * @fake_user_interrupt: Callback for 'fake exception' handling.
@@ -174,8 +173,6 @@ struct TCGCPUOps {
      */
     bool (*need_replay_interrupt)(int interrupt_request);
 #endif /* !CONFIG_USER_ONLY */
-#endif /* NEED_CPU_H */
-
 };
 
 #if defined(CONFIG_USER_ONLY)
Signature · 1 line
2.41.0
#3 lore raw

PATCH 3/21 exec: Rename NEED_CPU_H -> COMPILING_PER_TARGET

In reply to Philippe Mathieu-Daudé

'NEED_CPU_H' guard target-specific code; it is defined by meson altogether with the 'CONFIG_TARGET' definition. Rename NEED_CPU_H as COMPILING_PER_TARGET to clarify its meaning.

Mechanical change running:

 $ sed -i s/NEED_CPU_H/COMPILING_PER_TARGET/g $(git grep -l NEED_CPU_H)

then manually add a /* COMPILING_PER_TARGET */ comment after the '#endif' when the block is large.

Message-Id: <[email protected]>

---
 meson.build                | 4 ++--
 include/exec/cpu-defs.h    | 2 +-
 include/exec/helper-head.h | 4 ++--
 include/exec/memop.h       | 4 ++--
 include/exec/memory.h      | 4 ++--
 include/exec/tswap.h       | 4 ++--
 include/gdbstub/helpers.h  | 2 +-
 include/hw/core/cpu.h      | 4 ++--
 include/qemu/osdep.h       | 2 +-
 include/sysemu/hvf.h       | 8 ++++----
 include/sysemu/kvm.h       | 6 +++---
 include/sysemu/nvmm.h      | 4 ++--
 include/sysemu/whpx.h      | 4 ++--
 include/sysemu/xen.h       | 4 ++--
 target/arm/kvm-consts.h    | 4 ++--
 scripts/analyze-inclusions | 6 +++---
 16 files changed, 33 insertions(+), 33 deletions(-)
meson.build +2 -2
index 91a0aa64c6..da8295b405 100644
@@ -3641,7 +3641,7 @@ foreach d, list : target_modules
         if target.endswith('-softmmu')
           config_target = config_target_mak[target]
           target_inc = [include_directories('target' / config_target['TARGET_BASE_ARCH'])]
-          c_args = ['-DNEED_CPU_H',
+          c_args = ['-DCOMPILING_PER_TARGET',
                     '-DCONFIG_TARGET="@[email protected]"'.format(target),
                     '-DCONFIG_DEVICES="@[email protected]"'.format(target)]
           target_module_ss = module_ss.apply(config_target, strict: false)
@@ -3824,7 +3824,7 @@ foreach target : target_dirs
   target_base_arch = config_target['TARGET_BASE_ARCH']
   arch_srcs = [config_target_h[target]]
   arch_deps = []
-  c_args = ['-DNEED_CPU_H',
+  c_args = ['-DCOMPILING_PER_TARGET',
             '-DCONFIG_TARGET="@[email protected]"'.format(target),
             '-DCONFIG_DEVICES="@[email protected]"'.format(target)]
   link_args = emulator_link_args
include/exec/cpu-defs.h +1 -1
index 3915438b83..0dbef3010c 100644
@@ -19,7 +19,7 @@
 #ifndef CPU_DEFS_H
 #define CPU_DEFS_H
 
-#ifndef NEED_CPU_H
+#ifndef COMPILING_PER_TARGET
 #error cpu.h included from common code
 #endif
 
include/exec/helper-head.h +2 -2
index 28ceab0a46..5ef467a79d 100644
@@ -43,7 +43,7 @@
 #define dh_ctype_noreturn G_NORETURN void
 #define dh_ctype(t) dh_ctype_##t
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 # ifdef TARGET_LONG_BITS
 #  if TARGET_LONG_BITS == 32
 #   define dh_alias_tl i32
@@ -54,7 +54,7 @@
 #  endif
 # endif
 # define dh_ctype_tl target_ulong
-#endif
+#endif /* COMPILING_PER_TARGET */
 
 /* We can't use glue() here because it falls foul of C preprocessor
    recursive expansion rules.  */
include/exec/memop.h +2 -2
index a86dc6743a..06417ff361 100644
@@ -35,7 +35,7 @@ typedef enum MemOp {
     MO_LE    = 0,
     MO_BE    = MO_BSWAP,
 #endif
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 #if TARGET_BIG_ENDIAN
     MO_TE    = MO_BE,
 #else
@@ -135,7 +135,7 @@ typedef enum MemOp {
     MO_BESL  = MO_BE | MO_SL,
     MO_BESQ  = MO_BE | MO_SQ,
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
     MO_TEUW  = MO_TE | MO_UW,
     MO_TEUL  = MO_TE | MO_UL,
     MO_TEUQ  = MO_TE | MO_UQ,
include/exec/memory.h +2 -2
index 8626a355b3..bb51e90fe1 100644
@@ -3087,7 +3087,7 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
 MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
                               uint8_t c, hwaddr len, MemTxAttrs attrs);
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 /* enum device_endian to MemOp.  */
 static inline MemOp devend_memop(enum device_endian end)
 {
@@ -3105,7 +3105,7 @@ static inline MemOp devend_memop(enum device_endian end)
     return (end == non_host_endianness) ? MO_BSWAP : 0;
 #endif
 }
-#endif
+#endif /* COMPILING_PER_TARGET */
 
 /*
  * Inhibit technologies that require discarding of pages in RAM blocks, e.g.,
include/exec/tswap.h +2 -2
index 68944a880b..5089cd6a4c 100644
@@ -15,11 +15,11 @@
  * If we're in target-specific code, we can hard-code the swapping
  * condition, otherwise we have to do (slower) run-time checks.
  */
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 #define target_needs_bswap()  (HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN)
 #else
 #define target_needs_bswap()  (target_words_bigendian() != HOST_BIG_ENDIAN)
-#endif
+#endif /* COMPILING_PER_TARGET */
 
 static inline uint16_t tswap16(uint16_t s)
 {
include/gdbstub/helpers.h +1 -1
index 53e88d807c..6277a858a1 100644
@@ -12,7 +12,7 @@
 #ifndef _GDBSTUB_HELPERS_H_
 #define _GDBSTUB_HELPERS_H_
 
-#ifndef NEED_CPU_H
+#ifndef COMPILING_PER_TARGET
 #error "gdbstub helpers should only be included by target specific code"
 #endif
 
include/hw/core/cpu.h +2 -2
index ec14f74ce5..7f037b158e 100644
@@ -1182,7 +1182,7 @@ bool target_words_bigendian(void);
 
 const char *target_name(void);
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 
 #ifndef CONFIG_USER_ONLY
 
@@ -1197,7 +1197,7 @@ extern const VMStateDescription vmstate_cpu_common;
 }
 #endif /* !CONFIG_USER_ONLY */
 
-#endif /* NEED_CPU_H */
+#endif /* COMPILING_PER_TARGET */
 
 #define UNASSIGNED_CPU_INDEX -1
 #define UNASSIGNED_CLUSTER_INDEX -1
include/qemu/osdep.h +1 -1
index c7053cdc2b..f61edcfdc2 100644
@@ -32,7 +32,7 @@
 #endif
 
 #include "config-host.h"
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 #include CONFIG_TARGET
 #else
 #include "exec/poison.h"
include/sysemu/hvf.h +4 -4
index 4a7c6af3a5..730f927f03 100644
@@ -16,7 +16,7 @@
 #include "qemu/accel.h"
 #include "qom/object.h"
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 #include "cpu.h"
 
 #ifdef CONFIG_HVF
@@ -26,7 +26,7 @@ extern bool hvf_allowed;
 #define hvf_enabled() 0
 #endif /* !CONFIG_HVF */
 
-#endif /* NEED_CPU_H */
+#endif /* COMPILING_PER_TARGET */
 
 #define TYPE_HVF_ACCEL ACCEL_CLASS_NAME("hvf")
 
@@ -34,7 +34,7 @@ typedef struct HVFState HVFState;
 DECLARE_INSTANCE_CHECKER(HVFState, HVF_STATE,
                          TYPE_HVF_ACCEL)
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 struct hvf_sw_breakpoint {
     vaddr pc;
     vaddr saved_insn;
@@ -66,6 +66,6 @@ void hvf_arch_update_guest_debug(CPUState *cpu);
  * Return whether the guest supports debugging.
  */
 bool hvf_arch_supports_guest_debug(void);
-#endif /* NEED_CPU_H */
+#endif /* COMPILING_PER_TARGET */
 
 #endif
include/sysemu/kvm.h +3 -3
index fad9a7e8ff..c618a59ba6 100644
@@ -20,7 +20,7 @@
 #include "qemu/accel.h"
 #include "qom/object.h"
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 # ifdef CONFIG_KVM
 #  include <linux/kvm.h>
 #  define CONFIG_KVM_IS_POSSIBLE
@@ -210,7 +210,7 @@ bool kvm_arm_supports_user_irq(void);
 int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
 int kvm_on_sigbus(int code, void *addr);
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 #include "cpu.h"
 
 void kvm_flush_coalesced_mmio_buffer(void);
@@ -435,7 +435,7 @@ void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);
 int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
                                        hwaddr *phys_addr);
 
-#endif /* NEED_CPU_H */
+#endif /* COMPILING_PER_TARGET */
 
 void kvm_cpu_synchronize_state(CPUState *cpu);
 
include/sysemu/nvmm.h +2 -2
index be7bc9a62d..6971ddb3a5 100644
@@ -12,7 +12,7 @@
 #ifndef QEMU_NVMM_H
 #define QEMU_NVMM_H
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 
 #ifdef CONFIG_NVMM
 
@@ -24,6 +24,6 @@ int nvmm_enabled(void);
 
 #endif /* CONFIG_NVMM */
 
-#endif /* NEED_CPU_H */
+#endif /* COMPILING_PER_TARGET */
 
 #endif /* QEMU_NVMM_H */
include/sysemu/whpx.h +2 -2
index 781ca5b2b6..00ff409b68 100644
@@ -15,7 +15,7 @@
 #ifndef QEMU_WHPX_H
 #define QEMU_WHPX_H
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 
 #ifdef CONFIG_WHPX
 
@@ -29,6 +29,6 @@ bool whpx_apic_in_platform(void);
 
 #endif /* CONFIG_WHPX */
 
-#endif /* NEED_CPU_H */
+#endif /* COMPILING_PER_TARGET */
 
 #endif /* QEMU_WHPX_H */
include/sysemu/xen.h +2 -2
index a9f591f26d..754ec2e6cb 100644
@@ -16,13 +16,13 @@
 
 #include "exec/cpu-common.h"
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 # ifdef CONFIG_XEN
 #  define CONFIG_XEN_IS_POSSIBLE
 # endif
 #else
 # define CONFIG_XEN_IS_POSSIBLE
-#endif
+#endif /* COMPILING_PER_TARGET */
 
 #ifdef CONFIG_XEN_IS_POSSIBLE
 
target/arm/kvm-consts.h +2 -2
index 7c6adc14f6..c44d23dbe7 100644
@@ -14,13 +14,13 @@
 #ifndef ARM_KVM_CONSTS_H
 #define ARM_KVM_CONSTS_H
 
-#ifdef NEED_CPU_H
+#ifdef COMPILING_PER_TARGET
 #ifdef CONFIG_KVM
 #include <linux/kvm.h>
 #include <linux/psci.h>
 #define MISMATCH_CHECK(X, Y) QEMU_BUILD_BUG_ON(X != Y)
 #endif
-#endif
+#endif /* COMPILING_PER_TARGET */
 
 #ifndef MISMATCH_CHECK
 #define MISMATCH_CHECK(X, Y) QEMU_BUILD_BUG_ON(0)
scripts/analyze-inclusions +3 -3
index 45c821de32..b6280f25c8 100644
@@ -92,7 +92,7 @@ echo trace/generated-tracers.h:
 analyze -include ../include/qemu/osdep.h trace/generated-tracers.h
 
 echo target/i386/cpu.h:
-analyze -DNEED_CPU_H -I../target/i386 -Ii386-softmmu -include ../include/qemu/osdep.h ../target/i386/cpu.h
+analyze -DCOMPILING_PER_TARGET -I../target/i386 -Ii386-softmmu -include ../include/qemu/osdep.h ../target/i386/cpu.h
 
-echo hw/hw.h + NEED_CPU_H:
-analyze -DNEED_CPU_H -I../target/i386 -Ii386-softmmu -include ../include/qemu/osdep.h ../include/hw/hw.h
+echo hw/hw.h + COMPILING_PER_TARGET:
+analyze -DCOMPILING_PER_TARGET -I../target/i386 -Ii386-softmmu -include ../include/qemu/osdep.h ../include/hw/hw.h
Signature · 1 line
2.41.0
#4 lore raw

PATCH 4/21 exec: Include 'cpu.h' before validating CPUArchState placement

In reply to Philippe Mathieu-Daudé

CPUArchState 'env' field is defined within the ArchCPU structure, so we need to include each target "cpu.h" header which defines it.

Message-Id: <[email protected]>

---
 include/exec/cpu-all.h | 1 +
 1 file changed, 1 insertion(+)
include/exec/cpu-all.h +1 -0
index 1a6510fd3b..b86209fc49 100644
@@ -391,6 +391,7 @@ static inline bool tlb_hit(uint64_t tlb_addr, vaddr addr)
 #endif /* !CONFIG_USER_ONLY */
 
 /* Validate correct placement of CPUArchState. */
+#include "cpu.h"
 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
 
Signature · 1 line
2.41.0
#5 lore raw

PATCH 5/21 exec: Expose 'target_page.h' API to user emulation

In reply to Philippe Mathieu-Daudé

User-only objects might benefit from the "exec/target_page.h" API, which allows to build some objects once for all targets.

Message-Id: <[email protected]>

---
 meson.build            |  2 +-
 page-target.c          | 44 ++++++++++++++++++++++++++++++++++++++++++
 system/physmem.c       | 30 ----------------------------
 target/target-common.c | 10 ----------
 target/meson.build     |  2 --
 5 files changed, 45 insertions(+), 43 deletions(-)
 create mode 100644 page-target.c
 delete mode 100644 target/target-common.c
meson.build +1 -1
index da8295b405..44d337f67b 100644
@@ -3554,7 +3554,7 @@ if get_option('b_lto')
   pagevary = declare_dependency(link_with: pagevary)
 endif
 common_ss.add(pagevary)
-specific_ss.add(files('page-vary-target.c'))
+specific_ss.add(files('page-target.c', 'page-vary-target.c'))
 
 subdir('backends')
 subdir('disas')
page-target.c new file +44 -0

44 lines not on this page · raw message

system/physmem.c +0 -30
index a4fe3d2bf8..dd7b222942 100644
@@ -3504,36 +3504,6 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
     return 0;
 }
 
-/*
- * Allows code that needs to deal with migration bitmaps etc to still be built
- * target independent.
- */
-size_t qemu_target_page_size(void)
-{
-    return TARGET_PAGE_SIZE;
-}
-
-int qemu_target_page_bits(void)
-{
-    return TARGET_PAGE_BITS;
-}
-
-int qemu_target_page_bits_min(void)
-{
-    return TARGET_PAGE_BITS_MIN;
-}
-
-/* Convert target pages to MiB (2**20). */
-size_t qemu_target_pages_to_MiB(size_t pages)
-{
-    int page_bits = TARGET_PAGE_BITS;
-
-    /* So far, the largest (non-huge) page size is 64k, i.e. 16 bits. */
-    g_assert(page_bits < 20);
-
-    return pages >> (20 - page_bits);
-}
-
 bool cpu_physical_memory_is_io(hwaddr phys_addr)
 {
     MemoryRegion*mr;
target/target-common.c deleted +0 -10
deleted file mode 100644
index 903b10cfe4..0000000000
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-#include "qemu/osdep.h"
-
-#include "cpu.h"
-#include "exec/target_page.h"
-
-int qemu_target_page_mask(void)
-{
-    return TARGET_PAGE_MASK;
-}
target/meson.build +0 -2
index dee2ac47e0..a53a60486f 100644
@@ -19,5 +19,3 @@ subdir('sh4')
 subdir('sparc')
 subdir('tricore')
 subdir('xtensa')
-
-specific_ss.add(files('target-common.c'))
Signature · 1 line
2.41.0
#6 lore raw

PATCH 6/21 target: Define TCG_GUEST_DEFAULT_MO in 'cpu-param.h'

In reply to Philippe Mathieu-Daudé

accel/tcg/ files requires the following definitions:

- TARGET_LONG_BITS
- TARGET_PAGE_BITS
- TARGET_PHYS_ADDR_SPACE_BITS
- TCG_GUEST_DEFAULT_MO

The first 3 are defined in "cpu-param.h". The last one in "cpu.h", with a bunch of definitions irrelevant for TCG. By moving the TCG_GUEST_DEFAULT_MO definition to "cpu-param.h", we can simplify various accel/tcg includes.

Message-Id: <[email protected]>

---
 target/alpha/cpu-param.h      |  3 +++
 target/alpha/cpu.h            |  3 ---
 target/arm/cpu-param.h        |  8 +++++---
 target/arm/cpu.h              |  3 ---
 target/avr/cpu-param.h        |  2 ++
 target/avr/cpu.h              |  2 --
 target/hppa/cpu-param.h       |  8 ++++++++
 target/hppa/cpu.h             |  6 ------
 target/i386/cpu-param.h       |  3 +++
 target/i386/cpu.h             |  3 ---
 target/loongarch/cpu-param.h  |  2 ++
 target/loongarch/cpu.h        |  2 --
 target/microblaze/cpu-param.h |  3 +++
 target/microblaze/cpu.h       |  3 ---
 target/mips/cpu-param.h       |  2 ++
 target/mips/cpu.h             |  2 --
 target/openrisc/cpu-param.h   |  2 ++
 target/openrisc/cpu.h         |  2 --
 target/ppc/cpu-param.h        |  2 ++
 target/ppc/cpu.h              |  2 --
 target/riscv/cpu-param.h      |  2 ++
 target/riscv/cpu.h            |  2 --
 target/s390x/cpu-param.h      |  6 ++++++
 target/s390x/cpu.h            |  3 ---
 target/sparc/cpu-param.h      | 23 +++++++++++++++++++++++
 target/sparc/cpu.h            | 23 -----------------------
 target/xtensa/cpu-param.h     |  3 +++
 target/xtensa/cpu.h           |  3 ---
 28 files changed, 66 insertions(+), 62 deletions(-)
target/alpha/cpu-param.h +3 -0
index c969cb016b..5ce213a9a1 100644
@@ -27,4 +27,7 @@
 # define TARGET_VIRT_ADDR_SPACE_BITS  (30 + TARGET_PAGE_BITS)
 #endif
 
+/* Alpha processors have a weak memory model */
+#define TCG_GUEST_DEFAULT_MO      (0)
+
 #endif
target/alpha/cpu.h +0 -3
index 7188a409a0..f9e2ecb90a 100644
@@ -24,9 +24,6 @@
 #include "exec/cpu-defs.h"
 #include "qemu/cpu-float.h"
 
-/* Alpha processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
 #define ICACHE_LINE_SIZE 32
 #define DCACHE_LINE_SIZE 32
 
target/arm/cpu-param.h +5 -3
index da3243ab21..2d5f3aa312 100644
@@ -27,14 +27,16 @@
 # else
 #  define TARGET_PAGE_BITS 12
 # endif
-#else
+#else /* !CONFIG_USER_ONLY */
 /*
  * ARMv7 and later CPUs have 4K pages minimum, but ARMv5 and v6
  * have to support 1K tiny pages.
  */
 # define TARGET_PAGE_BITS_VARY
 # define TARGET_PAGE_BITS_MIN  10
-
-#endif
+#endif /* !CONFIG_USER_ONLY */
+
+/* ARM processors have a weak memory model */
+#define TCG_GUEST_DEFAULT_MO      (0)
 
 #endif
target/arm/cpu.h +0 -3
index bc0c84873f..98f58d04c1 100644
@@ -30,9 +30,6 @@
 #include "target/arm/multiprocessing.h"
 #include "target/arm/gtimer.h"
 
-/* ARM processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
 #ifdef TARGET_AARCH64
 #define KVM_HAVE_MCE_INJECTION 1
 #endif
target/avr/cpu-param.h +2 -0
index 9a92bc74fc..93c2f470d0 100644
@@ -32,4 +32,6 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 24
 #define TARGET_VIRT_ADDR_SPACE_BITS 24
 
+#define TCG_GUEST_DEFAULT_MO 0
+
 #endif
target/avr/cpu.h +0 -2
index d185d20dcb..4725535102 100644
@@ -30,8 +30,6 @@
 
 #define CPU_RESOLVING_TYPE TYPE_AVR_CPU
 
-#define TCG_GUEST_DEFAULT_MO 0
-
 /*
  * AVR has two memory spaces, data & code.
  * e.g. both have 0 address
target/hppa/cpu-param.h +8 -0
index bb3d7ef6f7..473d489f01 100644
@@ -21,4 +21,12 @@
 
 #define TARGET_PAGE_BITS 12
 
+/* PA-RISC 1.x processors have a strong memory model.  */
+/*
+ * ??? While we do not yet implement PA-RISC 2.0, those processors have
+ * a weak memory model, but with TLB bits that force ordering on a per-page
+ * basis.  It's probably easier to fall back to a strong memory model.
+ */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
 #endif
target/hppa/cpu.h +0 -6
index a072d0bb63..fb2e4c4a98 100644
@@ -25,12 +25,6 @@
 #include "qemu/cpu-float.h"
 #include "qemu/interval-tree.h"
 
-/* PA-RISC 1.x processors have a strong memory model.  */
-/* ??? While we do not yet implement PA-RISC 2.0, those processors have
-   a weak memory model, but with TLB bits that force ordering on a per-page
-   basis.  It's probably easier to fall back to a strong memory model.  */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
 #define MMU_ABS_W_IDX     6
 #define MMU_ABS_IDX       7
 #define MMU_KERNEL_IDX    8
target/i386/cpu-param.h +3 -0
index 911b4cd51b..5e15335203 100644
@@ -24,4 +24,7 @@
 #endif
 #define TARGET_PAGE_BITS 12
 
+/* The x86 has a strong memory model with some store-after-load re-ordering */
+#define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)
+
 #endif
target/i386/cpu.h +0 -3
index 6b05738079..a6ca593547 100644
@@ -30,9 +30,6 @@
 
 #define XEN_NR_VIRQS 24
 
-/* The x86 has a strong memory model with some store-after-load re-ordering */
-#define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)
-
 #define KVM_HAVE_MCE_INJECTION 1
 
 /* support for self modifying code even if the modified instruction is
target/loongarch/cpu-param.h +2 -0
index cfe195db4e..db5ad1c69f 100644
@@ -14,4 +14,6 @@
 
 #define TARGET_PAGE_BITS 12
 
+#define TCG_GUEST_DEFAULT_MO (0)
+
 #endif
target/loongarch/cpu.h +0 -2
index ec37579fd6..abb01b2cc7 100644
@@ -39,8 +39,6 @@
 
 #define IOCSR_MEM_SIZE          0x428
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
 #define FCSR0_M1    0x1f         /* FCSR1 mask, Enables */
 #define FCSR0_M2    0x1f1f0000   /* FCSR2 mask, Cause and Flags */
 #define FCSR0_M3    0x300        /* FCSR3 mask, Round Mode */
target/microblaze/cpu-param.h +3 -0
index 9770b0eb52..e530fead1c 100644
@@ -29,4 +29,7 @@
 /* FIXME: MB uses variable pages down to 1K but linux only uses 4k.  */
 #define TARGET_PAGE_BITS 12
 
+/* MicroBlaze is always in-order. */
+#define TCG_GUEST_DEFAULT_MO  TCG_MO_ALL
+
 #endif
target/microblaze/cpu.h +0 -3
index c0c7574dbd..3e5a3e5c60 100644
@@ -24,9 +24,6 @@
 #include "exec/cpu-defs.h"
 #include "qemu/cpu-float.h"
 
-/* MicroBlaze is always in-order. */
-#define TCG_GUEST_DEFAULT_MO  TCG_MO_ALL
-
 typedef struct CPUArchState CPUMBState;
 #if !defined(CONFIG_USER_ONLY)
 #include "mmu.h"
target/mips/cpu-param.h +2 -0
index 594c91a156..6f6ac1688f 100644
@@ -30,4 +30,6 @@
 #define TARGET_PAGE_BITS_MIN 12
 #endif
 
+#define TCG_GUEST_DEFAULT_MO (0)
+
 #endif
target/mips/cpu.h +0 -2
index 7329226d39..3e906a175a 100644
@@ -10,8 +10,6 @@
 #include "hw/clock.h"
 #include "mips-defs.h"
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
 typedef struct CPUMIPSTLBContext CPUMIPSTLBContext;
 
 /* MSA Context */
target/openrisc/cpu-param.h +2 -0
index 3f08207485..fbfc0f568b 100644
@@ -13,4 +13,6 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+#define TCG_GUEST_DEFAULT_MO (0)
+
 #endif
target/openrisc/cpu.h +0 -2
index b1b7db5cbd..c9fe9ae12d 100644
@@ -24,8 +24,6 @@
 #include "exec/cpu-defs.h"
 #include "fpu/softfloat-types.h"
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
 /**
  * OpenRISCCPUClass:
  * @parent_realize: The parent class' realize handler.
target/ppc/cpu-param.h +2 -0
index b7ad52de03..77c5ed9a67 100644
@@ -40,4 +40,6 @@
 # define TARGET_PAGE_BITS 12
 #endif
 
+#define TCG_GUEST_DEFAULT_MO 0
+
 #endif
target/ppc/cpu.h +0 -2
index 67e6b2effd..0ac55d6b25 100644
@@ -29,8 +29,6 @@
 
 #define CPU_RESOLVING_TYPE TYPE_POWERPC_CPU
 
-#define TCG_GUEST_DEFAULT_MO 0
-
 #define TARGET_PAGE_BITS_64K 16
 #define TARGET_PAGE_BITS_16M 24
 
target/riscv/cpu-param.h +2 -0
index b2a9396dec..1fbd64939d 100644
@@ -28,4 +28,6 @@
  *  - M mode HLV/HLVX/HSV 0b111
  */
 
+#define TCG_GUEST_DEFAULT_MO 0
+
 #endif
target/riscv/cpu.h +0 -2
index 3b1a02b944..2d0c02c35b 100644
@@ -43,8 +43,6 @@ typedef struct CPUArchState CPURISCVState;
 # define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE64
 #endif
 
-#define TCG_GUEST_DEFAULT_MO 0
-
 /*
  * RISC-V-specific extra insn start words:
  * 1: Original instruction opcode
target/s390x/cpu-param.h +6 -0
index 84ca08626b..11d23b600d 100644
@@ -13,4 +13,10 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 64
 #define TARGET_VIRT_ADDR_SPACE_BITS 64
 
+/*
+ * The z/Architecture has a strong memory model with some
+ * store-after-load re-ordering.
+ */
+#define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)
+
 #endif
target/s390x/cpu.h +0 -3
index 43a46a5a06..414680eed1 100644
@@ -33,9 +33,6 @@
 
 #define ELF_MACHINE_UNAME "S390X"
 
-/* The z/Architecture has a strong memory model with some store-after-load re-ordering */
-#define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)
-
 #define TARGET_HAS_PRECISE_SMC
 
 #define TARGET_INSN_START_EXTRA_WORDS 2
target/sparc/cpu-param.h +23 -0
index cb11980404..82293fb844 100644
@@ -23,4 +23,27 @@
 # define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
+/*
+ * From Oracle SPARC Architecture 2015:
+ *
+ *   Compatibility notes: The PSO memory model described in SPARC V8 and
+ *   SPARC V9 compatibility architecture specifications was never implemented
+ *   in a SPARC V9 implementation and is not included in the Oracle SPARC
+ *   Architecture specification.
+ *
+ *   The RMO memory model described in the SPARC V9 specification was
+ *   implemented in some non-Sun SPARC V9 implementations, but is not
+ *   directly supported in Oracle SPARC Architecture 2015 implementations.
+ *
+ * Therefore always use TSO in QEMU.
+ *
+ * D.5 Specification of Partial Store Order (PSO)
+ *   ... [loads] are followed by an implied MEMBAR #LoadLoad | #LoadStore.
+ *
+ * D.6 Specification of Total Store Order (TSO)
+ *   ... PSO with the additional requirement that all [stores] are followed
+ *   by an implied MEMBAR #StoreStore.
+ */
+#define TCG_GUEST_DEFAULT_MO  (TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_MO_ST_ST)
+
 #endif
target/sparc/cpu.h +0 -23
index f3cdd17c62..dfd9512a21 100644
@@ -6,29 +6,6 @@
 #include "exec/cpu-defs.h"
 #include "qemu/cpu-float.h"
 
-/*
- * From Oracle SPARC Architecture 2015:
- *
- *   Compatibility notes: The PSO memory model described in SPARC V8 and
- *   SPARC V9 compatibility architecture specifications was never implemented
- *   in a SPARC V9 implementation and is not included in the Oracle SPARC
- *   Architecture specification.
- *
- *   The RMO memory model described in the SPARC V9 specification was
- *   implemented in some non-Sun SPARC V9 implementations, but is not
- *   directly supported in Oracle SPARC Architecture 2015 implementations.
- *
- * Therefore always use TSO in QEMU.
- *
- * D.5 Specification of Partial Store Order (PSO)
- *   ... [loads] are followed by an implied MEMBAR #LoadLoad | #LoadStore.
- *
- * D.6 Specification of Total Store Order (TSO)
- *   ... PSO with the additional requirement that all [stores] are followed
- *   by an implied MEMBAR #StoreStore.
- */
-#define TCG_GUEST_DEFAULT_MO  (TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_MO_ST_ST)
-
 #if !defined(TARGET_SPARC64)
 #define TARGET_DPREGS 16
 #define TARGET_FCCREGS 1
target/xtensa/cpu-param.h +3 -0
index b1da0555de..0000725f2f 100644
@@ -17,4 +17,7 @@
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
+/* Xtensa processors have a weak memory model */
+#define TCG_GUEST_DEFAULT_MO      (0)
+
 #endif
target/xtensa/cpu.h +0 -3
index 6b8d0636d2..9f2341d856 100644
@@ -34,9 +34,6 @@
 #include "hw/clock.h"
 #include "xtensa-isa.h"
 
-/* Xtensa processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
 enum {
     /* Additional instructions */
     XTENSA_OPTION_CODE_DENSITY,
Signature · 1 line
2.41.0
#7 lore raw

PATCH 7/21 accel: Include missing 'exec/cpu_ldst.h' header

In reply to Philippe Mathieu-Daudé

Theses files call cpu_ldl_code() which is declared in "exec/cpu_ldst.h".

Message-Id: <[email protected]>

---
 accel/tcg/translator.c        | 1 +
 target/hexagon/translate.c    | 1 +
 target/microblaze/cpu.c       | 1 +
 target/microblaze/translate.c | 1 +
 target/nios2/translate.c      | 1 +
 5 files changed, 5 insertions(+)
accel/tcg/translator.c +1 -0
index 9de0bc34c8..6832e55135 100644
@@ -12,6 +12,7 @@
 #include "qemu/error-report.h"
 #include "exec/exec-all.h"
 #include "exec/translator.h"
+#include "exec/cpu_ldst.h"
 #include "exec/plugin-gen.h"
 #include "tcg/tcg-op-common.h"
 #include "internal-target.h"
target/hexagon/translate.c +1 -0
index f163eefe97..47a870f42d 100644
@@ -23,6 +23,7 @@
 #include "exec/helper-gen.h"
 #include "exec/helper-proto.h"
 #include "exec/translation-block.h"
+#include "exec/cpu_ldst.h"
 #include "exec/log.h"
 #include "internal.h"
 #include "attribs.h"
target/microblaze/cpu.c +1 -0
index 96c2b71f7f..d05e2e6ea7 100644
@@ -28,6 +28,7 @@
 #include "qemu/module.h"
 #include "hw/qdev-properties.h"
 #include "exec/exec-all.h"
+#include "exec/cpu_ldst.h"
 #include "exec/gdbstub.h"
 #include "fpu/softfloat-helpers.h"
 #include "tcg/tcg.h"
target/microblaze/translate.c +1 -0
index fc451befae..6d89c1a175 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "disas/disas.h"
 #include "exec/exec-all.h"
+#include "exec/cpu_ldst.h"
 #include "tcg/tcg-op.h"
 #include "exec/helper-proto.h"
 #include "exec/helper-gen.h"
target/nios2/translate.c +1 -0
index 7ddc6ac1a2..bcfcc3b112 100644
@@ -25,6 +25,7 @@
 #include "cpu.h"
 #include "tcg/tcg-op.h"
 #include "exec/exec-all.h"
+#include "exec/cpu_ldst.h"
 #include "disas/disas.h"
 #include "exec/helper-proto.h"
 #include "exec/helper-gen.h"
Signature · 1 line
2.41.0
#8 lore raw

PATCH 8/21 gdbstub: Include missing 'hw/core/cpu.h' header

In reply to Philippe Mathieu-Daudé

Functions such gdb_get_cpu_pid() dereference CPUState so require the structure declaration from "hw/core/cpu.h":

  static uint32_t gdb_get_cpu_pid(CPUState *cpu)
  {
    ...
    return cpu->cluster_index + 1;
  }

Message-Id: <[email protected]>

---
 gdbstub/gdbstub.c | 1 +
 1 file changed, 1 insertion(+)
gdbstub/gdbstub.c +1 -0
index 9c23d44baf..9c2b8b5d0a 100644
@@ -37,6 +37,7 @@
 #include "hw/cpu/cluster.h"
 #include "hw/boards.h"
 #endif
+#include "hw/core/cpu.h"
 
 #include "sysemu/hw_accel.h"
 #include "sysemu/runstate.h"
Signature · 1 line
2.41.0
Reviewed-by on v1 8/21
#9 lore raw

Re: [PATCH 08/21] gdbstub: Include missing 'hw/core/cpu.h' header

Quoted 9 lines · Philippe Mathieu-Daudé

Functions such gdb_get_cpu_pid() dereference CPUState so require the structure declaration from "hw/core/cpu.h":

   static uint32_t gdb_get_cpu_pid(CPUState *cpu)
   {
     ...
     return cpu->cluster_index + 1;
   }
Quoted 6 lines

Message-Id:<[email protected]>

---
  gdbstub/gdbstub.c | 1 +
  1 file changed, 1 insertion(+)

r~

#10 lore raw

PATCH 9/21 semihosting/uaccess: Avoid including 'cpu.h'

In reply to Philippe Mathieu-Daudé

"semihosting/uaccess.h" only requires declarations from "exec/cpu-defs.h". Avoid including the huge "cpu.h".

Message-Id: <[email protected]>

---
 include/semihosting/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/semihosting/uaccess.h +1 -1
index 3963eafc3e..6c8835fbcb 100644
@@ -14,7 +14,7 @@
 #error Cannot include semihosting/uaccess.h from user emulation
 #endif
 
-#include "cpu.h"
+#include "exec/cpu-defs.h"
 
 #define get_user_u64(val, addr)                                         \
     ({ uint64_t val_ = 0;                                               \
Signature · 1 line
2.41.0
#11 lore raw

Re: [PATCH 09/21] semihosting/uaccess: Avoid including 'cpu.h'

Quoted 15 lines · Philippe Mathieu-Daudé

"semihosting/uaccess.h" only requires declarations from "exec/cpu-defs.h". Avoid including the huge "cpu.h".

Message-Id: <[email protected]>

---
  include/semihosting/uaccess.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/semihosting/uaccess.h +0 -0
index 3963eafc3e..6c8835fbcb 100644

include/semihosting/uaccess.h line 20

Quoted 8 lines
include/semihosting/uaccess.h +1 -1
@@ -14,7 +14,7 @@
  #error Cannot include semihosting/uaccess.h from user emulation
  #endif
 
-#include "cpu.h"
+#include "exec/cpu-defs.h"
 
  #define get_user_u64(val, addr)                                         \
      ({ uint64_t val_ = 0;                                               \

Does this actually need anything besides exec/tswap.h?

r~

author Reviewed-by Richard Henderson
#12 lore raw

Re: [PATCH 09/21] semihosting/uaccess: Avoid including 'cpu.h'

Quoted 11 lines · Richard Henderson
Quoted 10 lines · Philippe Mathieu-Daudé

"semihosting/uaccess.h" only requires declarations from "exec/cpu-defs.h". Avoid including the huge "cpu.h".

Message-Id: <[email protected]>
---
  include/semihosting/uaccess.h | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

include/semihosting/uaccess.h line 18

Quoted 11 lines
include/semihosting/uaccess.h +1 -1
index 3963eafc3e..6c8835fbcb 100644
@@ -14,7 +14,7 @@
   #error Cannot include semihosting/uaccess.h from user emulation
   #endif
-#include "cpu.h"
+#include "exec/cpu-defs.h"
   #define get_user_u64(val, addr)                                         \
       ({ uint64_t val_ = 0;                                               \

Does this actually need anything besides exec/tswap.h?

Actually what is needed is:

#include "exec/cpu-common.h" // cpu_memory_rw_debug
#include "exec/cpu-defs.h" // target_ulong
#include "exec/tswap.h" // tswap32

Fixed locally as:

-- >8 --

Author: Philippe Mathieu-Daudé <[email protected]>
Date:   Wed Dec 6 16:11:15 2023 +0100

semihosting/uaccess: Avoid including 'cpu.h'

"semihosting/uaccess.h" only requires the following headers:

- "exec/cpu-defs.h" for target_ulong,
- "exec/cpu-common.h" for cpu_memory_rw_debug()
- "exec/tswap.h" for tswap32() and tswap64().

Include them instead of the huge "cpu.h".

include/semihosting/uaccess.h +3 -1
index 3963eafc3e..dd289af8dd 100644
@@ -17 +17,3 @@
-#include "cpu.h"
+#include "exec/cpu-common.h"
+#include "exec/cpu-defs.h"
+#include "exec/tswap.h"

---

#13 lore raw

PATCH 10/21 semihosting/guestfd: Remove unused 'semihosting/uaccess.h' header

In reply to Philippe Mathieu-Daudé

Nothing in guestfd.c requires "semihosting/uaccess.h" nor "qemu.h".

Message-Id: <[email protected]>

---
 semihosting/guestfd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
semihosting/guestfd.c +1 -4
index 955c2efbd0..d3241434c5 100644
@@ -12,10 +12,7 @@
 #include "gdbstub/syscalls.h"
 #include "semihosting/semihost.h"
 #include "semihosting/guestfd.h"
-#ifdef CONFIG_USER_ONLY
-#include "qemu.h"
-#else
-#include "semihosting/uaccess.h"
+#ifndef CONFIG_USER_ONLY
 #include CONFIG_DEVICES
 #endif
 
Signature · 1 line
2.41.0
Reviewed-by on v1 10/21
#14 lore raw

Re: [PATCH 10/21] semihosting/guestfd: Remove unused 'semihosting/uaccess.h' header

Quoted 8 lines · Philippe Mathieu-Daudé

Nothing in guestfd.c requires "semihosting/uaccess.h" nor "qemu.h".

Message-Id:<[email protected]>

---
  semihosting/guestfd.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)

r~

#15 lore raw

PATCH 11/21 exec/cpu-all: Reduce 'qemu/rcu.h' header inclusion

In reply to Philippe Mathieu-Daudé

"exec/cpu-all.h" doesn't need definitions from "qemu/rcu.h", however "exec/ram_addr.h" does.

Message-Id: <[email protected]>

---
 include/exec/cpu-all.h  | 1 -
 include/exec/ram_addr.h | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
include/exec/cpu-all.h +0 -1
index b86209fc49..586dc56d9e 100644
@@ -24,7 +24,6 @@
 #include "exec/tswap.h"
 #include "qemu/thread.h"
 #include "hw/core/cpu.h"
-#include "qemu/rcu.h"
 
 /* some important defines:
  *
include/exec/ram_addr.h +1 -0
index de45ba7bc9..3fc83587c0 100644
@@ -26,6 +26,7 @@
 #include "exec/ramlist.h"
 #include "exec/ramblock.h"
 #include "exec/exec-all.h"
+#include "qemu/rcu.h"
 
 extern uint64_t total_dirty_pages;
 
Signature · 1 line
2.41.0
#16 lore raw

PATCH 12/21 target/ppc/excp_helper: Avoid 'abi_ptr' in system emulation

In reply to Philippe Mathieu-Daudé

'abi_ptr' is a user specific type. The system emulation equivalent is 'target_ulong'. Use it in ppc_ldl_code() to emphasis this is not an user emulation function.

Message-Id: <[email protected]>

---
 target/ppc/excp_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/excp_helper.c +1 -1
index 674c05a2ce..0712098cf7 100644
@@ -142,7 +142,7 @@ static inline bool insn_need_byteswap(CPUArchState *env)
     return !!(env->msr & ((target_ulong)1 << MSR_LE));
 }
 
-static uint32_t ppc_ldl_code(CPUArchState *env, abi_ptr addr)
+static uint32_t ppc_ldl_code(CPUArchState *env, target_ulong addr)
 {
     uint32_t insn = cpu_ldl_code(env, addr);
 
Signature · 1 line
2.41.0
Reviewed-by on v1 12/21
#17 lore raw

Re: [PATCH 12/21] target/ppc/excp_helper: Avoid 'abi_ptr' in system emulation

Quoted 11 lines · Philippe Mathieu-Daudé

'abi_ptr' is a user specific type. The system emulation equivalent is 'target_ulong'. Use it in ppc_ldl_code() to emphasis this is not an user emulation function.

Message-Id:<[email protected]>

---
  target/ppc/excp_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

r~

#18 lore raw

PATCH 13/21 accel/tcg: Un-inline retaddr helpers to 'user-retaddr.h'

In reply to Philippe Mathieu-Daudé

set_helper_retaddr() is only used in accel/tcg/user-exec.c.

clear_helper_retaddr() is only used in accel/tcg/user-exec.c and accel/tcg/user-exec.c.

No need to expose their definitions to all user-emulation files including "exec/cpu_ldst.h", move them to a new "user-retaddr.h" header (restricted to accel/tcg/).

Message-Id: <[email protected]>

---
 accel/tcg/user-retaddr.h | 28 ++++++++++++++++++++++++++++
 include/exec/cpu_ldst.h  | 28 ++--------------------------
 accel/tcg/cpu-exec.c     |  3 +++
 accel/tcg/user-exec.c    |  1 +
 4 files changed, 34 insertions(+), 26 deletions(-)
 create mode 100644 accel/tcg/user-retaddr.h
accel/tcg/user-retaddr.h new file +28 -0
new file mode 100644
index 0000000000..e0f57e1994
@@ -0,0 +1,28 @@
+#ifndef ACCEL_TCG_USER_RETADDR_H
+#define ACCEL_TCG_USER_RETADDR_H
+
+#include "qemu/atomic.h"
+
+extern __thread uintptr_t helper_retaddr;
+
+static inline void set_helper_retaddr(uintptr_t ra)
+{
+    helper_retaddr = ra;
+    /*
+     * Ensure that this write is visible to the SIGSEGV handler that
+     * may be invoked due to a subsequent invalid memory operation.
+     */
+    signal_barrier();
+}
+
+static inline void clear_helper_retaddr(void)
+{
+    /*
+     * Ensure that previous memory operations have succeeded before
+     * removing the data visible to the signal handler.
+     */
+    signal_barrier();
+    helper_retaddr = 0;
+}
+
+#endif
include/exec/cpu_ldst.h +2 -26
index eb8f3f0595..82690d3947 100644
@@ -300,31 +300,7 @@ Int128 cpu_atomic_cmpxchgo_be_mmu(CPUArchState *env, abi_ptr addr,
                                   Int128 cmpv, Int128 newv,
                                   MemOpIdx oi, uintptr_t retaddr);
 
-#if defined(CONFIG_USER_ONLY)
-
-extern __thread uintptr_t helper_retaddr;
-
-static inline void set_helper_retaddr(uintptr_t ra)
-{
-    helper_retaddr = ra;
-    /*
-     * Ensure that this write is visible to the SIGSEGV handler that
-     * may be invoked due to a subsequent invalid memory operation.
-     */
-    signal_barrier();
-}
-
-static inline void clear_helper_retaddr(void)
-{
-    /*
-     * Ensure that previous memory operations have succeeded before
-     * removing the data visible to the signal handler.
-     */
-    signal_barrier();
-    helper_retaddr = 0;
-}
-
-#else
+#if !defined(CONFIG_USER_ONLY)
 
 #include "tcg/oversized-guest.h"
 
@@ -376,7 +352,7 @@ static inline CPUTLBEntry *tlb_entry(CPUState *cpu, uintptr_t mmu_idx,
     return &cpu->neg.tlb.f[mmu_idx].table[tlb_index(cpu, mmu_idx, addr)];
 }
 
-#endif /* defined(CONFIG_USER_ONLY) */
+#endif /* !defined(CONFIG_USER_ONLY) */
 
 #if TARGET_BIG_ENDIAN
 # define cpu_lduw_data        cpu_lduw_be_data
accel/tcg/cpu-exec.c +3 -0
index 5c70748060..225e5fbd3e 100644
@@ -41,6 +41,9 @@
 #include "tb-context.h"
 #include "internal-common.h"
 #include "internal-target.h"
+#if defined(CONFIG_USER_ONLY)
+#include "user-retaddr.h"
+#endif
 
 /* -icount align implementation. */
 
accel/tcg/user-exec.c +1 -0
index 3cac3a78c4..1c621477ad 100644
@@ -31,6 +31,7 @@
 #include "tcg/tcg-ldst.h"
 #include "internal-common.h"
 #include "internal-target.h"
+#include "user-retaddr.h"
 
 __thread uintptr_t helper_retaddr;
 
Signature · 1 line
2.41.0
#19 lore raw

Re: [PATCH 13/21] accel/tcg: Un-inline retaddr helpers to 'user-retaddr.h'

Quoted 4 lines · Philippe Mathieu-Daudé

set_helper_retaddr() is only used in accel/tcg/user-exec.c.

clear_helper_retaddr() is only used in accel/tcg/user-exec.c and accel/tcg/user-exec.c.

Typo here, repeating the same filename.

r~

#20 lore raw

Re: [PATCH 13/21] accel/tcg: Un-inline retaddr helpers to 'user-retaddr.h'

Quoted 4 lines · Richard Henderson
Quoted 3 lines · Philippe Mathieu-Daudé

set_helper_retaddr() is only used in accel/tcg/user-exec.c.

clear_helper_retaddr() is only used in accel/tcg/user-exec.c

Here should be "accel/tcg/cpu-exec.c", fixed.

Quoted 5 lines
Quoted 1 line

and accel/tcg/user-exec.c.

Typo here, repeating the same filename.

r~

#21 lore raw

PATCH 14/21 target/i386: Include missing 'exec/exec-all.h' header

In reply to Philippe Mathieu-Daudé

The XRSTOR instruction ends calling tlb_flush(), declared in "exec/exec-all.h".

Message-Id: <[email protected]>

---
 target/i386/tcg/fpu_helper.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/tcg/fpu_helper.c +1 -0
index 4b965a5d6c..ece22a3553 100644
@@ -21,6 +21,7 @@
 #include <math.h>
 #include "cpu.h"
 #include "tcg-cpu.h"
+#include "exec/exec-all.h"
 #include "exec/cpu_ldst.h"
 #include "exec/helper-proto.h"
 #include "fpu/softfloat.h"
Signature · 1 line
2.41.0
#22 lore raw

PATCH 15/21 accel/tcg: Include missing 'hw/core/cpu.h' header

In reply to Philippe Mathieu-Daudé

tcg_cpu_init_cflags() accesses CPUState fields, so requires "hw/core/cpu.h" to get its structure definition.

Message-Id: <[email protected]>

---
 accel/tcg/tcg-accel-ops.c | 2 ++
 1 file changed, 2 insertions(+)
accel/tcg/tcg-accel-ops.c +2 -0
index 9c957f421c..2c7b0cc09e 100644
@@ -37,6 +37,8 @@
 #include "exec/tb-flush.h"
 #include "exec/gdbstub.h"
 
+#include "hw/core/cpu.h"
+
 #include "tcg-accel-ops.h"
 #include "tcg-accel-ops-mttcg.h"
 #include "tcg-accel-ops-rr.h"
Signature · 1 line
2.41.0
Reviewed-by on v1 15/21
#23 lore raw

Re: [PATCH 15/21] accel/tcg: Include missing 'hw/core/cpu.h' header

Quoted 9 lines · Philippe Mathieu-Daudé

tcg_cpu_init_cflags() accesses CPUState fields, so requires "hw/core/cpu.h" to get its structure definition.

Message-Id:<[email protected]>

---
  accel/tcg/tcg-accel-ops.c | 2 ++
  1 file changed, 2 insertions(+)

r~

#24 lore raw

PATCH 16/21 exec/cpu-all: Remove unused 'qemu/thread.h' header

In reply to Philippe Mathieu-Daudé

Nothing is required from "qemu/thread.h" in "exec/cpu-all.h".

Message-Id: <[email protected]>

---
 include/exec/cpu-all.h | 1 -
 1 file changed, 1 deletion(-)
include/exec/cpu-all.h +0 -1
index 586dc56d9e..4de0d5a0d7 100644
@@ -22,7 +22,6 @@
 #include "exec/cpu-common.h"
 #include "exec/memory.h"
 #include "exec/tswap.h"
-#include "qemu/thread.h"
 #include "hw/core/cpu.h"
 
 /* some important defines:
Signature · 1 line
2.41.0
#26 lore raw

PATCH 17/21 exec/cpu-all: Remove unused tswapls() definitions

In reply to Philippe Mathieu-Daudé

Last use of tswapls() was removed 2 years ago in commit aee14c77f4 ("linux-user: Rewrite do_getdents, do_getdents64").

Message-Id: <[email protected]>

---
 include/exec/cpu-all.h | 2 --
 1 file changed, 2 deletions(-)
include/exec/cpu-all.h +0 -2
index 4de0d5a0d7..7c44ffb3af 100644
@@ -38,11 +38,9 @@
 
 #if TARGET_LONG_SIZE == 4
 #define tswapl(s) tswap32(s)
-#define tswapls(s) tswap32s((uint32_t *)(s))
 #define bswaptls(s) bswap32s(s)
 #else
 #define tswapl(s) tswap64(s)
-#define tswapls(s) tswap64s((uint64_t *)(s))
 #define bswaptls(s) bswap64s(s)
 #endif
 
Signature · 1 line
2.41.0
Reviewed-by on v1 17/21
#27 lore raw

Re: [PATCH 17/21] exec/cpu-all: Remove unused tswapls() definitions

Quoted 9 lines · Philippe Mathieu-Daudé

Last use of tswapls() was removed 2 years ago in commit aee14c77f4 ("linux-user: Rewrite do_getdents, do_getdents64").

Message-Id:<[email protected]>

---
  include/exec/cpu-all.h | 2 --
  1 file changed, 2 deletions(-)

r~

#28 lore raw

PATCH 18/21 exec: Declare target_words_bigendian() in 'exec/tswap.h'

In reply to Philippe Mathieu-Daudé

We usually check target endianess before swapping values, so target_words_bigendian() declaration makes sense in "exec/tswap.h" with the target swapping helpers.

Remove "hw/core/cpu.h" when it was only included to get the target_words_bigendian() declaration.

Message-Id: <[email protected]>

---
 include/exec/tswap.h     | 12 +++++++++++-
 include/hw/core/cpu.h    | 11 -----------
 cpu-target.c             |  1 +
 disas/disas.c            |  1 +
 hw/audio/virtio-snd.c    |  2 +-
 hw/core/cpu-sysemu.c     |  2 +-
 hw/core/generic-loader.c |  2 +-
 hw/display/vga.c         |  2 +-
 hw/virtio/virtio.c       |  1 +
 9 files changed, 18 insertions(+), 16 deletions(-)
include/exec/tswap.h +11 -1
index 5089cd6a4c..b7a4191347 100644
@@ -8,9 +8,19 @@
 #ifndef TSWAP_H
 #define TSWAP_H
 
-#include "hw/core/cpu.h"
 #include "qemu/bswap.h"
 
+/**
+ * target_words_bigendian:
+ * Returns true if the (default) endianness of the target is big endian,
+ * false otherwise. Note that in target-specific code, you can use
+ * TARGET_BIG_ENDIAN directly instead. On the other hand, common
+ * code should normally never need to know about the endianness of the
+ * target, so please do *not* use this function unless you know very well
+ * what you are doing!
+ */
+bool target_words_bigendian(void);
+
 /*
  * If we're in target-specific code, we can hard-code the swapping
  * condition, otherwise we have to do (slower) run-time checks.
include/hw/core/cpu.h +0 -11
index 7f037b158e..3a66d8581e 100644
@@ -1169,17 +1169,6 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp);
 void cpu_exec_unrealizefn(CPUState *cpu);
 void cpu_exec_reset_hold(CPUState *cpu);
 
-/**
- * target_words_bigendian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Note that in target-specific code, you can use
- * TARGET_BIG_ENDIAN directly instead. On the other hand, common
- * code should normally never need to know about the endianness of the
- * target, so please do *not* use this function unless you know very well
- * what you are doing!
- */
-bool target_words_bigendian(void);
-
 const char *target_name(void);
 
 #ifdef COMPILING_PER_TARGET
cpu-target.c +1 -0
index 4c0621bf33..f88649c299 100644
@@ -35,6 +35,7 @@
 #endif
 #include "sysemu/cpus.h"
 #include "sysemu/tcg.h"
+#include "exec/tswap.h"
 #include "exec/replay-core.h"
 #include "exec/cpu-common.h"
 #include "exec/exec-all.h"
disas/disas.c +1 -0
index 7e3b0bb46c..ec14715ecd 100644
@@ -6,6 +6,7 @@
 #include "disas/disas.h"
 #include "disas/capstone.h"
 #include "hw/core/cpu.h"
+#include "exec/tswap.h"
 #include "exec/memory.h"
 
 /* Filled in by elfload.c.  Simplistic, but will do for now. */
hw/audio/virtio-snd.c +1 -1
index c80b58bf5d..6a2ee085c0 100644
@@ -20,11 +20,11 @@
 #include "qemu/log.h"
 #include "qemu/error-report.h"
 #include "include/qemu/lockable.h"
+#include "exec/tswap.h"
 #include "sysemu/runstate.h"
 #include "trace.h"
 #include "qapi/error.h"
 #include "hw/audio/virtio-snd.h"
-#include "hw/core/cpu.h"
 
 #define VIRTIO_SOUND_VM_VERSION 1
 #define VIRTIO_SOUND_JACK_DEFAULT 0
hw/core/cpu-sysemu.c +1 -1
index d0d6a910f9..2a9a2a4eb5 100644
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "hw/core/cpu.h"
+#include "exec/tswap.h"
 #include "hw/core/sysemu-cpu-ops.h"
 
 bool cpu_paging_enabled(const CPUState *cpu)
hw/core/generic-loader.c +1 -1
index d4b5c501d8..ea8628b892 100644
@@ -31,7 +31,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/core/cpu.h"
+#include "exec/tswap.h"
 #include "sysemu/dma.h"
 #include "sysemu/reset.h"
 #include "hw/boards.h"
hw/display/vga.c +1 -1
index 77f59e8c11..d17ff4b93a 100644
@@ -26,7 +26,7 @@
 #include "qemu/units.h"
 #include "sysemu/reset.h"
 #include "qapi/error.h"
-#include "hw/core/cpu.h"
+#include "exec/tswap.h"
 #include "hw/display/vga.h"
 #include "hw/i386/x86.h"
 #include "hw/pci/pci.h"
hw/virtio/virtio.c +1 -0
index 871674f9be..893a072c9d 100644
@@ -20,6 +20,7 @@
 #include "qemu/log.h"
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
+#include "exec/tswap.h"
 #include "qom/object_interfaces.h"
 #include "hw/core/cpu.h"
 #include "hw/virtio/virtio.h"
Signature · 1 line
2.41.0
Reviewed-by on v1 18/21
#29 lore raw

Re: [PATCH 18/21] exec: Declare target_words_bigendian() in 'exec/tswap.h'

Quoted 10 lines · Philippe Mathieu-Daudé

We usually check target endianess before swapping values, so target_words_bigendian() declaration makes sense in "exec/tswap.h" with the target swapping helpers.

Remove "hw/core/cpu.h" when it was only included to get the target_words_bigendian() declaration.

Message-Id: <[email protected]>

Quoted 11 lines
---
  include/exec/tswap.h     | 12 +++++++++++-
  include/hw/core/cpu.h    | 11 -----------
  cpu-target.c             |  1 +
  disas/disas.c            |  1 +
  hw/audio/virtio-snd.c    |  2 +-
  hw/core/cpu-sysemu.c     |  2 +-
  hw/core/generic-loader.c |  2 +-
  hw/display/vga.c         |  2 +-
  hw/virtio/virtio.c       |  1 +
  9 files changed, 18 insertions(+), 16 deletions(-)

As an intermediate step, this is ok, I guess, so

But most of these files that include this header should be using a CPUClass hook, or a device property, or something else.

r~

#30 lore raw

PATCH 19/21 exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h'

In reply to Philippe Mathieu-Daudé

tswapl() and bswaptls() are target-dependent and only used by user emulation. Move their definitions to a new header:
"exec/user/tswap-target.h".

Message-Id: <[email protected]>

---
 MAINTAINERS                        |  1 +
 bsd-user/freebsd/target_os_elf.h   |  1 +
 bsd-user/freebsd/target_os_stack.h |  1 +
 bsd-user/netbsd/target_os_elf.h    |  1 +
 bsd-user/openbsd/target_os_elf.h   |  1 +
 include/exec/cpu-all.h             |  8 --------
 include/exec/user/abitypes.h       |  1 +
 include/user/tswap-target.h        | 22 ++++++++++++++++++++++
 bsd-user/signal.c                  |  1 +
 bsd-user/strace.c                  |  1 +
 linux-user/elfload.c               |  1 +
 linux-user/i386/signal.c           |  1 +
 linux-user/ppc/signal.c            |  1 +
 13 files changed, 33 insertions(+), 8 deletions(-)
 create mode 100644 include/user/tswap-target.h
MAINTAINERS +1 -0
index f1f6922025..e85b358683 100644
@@ -3704,6 +3704,7 @@ Overall usermode emulation
 M: Riku Voipio <[email protected]>
 S: Maintained
 F: accel/tcg/user-exec*.c
+F: include/exec/user/
 F: include/user/
 F: common-user/
 
bsd-user/freebsd/target_os_elf.h +1 -0
index 9df17d56d8..01124979f7 100644
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "user/tswap-target.h"
 
 #define bsd_get_ncpu() 1 /* until we pull in bsd-proc.[hc] */
 
bsd-user/freebsd/target_os_stack.h +1 -0
index d15fc3263f..ac0ef22cd7 100644
@@ -23,6 +23,7 @@
 #include <sys/param.h>
 #include "target_arch_sigtramp.h"
 #include "qemu/guest-random.h"
+#include "user/tswap-target.h"
 
 /*
  * The initial FreeBSD stack is as follows:
bsd-user/netbsd/target_os_elf.h +1 -0
index 2f3cb20871..9de0f290c0 100644
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "user/tswap-target.h"
 
 /* this flag is uneffective under linux too, should be deleted */
 #ifndef MAP_DENYWRITE
bsd-user/openbsd/target_os_elf.h +1 -0
index 6dca9c5a85..4cf5747dcd 100644
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "user/tswap-target.h"
 
 /* this flag is uneffective under linux too, should be deleted */
 #ifndef MAP_DENYWRITE
include/exec/cpu-all.h +0 -8
index 7c44ffb3af..78848f018c 100644
@@ -36,14 +36,6 @@
 #define BSWAP_NEEDED
 #endif
 
-#if TARGET_LONG_SIZE == 4
-#define tswapl(s) tswap32(s)
-#define bswaptls(s) bswap32s(s)
-#else
-#define tswapl(s) tswap64(s)
-#define bswaptls(s) bswap64s(s)
-#endif
-
 /* Target-endianness CPU memory access functions. These fit into the
  * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
  */
include/exec/user/abitypes.h +1 -0
index 6178453d94..56e96fcb99 100644
@@ -2,6 +2,7 @@
 #define EXEC_USER_ABITYPES_H
 
 #include "cpu.h"
+#include "user/tswap-target.h"
 
 #ifdef TARGET_ABI32
 #define TARGET_ABI_BITS 32
include/user/tswap-target.h new file +22 -0
new file mode 100644
index 0000000000..4719330dbb
@@ -0,0 +1,22 @@
+/*
+ * target-specific swap() definitions
+ *
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+#ifndef USER_TSWAP_H
+#define USER_TSWAP_H
+
+#include "exec/cpu-defs.h"
+#include "exec/tswap.h"
+
+#if TARGET_LONG_SIZE == 4
+#define tswapl(s) tswap32(s)
+#define bswaptls(s) bswap32s(s)
+#else
+#define tswapl(s) tswap64(s)
+#define bswaptls(s) bswap64s(s)
+#endif
+
+#endif
bsd-user/signal.c +1 -0
index e5a773ddde..b2faf1d0dd 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "qemu.h"
+#include "user/tswap-target.h"
 #include "gdbstub/user.h"
 #include "signal-common.h"
 #include "trace.h"
bsd-user/strace.c +1 -0
index 96499751eb..6dc01d3be7 100644
@@ -22,6 +22,7 @@
 #include <sys/ioccom.h>
 
 #include "qemu.h"
+#include "user/tswap-target.h"
 
 #include "os-strace.h"  /* OS dependent strace print functions */
 
linux-user/elfload.c +1 -0
index 60cf55b36c..28d9e8a9a5 100644
@@ -7,6 +7,7 @@
 #include <sys/shm.h>
 
 #include "qemu.h"
+#include "user/tswap-target.h"
 #include "user-internals.h"
 #include "signal-common.h"
 #include "loader.h"
linux-user/i386/signal.c +1 -0
index cfe70fc5cf..990048f42a 100644
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "user/tswap-target.h"
 
 /* from the Linux kernel - /arch/x86/include/uapi/asm/sigcontext.h */
 
linux-user/ppc/signal.c +1 -0
index 652038a53c..a1d8c0bccc 100644
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "user/tswap-target.h"
 #include "vdso-asmoffset.h"
 
 /* See arch/powerpc/include/asm/ucontext.h.  Only used for 32-bit PPC;
Signature · 1 line
2.41.0
Reviewed-by on v1 19/21
#31 lore raw

Re: [PATCH 19/21] exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h'

Quoted 22 lines · Philippe Mathieu-Daudé

tswapl() and bswaptls() are target-dependent and only used by user emulation. Move their definitions to a new header:
"exec/user/tswap-target.h".

Message-Id:<[email protected]>

---
  MAINTAINERS                        |  1 +
  bsd-user/freebsd/target_os_elf.h   |  1 +
  bsd-user/freebsd/target_os_stack.h |  1 +
  bsd-user/netbsd/target_os_elf.h    |  1 +
  bsd-user/openbsd/target_os_elf.h   |  1 +
  include/exec/cpu-all.h             |  8 --------
  include/exec/user/abitypes.h       |  1 +
  include/user/tswap-target.h        | 22 ++++++++++++++++++++++
  bsd-user/signal.c                  |  1 +
  bsd-user/strace.c                  |  1 +
  linux-user/elfload.c               |  1 +
  linux-user/i386/signal.c           |  1 +
  linux-user/ppc/signal.c            |  1 +
  13 files changed, 33 insertions(+), 8 deletions(-)
Quoted 1 line

create mode 100644 include/user/tswap-target.h

r~

#32 lore raw

PATCH 20/21 exec/user: Do not include 'cpu.h' in 'abitypes.h'

In reply to Philippe Mathieu-Daudé

"exec/user/abitypes.h" requires:

- "exec/cpu-defs.h" (TARGET_LONG_BITS)
- "exec/tswap.h" (tswap32)

In order to avoid "cpu.h", pick the minimum required headers.

Assert this user-specific header is only included from user emulation.

Message-Id: <[email protected]>

---
 include/exec/user/abitypes.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
include/exec/user/abitypes.h +6 -1
index 56e96fcb99..b5c7ad4d1a 100644
@@ -1,7 +1,12 @@
 #ifndef EXEC_USER_ABITYPES_H
 #define EXEC_USER_ABITYPES_H
 
-#include "cpu.h"
+#ifndef CONFIG_USER_ONLY
+#error Cannot include this header from system emulation
+#endif
+
+#include "exec/cpu-defs.h"
+#include "exec/tswap.h"
 #include "user/tswap-target.h"
 
 #ifdef TARGET_ABI32
Signature · 1 line
2.41.0
Reviewed-by on v1 20/21
#33 lore raw

Re: [PATCH 20/21] exec/user: Do not include 'cpu.h' in 'abitypes.h'

Quoted 10 lines · Philippe Mathieu-Daudé

"exec/user/abitypes.h" requires:

- "exec/cpu-defs.h" (TARGET_LONG_BITS)
- "exec/tswap.h" (tswap32)

In order to avoid "cpu.h", pick the minimum required headers.

Assert this user-specific header is only included from user emulation.

Quoted 6 lines

Message-Id:<[email protected]>

---
  include/exec/user/abitypes.h | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)

r~

#34 lore raw

PATCH 21/21 exec: Declare abi_ptr type in its own 'abi_ptr.h' header

In reply to Philippe Mathieu-Daudé

The abi_ptr type is declared in "exec/cpu_ldst.h" with all the load/store helpers. Some source files requiring abi_ptr type don't need the load/store helpers. In order to simplify, create a new "exec/abi_ptr.h" header.

Message-Id: <[email protected]>

---
 include/exec/abi_ptr.h    | 33 +++++++++++++++++++++++++++++++++
 include/exec/cpu_ldst.h   | 17 +++--------------
 include/exec/exec-all.h   |  1 +
 include/exec/translator.h |  5 ++++-
 4 files changed, 41 insertions(+), 15 deletions(-)
 create mode 100644 include/exec/abi_ptr.h
include/exec/abi_ptr.h new file +33 -0
new file mode 100644
index 0000000000..2aedcceb0c
@@ -0,0 +1,33 @@
+/*
+ * QEMU abi_ptr type definitions
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+#ifndef EXEC_ABI_PTR_H
+#define EXEC_ABI_PTR_H
+
+#include "cpu-param.h"
+
+#if defined(CONFIG_USER_ONLY)
+/*
+ * sparc32plus has 64bit long but 32bit space address
+ * this can make bad result with g2h() and h2g()
+ */
+#if TARGET_VIRT_ADDR_SPACE_BITS <= 32
+typedef uint32_t abi_ptr;
+#define TARGET_ABI_FMT_ptr "%x"
+#else
+typedef uint64_t abi_ptr;
+#define TARGET_ABI_FMT_ptr "%"PRIx64
+#endif
+
+#else /* !CONFIG_USER_ONLY */
+
+#include "exec/target_long.h"
+
+typedef target_ulong abi_ptr;
+#define TARGET_ABI_FMT_ptr TARGET_FMT_lx
+
+#endif /* !CONFIG_USER_ONLY */
+
+#endif
include/exec/cpu_ldst.h +3 -14
index 82690d3947..64e0319996 100644
@@ -63,20 +63,11 @@
 #define CPU_LDST_H
 
 #include "exec/memopidx.h"
+#include "exec/abi_ptr.h"
 #include "qemu/int128.h"
 #include "cpu.h"
 
 #if defined(CONFIG_USER_ONLY)
-/* sparc32plus has 64bit long but 32bit space address
- * this can make bad result with g2h() and h2g()
- */
-#if TARGET_VIRT_ADDR_SPACE_BITS <= 32
-typedef uint32_t abi_ptr;
-#define TARGET_ABI_FMT_ptr "%x"
-#else
-typedef uint64_t abi_ptr;
-#define TARGET_ABI_FMT_ptr "%"PRIx64
-#endif
 
 #ifndef TARGET_TAGGED_ADDRESSES
 static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x)
@@ -120,10 +111,8 @@ static inline bool guest_range_valid_untagged(abi_ulong start, abi_ulong len)
     assert(h2g_valid(x)); \
     h2g_nocheck(x); \
 })
-#else
-typedef vaddr abi_ptr;
-#define TARGET_ABI_FMT_ptr VADDR_PRIx
-#endif
+
+#endif /* CONFIG_USER_ONLY */
 
 uint32_t cpu_ldub_data(CPUArchState *env, abi_ptr ptr);
 int cpu_ldsb_data(CPUArchState *env, abi_ptr ptr);
include/exec/exec-all.h +1 -0
index 3e53501691..e932d364b6 100644
@@ -22,6 +22,7 @@
 
 #include "cpu.h"
 #if defined(CONFIG_USER_ONLY)
+#include "exec/abi_ptr.h"
 #include "exec/cpu_ldst.h"
 #endif
 #include "exec/translation-block.h"
include/exec/translator.h +4 -1
index 2c4fb818e7..6cd937ac5c 100644
@@ -19,7 +19,10 @@
  */
 
 #include "qemu/bswap.h"
-#include "exec/cpu_ldst.h"	/* for abi_ptr */
+#include "exec/cpu-common.h"
+#include "exec/cpu-defs.h"
+#include "exec/abi_ptr.h"
+#include "cpu.h"
 
 /**
  * gen_intermediate_code
Signature · 1 line
2.41.0