@samitouri / QOSamiQemu / commits / c400bd4058

semihosting/uaccess: Use the cpu_internal_tswap() functions

The semihosting ABI [1] states: > Multi-byte values in memory must be formatted as pure little-endian or pure > big-endian to match the endianness mapping configuration of the processor. This commits ensures that semihosting data is properly byte-swapped if the guest's CPU is currently in a different runtime-configurable endianness than the host's CPU. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3258 Buglink: https://github.com/taiki-e/semihosting/issues/18 [1]: https://github.com/ARM-software/abi-aa/blob/2025Q1/semihosting/semihosting.rst#the-semihosting-interface Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 20260311-semihosting-cpu-tswap-v3-3-8e239575ec08@eonerc.rwth-aachen.de Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

Martin Kröning committed Mar 11, 2026 at 17:27 UTC c400bd4058b71b744e2979084ca1b9449fed1e58
1 file changed +4 -4
include/semihosting/uaccess.h
+4 -4
@@ -28,7 +28,7 @@
28 ({ uint64_t val_ = 0; \
29 int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \
30 &val_, sizeof(val_), 0); \
31 - (val) = tswap64(val_); ret_; })
31 + (val) = cpu_internal_tswap64(cs, val_); ret_; })
32
33 /**
34 * get_user_u32:
@@ -39,7 +39,7 @@
39 ({ uint32_t val_ = 0; \
40 int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \
41 &val_, sizeof(val_), 0); \
42 - (val) = tswap32(val_); ret_; })
42 + (val) = cpu_internal_tswap32(cs, val_); ret_; })
43
44 /**
45 * get_user_u8:
@@ -65,7 +65,7 @@
65 * Returns: 0 on success, -1 on error.
66 */
67 #define put_user_u64(val, addr) \
68 - ({ uint64_t val_ = tswap64(val); \
68 + ({ uint64_t val_ = cpu_internal_tswap64(cs, val); \
69 cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); })
70
71 /**
@@ -74,7 +74,7 @@
74 * Returns: 0 on success, -1 on error.
75 */
76 #define put_user_u32(val, addr) \
77 - ({ uint32_t val_ = tswap32(val); \
77 + ({ uint32_t val_ = cpu_internal_tswap32(cs, val); \
78 cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); })
79
80 /**