Browse Source

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>
pull/319/head
Philippe Mathieu-Daudé 2 months ago
parent
commit
cf7719d302
  1. 9
      target/ppc/cpu_init.c
  2. 2
      target/ppc/gdbstub.c
  3. 5
      target/ppc/internal.h
  4. 8
      target/ppc/mem_helper.c

9
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

2
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);

5
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

8
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); \

Loading…
Cancel
Save