[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 53/59] target/mips: Remove tswap() calls in semihosting uhi_fstat_
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 53/59] target/mips: Remove tswap() calls in semihosting uhi_fstat_cb() |
Date: |
Fri, 20 Dec 2024 17:15:44 +0100 |
In preparation of heterogeneous emulation where cores with
different endianness can run concurrently, we need to remove
the tswap() calls -- which use a fixed per-binary endianness.
Get the endianness of the UHI CPU accessed using
mips_env_is_bigendian() and replace the tswap() calls
by bswap() ones when necessary.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20241211230357.97036-3-philmd@linaro.org>
---
target/mips/tcg/system/mips-semi.c | 43 +++++++++++++++++++++---------
1 file changed, 30 insertions(+), 13 deletions(-)
diff --git a/target/mips/tcg/system/mips-semi.c
b/target/mips/tcg/system/mips-semi.c
index 5ba06e95734..df0c3256d9e 100644
--- a/target/mips/tcg/system/mips-semi.c
+++ b/target/mips/tcg/system/mips-semi.c
@@ -168,6 +168,7 @@ static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int
err)
if (!err) {
CPUMIPSState *env = cpu_env(cs);
+ bool swap_needed = HOST_BIG_ENDIAN != mips_env_is_bigendian(env);
target_ulong addr = env->active_tc.gpr[5];
UHIStat *dst = lock_user(VERIFY_WRITE, addr, sizeof(UHIStat), 1);
struct gdb_stat s;
@@ -179,19 +180,35 @@ static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int
err)
memcpy(&s, dst, sizeof(struct gdb_stat));
memset(dst, 0, sizeof(UHIStat));
- dst->uhi_st_dev = tswap16(be32_to_cpu(s.gdb_st_dev));
- dst->uhi_st_ino = tswap16(be32_to_cpu(s.gdb_st_ino));
- dst->uhi_st_mode = tswap32(be32_to_cpu(s.gdb_st_mode));
- dst->uhi_st_nlink = tswap16(be32_to_cpu(s.gdb_st_nlink));
- dst->uhi_st_uid = tswap16(be32_to_cpu(s.gdb_st_uid));
- dst->uhi_st_gid = tswap16(be32_to_cpu(s.gdb_st_gid));
- dst->uhi_st_rdev = tswap16(be32_to_cpu(s.gdb_st_rdev));
- dst->uhi_st_size = tswap64(be64_to_cpu(s.gdb_st_size));
- dst->uhi_st_atime = tswap64(be32_to_cpu(s.gdb_st_atime));
- dst->uhi_st_mtime = tswap64(be32_to_cpu(s.gdb_st_mtime));
- dst->uhi_st_ctime = tswap64(be32_to_cpu(s.gdb_st_ctime));
- dst->uhi_st_blksize = tswap64(be64_to_cpu(s.gdb_st_blksize));
- dst->uhi_st_blocks = tswap64(be64_to_cpu(s.gdb_st_blocks));
+ dst->uhi_st_dev = be32_to_cpu(s.gdb_st_dev);
+ dst->uhi_st_ino = be32_to_cpu(s.gdb_st_ino);
+ dst->uhi_st_mode = be32_to_cpu(s.gdb_st_mode);
+ dst->uhi_st_nlink = be32_to_cpu(s.gdb_st_nlink);
+ dst->uhi_st_uid = be32_to_cpu(s.gdb_st_uid);
+ dst->uhi_st_gid = be32_to_cpu(s.gdb_st_gid);
+ dst->uhi_st_rdev = be32_to_cpu(s.gdb_st_rdev);
+ dst->uhi_st_size = be64_to_cpu(s.gdb_st_size);
+ dst->uhi_st_atime = be32_to_cpu(s.gdb_st_atime);
+ dst->uhi_st_mtime = be32_to_cpu(s.gdb_st_mtime);
+ dst->uhi_st_ctime = be32_to_cpu(s.gdb_st_ctime);
+ dst->uhi_st_blksize = be64_to_cpu(s.gdb_st_blksize);
+ dst->uhi_st_blocks = be64_to_cpu(s.gdb_st_blocks);
+
+ if (swap_needed) {
+ dst->uhi_st_dev = bswap16(dst->uhi_st_dev);
+ dst->uhi_st_ino = bswap16(dst->uhi_st_ino);
+ dst->uhi_st_mode = bswap32(dst->uhi_st_mode);
+ dst->uhi_st_nlink = bswap16(dst->uhi_st_nlink);
+ dst->uhi_st_uid = bswap16(dst->uhi_st_uid);
+ dst->uhi_st_gid = bswap16(dst->uhi_st_gid);
+ dst->uhi_st_rdev = bswap16(dst->uhi_st_rdev);
+ dst->uhi_st_size = bswap64(dst->uhi_st_size);
+ dst->uhi_st_atime = bswap64(dst->uhi_st_atime);
+ dst->uhi_st_mtime = bswap64(dst->uhi_st_mtime);
+ dst->uhi_st_ctime = bswap64(dst->uhi_st_ctime);
+ dst->uhi_st_blksize = bswap64(dst->uhi_st_blksize);
+ dst->uhi_st_blocks = bswap64(dst->uhi_st_blocks);
+ }
unlock_user(dst, addr, sizeof(UHIStat));
}
--
2.47.1
- [PULL 42/59] target/sparc: Uninline cpu_get_tb_cpu_state(), (continued)
- [PULL 42/59] target/sparc: Uninline cpu_get_tb_cpu_state(), Philippe Mathieu-Daudé, 2024/12/20
- [PULL 44/59] exec/cpu-all: Include 'cpu.h' earlier so MMU_USER_IDX is always defined, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 45/59] accel/tcg: Declare cpu_loop_exit_requested() in 'exec/cpu-common.h', Philippe Mathieu-Daudé, 2024/12/20
- [PULL 46/59] exec/translation-block: Include missing 'qemu/atomic.h' header, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 47/59] qemu/coroutine: Include missing 'qemu/atomic.h' header, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 48/59] accel/tcg: Restrict curr_cflags() declaration to 'internal-common.h', Philippe Mathieu-Daudé, 2024/12/20
- [PULL 49/59] accel/tcg: Move tcg_cflags_has/set() to 'exec/translation-block.h', Philippe Mathieu-Daudé, 2024/12/20
- [PULL 50/59] accel/tcg: Include missing 'exec/translation-block.h' header, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 51/59] accel/tcg: Un-inline translator_is_same_page(), Philippe Mathieu-Daudé, 2024/12/20
- [PULL 52/59] target/xtensa: Remove tswap() calls in semihosting simcall() helper, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 53/59] target/mips: Remove tswap() calls in semihosting uhi_fstat_cb(),
Philippe Mathieu-Daudé <=
- [PULL 55/59] hw/xen: Remove unnecessary 'exec/cpu-common.h' header, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 54/59] target/mips: Drop left-over comment about Jazz machine, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 56/59] system/numa: Remove unnecessary 'exec/cpu-common.h' header, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 57/59] system/accel-ops: Remove unnecessary 'exec/cpu-common.h' header, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 58/59] meson: Do not define CONFIG_DEVICES on user emulation, Philippe Mathieu-Daudé, 2024/12/20
- [PULL 59/59] util/qemu-timer: fix indentation, Philippe Mathieu-Daudé, 2024/12/20
- Re: [PULL 00/59] Accel & exec patches for 2024-12-20, Stefan Hajnoczi, 2024/12/21