• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisionf310df58bd2c570be8b802bffb37cb30da0c346e (tree)
Time2022-01-21 14:52:57
AuthorLIU Zhiwei <zhiwei_liu@c-sk...>
CommiterAlistair Francis

Log Message

target/riscv: Enable uxl field write

Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-id: 20220120122050.41546-23-zhiwei_liu@c-sky.com
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Change Summary

Incremental Difference

--- a/target/riscv/cpu_bits.h
+++ b/target/riscv/cpu_bits.h
@@ -449,6 +449,9 @@ typedef enum {
449449 #define COUNTEREN_IR (1 << 2)
450450 #define COUNTEREN_HPM3 (1 << 3)
451451
452+/* vsstatus CSR bits */
453+#define VSSTATUS64_UXL 0x0000000300000000ULL
454+
452455 /* Privilege modes */
453456 #define PRV_U 0
454457 #define PRV_S 1
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -496,7 +496,7 @@ static const target_ulong vs_delegable_excps = DELEGABLE_EXCPS &
496496 (1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT)));
497497 static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE |
498498 SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS |
499- SSTATUS_SUM | SSTATUS_MXR | SSTATUS_VS | (target_ulong)SSTATUS64_UXL;
499+ SSTATUS_SUM | SSTATUS_MXR | SSTATUS_VS;
500500 static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP;
501501 static const target_ulong hip_writable_mask = MIP_VSSIP;
502502 static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP;
@@ -572,6 +572,7 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
572572 {
573573 uint64_t mstatus = env->mstatus;
574574 uint64_t mask = 0;
575+ RISCVMXL xl = riscv_cpu_mxl(env);
575576
576577 /* flush tlb on mstatus fields that affect VM */
577578 if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | MSTATUS_MPV |
@@ -583,21 +584,22 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,
583584 MSTATUS_MPP | MSTATUS_MXR | MSTATUS_TVM | MSTATUS_TSR |
584585 MSTATUS_TW | MSTATUS_VS;
585586
586- if (riscv_cpu_mxl(env) != MXL_RV32) {
587+ if (xl != MXL_RV32) {
587588 /*
588589 * RV32: MPV and GVA are not in mstatus. The current plan is to
589590 * add them to mstatush. For now, we just don't support it.
590591 */
591592 mask |= MSTATUS_MPV | MSTATUS_GVA;
593+ if ((val & MSTATUS64_UXL) != 0) {
594+ mask |= MSTATUS64_UXL;
595+ }
592596 }
593597
594598 mstatus = (mstatus & ~mask) | (val & mask);
595599
596- RISCVMXL xl = riscv_cpu_mxl(env);
597600 if (xl > MXL_RV32) {
598- /* SXL and UXL fields are for now read only */
601+ /* SXL field is for now read only */
599602 mstatus = set_field(mstatus, MSTATUS64_SXL, xl);
600- mstatus = set_field(mstatus, MSTATUS64_UXL, xl);
601603 }
602604 env->mstatus = mstatus;
603605 env->xl = cpu_recompute_xl(env);
@@ -898,6 +900,9 @@ static RISCVException read_sstatus_i128(CPURISCVState *env, int csrno,
898900 {
899901 uint64_t mask = sstatus_v1_10_mask;
900902 uint64_t sstatus = env->mstatus & mask;
903+ if (env->xl != MXL_RV32) {
904+ mask |= SSTATUS64_UXL;
905+ }
901906
902907 *val = int128_make128(sstatus, add_status_sd(MXL_RV128, sstatus));
903908 return RISCV_EXCP_NONE;
@@ -907,7 +912,9 @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno,
907912 target_ulong *val)
908913 {
909914 target_ulong mask = (sstatus_v1_10_mask);
910-
915+ if (env->xl != MXL_RV32) {
916+ mask |= SSTATUS64_UXL;
917+ }
911918 /* TODO: Use SXL not MXL. */
912919 *val = add_status_sd(riscv_cpu_mxl(env), env->mstatus & mask);
913920 return RISCV_EXCP_NONE;
@@ -917,6 +924,12 @@ static RISCVException write_sstatus(CPURISCVState *env, int csrno,
917924 target_ulong val)
918925 {
919926 target_ulong mask = (sstatus_v1_10_mask);
927+
928+ if (env->xl != MXL_RV32) {
929+ if ((val & SSTATUS64_UXL) != 0) {
930+ mask |= SSTATUS64_UXL;
931+ }
932+ }
920933 target_ulong newval = (env->mstatus & ~mask) | (val & mask);
921934 return write_mstatus(env, CSR_MSTATUS, newval);
922935 }
@@ -1380,6 +1393,9 @@ static RISCVException write_vsstatus(CPURISCVState *env, int csrno,
13801393 target_ulong val)
13811394 {
13821395 uint64_t mask = (target_ulong)-1;
1396+ if ((val & VSSTATUS64_UXL) == 0) {
1397+ mask &= ~VSSTATUS64_UXL;
1398+ }
13831399 env->vsstatus = (env->vsstatus & ~mask) | (uint64_t)val;
13841400 return RISCV_EXCP_NONE;
13851401 }