target/arm: Allow access to SPSR_hyp from hyp mode
authorPeter Maydell <peter.maydell@linaro.org>
Tue, 6 Feb 2024 13:29:22 +0000 (13:29 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 15 Feb 2024 14:32:38 +0000 (14:32 +0000)
commitf2b4a98930c122648e9dc494e49cea5dffbcc2be
treed9efa553d1f508012bc17b4ee64254cb7e72990a
parent282a48eca4c84c3f146165aab3a64e82b4b60670
target/arm: Allow access to SPSR_hyp from hyp mode

Architecturally, the AArch32 MSR/MRS to/from banked register
instructions are UNPREDICTABLE for attempts to access a banked
register that the guest could access in a more direct way (e.g.
using this insn to access r8_fiq when already in FIQ mode).  QEMU has
chosen to UNDEF on all of these.

However, for the case of accessing SPSR_hyp from hyp mode, it turns
out that real hardware permits this, with the same effect as if the
guest had directly written to SPSR. Further, there is some
guest code out there that assumes it can do this, because it
happens to work on hardware: an example Cortex-R52 startup code
fragment uses this, and it got copied into various other places,
including Zephyr. Zephyr was fixed to not use this:
 https://github.com/zephyrproject-rtos/zephyr/issues/47330
but other examples are still out there, like the selftest
binary for the MPS3-AN536.

For convenience of being able to run guest code, permit
this UNPREDICTABLE access instead of UNDEFing it.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20240206132931.38376-5-peter.maydell@linaro.org
target/arm/tcg/op_helper.c
target/arm/tcg/translate.c