QEMU-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] riscv: csr: do not drop C bit on misa write
@ 2026-08-06 13:37 Vladimir Isaev
  2026-08-06 13:37 ` [PATCH 2/2] tests/tcg/riscv64: add misa write test Vladimir Isaev
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Vladimir Isaev @ 2026-08-06 13:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: palmer, alistair.francis, liwei1518, daniel.barboza, zhiwei_liu,
	chao.liu, qemu-riscv, Vladimir Isaev

According to spec:
> Writing misa may increase IALIGN, e.g., by disabling the "C" extension.
> If an instruction that would write misa increases IALIGN, and the
> subsequent instruction’s address is not IALIGN-bit aligned, the
> write to misa is suppressed, leaving misa unchanged.

So attempt to disable C extension if next instruction is not aligned should not
change the misa.

Signed-off-by: Vladimir Isaev <vvisaev@gmail.com>
---
 target/riscv/tcg/csr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/target/riscv/tcg/csr.c b/target/riscv/tcg/csr.c
index 36f2004bc5..58c206c1fa 100644
--- a/target/riscv/tcg/csr.c
+++ b/target/riscv/tcg/csr.c
@@ -2182,9 +2182,10 @@ static RISCVException write_misa(CPURISCVState *env, int csrno,
     /* Mask extensions that are not supported by this hart */
     val &= env->misa_ext_mask;
 
-    /* Suppress 'C' if next instruction is not aligned. */
-    if ((val & RVC) && (get_next_pc(env, ra) & 3) != 0) {
-        val &= ~RVC;
+    /* drop write if RVC is cleared and next instruction is not aligned */
+    if ((env->misa_ext & RVC) && !(val & RVC) &&
+         (get_next_pc(env, ra) & 3) != 0) {
+        return RISCV_EXCP_NONE;
     }
 
     /* Disable RVG if any of its dependencies are disabled */
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-13 10:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06 13:37 [PATCH 1/2] riscv: csr: do not drop C bit on misa write Vladimir Isaev
2026-08-06 13:37 ` [PATCH 2/2] tests/tcg/riscv64: add misa write test Vladimir Isaev
2026-08-12 17:38   ` Alistair
2026-08-12 17:37 ` [PATCH 1/2] riscv: csr: do not drop C bit on misa write Alistair
2026-08-13 10:15 ` Joel Stanley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox