[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 5/8] target/riscv: Correct mcause/scause bit width for RV32 in
From: |
LIU Zhiwei |
Subject: |
[PATCH v7 5/8] target/riscv: Correct mcause/scause bit width for RV32 in RV64 QEMU |
Date: |
Thu, 19 Sep 2024 13:50:45 +0800 |
From: TANG Tiancheng <tangtiancheng.ttc@alibaba-inc.com>
Ensure mcause high bit is correctly set by using 32-bit width for RV32
mode and 64-bit width for RV64 mode.
Signed-off-by: TANG Tiancheng <tangtiancheng.ttc@alibaba-inc.com>
Reviewed-by: Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu_helper.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index 521d49112f..077f6d77c3 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -1677,6 +1677,8 @@ void riscv_cpu_do_interrupt(CPUState *cs)
target_ulong tinst = 0;
target_ulong htval = 0;
target_ulong mtval2 = 0;
+ int sxlen = 0;
+ int mxlen = 0;
if (!async) {
/* set tval to badaddr for traps with address information */
@@ -1803,7 +1805,8 @@ void riscv_cpu_do_interrupt(CPUState *cs)
s = set_field(s, MSTATUS_SPP, env->priv);
s = set_field(s, MSTATUS_SIE, 0);
env->mstatus = s;
- env->scause = cause | ((target_ulong)async << (TARGET_LONG_BITS - 1));
+ sxlen = 16 << riscv_cpu_sxl(env);
+ env->scause = cause | ((target_ulong)async << (sxlen - 1));
env->sepc = env->pc;
env->stval = tval;
env->htval = htval;
@@ -1834,7 +1837,8 @@ void riscv_cpu_do_interrupt(CPUState *cs)
s = set_field(s, MSTATUS_MPP, env->priv);
s = set_field(s, MSTATUS_MIE, 0);
env->mstatus = s;
- env->mcause = cause | ~(((target_ulong)-1) >> async);
+ mxlen = 16 << riscv_cpu_mxl(env);
+ env->mcause = cause | ((target_ulong)async << (mxlen - 1));
env->mepc = env->pc;
env->mtval = tval;
env->mtval2 = mtval2;
--
2.43.0
- [PATCH v7 0/8] target/riscv: Expose RV32 cpu to RV64 QEMU, LIU Zhiwei, 2024/09/19
- [PATCH v7 1/8] target/riscv: Add fw_dynamic_info32 for booting RV32 OpenSBI, LIU Zhiwei, 2024/09/19
- [PATCH v7 2/8] target/riscv: Adjust PMP size for no-MMU RV64 QEMU running RV32, LIU Zhiwei, 2024/09/19
- [PATCH v7 3/8] target/riscv: Correct SXL return value for RV32 in RV64 QEMU, LIU Zhiwei, 2024/09/19
- [PATCH v7 4/8] target/riscv: Detect sxl to set bit width for RV32 in RV64, LIU Zhiwei, 2024/09/19
- [PATCH v7 5/8] target/riscv: Correct mcause/scause bit width for RV32 in RV64 QEMU,
LIU Zhiwei <=
- [PATCH v7 6/8] target/riscv: Enable RV32 CPU support in RV64 QEMU, LIU Zhiwei, 2024/09/19
- [PATCH v7 7/8] target/riscv: Add max32 CPU for RV64 QEMU, LIU Zhiwei, 2024/09/19
- [PATCH v7 8/8] tests/avocado: Boot Linux for RV32 cpu on RV64 QEMU, LIU Zhiwei, 2024/09/19