From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Christoph Muellner" <christoph.muellner@vrull.eu>,
"Heinrich Schuchardt" <heinrich.schuchardt@canonical.com>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Alistair Francis" <alistair.francis@wdc.com>,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>,
"Anton Johansson" <anjo@rev.ng>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Valentin Haudiquet" <valentin.haudiquet@canonical.com>,
"Weiwei Li" <liwei1518@gmail.com>,
qemu-riscv@nongnu.org,
"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 13/13] target/riscv: Introduce mo_endian_env() helper
Date: Fri, 10 Oct 2025 17:50:44 +0200 [thread overview]
Message-ID: <20251010155045.78220-14-philmd@linaro.org> (raw)
In-Reply-To: <20251010155045.78220-1-philmd@linaro.org>
mo_endian_env() returns the target endianness from CPUArchState.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
target/riscv/op_helper.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c
index c486f771d35..9d048089e2a 100644
--- a/target/riscv/op_helper.c
+++ b/target/riscv/op_helper.c
@@ -28,6 +28,18 @@
#include "exec/tlb-flags.h"
#include "trace.h"
+static inline MemOp mo_endian_env(CPURISCVState *env)
+{
+ /*
+ * A couple of bits in MSTATUS set the endianness:
+ * - MSTATUS_UBE (User-mode),
+ * - MSTATUS_SBE (Supervisor-mode),
+ * - MSTATUS_MBE (Machine-mode)
+ * but we don't implement that yet.
+ */
+ return MO_TE;
+}
+
/* Exceptions processing helpers */
G_NORETURN void riscv_raise_exception(CPURISCVState *env,
RISCVException exception,
@@ -633,7 +645,7 @@ target_ulong helper_hyp_hlv_hu(CPURISCVState *env, target_ulong addr)
{
uintptr_t ra = GETPC();
int mmu_idx = check_access_hlsv(env, false, ra);
- MemOpIdx oi = make_memop_idx(MO_TE | MO_UW, mmu_idx);
+ MemOpIdx oi = make_memop_idx(mo_endian_env(env) | MO_UW, mmu_idx);
return cpu_ldw_mmu(env, adjust_addr_virt(env, addr), oi, ra);
}
@@ -642,7 +654,7 @@ target_ulong helper_hyp_hlv_wu(CPURISCVState *env, target_ulong addr)
{
uintptr_t ra = GETPC();
int mmu_idx = check_access_hlsv(env, false, ra);
- MemOpIdx oi = make_memop_idx(MO_TE | MO_UL, mmu_idx);
+ MemOpIdx oi = make_memop_idx(mo_endian_env(env) | MO_UL, mmu_idx);
return cpu_ldl_mmu(env, adjust_addr_virt(env, addr), oi, ra);
}
@@ -651,7 +663,7 @@ target_ulong helper_hyp_hlv_d(CPURISCVState *env, target_ulong addr)
{
uintptr_t ra = GETPC();
int mmu_idx = check_access_hlsv(env, false, ra);
- MemOpIdx oi = make_memop_idx(MO_TE | MO_UQ, mmu_idx);
+ MemOpIdx oi = make_memop_idx(mo_endian_env(env) | MO_UQ, mmu_idx);
return cpu_ldq_mmu(env, adjust_addr_virt(env, addr), oi, ra);
}
@@ -669,7 +681,7 @@ void helper_hyp_hsv_h(CPURISCVState *env, target_ulong addr, target_ulong val)
{
uintptr_t ra = GETPC();
int mmu_idx = check_access_hlsv(env, false, ra);
- MemOpIdx oi = make_memop_idx(MO_TE | MO_UW, mmu_idx);
+ MemOpIdx oi = make_memop_idx(mo_endian_env(env) | MO_UW, mmu_idx);
cpu_stw_mmu(env, adjust_addr_virt(env, addr), val, oi, ra);
}
@@ -678,7 +690,7 @@ void helper_hyp_hsv_w(CPURISCVState *env, target_ulong addr, target_ulong val)
{
uintptr_t ra = GETPC();
int mmu_idx = check_access_hlsv(env, false, ra);
- MemOpIdx oi = make_memop_idx(MO_TE | MO_UL, mmu_idx);
+ MemOpIdx oi = make_memop_idx(mo_endian_env(env) | MO_UL, mmu_idx);
cpu_stl_mmu(env, adjust_addr_virt(env, addr), val, oi, ra);
}
@@ -687,7 +699,7 @@ void helper_hyp_hsv_d(CPURISCVState *env, target_ulong addr, target_ulong val)
{
uintptr_t ra = GETPC();
int mmu_idx = check_access_hlsv(env, false, ra);
- MemOpIdx oi = make_memop_idx(MO_TE | MO_UQ, mmu_idx);
+ MemOpIdx oi = make_memop_idx(mo_endian_env(env) | MO_UQ, mmu_idx);
cpu_stq_mmu(env, adjust_addr_virt(env, addr), val, oi, ra);
}
@@ -703,7 +715,7 @@ target_ulong helper_hyp_hlvx_hu(CPURISCVState *env, target_ulong addr)
{
uintptr_t ra = GETPC();
int mmu_idx = check_access_hlsv(env, true, ra);
- MemOpIdx oi = make_memop_idx(MO_TE | MO_UW, mmu_idx);
+ MemOpIdx oi = make_memop_idx(mo_endian_env(env) | MO_UW, mmu_idx);
return cpu_ldw_code_mmu(env, addr, oi, GETPC());
}
@@ -712,7 +724,7 @@ target_ulong helper_hyp_hlvx_wu(CPURISCVState *env, target_ulong addr)
{
uintptr_t ra = GETPC();
int mmu_idx = check_access_hlsv(env, true, ra);
- MemOpIdx oi = make_memop_idx(MO_TE | MO_UL, mmu_idx);
+ MemOpIdx oi = make_memop_idx(mo_endian_env(env) | MO_UL, mmu_idx);
return cpu_ldl_code_mmu(env, addr, oi, ra);
}
--
2.51.0
next prev parent reply other threads:[~2025-10-10 15:54 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-10 15:50 [PATCH 00/13] target/riscv: Centralize MO_TE uses in a pair of helpers Philippe Mathieu-Daudé
2025-10-10 15:50 ` [PATCH 01/13] target/riscv: Really use little endianness for 128-bit loads/stores Philippe Mathieu-Daudé
2025-10-10 18:44 ` Richard Henderson
2025-10-10 15:50 ` [PATCH 02/13] target/riscv: Explode MO_TExx -> MO_TE | MO_xx Philippe Mathieu-Daudé
2025-10-10 18:45 ` Richard Henderson
2025-10-14 4:59 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 03/13] target/riscv: Conceal MO_TE within gen_amo() Philippe Mathieu-Daudé
2025-10-10 18:46 ` Richard Henderson
2025-10-14 5:00 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 04/13] target/riscv: Conceal MO_TE within gen_inc() Philippe Mathieu-Daudé
2025-10-10 18:47 ` Richard Henderson
2025-10-14 5:01 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 05/13] target/riscv: Conceal MO_TE within gen_load() / gen_store() Philippe Mathieu-Daudé
2025-10-10 18:47 ` Richard Henderson
2025-10-14 5:02 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 06/13] target/riscv: Conceal MO_TE within gen_load_idx() / gen_store_idx() Philippe Mathieu-Daudé
2025-10-10 18:48 ` Richard Henderson
2025-10-14 5:03 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 07/13] target/riscv: Conceal MO_TE within gen_fload_idx() / gen_fstore_idx() Philippe Mathieu-Daudé
2025-10-10 18:49 ` Richard Henderson
2025-10-14 5:05 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 08/13] target/riscv: Conceal MO_TE within gen_storepair_tl() Philippe Mathieu-Daudé
2025-10-10 18:49 ` Richard Henderson
2025-10-14 5:06 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 09/13] target/riscv: Conceal MO_TE within gen_cmpxchg*() Philippe Mathieu-Daudé
2025-10-10 18:50 ` Richard Henderson
2025-10-14 5:07 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 10/13] target/riscv: Conceal MO_TE|MO_ALIGN within gen_lr() / gen_sc() Philippe Mathieu-Daudé
2025-10-10 18:51 ` Richard Henderson
2025-10-14 5:08 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 11/13] target/riscv: Factor MemOp variable out when MO_TE is set Philippe Mathieu-Daudé
2025-10-10 16:18 ` Heinrich Schuchardt
2025-10-14 5:11 ` Alistair Francis
2025-10-10 15:50 ` [PATCH 12/13] target/riscv: Introduce mo_endian() helper Philippe Mathieu-Daudé
2025-10-10 16:35 ` Heinrich Schuchardt
2025-10-10 18:52 ` Richard Henderson
2025-10-14 5:13 ` Alistair Francis
2025-10-10 15:50 ` Philippe Mathieu-Daudé [this message]
2025-10-10 16:38 ` [PATCH 13/13] target/riscv: Introduce mo_endian_env() helper Heinrich Schuchardt
2025-10-14 5:15 ` Alistair Francis
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=20251010155045.78220-14-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=anjo@rev.ng \
--cc=christoph.muellner@vrull.eu \
--cc=dbarboza@ventanamicro.com \
--cc=heinrich.schuchardt@canonical.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=valentin.haudiquet@canonical.com \
--cc=zhiwei_liu@linux.alibaba.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).