target/sparc: Handle FPRS correctly on big-endian hosts
authorPeter Maydell <peter.maydell@linaro.org>
Mon, 17 Jul 2023 10:35:44 +0000 (11:35 +0100)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Tue, 25 Jul 2023 12:42:00 +0000 (14:42 +0200)
commitca4d5d862df43630381647552725eaf1099033b8
treee53a2fb2c63fe60fdb990e4427b4f84ba1b89f08
parent0fe4cac5dda1028c22ec3a6997e1b9155a768004
target/sparc: Handle FPRS correctly on big-endian hosts

In CPUSparcState we define the fprs field as uint64_t.  However we
then refer to it in translate.c via a TCGv_i32 which we set up with
tcg_global_mem_new_ptr().  This means that on a big-endian host when
the guest does something to writo te the FPRS register this value
ends up in the wrong half of the uint64_t, and the QEMU C code that
refers to env->fprs sees the wrong value.  The effect of this is that
guest code that enables the FPU crashes with spurious FPU Disabled
exceptions.  In particular, this is why
 tests/avocado/machine_sparc64_sun4u.py:Sun4uMachine.test_sparc64_sun4u
times out on an s390 host.

There are multiple ways we could fix this; since there are actually
only three bits in the FPRS register and the code in translate.c
would be a bit painful to convert to dealing with a TCGv_i64, change
the type of the CPU state struct field to match what translate.c is
expecting.

(None of the other fields referenced by the r32[] array in
sparc_tcg_init() have the wrong type.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Message-Id: <20230717103544.637453-1-peter.maydell@linaro.org>
target/sparc/cpu.c
target/sparc/cpu.h
target/sparc/machine.c
target/sparc/monitor.c