exec: Remove TARGET_LONG_SIZE definition
cover exec: Remove TARGET_LONG_SIZE definition
TARGET_LONG_SIZE is only used in 1 source file
and 1 header. Remove it to be able to focus on
making TARGET_LONG_BITS target agnostic.
Philippe Mathieu-Daudé (5):
target/i386: Use explicit little-endian LD/ST API
gdbstub: Remove ldtul_be_p() and ldtul_le_p() macros target/ppc/gdbstub: Replace TARGET_LONG_SIZE -> sizeof(target_ulong) user/tswap: Replace TARGET_LONG_SIZE -> TARGET_LONG_BITS exec/target_long: Remove TARGET_LONG_SIZE definition
include/exec/target_long.h | 8 +++---- include/gdbstub/helpers.h | 4 ---- include/user/tswap-target.h | 2 +- target/i386/gdbstub.c | 24 ++++++++++----------- target/i386/tcg/system/excp_helper.c | 4 ++-- target/i386/xsave_helper.c | 32 ++++++++++++++-------------- target/ppc/gdbstub.c | 10 ++++----- 7 files changed, 39 insertions(+), 45 deletions(-)
Signature · 1 line
2.47.1
PATCH 1/5 target/i386: Use explicit little-endian LD/ST API
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/); \
doneMessage-Id: <[email protected]>
--- target/i386/gdbstub.c | 24 ++++++++++----------- target/i386/tcg/system/excp_helper.c | 4 ++-- target/i386/xsave_helper.c | 32 ++++++++++++++-------------- 3 files changed, 30 insertions(+), 30 deletions(-)
target/i386/gdbstub.c +12 -12
@@ -94,10 +94,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 ; }
@@ -231,7 +231,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 )
@@ -287,15 +287,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]] =ldq_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]] =ldq_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 ) {
@@ -306,8 +306,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 {
@@ -315,7 +315,7 @@ int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)case IDX_IP_REG :return gdb_write_reg (env, mem_buf, &env->eip);case IDX_FLAGS_REG : - env->eflags =ldl_p (mem_buf); + env->eflags =ldl_le_p (mem_buf);return 4 ;case IDX_SEG_REGS :
@@ -341,10 +341,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 ;
@@ -362,7 +362,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/system/excp_helper.c +2 -2
@@ -85,7 +85,7 @@ static bool ptw_translate(PTETranslate *inout, hwaddr addr)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); }
@@ -93,7 +93,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
@@ -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.47.1
PATCH 2/5 gdbstub: Remove ldtul_be_p() and ldtul_le_p() macros
In reply to Philippe Mathieu-DaudéLast uses of ldtul_be_p() were removed in commit 78920b4ff2b ("target/sparc: Use explicit big-endian LD/ST API"), and of ldtul_le_p() in 39631d57d7c ("target/riscv: Use explicit little-endian LD/ST API"). Remove these legacy macros.
--- include/gdbstub/helpers.h | 4 ---- 1 file changed, 4 deletions(-)
include/gdbstub/helpers.h +0 -4
@@ -95,13 +95,9 @@ 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) -#define ldtul_le_p (addr) ldq_le_p(addr) -#define ldtul_be_p (addr) ldq_be_p(addr)#else #define gdb_get_regl (buf, val) gdb_get_reg32(buf, val)#define ldtul_p (addr) ldl_p(addr) -#define ldtul_le_p (addr) ldl_le_p(addr) -#define ldtul_be_p (addr) ldl_be_p(addr)#endif #endif /* _GDBSTUB_HELPERS_H_ */
Signature · 1 line
2.47.1
Re: [PATCH-for-10.1 2/5] gdbstub: Remove ldtul_be_p() and ldtul_le_p() macros
Quoted 4 lines · Philippe Mathieu-Daudé
Last uses of
ldtul_be_p()were removed in commit78920b4ff2b("target/sparc: Use explicit big-endian LD/ST API"), and ofldtul_le_p()in39631d57d7c("target/riscv: Use explicit little-endian LD/ST API"). Remove these legacy macros.
I'm guessing these are commits in your tree because I can't see them in origin.
Quoted 24 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/gdbstub/helpers.h | 4 ---- 1 file changed, 4 deletions(-)include/gdbstub/helpers.h +0
-4@@ -95,13 +95,9 @@ 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) -#define ldtul_le_p (addr) ldq_le_p(addr) -#define ldtul_be_p (addr) ldq_be_p(addr)#else #define gdb_get_regl (buf, val) gdb_get_reg32(buf, val)#define ldtul_p (addr) ldl_p(addr) -#define ldtul_le_p (addr) ldl_le_p(addr) -#define ldtul_be_p (addr) ldl_be_p(addr)#endif #endif /* _GDBSTUB_HELPERS_H_ */
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH-for-10.1 2/5] gdbstub: Remove ldtul_be_p() and ldtul_le_p() macros
Quoted 9 lines · Alex Bennée
Quoted 4 lines · Philippe Mathieu-Daudé
Last uses of
ldtul_be_p()were removed in commit78920b4ff2b("target/sparc: Use explicit big-endian LD/ST API"), and ofldtul_le_p()in39631d57d7c("target/riscv: Use explicit little-endian LD/ST API"). Remove these legacy macros.I'm guessing these are commits in your tree because I can't see them in origin.
Oops. I'll respin altogether as a single series.
Quoted 6 lines
Quoted 6 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/gdbstub/helpers.h | 4 ---- 1 file changed, 4 deletions(-)
PATCH 3/5 target/ppc/gdbstub: Replace TARGET_LONG_SIZE -> sizeof(target_ulong)
In reply to Philippe Mathieu-DaudéTARGET_LONG_SIZE is equivalent of sizeof(target_ulong). Since this is the single use of TARGET_LONG_SIZE in a source file, use the equivalent form to be able to remove the definition in a pair of commits.
--- target/ppc/gdbstub.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
target/ppc/gdbstub.c +5 -5
@@ -367,6 +367,7 @@ static int gdb_get_spr_reg(CPUState *cs, GByteArray *buf, int n) {PowerPCCPU *cpu =POWERPC_CPU (cs);CPUPPCState *env = &cpu->env; +target_ulong val;int reg;int len;
@@ -375,10 +376,7 @@ static int gdb_get_spr_reg(CPUState *cs, GByteArray *buf, int n)return 0 ; } - len =TARGET_LONG_SIZE ; -/* Handle those SPRs that are not part of the env->spr[] array */ -target_ulong val;switch (reg) {#if defined(TARGET_PPC64 )case SPR_CFAR :
@@ -402,6 +400,7 @@ static int gdb_get_spr_reg(CPUState *cs, GByteArray *buf, int n) }gdb_get_regl (buf, val); + len =sizeof (val);ppc_maybe_bswap_register (env,gdb_get_reg_ptr (buf, len), len);return len; }
@@ -410,6 +409,7 @@ static int gdb_set_spr_reg(CPUState *cs, uint8_t *mem_buf, int n) {PowerPCCPU *cpu =POWERPC_CPU (cs);CPUPPCState *env = &cpu->env; +target_ulong val;int reg;int len;
@@ -418,11 +418,11 @@ static int gdb_set_spr_reg(CPUState *cs, uint8_t *mem_buf, int n)return 0 ; } - len =TARGET_LONG_SIZE ; + len =sizeof (val);ppc_maybe_bswap_register (env, mem_buf, len);/* Handle those SPRs that are not part of the env->spr[] array */ -target_ulong val =ldn_p (mem_buf, len); + val =ldn_p (mem_buf, len);switch (reg) {#if defined(TARGET_PPC64 )case SPR_CFAR :
Signature · 1 line
2.47.1
PATCH 4/5 user/tswap: Replace TARGET_LONG_SIZE -> TARGET_LONG_BITS
In reply to Philippe Mathieu-DaudéHaving in "exec/target_long.h" this definition:
#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
It is safe to check TARGET_LONG_BITS == 32 instead of the equivalent TARGET_LONG_SIZE == 4 expression.
This removes the last use of TARGET_LONG_SIZE outside of "exec/target_long.h".
--- include/user/tswap-target.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/user/tswap-target.h +1 -1
@@ -11,7 +11,7 @@#include "exec/cpu-defs.h" #include "exec/tswap.h" -#if TARGET_LONG_SIZE ==4 +#if TARGET_LONG_BITS ==32 #define tswapl (s) tswap32(s)#define bswaptls (s) bswap32s(s)#else
Signature · 1 line
2.47.1
PATCH 5/5 exec/target_long: Remove TARGET_LONG_SIZE definition
In reply to Philippe Mathieu-DaudéDirectly use TARGET_LONG_BITS, so we don't need
the TARGET_LONG_SIZE definition at all.
--- include/exec/target_long.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
include/exec/target_long.h +3 -5
@@ -20,17 +20,15 @@#error TARGET_LONG_BITS not defined#endif -#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8) -/* target_ulong is the type of a virtual address */ -#if TARGET_LONG_SIZE ==4 +#if TARGET_LONG_BITS ==32 typedef int32_t target_long ;typedef uint32_t target_ulong ;#define TARGET_FMT_lx "%08x"#define TARGET_FMT_ld "%d"#define TARGET_FMT_lu "%u"#define MO_TL MO_32 -#elif TARGET_LONG_SIZE ==8 +#elif TARGET_LONG_BITS ==64 typedef int64_t target_long ;typedef uint64_t target_ulong ;#define TARGET_FMT_lx "%016" PRIx64
@@ -38,7 +36,7 @@ typedef uint64_t target_ulong;#define TARGET_FMT_lu "%" PRIu64#define MO_TL MO_64#else -#error TARGET_LONG_SIZE undefined +#error unsupported TARGET_LONG_BITS value#endif #endif /* _TARGET_LONG_H_ */
Signature · 1 line
2.47.1
Quoted 6 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (5):
target/i386: Use explicit little-endian LD/ST API
gdbstub: Removeldtul_be_p()andldtul_le_p()macros target/ppc/gdbstub: ReplaceTARGET_LONG_SIZE->sizeof(target_ulong)user/tswap: ReplaceTARGET_LONG_SIZE->TARGET_LONG_BITSexec/target_long: RemoveTARGET_LONG_SIZEdefinition
r~
Quoted 11 lines · Philippe Mathieu-Daudé
TARGET_LONG_SIZEis only used in 1 source file
and 1 header. Remove it to be able to focus on
makingTARGET_LONG_BITStarget agnostic.Philippe Mathieu-Daudé (5):
target/i386: Use explicit little-endian LD/ST API
gdbstub: Removeldtul_be_p()andldtul_le_p()macros target/ppc/gdbstub: ReplaceTARGET_LONG_SIZE->sizeof(target_ulong)user/tswap: ReplaceTARGET_LONG_SIZE->TARGET_LONG_BITSexec/target_long: RemoveTARGET_LONG_SIZEdefinition