Skip to contentSkip to conversation

misc: Use explicit endian LD/ST API

PATCH In review Philippe Mathieu-Daudé 4 participants 49 messages Oct 4, 2024 – Oct 7, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

v2 cover misc: Use explicit endian LD/ST API

For targets (or HW) which are only built for a particular endianness, the generic LD/ST helpers are defined as the target endianness variant. For example, on big-endian targets, stl_p() is equivalent of stl_be_p().

This series replaces in bulk these LD/ST calls.

This is helpful for the single binary project where we want to build a single binary for multiple targets of different endianness.

Philippe Mathieu-Daudé (25):
gdbstub/helpers: Have ldtul_p() definition use ldn_p() target/hexagon: Replace ldtul_p() -> ldl_p() target/alpha: Replace ldtul_p() -> ldq_p() target/s390x: Replace ldtul_p() -> ldq_p() gdbstub/helpers: Introduce ldtul_$endian_p() helpers target/alpha: Use explicit little-endian LD/ST API target/hexagon: Use explicit little-endian LD/ST API hw/i386: Use explicit little-endian LD/ST API target/i386: Use explicit little-endian LD/ST API target/avr: Use explicit little-endian LD/ST API linux-user/i386: Use explicit little-endian LD/ST API target/loongarch: Use explicit little-endian LD/ST API target/sh4: Use explicit little-endian LD/ST API target/tricore: Use explicit little-endian LD/ST API target/rx: Use explicit little-endian LD/ST API target/riscv: Use explicit little-endian LD/ST API hw/m68k: Use explicit big-endian LD/ST API target/m68k: Use explicit big-endian LD/ST API hw/sparc: Use explicit big-endian LD/ST API target/sparc: Use explicit big-endian LD/ST API target/hppa: Use explicit big-endian LD/ST API hw/s390x: Use explicit big-endian LD/ST API target/s390x: Use explicit big-endian LD/ST API target/openrisc: Use explicit big-endian LD/ST API hw/ppc/e500: Use explicit big-endian LD/ST API

 hw/m68k/bootinfo.h                   |  28 ++---
 include/gdbstub/helpers.h            |   6 +-
 hw/i386/multiboot.c                  |  36 +++---
 hw/i386/x86-common.c                 |  26 ++---
 hw/m68k/mcf5208.c                    |   2 +-
 hw/m68k/next-cube.c                  |   2 +-
 hw/m68k/q800.c                       |   4 +-
 hw/ppc/ppce500_spin.c                |  24 ++--
 hw/s390x/ipl.c                       |   4 +-
 hw/s390x/s390-pci-inst.c             | 166 +++++++++++++--------------
 hw/sparc/leon3.c                     |  42 +++----
 hw/sparc/sun4m.c                     |   6 +-
 hw/sparc64/sun4u.c                   |   6 +-
 linux-user/i386/signal.c             |   4 +-
 target/alpha/gdbstub.c               |   2 +-
 target/avr/gdbstub.c                 |   4 +-
 target/hexagon/gdbstub.c             |  10 +-
 target/hppa/gdbstub.c                |   2 +-
 target/i386/gdbstub.c                |  30 ++---
 target/i386/tcg/sysemu/excp_helper.c |   4 +-
 target/i386/xsave_helper.c           |  32 +++---
 target/loongarch/gdbstub.c           |   8 +-
 target/m68k/gdbstub.c                |   2 +-
 target/m68k/helper.c                 |  10 +-
 target/openrisc/gdbstub.c            |   2 +-
 target/riscv/gdbstub.c               |  14 +--
 target/rx/cpu.c                      |   2 +-
 target/rx/gdbstub.c                  |  24 ++--
 target/s390x/gdbstub.c               |  34 +++---
 target/s390x/ioinst.c                |   2 +-
 target/sh4/gdbstub.c                 |  36 +++---
 target/sparc/gdbstub.c               |   6 +-
 target/tricore/gdbstub.c             |   2 +-
 33 files changed, 292 insertions(+), 290 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH v2 1/25 gdbstub/helpers: Have ldtul_p() definition use ldn_p()

Use ldn_p(TARGET_LONG_SIZE) instead of ldl_p() / ldq_p().

---
 include/gdbstub/helpers.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/gdbstub/helpers.h +2 -2
index 26140ef1ac0..fd83e366a51 100644
@@ -94,10 +94,10 @@ static inline uint8_t *gdb_get_reg_ptr(GByteArray *buf, int len)
 
 #if TARGET_LONG_BITS == 64
 #define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
-#define ldtul_p(addr) ldq_p(addr)
 #else
 #define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
-#define ldtul_p(addr) ldl_p(addr)
 #endif
 
+#define ldtul_p(addr) ldn_p(addr, TARGET_LONG_SIZE)
+
 #endif /* _GDBSTUB_HELPERS_H_ */
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH v2 01/25] gdbstub/helpers: Have ldtul_p() definition use ldn_p()

Quoted 12 lines · Philippe Mathieu-Daudé

Use ldn_p(TARGET_LONG_SIZE) instead of ldl_p() / ldq_p().

---
  include/gdbstub/helpers.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
include/gdbstub/helpers.h +0 -0
index 26140ef1ac0..fd83e366a51 100644

include/gdbstub/helpers.h static inline uint8_t *gdb_get_reg_ptr(GByteArray *buf, int len) · line 101

Quoted 10 lines
include/gdbstub/helpers.h +1 -2
@@ -94,10 +94,10 @@ static inline uint8_t *gdb_get_reg_ptr(GByteArray *buf, int len)
 
  #if TARGET_LONG_BITS == 64
  #define gdb_get_regl(buf, val) gdb_get_reg64(buf, val)
-#define ldtul_p(addr) ldq_p(addr)
  #else
  #define gdb_get_regl(buf, val) gdb_get_reg32(buf, val)
-#define ldtul_p(addr) ldl_p(addr)
  #endif
 
+#define ldtul_p(addr) ldn_p(addr, TARGET_LONG_SIZE)

This does not aid anything in the short term.

r~

#3 lore raw

PATCH v2 2/25 target/hexagon: Replace ldtul_p() -> ldl_p()

In reply to Philippe Mathieu-Daudé

The Hexagon target is only built for 64-bit.
Using ldtul_p() is pointless, replace by ldl_p().

Mechanical change doing:

  $ sed -i -e 's/ldtul_p/ldl_p/' \
      $(git grep -wl ldtul_p target/hexagon/)
---
 target/hexagon/gdbstub.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
target/hexagon/gdbstub.c +5 -5
index 94e1db8ef8d..557b3029785 100644
@@ -52,7 +52,7 @@ int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     CPUHexagonState *env = cpu_env(cs);
 
     if (n == HEX_REG_P3_0_ALIASED) {
-        uint32_t p3_0 = ldtul_p(mem_buf);
+        uint32_t p3_0 = ldl_p(mem_buf);
         for (int i = 0; i < NUM_PREGS; i++) {
             env->pred[i] = extract32(p3_0, i * 8, 8);
         }
@@ -60,14 +60,14 @@ int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     }
 
     if (n < TOTAL_PER_THREAD_REGS) {
-        env->gpr[n] = ldtul_p(mem_buf);
+        env->gpr[n] = ldl_p(mem_buf);
         return sizeof(target_ulong);
     }
 
     n -= TOTAL_PER_THREAD_REGS;
 
     if (n < NUM_PREGS) {
-        env->pred[n] = ldtul_p(mem_buf) & 0xff;
+        env->pred[n] = ldl_p(mem_buf) & 0xff;
         return sizeof(uint8_t);
     }
 
@@ -117,7 +117,7 @@ static int gdb_put_vreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
 {
     int i;
     for (i = 0; i < ARRAY_SIZE(env->VRegs[n].uw); i++) {
-        env->VRegs[n].uw[i] = ldtul_p(mem_buf);
+        env->VRegs[n].uw[i] = ldl_p(mem_buf);
         mem_buf += 4;
     }
     return MAX_VEC_SIZE_BYTES;
@@ -127,7 +127,7 @@ static int gdb_put_qreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
 {
     int i;
     for (i = 0; i < ARRAY_SIZE(env->QRegs[n].uw); i++) {
-        env->QRegs[n].uw[i] = ldtul_p(mem_buf);
+        env->QRegs[n].uw[i] = ldl_p(mem_buf);
         mem_buf += 4;
     }
     return MAX_VEC_SIZE_BYTES / 8;
Signature · 1 line
2.45.2
Reviewed-by on v2 2/25
#4 lore raw

Re: [PATCH v2 02/25] target/hexagon: Replace ldtul_p() -> ldl_p()

Quoted 1 line · Philippe Mathieu-Daudé

The Hexagon target is only built for 64-bit.

32-bit, which confuses the reading of the patch. :-)

Otherwise,

r~

#5 lore raw

PATCH v2 3/25 target/alpha: Replace ldtul_p() -> ldq_p()

In reply to Philippe Mathieu-Daudé

The Alpha target is only built for 64-bit.
Using ldtul_p() is pointless, replace by ldq_p().

Mechanical change doing:

  $ sed -i -e 's/ldtul_p/ldq_p/' $(git grep -wl ldtul_p target/alpha/)
---
 target/alpha/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/alpha/gdbstub.c +1 -1
index 13694fd321e..bf5091c2a6e 100644
@@ -59,7 +59,7 @@ int alpha_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
 int alpha_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 {
     CPUAlphaState *env = cpu_env(cs);
-    target_ulong tmp = ldtul_p(mem_buf);
+    target_ulong tmp = ldq_p(mem_buf);
     CPU_DoubleU d;
 
     switch (n) {
Signature · 1 line
2.45.2
Reviewed-by on v2 3/25
#6 lore raw

Re: [PATCH v2 03/25] target/alpha: Replace ldtul_p() -> ldq_p()

Quoted 11 lines · Philippe Mathieu-Daudé

The Alpha target is only built for 64-bit.
Using ldtul_p() is pointless, replace by ldq_p().

Mechanical change doing:

   $ sed -i -e 's/ldtul_p/ldq_p/' $(git grep -wl ldtul_p target/alpha/)
---
  target/alpha/gdbstub.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

r~

#7 lore raw

PATCH v2 4/25 target/s390x: Replace ldtul_p() -> ldq_p()

In reply to Philippe Mathieu-Daudé

The S390X target is only built for 64-bit.
Using ldtul_p() is pointless, replace by ldq_p().

Mechanical change doing:

  $ sed -i -e 's/ldtul_p/ldq_p/' $(git grep -wl ldtul_p target/s390x/)
---
 target/s390x/gdbstub.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
target/s390x/gdbstub.c +15 -15
index a9f4eb92adf..9ffec0bccbc 100644
@@ -46,7 +46,7 @@ int s390_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
 int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 {
     CPUS390XState *env = cpu_env(cs);
-    target_ulong tmpl = ldtul_p(mem_buf);
+    target_ulong tmpl = ldq_p(mem_buf);
 
     switch (n) {
     case S390_PSWM_REGNUM:
@@ -126,7 +126,7 @@ static int cpu_write_fp_reg(CPUState *cs, uint8_t *mem_buf, int n)
         env->fpc = ldl_p(mem_buf);
         return 4;
     case S390_F0_REGNUM ... S390_F15_REGNUM:
-        *get_freg(env, n - S390_F0_REGNUM) = ldtul_p(mem_buf);
+        *get_freg(env, n - S390_F0_REGNUM) = ldq_p(mem_buf);
         return 8;
     default:
         return 0;
@@ -167,11 +167,11 @@ static int cpu_write_vreg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_V0L_REGNUM ... S390_V15L_REGNUM:
-        env->vregs[n][1] = ldtul_p(mem_buf + 8);
+        env->vregs[n][1] = ldq_p(mem_buf + 8);
         return 8;
     case S390_V16_REGNUM ... S390_V31_REGNUM:
-        env->vregs[n][0] = ldtul_p(mem_buf);
-        env->vregs[n][1] = ldtul_p(mem_buf + 8);
+        env->vregs[n][0] = ldq_p(mem_buf);
+        env->vregs[n][1] = ldq_p(mem_buf + 8);
         return 16;
     default:
         return 0;
@@ -203,7 +203,7 @@ static int cpu_write_c_reg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_C0_REGNUM ... S390_C15_REGNUM:
-        env->cregs[n] = ldtul_p(mem_buf);
+        env->cregs[n] = ldq_p(mem_buf);
         if (tcg_enabled()) {
             tlb_flush(env_cpu(env));
         }
@@ -246,19 +246,19 @@ static int cpu_write_virt_reg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_VIRT_CKC_REGNUM:
-        env->ckc = ldtul_p(mem_buf);
+        env->ckc = ldq_p(mem_buf);
         cpu_synchronize_post_init(cs);
         return 8;
     case S390_VIRT_CPUTM_REGNUM:
-        env->cputm = ldtul_p(mem_buf);
+        env->cputm = ldq_p(mem_buf);
         cpu_synchronize_post_init(cs);
         return 8;
     case S390_VIRT_BEA_REGNUM:
-        env->gbea = ldtul_p(mem_buf);
+        env->gbea = ldq_p(mem_buf);
         cpu_synchronize_post_init(cs);
         return 8;
     case S390_VIRT_PREFIX_REGNUM:
-        env->psa = ldtul_p(mem_buf);
+        env->psa = ldq_p(mem_buf);
         cpu_synchronize_post_init(cs);
         return 8;
     default:
@@ -298,19 +298,19 @@ static int cpu_write_virt_kvm_reg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_VIRT_KVM_PP_REGNUM:
-        env->pp = ldtul_p(mem_buf);
+        env->pp = ldq_p(mem_buf);
         cpu_synchronize_post_init(env_cpu(env));
         return 8;
     case S390_VIRT_KVM_PFT_REGNUM:
-        env->pfault_token = ldtul_p(mem_buf);
+        env->pfault_token = ldq_p(mem_buf);
         cpu_synchronize_post_init(env_cpu(env));
         return 8;
     case S390_VIRT_KVM_PFS_REGNUM:
-        env->pfault_select = ldtul_p(mem_buf);
+        env->pfault_select = ldq_p(mem_buf);
         cpu_synchronize_post_init(env_cpu(env));
         return 8;
     case S390_VIRT_KVM_PFC_REGNUM:
-        env->pfault_compare = ldtul_p(mem_buf);
+        env->pfault_compare = ldq_p(mem_buf);
         cpu_synchronize_post_init(env_cpu(env));
         return 8;
     default:
@@ -338,7 +338,7 @@ static int cpu_write_gs_reg(CPUState *cs, uint8_t *mem_buf, int n)
     S390CPU *cpu = S390_CPU(cs);
     CPUS390XState *env = &cpu->env;
 
-    env->gscb[n] = ldtul_p(mem_buf);
+    env->gscb[n] = ldq_p(mem_buf);
     cpu_synchronize_post_init(env_cpu(env));
     return 8;
 }
Signature · 1 line
2.45.2
Reviewed-by on v2 4/25
#8 lore raw

Re: [PATCH v2 04/25] target/s390x: Replace ldtul_p() -> ldq_p()

Quoted 11 lines · Philippe Mathieu-Daudé

The S390X target is only built for 64-bit.
Using ldtul_p() is pointless, replace by ldq_p().

Mechanical change doing:

   $ sed -i -e 's/ldtul_p/ldq_p/' $(git grep -wl ldtul_p target/s390x/)
---
  target/s390x/gdbstub.c | 30 +++++++++++++++---------------
  1 file changed, 15 insertions(+), 15 deletions(-)

r~

#9 lore raw

PATCH v2 5/25 gdbstub/helpers: Introduce ldtul_$endian_p() helpers

In reply to Philippe Mathieu-Daudé

Introduce ldtul_le_p() and ldtul_be_p() to use directly in place of ldtul_p() when a target endianness is fixed.

---
 include/gdbstub/helpers.h | 2 ++
 1 file changed, 2 insertions(+)
include/gdbstub/helpers.h +2 -0
index fd83e366a51..e783d166865 100644
@@ -99,5 +99,7 @@ static inline uint8_t *gdb_get_reg_ptr(GByteArray *buf, int len)
 #endif
 
 #define ldtul_p(addr) ldn_p(addr, TARGET_LONG_SIZE)
+#define ldtul_le_p(addr) ldn_le_p(addr, TARGET_LONG_SIZE)
+#define ldtul_be_p(addr) ldn_be_p(addr, TARGET_LONG_SIZE)
 
 #endif /* _GDBSTUB_HELPERS_H_ */
Signature · 1 line
2.45.2
#10 lore raw

Re: [PATCH v2 05/25] gdbstub/helpers: Introduce ldtul_$endian_p() helpers

Quoted 13 lines · Philippe Mathieu-Daudé

Introduce ldtul_le_p() and ldtul_be_p() to use directly in place of ldtul_p() when a target endianness is fixed.

---
  include/gdbstub/helpers.h | 2 ++
  1 file changed, 2 insertions(+)
include/gdbstub/helpers.h +0 -0
index fd83e366a51..e783d166865 100644

include/gdbstub/helpers.h static inline uint8_t *gdb_get_reg_ptr(GByteArray *buf, int len) · line 103

Quoted 5 lines
include/gdbstub/helpers.h +2 -0
@@ -99,5 +99,7 @@ static inline uint8_t *gdb_get_reg_ptr(GByteArray *buf, int len)
  #endif
 
  #define ldtul_p(addr) ldn_p(addr, TARGET_LONG_SIZE)
+#define ldtul_le_p(addr) ldn_le_p(addr, TARGET_LONG_SIZE)
+#define ldtul_be_p(addr) ldn_be_p(addr, TARGET_LONG_SIZE)

I'd be happier if these were defined in the preceeding ifdef for now.

r~

#11 lore raw

PATCH v2 6/25 target/alpha: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/alpha/); \
    done
---
 target/alpha/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/alpha/gdbstub.c +1 -1
index bf5091c2a6e..1a7e2dd9202 100644
@@ -59,7 +59,7 @@ int alpha_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
 int alpha_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 {
     CPUAlphaState *env = cpu_env(cs);
-    target_ulong tmp = ldq_p(mem_buf);
+    target_ulong tmp = ldq_le_p(mem_buf);
     CPU_DoubleU d;
 
     switch (n) {
Signature · 1 line
2.45.2
Reviewed-by on v2 6/25
#12 lore raw

Re: [PATCH v2 06/25] target/alpha: Use explicit little-endian LD/ST API

Quoted 12 lines · Philippe Mathieu-Daudé

The Alpha architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

   $ end=le; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/alpha/); \
     done
Quoted 4 lines
---
  target/alpha/gdbstub.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

r~

#13 lore raw

PATCH v2 7/25 target/hexagon: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The Hexagon architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/hexagon/); \
    done
---
 target/hexagon/gdbstub.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
target/hexagon/gdbstub.c +5 -5
index 557b3029785..12d6b3bbcbb 100644
@@ -52,7 +52,7 @@ int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     CPUHexagonState *env = cpu_env(cs);
 
     if (n == HEX_REG_P3_0_ALIASED) {
-        uint32_t p3_0 = ldl_p(mem_buf);
+        uint32_t p3_0 = ldl_le_p(mem_buf);
         for (int i = 0; i < NUM_PREGS; i++) {
             env->pred[i] = extract32(p3_0, i * 8, 8);
         }
@@ -60,14 +60,14 @@ int hexagon_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     }
 
     if (n < TOTAL_PER_THREAD_REGS) {
-        env->gpr[n] = ldl_p(mem_buf);
+        env->gpr[n] = ldl_le_p(mem_buf);
         return sizeof(target_ulong);
     }
 
     n -= TOTAL_PER_THREAD_REGS;
 
     if (n < NUM_PREGS) {
-        env->pred[n] = ldl_p(mem_buf) & 0xff;
+        env->pred[n] = ldl_le_p(mem_buf) & 0xff;
         return sizeof(uint8_t);
     }
 
@@ -117,7 +117,7 @@ static int gdb_put_vreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
 {
     int i;
     for (i = 0; i < ARRAY_SIZE(env->VRegs[n].uw); i++) {
-        env->VRegs[n].uw[i] = ldl_p(mem_buf);
+        env->VRegs[n].uw[i] = ldl_le_p(mem_buf);
         mem_buf += 4;
     }
     return MAX_VEC_SIZE_BYTES;
@@ -127,7 +127,7 @@ static int gdb_put_qreg(CPUHexagonState *env, uint8_t *mem_buf, int n)
 {
     int i;
     for (i = 0; i < ARRAY_SIZE(env->QRegs[n].uw); i++) {
-        env->QRegs[n].uw[i] = ldl_p(mem_buf);
+        env->QRegs[n].uw[i] = ldl_le_p(mem_buf);
         mem_buf += 4;
     }
     return MAX_VEC_SIZE_BYTES / 8;
Signature · 1 line
2.45.2
Reviewed-by on v2 7/25
#14 lore raw

Re: [PATCH v2 07/25] target/hexagon: Use explicit little-endian LD/ST API

Quoted 12 lines · Philippe Mathieu-Daudé

The Hexagon architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

   $ end=le; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/hexagon/); \
     done
Quoted 4 lines
---
  target/hexagon/gdbstub.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)

r~

#15 lore raw

PATCH v2 8/25 hw/i386: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The x86 architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' hw/i386/); \
    done
---
 hw/i386/multiboot.c  | 36 ++++++++++++++++++------------------
 hw/i386/x86-common.c | 26 +++++++++++++-------------
 2 files changed, 31 insertions(+), 31 deletions(-)
hw/i386/multiboot.c +18 -18
index 3332712ab35..ba4ead5270c 100644
@@ -133,9 +133,9 @@ static void mb_add_mod(MultibootState *s,
 
     p = (char *)s->mb_buf + s->offset_mbinfo + MB_MOD_SIZE * s->mb_mods_count;
 
-    stl_p(p + MB_MOD_START,   start);
-    stl_p(p + MB_MOD_END,     end);
-    stl_p(p + MB_MOD_CMDLINE, cmdline_phys);
+    stl_le_p(p + MB_MOD_START,   start);
+    stl_le_p(p + MB_MOD_END,     end);
+    stl_le_p(p + MB_MOD_CMDLINE, cmdline_phys);
 
     mb_debug("mod%02d: "HWADDR_FMT_plx" - "HWADDR_FMT_plx,
              s->mb_mods_count, start, end);
@@ -168,9 +168,9 @@ int load_multiboot(X86MachineState *x86ms,
     /* Ok, let's see if it is a multiboot image.
        The header is 12x32bit long, so the latest entry may be 8192 - 48. */
     for (i = 0; i < (8192 - 48); i += 4) {
-        if (ldl_p(header+i) == 0x1BADB002) {
-            uint32_t checksum = ldl_p(header+i+8);
-            flags = ldl_p(header+i+4);
+        if (ldl_le_p(header+i) == 0x1BADB002) {
+            uint32_t checksum = ldl_le_p(header+i+8);
+            flags = ldl_le_p(header+i+4);
             checksum += flags;
             checksum += (uint32_t)0x1BADB002;
             if (!checksum) {
@@ -223,11 +223,11 @@ int load_multiboot(X86MachineState *x86ms,
                  mb_kernel_size, (size_t)mh_entry_addr);
     } else {
         /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */
-        uint32_t mh_header_addr = ldl_p(header+i+12);
-        uint32_t mh_load_end_addr = ldl_p(header+i+20);
-        uint32_t mh_bss_end_addr = ldl_p(header+i+24);
+        uint32_t mh_header_addr = ldl_le_p(header+i+12);
+        uint32_t mh_load_end_addr = ldl_le_p(header+i+20);
+        uint32_t mh_bss_end_addr = ldl_le_p(header+i+24);
 
-        mh_load_addr = ldl_p(header+i+16);
+        mh_load_addr = ldl_le_p(header+i+16);
         if (mh_header_addr < mh_load_addr) {
             error_report("invalid load_addr address");
             exit(1);
@@ -239,7 +239,7 @@ int load_multiboot(X86MachineState *x86ms,
 
         uint32_t mb_kernel_text_offset = i - (mh_header_addr - mh_load_addr);
         uint32_t mb_load_size = 0;
-        mh_entry_addr = ldl_p(header+i+28);
+        mh_entry_addr = ldl_le_p(header+i+28);
 
         if (mh_load_end_addr) {
             if (mh_load_end_addr < mh_load_addr) {
@@ -364,22 +364,22 @@ int load_multiboot(X86MachineState *x86ms,
 
     /* Commandline support */
     kcmdline = g_strdup_printf("%s %s", kernel_filename, kernel_cmdline);
-    stl_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline));
+    stl_le_p(bootinfo + MBI_CMDLINE, mb_add_cmdline(&mbs, kcmdline));
 
-    stl_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name));
+    stl_le_p(bootinfo + MBI_BOOTLOADER, mb_add_bootloader(&mbs, bootloader_name));
 
-    stl_p(bootinfo + MBI_MODS_ADDR,  mbs.mb_buf_phys + mbs.offset_mbinfo);
-    stl_p(bootinfo + MBI_MODS_COUNT, mbs.mb_mods_count); /* mods_count */
+    stl_le_p(bootinfo + MBI_MODS_ADDR,  mbs.mb_buf_phys + mbs.offset_mbinfo);
+    stl_le_p(bootinfo + MBI_MODS_COUNT, mbs.mb_mods_count); /* mods_count */
 
     /* the kernel is where we want it to be now */
-    stl_p(bootinfo + MBI_FLAGS, MULTIBOOT_FLAGS_MEMORY
+    stl_le_p(bootinfo + MBI_FLAGS, MULTIBOOT_FLAGS_MEMORY
                                 | MULTIBOOT_FLAGS_BOOT_DEVICE
                                 | MULTIBOOT_FLAGS_CMDLINE
                                 | MULTIBOOT_FLAGS_MODULES
                                 | MULTIBOOT_FLAGS_MMAP
                                 | MULTIBOOT_FLAGS_BOOTLOADER);
-    stl_p(bootinfo + MBI_BOOT_DEVICE, 0x8000ffff); /* XXX: use the -boot switch? */
-    stl_p(bootinfo + MBI_MMAP_ADDR,   ADDR_E820_MAP);
+    stl_le_p(bootinfo + MBI_BOOT_DEVICE, 0x8000ffff); /* XXX: use the -boot switch? */
+    stl_le_p(bootinfo + MBI_MMAP_ADDR,   ADDR_E820_MAP);
 
     mb_debug("multiboot: entry_addr = %#x", mh_entry_addr);
     mb_debug("           mb_buf_phys   = "HWADDR_FMT_plx, mbs.mb_buf_phys);
hw/i386/x86-common.c +13 -13
index 992ea1f25e9..b86c38212ea 100644
@@ -586,7 +586,7 @@ static bool load_elfboot(const char *kernel_filename,
     uint64_t elf_low, elf_high;
     int kernel_size;
 
-    if (ldl_p(header) != 0x464c457f) {
+    if (ldl_le_p(header) != 0x464c457f) {
         return false; /* no elfboot */
     }
 
@@ -669,8 +669,8 @@ void x86_load_linux(X86MachineState *x86ms,
      * kernel protocol version.
      * Please see https://www.kernel.org/doc/Documentation/x86/boot.txt
      */
-    if (ldl_p(header + 0x202) == 0x53726448) /* Magic signature "HdrS" */ {
-        protocol = lduw_p(header + 0x206);
+    if (ldl_le_p(header + 0x202) == 0x53726448) /* Magic signature "HdrS" */ {
+        protocol = lduw_le_p(header + 0x206);
     } else {
         /*
          * This could be a multiboot kernel. If it is, let's stop treating it
@@ -762,7 +762,7 @@ void x86_load_linux(X86MachineState *x86ms,
 
     /* highest address for loading the initrd */
     if (protocol >= 0x20c &&
-        lduw_p(header + 0x236) & XLF_CAN_BE_LOADED_ABOVE_4G) {
+        lduw_le_p(header + 0x236) & XLF_CAN_BE_LOADED_ABOVE_4G) {
         /*
          * Linux has supported initrd up to 4 GB for a very long time (2007,
          * long before XLF_CAN_BE_LOADED_ABOVE_4G which was added in 2013),
@@ -781,7 +781,7 @@ void x86_load_linux(X86MachineState *x86ms,
          */
         initrd_max = UINT32_MAX;
     } else if (protocol >= 0x203) {
-        initrd_max = ldl_p(header + 0x22c);
+        initrd_max = ldl_le_p(header + 0x22c);
     } else {
         initrd_max = 0x37ffffff;
     }
@@ -797,10 +797,10 @@ void x86_load_linux(X86MachineState *x86ms,
     sev_load_ctx.cmdline_size = strlen(kernel_cmdline) + 1;
 
     if (protocol >= 0x202) {
-        stl_p(header + 0x228, cmdline_addr);
+        stl_le_p(header + 0x228, cmdline_addr);
     } else {
-        stw_p(header + 0x20, 0xA33F);
-        stw_p(header + 0x22, cmdline_addr - real_addr);
+        stw_le_p(header + 0x20, 0xA33F);
+        stw_le_p(header + 0x22, cmdline_addr - real_addr);
     }
 
     /* handle vga= parameter */
@@ -824,7 +824,7 @@ void x86_load_linux(X86MachineState *x86ms,
                 exit(1);
             }
         }
-        stw_p(header + 0x1fa, video_mode);
+        stw_le_p(header + 0x1fa, video_mode);
     }
 
     /* loader type */
@@ -839,7 +839,7 @@ void x86_load_linux(X86MachineState *x86ms,
     /* heap */
     if (protocol >= 0x201) {
         header[0x211] |= 0x80; /* CAN_USE_HEAP */
-        stw_p(header + 0x224, cmdline_addr - real_addr - 0x200);
+        stw_le_p(header + 0x224, cmdline_addr - real_addr - 0x200);
     }
 
     /* load initrd */
@@ -879,8 +879,8 @@ void x86_load_linux(X86MachineState *x86ms,
         sev_load_ctx.initrd_data = initrd_data;
         sev_load_ctx.initrd_size = initrd_size;
 
-        stl_p(header + 0x218, initrd_addr);
-        stl_p(header + 0x21c, initrd_size);
+        stl_le_p(header + 0x218, initrd_addr);
+        stl_le_p(header + 0x21c, initrd_size);
     }
 
     /* load kernel and setup */
@@ -926,7 +926,7 @@ void x86_load_linux(X86MachineState *x86ms,
         kernel_size = setup_data_offset + sizeof(struct setup_data) + dtb_size;
         kernel = g_realloc(kernel, kernel_size);
 
-        stq_p(header + 0x250, prot_addr + setup_data_offset);
+        stq_le_p(header + 0x250, prot_addr + setup_data_offset);
 
         setup_data = (struct setup_data *)(kernel + setup_data_offset);
         setup_data->next = 0;
Signature · 1 line
2.45.2
Reviewed-by on v2 8/25
#16 lore raw

Re: [PATCH v2 08/25] hw/i386: Use explicit little-endian LD/ST API

Quoted 12 lines · Philippe Mathieu-Daudé

The x86 architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

   $ end=le; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' hw/i386/); \
     done
Quoted 5 lines
---
  hw/i386/multiboot.c  | 36 ++++++++++++++++++------------------
  hw/i386/x86-common.c | 26 +++++++++++++-------------
  2 files changed, 31 insertions(+), 31 deletions(-)

r~

#17 lore raw

PATCH v2 9/25 target/i386: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The x86 architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/i386/); \
    done
---
 target/i386/gdbstub.c                | 30 +++++++++++++-------------
 target/i386/tcg/sysemu/excp_helper.c |  4 ++--
 target/i386/xsave_helper.c           | 32 ++++++++++++++--------------
 3 files changed, 33 insertions(+), 33 deletions(-)
target/i386/gdbstub.c +15 -15
index 4acf485879e..28ccf06309d 100644
@@ -89,10 +89,10 @@ static int gdb_read_reg_cs64(uint32_t hflags, GByteArray *buf, target_ulong val)
 static int gdb_write_reg_cs64(uint32_t hflags, uint8_t *buf, target_ulong *val)
 {
     if (hflags & HF_CS64_MASK) {
-        *val = ldq_p(buf);
+        *val = ldq_le_p(buf);
         return 8;
     }
-    *val = ldl_p(buf);
+    *val = ldl_le_p(buf);
     return 4;
 }
 
@@ -221,7 +221,7 @@ int x86_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
 static int x86_cpu_gdb_load_seg(X86CPU *cpu, X86Seg sreg, uint8_t *mem_buf)
 {
     CPUX86State *env = &cpu->env;
-    uint16_t selector = ldl_p(mem_buf);
+    uint16_t selector = ldl_le_p(mem_buf);
 
     if (selector != env->segs[sreg].selector) {
 #if defined(CONFIG_USER_ONLY)
@@ -262,15 +262,15 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     if (n < CPU_NB_REGS) {
         if (TARGET_LONG_BITS == 64) {
             if (env->hflags & HF_CS64_MASK) {
-                env->regs[gpr_map[n]] = ldtul_p(mem_buf);
+                env->regs[gpr_map[n]] = ldtul_le_p(mem_buf);
             } else if (n < CPU_NB_REGS32) {
-                env->regs[gpr_map[n]] = ldtul_p(mem_buf) & 0xffffffffUL;
+                env->regs[gpr_map[n]] = ldtul_le_p(mem_buf) & 0xffffffffUL;
             }
             return sizeof(target_ulong);
         } else if (n < CPU_NB_REGS32) {
             n = gpr_map32[n];
             env->regs[n] &= ~0xffffffffUL;
-            env->regs[n] |= (uint32_t)ldl_p(mem_buf);
+            env->regs[n] |= (uint32_t)ldl_le_p(mem_buf);
             return 4;
         }
     } else if (n >= IDX_FP_REGS && n < IDX_FP_REGS + 8) {
@@ -281,8 +281,8 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     } else if (n >= IDX_XMM_REGS && n < IDX_XMM_REGS + CPU_NB_REGS) {
         n -= IDX_XMM_REGS;
         if (n < CPU_NB_REGS32 || TARGET_LONG_BITS == 64) {
-            env->xmm_regs[n].ZMM_Q(0) = ldq_p(mem_buf);
-            env->xmm_regs[n].ZMM_Q(1) = ldq_p(mem_buf + 8);
+            env->xmm_regs[n].ZMM_Q(0) = ldq_le_p(mem_buf);
+            env->xmm_regs[n].ZMM_Q(1) = ldq_le_p(mem_buf + 8);
             return 16;
         }
     } else {
@@ -290,18 +290,18 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
         case IDX_IP_REG:
             if (TARGET_LONG_BITS == 64) {
                 if (env->hflags & HF_CS64_MASK) {
-                    env->eip = ldq_p(mem_buf);
+                    env->eip = ldq_le_p(mem_buf);
                 } else {
-                    env->eip = ldq_p(mem_buf) & 0xffffffffUL;
+                    env->eip = ldq_le_p(mem_buf) & 0xffffffffUL;
                 }
                 return 8;
             } else {
                 env->eip &= ~0xffffffffUL;
-                env->eip |= (uint32_t)ldl_p(mem_buf);
+                env->eip |= (uint32_t)ldl_le_p(mem_buf);
                 return 4;
             }
         case IDX_FLAGS_REG:
-            env->eflags = ldl_p(mem_buf);
+            env->eflags = ldl_le_p(mem_buf);
             return 4;
 
         case IDX_SEG_REGS:
@@ -327,10 +327,10 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
             return 4;
 
         case IDX_FP_REGS + 8:
-            cpu_set_fpuc(env, ldl_p(mem_buf));
+            cpu_set_fpuc(env, ldl_le_p(mem_buf));
             return 4;
         case IDX_FP_REGS + 9:
-            tmp = ldl_p(mem_buf);
+            tmp = ldl_le_p(mem_buf);
             env->fpstt = (tmp >> 11) & 7;
             env->fpus = tmp & ~0x3800;
             return 4;
@@ -348,7 +348,7 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
             return 4;
 
         case IDX_MXCSR_REG:
-            cpu_set_mxcsr(env, ldl_p(mem_buf));
+            cpu_set_mxcsr(env, ldl_le_p(mem_buf));
             return 4;
 
         case IDX_CTL_CR0_REG:
target/i386/tcg/sysemu/excp_helper.c +2 -2
index 8fb05b1f531..de6765099f3 100644
@@ -86,7 +86,7 @@ static bool ptw_translate(PTETranslate *inout, hwaddr addr, uint64_t ra)
 static inline uint32_t ptw_ldl(const PTETranslate *in, uint64_t ra)
 {
     if (likely(in->haddr)) {
-        return ldl_p(in->haddr);
+        return ldl_le_p(in->haddr);
     }
     return cpu_ldl_mmuidx_ra(in->env, in->gaddr, in->ptw_idx, ra);
 }
@@ -94,7 +94,7 @@ static inline uint32_t ptw_ldl(const PTETranslate *in, uint64_t ra)
 static inline uint64_t ptw_ldq(const PTETranslate *in, uint64_t ra)
 {
     if (likely(in->haddr)) {
-        return ldq_p(in->haddr);
+        return ldq_le_p(in->haddr);
     }
     return cpu_ldq_mmuidx_ra(in->env, in->gaddr, in->ptw_idx, ra);
 }
target/i386/xsave_helper.c +16 -16
index 996e9f3bfef..fc10bfa6718 100644
@@ -43,8 +43,8 @@ void x86_cpu_xsave_all_areas(X86CPU *cpu, void *buf, uint32_t buflen)
     for (i = 0; i < CPU_NB_REGS; i++) {
         uint8_t *xmm = legacy->xmm_regs[i];
 
-        stq_p(xmm,     env->xmm_regs[i].ZMM_Q(0));
-        stq_p(xmm + 8, env->xmm_regs[i].ZMM_Q(1));
+        stq_le_p(xmm,     env->xmm_regs[i].ZMM_Q(0));
+        stq_le_p(xmm + 8, env->xmm_regs[i].ZMM_Q(1));
     }
 
     header->xstate_bv = env->xstate_bv;
@@ -58,8 +58,8 @@ void x86_cpu_xsave_all_areas(X86CPU *cpu, void *buf, uint32_t buflen)
         for (i = 0; i < CPU_NB_REGS; i++) {
             uint8_t *ymmh = avx->ymmh[i];
 
-            stq_p(ymmh,     env->xmm_regs[i].ZMM_Q(2));
-            stq_p(ymmh + 8, env->xmm_regs[i].ZMM_Q(3));
+            stq_le_p(ymmh,     env->xmm_regs[i].ZMM_Q(2));
+            stq_le_p(ymmh + 8, env->xmm_regs[i].ZMM_Q(3));
         }
     }
 
@@ -101,10 +101,10 @@ void x86_cpu_xsave_all_areas(X86CPU *cpu, void *buf, uint32_t buflen)
         for (i = 0; i < CPU_NB_REGS; i++) {
             uint8_t *zmmh = zmm_hi256->zmm_hi256[i];
 
-            stq_p(zmmh,      env->xmm_regs[i].ZMM_Q(4));
-            stq_p(zmmh + 8,  env->xmm_regs[i].ZMM_Q(5));
-            stq_p(zmmh + 16, env->xmm_regs[i].ZMM_Q(6));
-            stq_p(zmmh + 24, env->xmm_regs[i].ZMM_Q(7));
+            stq_le_p(zmmh,      env->xmm_regs[i].ZMM_Q(4));
+            stq_le_p(zmmh + 8,  env->xmm_regs[i].ZMM_Q(5));
+            stq_le_p(zmmh + 16, env->xmm_regs[i].ZMM_Q(6));
+            stq_le_p(zmmh + 24, env->xmm_regs[i].ZMM_Q(7));
         }
 
 #ifdef TARGET_X86_64
@@ -177,8 +177,8 @@ void x86_cpu_xrstor_all_areas(X86CPU *cpu, const void *buf, uint32_t buflen)
     for (i = 0; i < CPU_NB_REGS; i++) {
         const uint8_t *xmm = legacy->xmm_regs[i];
 
-        env->xmm_regs[i].ZMM_Q(0) = ldq_p(xmm);
-        env->xmm_regs[i].ZMM_Q(1) = ldq_p(xmm + 8);
+        env->xmm_regs[i].ZMM_Q(0) = ldq_le_p(xmm);
+        env->xmm_regs[i].ZMM_Q(1) = ldq_le_p(xmm + 8);
     }
 
     env->xstate_bv = header->xstate_bv;
@@ -191,8 +191,8 @@ void x86_cpu_xrstor_all_areas(X86CPU *cpu, const void *buf, uint32_t buflen)
         for (i = 0; i < CPU_NB_REGS; i++) {
             const uint8_t *ymmh = avx->ymmh[i];
 
-            env->xmm_regs[i].ZMM_Q(2) = ldq_p(ymmh);
-            env->xmm_regs[i].ZMM_Q(3) = ldq_p(ymmh + 8);
+            env->xmm_regs[i].ZMM_Q(2) = ldq_le_p(ymmh);
+            env->xmm_regs[i].ZMM_Q(3) = ldq_le_p(ymmh + 8);
         }
     }
 
@@ -241,10 +241,10 @@ void x86_cpu_xrstor_all_areas(X86CPU *cpu, const void *buf, uint32_t buflen)
         for (i = 0; i < CPU_NB_REGS; i++) {
             const uint8_t *zmmh = zmm_hi256->zmm_hi256[i];
 
-            env->xmm_regs[i].ZMM_Q(4) = ldq_p(zmmh);
-            env->xmm_regs[i].ZMM_Q(5) = ldq_p(zmmh + 8);
-            env->xmm_regs[i].ZMM_Q(6) = ldq_p(zmmh + 16);
-            env->xmm_regs[i].ZMM_Q(7) = ldq_p(zmmh + 24);
+            env->xmm_regs[i].ZMM_Q(4) = ldq_le_p(zmmh);
+            env->xmm_regs[i].ZMM_Q(5) = ldq_le_p(zmmh + 8);
+            env->xmm_regs[i].ZMM_Q(6) = ldq_le_p(zmmh + 16);
+            env->xmm_regs[i].ZMM_Q(7) = ldq_le_p(zmmh + 24);
         }
 
 #ifdef TARGET_X86_64
Signature · 1 line
2.45.2
Reviewed-by on v2 9/25
#18 lore raw

Re: [PATCH v2 09/25] target/i386: Use explicit little-endian LD/ST API

Quoted 12 lines · Philippe Mathieu-Daudé

The x86 architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

   $ end=le; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/i386/); \
     done
Quoted 6 lines
---
  target/i386/gdbstub.c                | 30 +++++++++++++-------------
  target/i386/tcg/sysemu/excp_helper.c |  4 ++--
  target/i386/xsave_helper.c           | 32 ++++++++++++++--------------
  3 files changed, 33 insertions(+), 33 deletions(-)

r~

#19 lore raw

PATCH v2 10/25 target/avr: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The AVR architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/avr/); \
    done
---
 target/avr/gdbstub.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/avr/gdbstub.c +2 -2
index d6d3c1479b3..aea71282a58 100644
@@ -69,13 +69,13 @@ int avr_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 
     /*  SP */
     if (n == 33) {
-        env->sp = lduw_p(mem_buf);
+        env->sp = lduw_le_p(mem_buf);
         return 2;
     }
 
     /*  PC */
     if (n == 34) {
-        env->pc_w = ldl_p(mem_buf) / 2;
+        env->pc_w = ldl_le_p(mem_buf) / 2;
         return 4;
     }
 
Signature · 1 line
2.45.2
Reviewed-by on v2 10/25
#20 lore raw

Re: [PATCH v2 10/25] target/avr: Use explicit little-endian LD/ST API

Quoted 12 lines · Philippe Mathieu-Daudé

The AVR architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

   $ end=le; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/avr/); \
     done
Quoted 4 lines
---
  target/avr/gdbstub.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

r~

#21 lore raw

PATCH v2 11/25 linux-user/i386: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The x86 architecture uses little endianness. Directly use the little-endian LD/ST API.

---
 linux-user/i386/signal.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/i386/signal.c +2 -2
index cb90711834f..0f11dba831f 100644
@@ -754,8 +754,8 @@ static bool restore_sigcontext(CPUX86State *env, struct target_sigcontext *sc)
     env->eip = tswapl(sc->rip);
 #endif
 
-    cpu_x86_load_seg(env, R_CS, lduw_p(&sc->cs) | 3);
-    cpu_x86_load_seg(env, R_SS, lduw_p(&sc->ss) | 3);
+    cpu_x86_load_seg(env, R_CS, lduw_le_p(&sc->cs) | 3);
+    cpu_x86_load_seg(env, R_SS, lduw_le_p(&sc->ss) | 3);
 
     tmpflags = tswapl(sc->eflags);
     env->eflags = (env->eflags & ~0x40DD5) | (tmpflags & 0x40DD5);
Signature · 1 line
2.45.2
#23 lore raw

PATCH v2 12/25 target/loongarch: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The LoongArch architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/loongarch/); \
    done
---
 target/loongarch/gdbstub.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target/loongarch/gdbstub.c +4 -4
index 3a03cf9cba9..dafa4feb75d 100644
@@ -67,10 +67,10 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     int length = 0;
 
     if (is_la64(env)) {
-        tmp = ldq_p(mem_buf);
+        tmp = ldq_le_p(mem_buf);
         read_length = 8;
     } else {
-        tmp = ldl_p(mem_buf);
+        tmp = ldl_le_p(mem_buf);
         read_length = 4;
     }
 
@@ -106,13 +106,13 @@ static int loongarch_gdb_set_fpu(CPUState *cs, uint8_t *mem_buf, int n)
     int length = 0;
 
     if (0 <= n && n < 32) {
-        env->fpr[n].vreg.D(0) = ldq_p(mem_buf);
+        env->fpr[n].vreg.D(0) = ldq_le_p(mem_buf);
         length = 8;
     } else if (32 <= n && n < 40) {
         env->cf[n - 32] = ldub_p(mem_buf);
         length = 1;
     } else if (n == 40) {
-        env->fcsr0 = ldl_p(mem_buf);
+        env->fcsr0 = ldl_le_p(mem_buf);
         length = 4;
     }
     return length;
Signature · 1 line
2.45.2
Reviewed-by on v2 12/25
#24 lore raw

Re: [PATCH v2 12/25] target/loongarch: Use explicit little-endian LD/ST API

Quoted 12 lines · Philippe Mathieu-Daudé

The LoongArch architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

   $ end=le; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/loongarch/); \
     done
Quoted 4 lines
---
  target/loongarch/gdbstub.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

r~

#25 lore raw

PATCH v2 13/25 target/sh4: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

Since commit 73ceb12960e ("Remove the unused sh4eb target") we only build the SH4 architecture for little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/sh4/); \
    done
---
 target/sh4/gdbstub.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
target/sh4/gdbstub.c +18 -18
index 75926d4e049..194be1d5db3 100644
@@ -80,59 +80,59 @@ int superh_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     switch (n) {
     case 0 ... 7:
         if ((env->sr & (1u << SR_MD)) && (env->sr & (1u << SR_RB))) {
-            env->gregs[n + 16] = ldl_p(mem_buf);
+            env->gregs[n + 16] = ldl_le_p(mem_buf);
         } else {
-            env->gregs[n] = ldl_p(mem_buf);
+            env->gregs[n] = ldl_le_p(mem_buf);
         }
         break;
     case 8 ... 15:
-        env->gregs[n] = ldl_p(mem_buf);
+        env->gregs[n] = ldl_le_p(mem_buf);
         break;
     case 16:
-        env->pc = ldl_p(mem_buf);
+        env->pc = ldl_le_p(mem_buf);
         break;
     case 17:
-        env->pr = ldl_p(mem_buf);
+        env->pr = ldl_le_p(mem_buf);
         break;
     case 18:
-        env->gbr = ldl_p(mem_buf);
+        env->gbr = ldl_le_p(mem_buf);
         break;
     case 19:
-        env->vbr = ldl_p(mem_buf);
+        env->vbr = ldl_le_p(mem_buf);
         break;
     case 20:
-        env->mach = ldl_p(mem_buf);
+        env->mach = ldl_le_p(mem_buf);
         break;
     case 21:
-        env->macl = ldl_p(mem_buf);
+        env->macl = ldl_le_p(mem_buf);
         break;
     case 22:
-        cpu_write_sr(env, ldl_p(mem_buf));
+        cpu_write_sr(env, ldl_le_p(mem_buf));
         break;
     case 23:
-        env->fpul = ldl_p(mem_buf);
+        env->fpul = ldl_le_p(mem_buf);
         break;
     case 24:
-        env->fpscr = ldl_p(mem_buf);
+        env->fpscr = ldl_le_p(mem_buf);
         break;
     case 25 ... 40:
         if (env->fpscr & FPSCR_FR) {
-            env->fregs[n - 9] = ldl_p(mem_buf);
+            env->fregs[n - 9] = ldl_le_p(mem_buf);
         } else {
-            env->fregs[n - 25] = ldl_p(mem_buf);
+            env->fregs[n - 25] = ldl_le_p(mem_buf);
         }
         break;
     case 41:
-        env->ssr = ldl_p(mem_buf);
+        env->ssr = ldl_le_p(mem_buf);
         break;
     case 42:
-        env->spc = ldl_p(mem_buf);
+        env->spc = ldl_le_p(mem_buf);
         break;
     case 43 ... 50:
-        env->gregs[n - 43] = ldl_p(mem_buf);
+        env->gregs[n - 43] = ldl_le_p(mem_buf);
         break;
     case 51 ... 58:
-        env->gregs[n - (51 - 16)] = ldl_p(mem_buf);
+        env->gregs[n - (51 - 16)] = ldl_le_p(mem_buf);
         break;
     default:
         return 0;
Signature · 1 line
2.45.2
#26 lore raw

Re: [PATCH v2 13/25] target/sh4: Use explicit little-endian LD/ST API

target/sh4/gdbstub.c int superh_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)

Quoted 23 lines · Philippe Mathieu-Daudé

Since commit 73ceb12960e ("Remove the unused sh4eb target") we only build the SH4 architecture for little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

   $ end=le; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/sh4/); \
     done
---
  target/sh4/gdbstub.c | 36 ++++++++++++++++++------------------
  1 file changed, 18 insertions(+), 18 deletions(-)
target/sh4/gdbstub.c +0 -0
index 75926d4e049..194be1d5db3 100644
@@ -80,59 +80,59 @@ int superh_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)

As rth probably noticed, this is is wrong for the
sh4eb-linux-user target which we still build.

#27 lore raw

PATCH v2 14/25 target/tricore: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The TriCore architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/tricore/); \
    done
---
 target/tricore/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/tricore/gdbstub.c +1 -1
index 29a70051ffe..0b73b1280e0 100644
@@ -124,7 +124,7 @@ int tricore_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     CPUTriCoreState *env = cpu_env(cs);
     uint32_t tmp;
 
-    tmp = ldl_p(mem_buf);
+    tmp = ldl_le_p(mem_buf);
 
     if (n < 16) { /* data registers */
         env->gpr_d[n] = tmp;
Signature · 1 line
2.45.2
Reviewed-by on v2 14/25
#28 lore raw

Re: [PATCH v2 14/25] target/tricore: Use explicit little-endian LD/ST API

Quoted 22 lines · Philippe Mathieu-Daudé

The TriCore architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

   $ end=le; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/tricore/); \
     done
---
  target/tricore/gdbstub.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/tricore/gdbstub.c +0 -0
index 29a70051ffe..0b73b1280e0 100644

target/tricore/gdbstub.c int tricore_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) · line 130

Quoted 8 lines
target/tricore/gdbstub.c +1 -1
@@ -124,7 +124,7 @@ int tricore_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
      CPUTriCoreState *env = cpu_env(cs);
      uint32_t tmp;
 
-    tmp = ldl_p(mem_buf);
+    tmp = ldl_le_p(mem_buf);
 
      if (n < 16) { /* data registers */
          env->gpr_d[n] = tmp;

r~

#29 lore raw

PATCH v2 15/25 target/rx: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The RX architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/rx/); \
    done
---
 target/rx/cpu.c     |  2 +-
 target/rx/gdbstub.c | 24 ++++++++++++------------
 2 files changed, 13 insertions(+), 13 deletions(-)
target/rx/cpu.c +1 -1
index 36d2a6f1890..458b8ee072d 100644
@@ -86,7 +86,7 @@ static void rx_cpu_reset_hold(Object *obj, ResetType type)
     resetvec = rom_ptr(0xfffffffc, 4);
     if (resetvec) {
         /* In the case of kernel, it is ignored because it is not set. */
-        env->pc = ldl_p(resetvec);
+        env->pc = ldl_le_p(resetvec);
     }
     rx_cpu_unpack_psw(env, 0, 1);
     env->regs[0] = env->isp = env->usp = 0;
target/rx/gdbstub.c +12 -12
index f222bf003be..30074c9da7b 100644
@@ -56,7 +56,7 @@ int rx_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     uint32_t psw;
     switch (n) {
     case 0 ... 15:
-        env->regs[n] = ldl_p(mem_buf);
+        env->regs[n] = ldl_le_p(mem_buf);
         if (n == 0) {
             if (env->psw_u) {
                 env->usp = env->regs[0];
@@ -66,38 +66,38 @@ int rx_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
         }
         break;
     case 16:
-        env->usp = ldl_p(mem_buf);
+        env->usp = ldl_le_p(mem_buf);
         if (env->psw_u) {
-            env->regs[0] = ldl_p(mem_buf);
+            env->regs[0] = ldl_le_p(mem_buf);
         }
         break;
     case 17:
-        env->isp = ldl_p(mem_buf);
+        env->isp = ldl_le_p(mem_buf);
         if (!env->psw_u) {
-            env->regs[0] = ldl_p(mem_buf);
+            env->regs[0] = ldl_le_p(mem_buf);
         }
         break;
     case 18:
-        psw = ldl_p(mem_buf);
+        psw = ldl_le_p(mem_buf);
         rx_cpu_unpack_psw(env, psw, 1);
         break;
     case 19:
-        env->pc = ldl_p(mem_buf);
+        env->pc = ldl_le_p(mem_buf);
         break;
     case 20:
-        env->intb = ldl_p(mem_buf);
+        env->intb = ldl_le_p(mem_buf);
         break;
     case 21:
-        env->bpsw = ldl_p(mem_buf);
+        env->bpsw = ldl_le_p(mem_buf);
         break;
     case 22:
-        env->bpc = ldl_p(mem_buf);
+        env->bpc = ldl_le_p(mem_buf);
         break;
     case 23:
-        env->fintv = ldl_p(mem_buf);
+        env->fintv = ldl_le_p(mem_buf);
         break;
     case 24:
-        env->fpsw = ldl_p(mem_buf);
+        env->fpsw = ldl_le_p(mem_buf);
         break;
     case 25:
         return 8;
Signature · 1 line
2.45.2
#30 lore raw

PATCH v2 16/25 target/riscv: Use explicit little-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The Risc-V architecture uses little endianness. Directly use the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/riscv/); \
    done
---
 target/riscv/gdbstub.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
target/riscv/gdbstub.c +7 -7
index c07df972f1e..2e042f117f3 100644
@@ -84,15 +84,15 @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (mcc->misa_mxl_max) {
     case MXL_RV32:
-        tmp = (int32_t)ldl_p(mem_buf);
+        tmp = (int32_t)ldl_le_p(mem_buf);
         length = 4;
         break;
     case MXL_RV64:
     case MXL_RV128:
         if (env->xl < MXL_RV64) {
-            tmp = (int32_t)ldq_p(mem_buf);
+            tmp = (int32_t)ldq_le_p(mem_buf);
         } else {
-            tmp = ldq_p(mem_buf);
+            tmp = ldq_le_p(mem_buf);
         }
         length = 8;
         break;
@@ -130,7 +130,7 @@ static int riscv_gdb_set_fpu(CPUState *cs, uint8_t *mem_buf, int n)
     CPURISCVState *env = &cpu->env;
 
     if (n < 32) {
-        env->fpr[n] = ldq_p(mem_buf); /* always 64-bit */
+        env->fpr[n] = ldq_le_p(mem_buf); /* always 64-bit */
         return sizeof(uint64_t);
     }
     return 0;
@@ -162,7 +162,7 @@ static int riscv_gdb_set_vector(CPUState *cs, uint8_t *mem_buf, int n)
     if (n < 32) {
         int i;
         for (i = 0; i < vlenb; i += 8) {
-            env->vreg[(n * vlenb + i) / 8] = ldq_p(mem_buf + i);
+            env->vreg[(n * vlenb + i) / 8] = ldq_le_p(mem_buf + i);
         }
         return vlenb;
     }
@@ -193,7 +193,7 @@ static int riscv_gdb_set_csr(CPUState *cs, uint8_t *mem_buf, int n)
     CPURISCVState *env = &cpu->env;
 
     if (n < CSR_TABLE_SIZE) {
-        target_ulong val = ldtul_p(mem_buf);
+        target_ulong val = ldtul_le_p(mem_buf);
         int result;
 
         result = riscv_csrrw_debug(env, n, NULL, val, -1);
@@ -226,7 +226,7 @@ static int riscv_gdb_set_virtual(CPUState *cs, uint8_t *mem_buf, int n)
         RISCVCPU *cpu = RISCV_CPU(cs);
         CPURISCVState *env = &cpu->env;
 
-        env->priv = ldtul_p(mem_buf) & 0x3;
+        env->priv = ldtul_le_p(mem_buf) & 0x3;
         if (env->priv == PRV_RESERVED) {
             env->priv = PRV_S;
         }
Signature · 1 line
2.45.2
#31 lore raw

PATCH v2 17/25 hw/m68k: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The M68K architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

  $ end=be; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' hw/m68k/); \
    done
---
 hw/m68k/bootinfo.h  | 28 ++++++++++++++--------------
 hw/m68k/mcf5208.c   |  2 +-
 hw/m68k/next-cube.c |  2 +-
 hw/m68k/q800.c      |  4 ++--
 4 files changed, 18 insertions(+), 18 deletions(-)
hw/m68k/bootinfo.h +14 -14
index 70c1dc0e8c3..0b3e7c4ea01 100644
@@ -14,39 +14,39 @@
 
 #define BOOTINFO0(base, id) \
     do { \
-        stw_p(base, id); \
+        stw_be_p(base, id); \
         base += 2; \
-        stw_p(base, sizeof(struct bi_record)); \
+        stw_be_p(base, sizeof(struct bi_record)); \
         base += 2; \
     } while (0)
 
 #define BOOTINFO1(base, id, value) \
     do { \
-        stw_p(base, id); \
+        stw_be_p(base, id); \
         base += 2; \
-        stw_p(base, sizeof(struct bi_record) + 4); \
+        stw_be_p(base, sizeof(struct bi_record) + 4); \
         base += 2; \
-        stl_p(base, value); \
+        stl_be_p(base, value); \
         base += 4; \
     } while (0)
 
 #define BOOTINFO2(base, id, value1, value2) \
     do { \
-        stw_p(base, id); \
+        stw_be_p(base, id); \
         base += 2; \
-        stw_p(base, sizeof(struct bi_record) + 8); \
+        stw_be_p(base, sizeof(struct bi_record) + 8); \
         base += 2; \
-        stl_p(base, value1); \
+        stl_be_p(base, value1); \
         base += 4; \
-        stl_p(base, value2); \
+        stl_be_p(base, value2); \
         base += 4; \
     } while (0)
 
 #define BOOTINFOSTR(base, id, string) \
     do { \
-        stw_p(base, id); \
+        stw_be_p(base, id); \
         base += 2; \
-        stw_p(base, \
+        stw_be_p(base, \
                  (sizeof(struct bi_record) + strlen(string) + \
                   1 /* null termination */ + 3 /* padding */) & ~3); \
         base += 2; \
@@ -59,13 +59,13 @@
 
 #define BOOTINFODATA(base, id, data, len) \
     do { \
-        stw_p(base, id); \
+        stw_be_p(base, id); \
         base += 2; \
-        stw_p(base, \
+        stw_be_p(base, \
                  (sizeof(struct bi_record) + len + \
                   2 /* length field */ + 3 /* padding */) & ~3); \
         base += 2; \
-        stw_p(base, len); \
+        stw_be_p(base, len); \
         base += 2; \
         for (unsigned i_ = 0; i_ < len; ++i_) { \
             stb_p(base++, data[i_]); \
hw/m68k/mcf5208.c +1 -1
index b6677ad6bc3..e37cd50d189 100644
@@ -359,7 +359,7 @@ static void mcf5208evb_init(MachineState *machine)
         /* Initial PC is always at offset 4 in firmware binaries */
         ptr = rom_ptr(0x4, 4);
         assert(ptr != NULL);
-        env->pc = ldl_p(ptr);
+        env->pc = ldl_be_p(ptr);
     }
 
     /* Load kernel.  */
hw/m68k/next-cube.c +1 -1
index 9b78767ea8e..9832213e7ec 100644
@@ -1036,7 +1036,7 @@ static void next_cube_init(MachineState *machine)
         /* Initial PC is always at offset 4 in firmware binaries */
         ptr = rom_ptr(0x01000004, 4);
         g_assert(ptr != NULL);
-        env->pc = ldl_p(ptr);
+        env->pc = ldl_be_p(ptr);
         if (env->pc >= 0x01020000) {
             error_report("'%s' does not seem to be a valid firmware image.",
                          bios_name);
hw/m68k/q800.c +2 -2
index fa7683bf76f..556604e1dcf 100644
@@ -684,9 +684,9 @@ static void q800_machine_init(MachineState *machine)
 
             ptr = rom_ptr(MACROM_ADDR, bios_size);
             assert(ptr != NULL);
-            stl_phys(cs->as, 0, ldl_p(ptr));    /* reset initial SP */
+            stl_phys(cs->as, 0, ldl_be_p(ptr));    /* reset initial SP */
             stl_phys(cs->as, 4,
-                     MACROM_ADDR + ldl_p(ptr + 4)); /* reset initial PC */
+                     MACROM_ADDR + ldl_be_p(ptr + 4)); /* reset initial PC */
         }
     }
 }
Signature · 1 line
2.45.2
author Reviewed-by Thomas Huth on v2 17/25
#32 lore raw

Re: [PATCH v2 17/25] hw/m68k: Use explicit big-endian LD/ST API

Quoted 5 lines · Philippe Mathieu-Daudé

The M68K architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

Quoted 8 lines
   $ end=be; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' hw/m68k/); \
     done

Per v1:

Quoted 6 lines
---
  hw/m68k/bootinfo.h  | 28 ++++++++++++++--------------
  hw/m68k/mcf5208.c   |  2 +-
  hw/m68k/next-cube.c |  2 +-
  hw/m68k/q800.c      |  4 ++--
  4 files changed, 18 insertions(+), 18 deletions(-)
Reviewed-by on v2 17/25
#33 lore raw

Re: [PATCH v2 17/25] hw/m68k: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé
Quoted 12 lines · Philippe Mathieu-Daudé

The M68K architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

   $ end=be; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' hw/m68k/); \
     done
Quoted 7 lines
---
  hw/m68k/bootinfo.h  | 28 ++++++++++++++--------------
  hw/m68k/mcf5208.c   |  2 +-
  hw/m68k/next-cube.c |  2 +-
  hw/m68k/q800.c      |  4 ++--
  4 files changed, 18 insertions(+), 18 deletions(-)

r~

#34 lore raw

PATCH v2 18/25 target/m68k: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The M68K architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

  $ end=be; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/m68k/); \
    done
---
 target/m68k/gdbstub.c |  2 +-
 target/m68k/helper.c  | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)
target/m68k/gdbstub.c +1 -1
index 15547e2313c..136159f98f2 100644
@@ -52,7 +52,7 @@ int m68k_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
     CPUM68KState *env = cpu_env(cs);
     uint32_t tmp;
 
-    tmp = ldl_p(mem_buf);
+    tmp = ldl_be_p(mem_buf);
 
     if (n < 8) {
         /* D0-D7 */
target/m68k/helper.c +5 -5
index 4c85badd5d3..9d3db8419de 100644
@@ -57,15 +57,15 @@ static int cf_fpu_gdb_set_reg(CPUState *cs, uint8_t *mem_buf, int n)
 
     if (n < 8) {
         float_status s;
-        env->fregs[n].d = float64_to_floatx80(ldq_p(mem_buf), &s);
+        env->fregs[n].d = float64_to_floatx80(ldq_be_p(mem_buf), &s);
         return 8;
     }
     switch (n) {
     case 8: /* fpcontrol */
-        cpu_m68k_set_fpcr(env, ldl_p(mem_buf));
+        cpu_m68k_set_fpcr(env, ldl_be_p(mem_buf));
         return 4;
     case 9: /* fpstatus */
-        env->fpsr = ldl_p(mem_buf);
+        env->fpsr = ldl_be_p(mem_buf);
         return 4;
     case 10: /* fpiar, not implemented */
         return 4;
@@ -107,10 +107,10 @@ static int m68k_fpu_gdb_set_reg(CPUState *cs, uint8_t *mem_buf, int n)
     }
     switch (n) {
     case 8: /* fpcontrol */
-        cpu_m68k_set_fpcr(env, ldl_p(mem_buf));
+        cpu_m68k_set_fpcr(env, ldl_be_p(mem_buf));
         return 4;
     case 9: /* fpstatus */
-        cpu_m68k_set_fpsr(env, ldl_p(mem_buf));
+        cpu_m68k_set_fpsr(env, ldl_be_p(mem_buf));
         return 4;
     case 10: /* fpiar, not implemented */
         return 4;
Signature · 1 line
2.45.2
author Reviewed-by Thomas Huth on v2 18/25
#35 lore raw

Re: [PATCH v2 18/25] target/m68k: Use explicit big-endian LD/ST API

Quoted 5 lines · Philippe Mathieu-Daudé

The M68K architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

Quoted 8 lines
   $ end=be; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/m68k/); \
     done

Per v1:

Quoted 4 lines
---
  target/m68k/gdbstub.c |  2 +-
  target/m68k/helper.c  | 10 +++++-----
  2 files changed, 6 insertions(+), 6 deletions(-)
#36 lore raw

PATCH v2 19/25 hw/sparc: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The SPARC architecture uses big endianness. Directly use the big-endian LD/ST API.

for a in uw w l q;do sed -i -e "s/ld${a}_p(/ld${a}_be_p(/" $(git grep -wlE '(ld|st)u?[wlq]_p' hw/sparc/);done

---
 hw/sparc/leon3.c   | 42 +++++++++++++++++++++---------------------
 hw/sparc/sun4m.c   |  6 +++---
 hw/sparc64/sun4u.c |  6 +++---
 3 files changed, 27 insertions(+), 27 deletions(-)
hw/sparc/leon3.c +21 -21
index 6aaa04cb191..021b5070128 100644
@@ -78,21 +78,21 @@ typedef struct ResetData {
 
 static uint32_t *gen_store_u32(uint32_t *code, hwaddr addr, uint32_t val)
 {
-    stl_p(code++, 0x82100000); /* mov %g0, %g1                */
-    stl_p(code++, 0x84100000); /* mov %g0, %g2                */
-    stl_p(code++, 0x03000000 +
+    stl_be_p(code++, 0x82100000); /* mov %g0, %g1                */
+    stl_be_p(code++, 0x84100000); /* mov %g0, %g2                */
+    stl_be_p(code++, 0x03000000 +
       extract32(addr, 10, 22));
                                /* sethi %hi(addr), %g1        */
-    stl_p(code++, 0x82106000 +
+    stl_be_p(code++, 0x82106000 +
       extract32(addr, 0, 10));
                                /* or %g1, addr, %g1           */
-    stl_p(code++, 0x05000000 +
+    stl_be_p(code++, 0x05000000 +
       extract32(val, 10, 22));
                                /* sethi %hi(val), %g2         */
-    stl_p(code++, 0x8410a000 +
+    stl_be_p(code++, 0x8410a000 +
       extract32(val, 0, 10));
                                /* or %g2, val, %g2            */
-    stl_p(code++, 0xc4204000); /* st %g2, [ %g1 ]             */
+    stl_be_p(code++, 0xc4204000); /* st %g2, [ %g1 ]             */
 
     return code;
 }
@@ -112,13 +112,13 @@ static void write_bootloader(void *ptr, hwaddr kernel_addr)
 
     /* If we are running on a secondary CPU, jump directly to the kernel.  */
 
-    stl_p(p++, 0x85444000); /* rd %asr17, %g2      */
-    stl_p(p++, 0x8530a01c); /* srl  %g2, 0x1c, %g2 */
-    stl_p(p++, 0x80908000); /* tst  %g2            */
+    stl_be_p(p++, 0x85444000); /* rd %asr17, %g2      */
+    stl_be_p(p++, 0x8530a01c); /* srl  %g2, 0x1c, %g2 */
+    stl_be_p(p++, 0x80908000); /* tst  %g2            */
     /* Filled below.  */
     sec_cpu_branch_p = p;
-    stl_p(p++, 0x0BADC0DE); /* bne xxx             */
-    stl_p(p++, 0x01000000); /* nop */
+    stl_be_p(p++, 0x0BADC0DE); /* bne xxx             */
+    stl_be_p(p++, 0x01000000); /* nop */
 
     /* Initialize the UARTs                                        */
     /* *UART_CONTROL = UART_RECEIVE_ENABLE | UART_TRANSMIT_ENABLE; */
@@ -133,17 +133,17 @@ static void write_bootloader(void *ptr, hwaddr kernel_addr)
     p = gen_store_u32(p, 0x80000318, 3);
 
     /* Now, the relative branch above can be computed.  */
-    stl_p(sec_cpu_branch_p, 0x12800000
-          + (p - sec_cpu_branch_p));
+    stl_be_p(sec_cpu_branch_p, 0x12800000
+             + (p - sec_cpu_branch_p));
 
     /* JUMP to the entry point                                     */
-    stl_p(p++, 0x82100000); /* mov %g0, %g1 */
-    stl_p(p++, 0x03000000 + extract32(kernel_addr, 10, 22));
-                            /* sethi %hi(kernel_addr), %g1 */
-    stl_p(p++, 0x82106000 + extract32(kernel_addr, 0, 10));
-                            /* or kernel_addr, %g1 */
-    stl_p(p++, 0x81c04000); /* jmp  %g1 */
-    stl_p(p++, 0x01000000); /* nop */
+    stl_be_p(p++, 0x82100000); /* mov %g0, %g1 */
+    stl_be_p(p++, 0x03000000 + extract32(kernel_addr, 10, 22));
+                               /* sethi %hi(kernel_addr), %g1 */
+    stl_be_p(p++, 0x82106000 + extract32(kernel_addr, 0, 10));
+                               /* or kernel_addr, %g1 */
+    stl_be_p(p++, 0x81c04000); /* jmp  %g1 */
+    stl_be_p(p++, 0x01000000); /* nop */
 }
 
 static void leon3_cpu_reset(void *opaque)
hw/sparc/sun4m.c +3 -3
index d52e6a7213f..f375f0d389b 100644
@@ -271,9 +271,9 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
         if (*initrd_size > 0) {
             for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
                 ptr = rom_ptr(KERNEL_LOAD_ADDR + i, 24);
-                if (ptr && ldl_p(ptr) == 0x48647253) { /* HdrS */
-                    stl_p(ptr + 16, INITRD_LOAD_ADDR);
-                    stl_p(ptr + 20, *initrd_size);
+                if (ptr && ldl_be_p(ptr) == 0x48647253) { /* HdrS */
+                    stl_be_p(ptr + 16, INITRD_LOAD_ADDR);
+                    stl_be_p(ptr + 20, *initrd_size);
                     break;
                 }
             }
hw/sparc64/sun4u.c +3 -3
index 4ece1ac1ffc..e591e5a741a 100644
@@ -210,9 +210,9 @@ static uint64_t sun4u_load_kernel(const char *kernel_filename,
         if (*initrd_size > 0) {
             for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
                 ptr = rom_ptr(*kernel_addr + i, 32);
-                if (ptr && ldl_p(ptr + 8) == 0x48647253) { /* HdrS */
-                    stl_p(ptr + 24, *initrd_addr + *kernel_addr);
-                    stl_p(ptr + 28, *initrd_size);
+                if (ptr && ldl_be_p(ptr + 8) == 0x48647253) { /* HdrS */
+                    stl_be_p(ptr + 24, *initrd_addr + *kernel_addr);
+                    stl_be_p(ptr + 28, *initrd_size);
                     break;
                 }
             }
Signature · 1 line
2.45.2
#37 lore raw

PATCH v2 20/25 target/sparc: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The SPARC architectures use big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

  $ end=be; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/sparc/); \
    done
---
 target/sparc/gdbstub.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/sparc/gdbstub.c +3 -3
index ec0036e9ef6..6c82b7db8cf 100644
@@ -110,11 +110,11 @@ int sparc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 #if defined(TARGET_ABI32)
     uint32_t tmp;
 
-    tmp = ldl_p(mem_buf);
+    tmp = ldl_be_p(mem_buf);
 #else
     target_ulong tmp;
 
-    tmp = ldtul_p(mem_buf);
+    tmp = ldtul_be_p(mem_buf);
 #endif
 
     if (n < 8) {
@@ -165,7 +165,7 @@ int sparc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 #else
     else if (n < 64) {
         /* f0-f31 */
-        tmp = ldl_p(mem_buf);
+        tmp = ldl_be_p(mem_buf);
         if (n & 1) {
             env->fpr[(n - 32) / 2].l.lower = tmp;
         } else {
Signature · 1 line
2.45.2
#38 lore raw

PATCH v2 21/25 target/hppa: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The HPPA architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

  $ end=be; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/hppa/); \
    done
---
 target/hppa/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/hppa/gdbstub.c +1 -1
index 0daa52f7af2..537d0d2dfff 100644
@@ -150,7 +150,7 @@ int hppa_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
 int hppa_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 {
     CPUHPPAState *env = cpu_env(cs);
-    uint32_t val = ldl_p(mem_buf);
+    uint32_t val = ldl_be_p(mem_buf);
 
     switch (n) {
     case 0:
Signature · 1 line
2.45.2
#39 lore raw

PATCH v2 22/25 hw/s390x: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The S390X architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

  $ end=be; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' hw/s390x/); \
    done
---
 hw/s390x/ipl.c           |   4 +-
 hw/s390x/s390-pci-inst.c | 166 +++++++++++++++++++--------------------
 2 files changed, 85 insertions(+), 85 deletions(-)
hw/s390x/ipl.c +2 -2
index dd71689642b..5ab74339087 100644
@@ -252,8 +252,8 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
              */
             romptr = rom_ptr(INITRD_PARM_START, 16);
             if (romptr) {
-                stq_p(romptr, initrd_offset);
-                stq_p(romptr + 1, initrd_size);
+                stq_be_p(romptr, initrd_offset);
+                stq_be_p(romptr + 1, initrd_size);
             }
         }
     }
hw/s390x/s390-pci-inst.c +83 -83

376 lines not on this page · raw message

Signature · 1 line
2.45.2
Reviewed-by on v2 22/25
#40 lore raw

Re: [PATCH v2 22/25] hw/s390x: Use explicit big-endian LD/ST API

Quoted 12 lines · Philippe Mathieu-Daudé

The S390X architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

   $ end=be; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' hw/s390x/); \
     done
Quoted 5 lines
---
  hw/s390x/ipl.c           |   4 +-
  hw/s390x/s390-pci-inst.c | 166 +++++++++++++++++++--------------------
  2 files changed, 85 insertions(+), 85 deletions(-)
#41 lore raw

PATCH v2 23/25 target/s390x: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The S390X architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

  $ end=be; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/s390x/); \
    done
---
 target/s390x/gdbstub.c | 34 +++++++++++++++++-----------------
 target/s390x/ioinst.c  |  2 +-
 2 files changed, 18 insertions(+), 18 deletions(-)
target/s390x/gdbstub.c +17 -17
index 9ffec0bccbc..63373f02cef 100644
@@ -46,7 +46,7 @@ int s390_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
 int s390_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
 {
     CPUS390XState *env = cpu_env(cs);
-    target_ulong tmpl = ldq_p(mem_buf);
+    target_ulong tmpl = ldq_be_p(mem_buf);
 
     switch (n) {
     case S390_PSWM_REGNUM:
@@ -88,7 +88,7 @@ static int cpu_write_ac_reg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_A0_REGNUM ... S390_A15_REGNUM:
-        env->aregs[n] = ldl_p(mem_buf);
+        env->aregs[n] = ldl_be_p(mem_buf);
         cpu_synchronize_post_init(env_cpu(env));
         return 4;
     default:
@@ -123,10 +123,10 @@ static int cpu_write_fp_reg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_FPC_REGNUM:
-        env->fpc = ldl_p(mem_buf);
+        env->fpc = ldl_be_p(mem_buf);
         return 4;
     case S390_F0_REGNUM ... S390_F15_REGNUM:
-        *get_freg(env, n - S390_F0_REGNUM) = ldq_p(mem_buf);
+        *get_freg(env, n - S390_F0_REGNUM) = ldq_be_p(mem_buf);
         return 8;
     default:
         return 0;
@@ -167,11 +167,11 @@ static int cpu_write_vreg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_V0L_REGNUM ... S390_V15L_REGNUM:
-        env->vregs[n][1] = ldq_p(mem_buf + 8);
+        env->vregs[n][1] = ldq_be_p(mem_buf + 8);
         return 8;
     case S390_V16_REGNUM ... S390_V31_REGNUM:
-        env->vregs[n][0] = ldq_p(mem_buf);
-        env->vregs[n][1] = ldq_p(mem_buf + 8);
+        env->vregs[n][0] = ldq_be_p(mem_buf);
+        env->vregs[n][1] = ldq_be_p(mem_buf + 8);
         return 16;
     default:
         return 0;
@@ -203,7 +203,7 @@ static int cpu_write_c_reg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_C0_REGNUM ... S390_C15_REGNUM:
-        env->cregs[n] = ldq_p(mem_buf);
+        env->cregs[n] = ldq_be_p(mem_buf);
         if (tcg_enabled()) {
             tlb_flush(env_cpu(env));
         }
@@ -246,19 +246,19 @@ static int cpu_write_virt_reg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_VIRT_CKC_REGNUM:
-        env->ckc = ldq_p(mem_buf);
+        env->ckc = ldq_be_p(mem_buf);
         cpu_synchronize_post_init(cs);
         return 8;
     case S390_VIRT_CPUTM_REGNUM:
-        env->cputm = ldq_p(mem_buf);
+        env->cputm = ldq_be_p(mem_buf);
         cpu_synchronize_post_init(cs);
         return 8;
     case S390_VIRT_BEA_REGNUM:
-        env->gbea = ldq_p(mem_buf);
+        env->gbea = ldq_be_p(mem_buf);
         cpu_synchronize_post_init(cs);
         return 8;
     case S390_VIRT_PREFIX_REGNUM:
-        env->psa = ldq_p(mem_buf);
+        env->psa = ldq_be_p(mem_buf);
         cpu_synchronize_post_init(cs);
         return 8;
     default:
@@ -298,19 +298,19 @@ static int cpu_write_virt_kvm_reg(CPUState *cs, uint8_t *mem_buf, int n)
 
     switch (n) {
     case S390_VIRT_KVM_PP_REGNUM:
-        env->pp = ldq_p(mem_buf);
+        env->pp = ldq_be_p(mem_buf);
         cpu_synchronize_post_init(env_cpu(env));
         return 8;
     case S390_VIRT_KVM_PFT_REGNUM:
-        env->pfault_token = ldq_p(mem_buf);
+        env->pfault_token = ldq_be_p(mem_buf);
         cpu_synchronize_post_init(env_cpu(env));
         return 8;
     case S390_VIRT_KVM_PFS_REGNUM:
-        env->pfault_select = ldq_p(mem_buf);
+        env->pfault_select = ldq_be_p(mem_buf);
         cpu_synchronize_post_init(env_cpu(env));
         return 8;
     case S390_VIRT_KVM_PFC_REGNUM:
-        env->pfault_compare = ldq_p(mem_buf);
+        env->pfault_compare = ldq_be_p(mem_buf);
         cpu_synchronize_post_init(env_cpu(env));
         return 8;
     default:
@@ -338,7 +338,7 @@ static int cpu_write_gs_reg(CPUState *cs, uint8_t *mem_buf, int n)
     S390CPU *cpu = S390_CPU(cs);
     CPUS390XState *env = &cpu->env;
 
-    env->gscb[n] = ldq_p(mem_buf);
+    env->gscb[n] = ldq_be_p(mem_buf);
     cpu_synchronize_post_init(env_cpu(env));
     return 8;
 }
target/s390x/ioinst.c +1 -1
index bbe45a497a8..a944f16c254 100644
@@ -603,7 +603,7 @@ static int chsc_sei_nt2_have_event(void)
 #define CHSC_SEI_NT2    (1ULL << 61)
 static void ioinst_handle_chsc_sei(ChscReq *req, ChscResp *res)
 {
-    uint64_t selection_mask = ldq_p(&req->param1);
+    uint64_t selection_mask = ldq_be_p(&req->param1);
     uint8_t *res_flags = (uint8_t *)res->data;
     int have_event = 0;
     int have_more = 0;
Signature · 1 line
2.45.2
Reviewed-by on v2 23/25
#42 lore raw

Re: [PATCH v2 23/25] target/s390x: Use explicit big-endian LD/ST API

Quoted 12 lines · Philippe Mathieu-Daudé

The S390X architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

   $ end=be; \
     for acc in uw w l q tul; do \
       sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
              -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
         $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/s390x/); \
     done
Quoted 5 lines
---
  target/s390x/gdbstub.c | 34 +++++++++++++++++-----------------
  target/s390x/ioinst.c  |  2 +-
  2 files changed, 18 insertions(+), 18 deletions(-)
#43 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 6 lines · Philippe Mathieu-Daudé

For targets (or HW) which are only built for a particular endianness, the generic LD/ST helpers are defined as the target endianness variant. For example, on big-endian targets, stl_p() is equivalent of stl_be_p().

This series replaces in bulk these LD/ST calls.

This is the first part where we only convert the targets built for a single endianness.

The rest (MIPS, ARM, PPC, MicroBlaze and Xtensa) will be handled in different series.

I'm keeping hw/virtio/virtio-config-io.c last. Possibly current API will then be restricted to user-emu & system/ to avoid further uses.

$ git grep -wlE '(ld|st)t?u?[wlq]_p'
hw/mips/bootloader.c
hw/mips/fuloong2e.c
hw/mips/malta.c
hw/ppc/spapr.c
hw/ppc/spapr_vhyp_mmu.c
target/arm/cpu.c
target/arm/gdbstub.c
target/arm/gdbstub64.c
target/microblaze/gdbstub.c
target/mips/gdbstub.c
target/ppc/gdbstub.c
target/ppc/mmu-hash64.h
target/xtensa/gdbstub.c

accel/tcg/user-exec.c
hw/virtio/virtio-config-io.c
include/exec/cpu-all.h
include/gdbstub/helpers.h
monitor/hmp-cmds-target.c
system/ioport.c
system/memory_ldst.c.inc

Quoted 66 lines

This is helpful for the single binary project where we want to build a single binary for multiple targets of different endianness.

Philippe Mathieu-Daudé (25):
gdbstub/helpers: Have ldtul_p() definition use ldn_p() target/hexagon: Replace ldtul_p() -> ldl_p() target/alpha: Replace ldtul_p() -> ldq_p() target/s390x: Replace ldtul_p() -> ldq_p() gdbstub/helpers: Introduce ldtul_$endian_p() helpers target/alpha: Use explicit little-endian LD/ST API target/hexagon: Use explicit little-endian LD/ST API hw/i386: Use explicit little-endian LD/ST API target/i386: Use explicit little-endian LD/ST API target/avr: Use explicit little-endian LD/ST API linux-user/i386: Use explicit little-endian LD/ST API target/loongarch: Use explicit little-endian LD/ST API target/sh4: Use explicit little-endian LD/ST API target/tricore: Use explicit little-endian LD/ST API target/rx: Use explicit little-endian LD/ST API target/riscv: Use explicit little-endian LD/ST API hw/m68k: Use explicit big-endian LD/ST API target/m68k: Use explicit big-endian LD/ST API hw/sparc: Use explicit big-endian LD/ST API target/sparc: Use explicit big-endian LD/ST API target/hppa: Use explicit big-endian LD/ST API hw/s390x: Use explicit big-endian LD/ST API target/s390x: Use explicit big-endian LD/ST API target/openrisc: Use explicit big-endian LD/ST API hw/ppc/e500: Use explicit big-endian LD/ST API

  hw/m68k/bootinfo.h                   |  28 ++---
  include/gdbstub/helpers.h            |   6 +-
  hw/i386/multiboot.c                  |  36 +++---
  hw/i386/x86-common.c                 |  26 ++---
  hw/m68k/mcf5208.c                    |   2 +-
  hw/m68k/next-cube.c                  |   2 +-
  hw/m68k/q800.c                       |   4 +-
  hw/ppc/ppce500_spin.c                |  24 ++--
  hw/s390x/ipl.c                       |   4 +-
  hw/s390x/s390-pci-inst.c             | 166 +++++++++++++--------------
  hw/sparc/leon3.c                     |  42 +++----
  hw/sparc/sun4m.c                     |   6 +-
  hw/sparc64/sun4u.c                   |   6 +-
  linux-user/i386/signal.c             |   4 +-
  target/alpha/gdbstub.c               |   2 +-
  target/avr/gdbstub.c                 |   4 +-
  target/hexagon/gdbstub.c             |  10 +-
  target/hppa/gdbstub.c                |   2 +-
  target/i386/gdbstub.c                |  30 ++---
  target/i386/tcg/sysemu/excp_helper.c |   4 +-
  target/i386/xsave_helper.c           |  32 +++---
  target/loongarch/gdbstub.c           |   8 +-
  target/m68k/gdbstub.c                |   2 +-
  target/m68k/helper.c                 |  10 +-
  target/openrisc/gdbstub.c            |   2 +-
  target/riscv/gdbstub.c               |  14 +--
  target/rx/cpu.c                      |   2 +-
  target/rx/gdbstub.c                  |  24 ++--
  target/s390x/gdbstub.c               |  34 +++---
  target/s390x/ioinst.c                |   2 +-
  target/sh4/gdbstub.c                 |  36 +++---
  target/sparc/gdbstub.c               |   6 +-
  target/tricore/gdbstub.c             |   2 +-
  33 files changed, 292 insertions(+), 290 deletions(-)
#44 lore raw

PATCH v2 24/25 target/openrisc: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The OpenRISC architecture uses big endianness. Directly use the big-endian LD/ST API.

Mechanical change using:

  $ end=be; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/openrisc/); \
    done
---
 target/openrisc/gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/openrisc/gdbstub.c +1 -1
index c2a77d5d4d5..11f5c50423b 100644
@@ -55,7 +55,7 @@ int openrisc_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
         return 0;
     }
 
-    tmp = ldl_p(mem_buf);
+    tmp = ldl_be_p(mem_buf);
 
     if (n < 32) {
         cpu_set_gpr(env, n, tmp);
Signature · 1 line
2.45.2
#45 lore raw

PATCH v2 25/25 hw/ppc/e500: Use explicit big-endian LD/ST API

In reply to Philippe Mathieu-Daudé

The 32-bit PPC architecture uses big endianness. Directly use the big-endian LD/ST API for the E500 hardware.

Mechanical change using:

  $ end=be; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' hw/*/*e500*); \
    done
---
 hw/ppc/ppce500_spin.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
hw/ppc/ppce500_spin.c +12 -12
index e08739a443d..8e0ef9467e4 100644
@@ -64,9 +64,9 @@ static void spin_reset(DeviceState *dev)
     for (i = 0; i < MAX_CPUS; i++) {
         SpinInfo *info = &s->spin[i];
 
-        stl_p(&info->pir, i);
-        stq_p(&info->r3, i);
-        stq_p(&info->addr, 1);
+        stl_be_p(&info->pir, i);
+        stq_be_p(&info->r3, i);
+        stq_be_p(&info->addr, 1);
     }
 }
 
@@ -96,9 +96,9 @@ static void spin_kick(CPUState *cs, run_on_cpu_data data)
     hwaddr map_start;
 
     cpu_synchronize_state(cs);
-    stl_p(&curspin->pir, env->spr[SPR_BOOKE_PIR]);
-    env->nip = ldq_p(&curspin->addr) & (map_size - 1);
-    env->gpr[3] = ldq_p(&curspin->r3);
+    stl_be_p(&curspin->pir, env->spr[SPR_BOOKE_PIR]);
+    env->nip = ldq_be_p(&curspin->addr) & (map_size - 1);
+    env->gpr[3] = ldq_be_p(&curspin->r3);
     env->gpr[4] = 0;
     env->gpr[5] = 0;
     env->gpr[6] = 0;
@@ -106,7 +106,7 @@ static void spin_kick(CPUState *cs, run_on_cpu_data data)
     env->gpr[8] = 0;
     env->gpr[9] = 0;
 
-    map_start = ldq_p(&curspin->addr) & ~(map_size - 1);
+    map_start = ldq_be_p(&curspin->addr) & ~(map_size - 1);
     mmubooke_create_initial_mapping(env, 0, map_start, map_size);
 
     cs->halted = 0;
@@ -141,14 +141,14 @@ static void spin_write(void *opaque, hwaddr addr, uint64_t value,
         stb_p(curspin_p, value);
         break;
     case 2:
-        stw_p(curspin_p, value);
+        stw_be_p(curspin_p, value);
         break;
     case 4:
-        stl_p(curspin_p, value);
+        stl_be_p(curspin_p, value);
         break;
     }
 
-    if (!(ldq_p(&curspin->addr) & 1)) {
+    if (!(ldq_be_p(&curspin->addr) & 1)) {
         /* run CPU */
         run_on_cpu(cpu, spin_kick, RUN_ON_CPU_HOST_PTR(curspin));
     }
@@ -163,9 +163,9 @@ static uint64_t spin_read(void *opaque, hwaddr addr, unsigned len)
     case 1:
         return ldub_p(spin_p);
     case 2:
-        return lduw_p(spin_p);
+        return lduw_be_p(spin_p);
     case 4:
-        return ldl_p(spin_p);
+        return ldl_be_p(spin_p);
     default:
         hw_error("ppce500: unexpected %s with len = %u", __func__, len);
     }
Signature · 1 line
2.45.2
#46 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 18 lines · Philippe Mathieu-Daudé

Philippe Mathieu-Daudé (25):
gdbstub/helpers: Have ldtul_p() definition use ldn_p() target/hexagon: Replace ldtul_p() -> ldl_p() target/alpha: Replace ldtul_p() -> ldq_p() target/s390x: Replace ldtul_p() -> ldq_p() gdbstub/helpers: Introduce ldtul_$endian_p() helpers target/alpha: Use explicit little-endian LD/ST API target/hexagon: Use explicit little-endian LD/ST API hw/i386: Use explicit little-endian LD/ST API target/i386: Use explicit little-endian LD/ST API target/avr: Use explicit little-endian LD/ST API linux-user/i386: Use explicit little-endian LD/ST API target/loongarch: Use explicit little-endian LD/ST API target/sh4: Use explicit little-endian LD/ST API target/tricore: Use explicit little-endian LD/ST API target/rx: Use explicit little-endian LD/ST API target/riscv: Use explicit little-endian LD/ST API hw/m68k: Use explicit big-endian LD/ST API

Quoted 8 lines

target/m68k: Use explicit big-endian LD/ST API hw/sparc: Use explicit big-endian LD/ST API target/sparc: Use explicit big-endian LD/ST API target/hppa: Use explicit big-endian LD/ST API hw/s390x: Use explicit big-endian LD/ST API target/s390x: Use explicit big-endian LD/ST API target/openrisc: Use explicit big-endian LD/ST API hw/ppc/e500: Use explicit big-endian LD/ST API

The sh4, rx, and riscv targets *can* support multiple endianness.

While we removed sh4eb for system mode, we still support sh4eb-linux-user, and therefore the target/sh4 patch affecting gdbstub is wrong.

RX sets endianness via a pin sampled at reset; if we ever implement this, it would be via a property on the cpu. RISCV sets endianness via a couple of bits in MSTATUS; system mode would always use little-endian, but riscv64eb-user isn't out of the question.

While we have never supported rx or riscv in big-endian, but there's no reason that we can't, and those target/ patches make things harder. Since target/ will *always* have TARGET_BIG_ENDIAN available, I don't see that we're saving anything there.

r~

#47 lore raw

Le 05/10/2024 à 03:39, Richard Henderson a écrit :

Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 18 lines

Philippe Mathieu-Daudé (25):
gdbstub/helpers: Have ldtul_p() definition use ldn_p() target/hexagon: Replace ldtul_p() -> ldl_p() target/alpha: Replace ldtul_p() -> ldq_p() target/s390x: Replace ldtul_p() -> ldq_p() gdbstub/helpers: Introduce ldtul_$endian_p() helpers target/alpha: Use explicit little-endian LD/ST API target/hexagon: Use explicit little-endian LD/ST API hw/i386: Use explicit little-endian LD/ST API target/i386: Use explicit little-endian LD/ST API target/avr: Use explicit little-endian LD/ST API linux-user/i386: Use explicit little-endian LD/ST API target/loongarch: Use explicit little-endian LD/ST API target/sh4: Use explicit little-endian LD/ST API target/tricore: Use explicit little-endian LD/ST API target/rx: Use explicit little-endian LD/ST API target/riscv: Use explicit little-endian LD/ST API hw/m68k: Use explicit big-endian LD/ST API

Quoted 8 lines

target/m68k: Use explicit big-endian LD/ST API hw/sparc: Use explicit big-endian LD/ST API target/sparc: Use explicit big-endian LD/ST API target/hppa: Use explicit big-endian LD/ST API hw/s390x: Use explicit big-endian LD/ST API target/s390x: Use explicit big-endian LD/ST API target/openrisc: Use explicit big-endian LD/ST API hw/ppc/e500: Use explicit big-endian LD/ST API

The sh4, rx, and riscv targets *can* support multiple endianness.

While we removed sh4eb for system mode, we still support sh4eb-linux-user, and therefore the target/sh4 patch affecting gdbstub is wrong.

Quoted 7 lines

RX sets endianness via a pin sampled at reset; if we ever implement this, it would be via a property on the cpu. RISCV sets endianness via a couple of bits in MSTATUS; system mode would always use little-endian, but riscv64eb-user isn't out of the question.

While we have never supported rx or riscv in big-endian, but there's no reason that we can't, and those target/ patches make things harder. Since target/ will *always* have TARGET_BIG_ENDIAN available, I don't see that we're saving anything there.

Isn't this also true for the sparc CPU?
At least llvm seems to think so:

$ ssh gcc421  /usr/bin/llvm-mc-18 --version
Debian LLVM version 18.1.8
  Optimized build.

Registered Targets:
aarch64 - AArch64 (little endian)
....

    sparc      - Sparc
    sparcel    - Sparc LE
    sparcv9    - Sparc V9
    systemz    - SystemZ

Pierre Muller

#48 lore raw
Quoted 5 lines · Pierre Muller
Quoted 3 lines

While we have never supported rx or riscv in big-endian, but there's no reason that we can't, and those target/ patches make things harder. Since target/ will *always* have TARGET_BIG_ENDIAN available, I don't see that we're saving anything there.

  Isn't this also true for the sparc CPU?

Yes, I'd forgotten about that. Indeed, Sparc v9 has a couple of PSTATE bits that set the endianness, exactly like Arm and Power, which qemu has not implemented for system mode.

r~