From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
qemu-ppc@nongnu.org, qemu-arm@nongnu.org,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH v2 2/9] target/mips: Remove tswap() calls in semihosting uhi_fstat_cb()
Date: Thu, 12 Dec 2024 00:03:50 +0100 [thread overview]
Message-ID: <20241211230357.97036-3-philmd@linaro.org> (raw)
In-Reply-To: <20241211230357.97036-1-philmd@linaro.org>
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>
---
target/mips/tcg/sysemu/mips-semi.c | 43 +++++++++++++++++++++---------
1 file changed, 30 insertions(+), 13 deletions(-)
diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c
index 5ba06e95734..df0c3256d9e 100644
--- a/target/mips/tcg/sysemu/mips-semi.c
+++ b/target/mips/tcg/sysemu/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.45.2
next prev parent reply other threads:[~2024-12-11 23:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 23:03 [PATCH v2 0/9] misc: Reduce 'exec/tswap.h' inclusions Philippe Mathieu-Daudé
2024-12-11 23:03 ` [PATCH v2 1/9] target/xtensa: Remove tswap() calls in semihosting simcall() helper Philippe Mathieu-Daudé
2024-12-11 23:08 ` Philippe Mathieu-Daudé
2024-12-11 23:44 ` Richard Henderson
2024-12-11 23:03 ` Philippe Mathieu-Daudé [this message]
2024-12-11 23:03 ` [PATCH v2 3/9] accel/tcg: Include missing 'exec/tswap.h' header in translator.c Philippe Mathieu-Daudé
2024-12-11 23:47 ` Richard Henderson
2024-12-11 23:03 ` [PATCH v2 4/9] hw/arm: Include missing 'exec/tswap.h' header Philippe Mathieu-Daudé
2024-12-11 23:53 ` Richard Henderson
2024-12-17 15:20 ` Philippe Mathieu-Daudé
2024-12-11 23:03 ` [PATCH v2 5/9] hw/ppc: " Philippe Mathieu-Daudé
2024-12-12 0:00 ` Richard Henderson
2024-12-11 23:03 ` [PATCH v2 6/9] hw/mips: " Philippe Mathieu-Daudé
2024-12-12 0:01 ` Richard Henderson
2024-12-11 23:03 ` [PATCH v2 7/9] hw/sh4/r2d: " Philippe Mathieu-Daudé
2024-12-12 0:02 ` Richard Henderson
2024-12-11 23:03 ` [PATCH v2 8/9] hw/xtensa: " Philippe Mathieu-Daudé
2024-12-12 0:02 ` Richard Henderson
2024-12-11 23:03 ` [PATCH v2 9/9] exec/cpu-all: Do not include " Philippe Mathieu-Daudé
2024-12-12 0:02 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241211230357.97036-3-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.