diff mbox series

[1/3] target/arm: Expose arm_cpu_code_is_big_endian() prototype in 'cpu.h'

Message ID 20240930221205.59101-2-philmd@linaro.org
State New
Headers show
Series hw/arm: Replace tswap32() by stl_endian_p() | expand

Commit Message

Philippe Mathieu-Daudé Sept. 30, 2024, 10:12 p.m. UTC
Expose arm_cpu_code_is_big_endian() so it can be used by hw/ code.
Use it in few places where it was open coded.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/cpu.h              | 7 +++++++
 linux-user/aarch64/cpu_loop.c | 4 ++--
 linux-user/arm/cpu_loop.c     | 4 ++--
 target/arm/cpu.c              | 6 ++----
 4 files changed, 13 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index f065756c5c..da8f2b2ec8 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -3057,6 +3057,13 @@  static inline bool arm_cpu_data_is_big_endian(CPUARMState *env)
     }
 }
 
+static inline bool bswap_code(bool sctlr_b);
+
+static inline bool arm_cpu_code_is_big_endian(CPUARMState *env)
+{
+    return bswap_code(arm_sctlr_b(env));
+}
+
 #include "exec/cpu-all.h"
 
 /*
diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
index 71cdc8be50..68ff3c14f8 100644
--- a/linux-user/aarch64/cpu_loop.c
+++ b/linux-user/aarch64/cpu_loop.c
@@ -29,7 +29,7 @@ 
 
 #define get_user_code_u32(x, gaddr, env)                \
     ({ abi_long __r = get_user_u32((x), (gaddr));       \
-        if (!__r && bswap_code(arm_sctlr_b(env))) {     \
+        if (!__r && arm_cpu_code_is_big_endian(env)) {  \
             (x) = bswap32(x);                           \
         }                                               \
         __r;                                            \
@@ -37,7 +37,7 @@ 
 
 #define get_user_code_u16(x, gaddr, env)                \
     ({ abi_long __r = get_user_u16((x), (gaddr));       \
-        if (!__r && bswap_code(arm_sctlr_b(env))) {     \
+        if (!__r && arm_cpu_code_is_big_endian(env)) {  \
             (x) = bswap16(x);                           \
         }                                               \
         __r;                                            \
diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
index ec665862d9..0cc056be31 100644
--- a/linux-user/arm/cpu_loop.c
+++ b/linux-user/arm/cpu_loop.c
@@ -29,7 +29,7 @@ 
 
 #define get_user_code_u32(x, gaddr, env)                \
     ({ abi_long __r = get_user_u32((x), (gaddr));       \
-        if (!__r && bswap_code(arm_sctlr_b(env))) {     \
+        if (!__r && arm_cpu_code_is_big_endian(env)) {  \
             (x) = bswap32(x);                           \
         }                                               \
         __r;                                            \
@@ -37,7 +37,7 @@ 
 
 #define get_user_code_u16(x, gaddr, env)                \
     ({ abi_long __r = get_user_u16((x), (gaddr));       \
-        if (!__r && bswap_code(arm_sctlr_b(env))) {     \
+        if (!__r && arm_cpu_code_is_big_endian(env)) {  \
             (x) = bswap16(x);                           \
         }                                               \
         __r;                                            \
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 19191c2391..f3198ee2f2 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1167,7 +1167,6 @@  static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
 {
     ARMCPU *ac = ARM_CPU(cpu);
     CPUARMState *env = &ac->env;
-    bool sctlr_b;
 
     if (is_a64(env)) {
         info->cap_arch = CS_ARCH_ARM64;
@@ -1194,8 +1193,7 @@  static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
         info->cap_mode = cap_mode;
     }
 
-    sctlr_b = arm_sctlr_b(env);
-    if (bswap_code(sctlr_b)) {
+    if (arm_cpu_code_is_big_endian(env)) {
 #if TARGET_BIG_ENDIAN
         info->endian = BFD_ENDIAN_LITTLE;
 #else
@@ -1204,7 +1202,7 @@  static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
     }
     info->flags &= ~INSN_ARM_BE32;
 #ifndef CONFIG_USER_ONLY
-    if (sctlr_b) {
+    if (arm_sctlr_b(env)) {
         info->flags |= INSN_ARM_BE32;
     }
 #endif