Skip to content

Commit

Permalink
target/ppc: created ppc_{store,get}_vscr for generic vscr usage
Browse files Browse the repository at this point in the history
Some functions unrelated to TCG use helper_m{t,f}vscr, so generic versions
of those functions were added to cpu.c, in preparation for compilation
without TCG

Signed-off-by: Bruno Larsen (billionai) <bruno.larsen@eldorado.org.br>
Message-Id: <20210512140813.112884-2-bruno.larsen@eldorado.org.br>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
  • Loading branch information
Bruno Larsen (billionai) authored and dgibson committed May 19, 2021
1 parent 3e770bf commit c19940d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
3 changes: 1 addition & 2 deletions target/ppc/arch_dump.c
Expand Up @@ -17,7 +17,6 @@
#include "elf.h"
#include "sysemu/dump.h"
#include "sysemu/kvm.h"
#include "exec/helper-proto.h"

#ifdef TARGET_PPC64
#define ELFCLASS ELFCLASS64
Expand Down Expand Up @@ -176,7 +175,7 @@ static void ppc_write_elf_vmxregset(NoteFuncArg *arg, PowerPCCPU *cpu)
vmxregset->avr[i].u64[1] = avr->u64[1];
}
}
vmxregset->vscr.u32[3] = cpu_to_dump32(s, helper_mfvscr(&cpu->env));
vmxregset->vscr.u32[3] = cpu_to_dump32(s, ppc_get_vscr(&cpu->env));
}

static void ppc_write_elf_vsxregset(NoteFuncArg *arg, PowerPCCPU *cpu)
Expand Down
16 changes: 16 additions & 0 deletions target/ppc/cpu.c
Expand Up @@ -20,6 +20,7 @@
#include "qemu/osdep.h"
#include "cpu.h"
#include "cpu-models.h"
#include "fpu/softfloat-helpers.h"

target_ulong cpu_read_xer(CPUPPCState *env)
{
Expand All @@ -45,3 +46,18 @@ void cpu_write_xer(CPUPPCState *env, target_ulong xer)
(1ul << XER_OV) | (1ul << XER_CA) |
(1ul << XER_OV32) | (1ul << XER_CA32));
}

void ppc_store_vscr(CPUPPCState *env, uint32_t vscr)
{
env->vscr = vscr & ~(1u << VSCR_SAT);
/* Which bit we set is completely arbitrary, but clear the rest. */
env->vscr_sat.u64[0] = vscr & (1u << VSCR_SAT);
env->vscr_sat.u64[1] = 0;
set_flush_to_zero((vscr >> VSCR_NJ) & 1, &env->vec_status);
}

uint32_t ppc_get_vscr(CPUPPCState *env)
{
uint32_t sat = (env->vscr_sat.u64[0] | env->vscr_sat.u64[1]) != 0;
return env->vscr | (sat << VSCR_SAT);
}
2 changes: 2 additions & 0 deletions target/ppc/cpu.h
Expand Up @@ -2651,4 +2651,6 @@ static inline bool ppc_has_spr(PowerPCCPU *cpu, int spr)
void dump_mmu(CPUPPCState *env);

void ppc_maybe_bswap_register(CPUPPCState *env, uint8_t *mem_buf, int len);
void ppc_store_vscr(CPUPPCState *env, uint32_t vscr);
uint32_t ppc_get_vscr(CPUPPCState *env);
#endif /* PPC_CPU_H */
2 changes: 1 addition & 1 deletion target/ppc/cpu_init.c
Expand Up @@ -55,7 +55,7 @@ static inline void vscr_init(CPUPPCState *env, uint32_t val)
{
/* Altivec always uses round-to-nearest */
set_float_rounding_mode(float_round_nearest_even, &env->vec_status);
helper_mtvscr(env, val);
ppc_store_vscr(env, val);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions target/ppc/gdbstub.c
Expand Up @@ -498,7 +498,7 @@ static int gdb_get_avr_reg(CPUPPCState *env, GByteArray *buf, int n)
return 16;
}
if (n == 32) {
gdb_get_reg32(buf, helper_mfvscr(env));
gdb_get_reg32(buf, ppc_get_vscr(env));
mem_buf = gdb_get_reg_ptr(buf, 4);
ppc_maybe_bswap_register(env, mem_buf, 4);
return 4;
Expand Down Expand Up @@ -529,7 +529,7 @@ static int gdb_set_avr_reg(CPUPPCState *env, uint8_t *mem_buf, int n)
}
if (n == 32) {
ppc_maybe_bswap_register(env, mem_buf, 4);
helper_mtvscr(env, ldl_p(mem_buf));
ppc_store_vscr(env, ldl_p(mem_buf));
return 4;
}
if (n == 33) {
Expand Down
9 changes: 2 additions & 7 deletions target/ppc/int_helper.c
Expand Up @@ -462,17 +462,12 @@ SATCVT(sd, uw, int64_t, uint32_t, 0, UINT32_MAX)

void helper_mtvscr(CPUPPCState *env, uint32_t vscr)
{
env->vscr = vscr & ~(1u << VSCR_SAT);
/* Which bit we set is completely arbitrary, but clear the rest. */
env->vscr_sat.u64[0] = vscr & (1u << VSCR_SAT);
env->vscr_sat.u64[1] = 0;
set_flush_to_zero((vscr >> VSCR_NJ) & 1, &env->vec_status);
ppc_store_vscr(env, vscr);
}

uint32_t helper_mfvscr(CPUPPCState *env)
{
uint32_t sat = (env->vscr_sat.u64[0] | env->vscr_sat.u64[1]) != 0;
return env->vscr | (sat << VSCR_SAT);
return ppc_get_vscr(env);
}

static inline void set_vscr_sat(CPUPPCState *env)
Expand Down

0 comments on commit c19940d

Please sign in to comment.