Commit cf7719d302 for qemu.org
commit cf7719d302bd82539fac0f33567a766746824c5d
Author: Philippe Mathieu-Daudé <philmd@linaro.org>
Date: Mon Feb 2 21:35:57 2026 +0100
target/ppc: Introduce ppc_env_is_little_endian() helper
Centralize endianness check on MSR via a common helper.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Anton Johansson <anjo@rev.ng>
Message-Id: <20260202210106.93257-10-philmd@linaro.org>
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 0808284b72..c5cec7c2ed 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -7364,7 +7364,7 @@ static bool ppc_cpu_is_big_endian(CPUState *cs)
{
cpu_synchronize_state(cs);
- return !FIELD_EX64(cpu_env(cs)->msr, MSR, LE);
+ return !ppc_env_is_little_endian(cpu_env(cs));
}
static bool ppc_get_irq_stats(InterruptStatsProvider *obj,
@@ -7456,11 +7456,8 @@ static void ppc_disas_set_info(CPUState *cs, disassemble_info *info)
{
CPUPPCState *env = cpu_env(cs);
- if ((env->msr >> MSR_LE) & 1) {
- info->endian = BFD_ENDIAN_LITTLE;
- } else {
- info->endian = BFD_ENDIAN_BIG;
- }
+ info->endian = ppc_env_is_little_endian(env) ? BFD_ENDIAN_LITTLE
+ : BFD_ENDIAN_BIG;
info->mach = env->bfd_mach;
if (!env->bfd_mach) {
#ifdef TARGET_PPC64
diff --git a/target/ppc/gdbstub.c b/target/ppc/gdbstub.c
index 3b28d4e21c..b19c0f1ea9 100644
--- a/target/ppc/gdbstub.c
+++ b/target/ppc/gdbstub.c
@@ -84,7 +84,7 @@ static int ppc_gdb_register_len(int n)
void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len)
{
#ifndef CONFIG_USER_ONLY
- if (!FIELD_EX64(env->msr, MSR, LE)) {
+ if (!ppc_env_is_little_endian(env)) {
/* do nothing */
} else if (len == 4) {
bswap32s((uint32_t *)mem_buf);
diff --git a/target/ppc/internal.h b/target/ppc/internal.h
index c3d3590cc8..e6e60de95a 100644
--- a/target/ppc/internal.h
+++ b/target/ppc/internal.h
@@ -24,6 +24,11 @@
#include "exec/page-protection.h"
#include "accel/tcg/tb-cpu-state.h"
+static inline bool ppc_env_is_little_endian(const CPUPPCState *env)
+{
+ return FIELD_EX64(env->msr, MSR, LE);
+}
+
/**
* ppc_data_endian_env:
* @env: the cpu context
diff --git a/target/ppc/mem_helper.c b/target/ppc/mem_helper.c
index ca84131d1a..119dc1df23 100644
--- a/target/ppc/mem_helper.c
+++ b/target/ppc/mem_helper.c
@@ -420,7 +420,7 @@ target_ulong helper_lscbx(CPUPPCState *env, target_ulong addr, uint32_t reg,
int adjust = HI_IDX * (n_elems - 1); \
int sh = sizeof(r->element[0]) >> 1; \
int index = (addr & 0xf) >> sh; \
- bool byteswap = FIELD_EX64(env->msr, MSR, LE); \
+ bool byteswap = ppc_env_is_little_endian(env); \
\
if (byteswap) { \
index = n_elems - index - 1; \
@@ -446,7 +446,7 @@ LVE(LVEWX, cpu_ldl_be_data_ra, bswap32, u32)
int adjust = HI_IDX * (n_elems - 1); \
int sh = sizeof(r->element[0]) >> 1; \
int index = (addr & 0xf) >> sh; \
- bool byteswap = FIELD_EX64(env->msr, MSR, LE); \
+ bool byteswap = ppc_env_is_little_endian(env); \
\
if (byteswap) { \
index = n_elems - index - 1; \
@@ -479,7 +479,7 @@ void helper_##name(CPUPPCState *env, target_ulong addr, \
t.s128 = int128_zero(); \
if (nb) { \
nb = (nb >= 16) ? 16 : nb; \
- if (FIELD_EX64(env->msr, MSR, LE) && !lj) { \
+ if (ppc_env_is_little_endian(env) && !lj) { \
for (i = 16; i > 16 - nb; i--) { \
t.VsrB(i - 1) = cpu_ldub_data_ra(env, addr, GETPC()); \
addr = addr_add(env, addr, 1); \
@@ -510,7 +510,7 @@ void helper_##name(CPUPPCState *env, target_ulong addr, \
} \
\
nb = (nb >= 16) ? 16 : nb; \
- if (FIELD_EX64(env->msr, MSR, LE) && !lj) { \
+ if (ppc_env_is_little_endian(env) && !lj) { \
for (i = 16; i > 16 - nb; i--) { \
cpu_stb_data_ra(env, addr, xt->VsrB(i - 1), GETPC()); \
addr = addr_add(env, addr, 1); \