Revision | f310df58bd2c570be8b802bffb37cb30da0c346e (tree) |
---|---|
Time | 2022-01-21 14:52:57 |
Author | LIU Zhiwei <zhiwei_liu@c-sk...> |
Commiter | Alistair Francis |
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>
@@ -449,6 +449,9 @@ typedef enum { | ||
449 | 449 | #define COUNTEREN_IR (1 << 2) |
450 | 450 | #define COUNTEREN_HPM3 (1 << 3) |
451 | 451 | |
452 | +/* vsstatus CSR bits */ | |
453 | +#define VSSTATUS64_UXL 0x0000000300000000ULL | |
454 | + | |
452 | 455 | /* Privilege modes */ |
453 | 456 | #define PRV_U 0 |
454 | 457 | #define PRV_S 1 |
@@ -496,7 +496,7 @@ static const target_ulong vs_delegable_excps = DELEGABLE_EXCPS & | ||
496 | 496 | (1ULL << (RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT))); |
497 | 497 | static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE | |
498 | 498 | 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; | |
500 | 500 | static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP; |
501 | 501 | static const target_ulong hip_writable_mask = MIP_VSSIP; |
502 | 502 | 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, | ||
572 | 572 | { |
573 | 573 | uint64_t mstatus = env->mstatus; |
574 | 574 | uint64_t mask = 0; |
575 | + RISCVMXL xl = riscv_cpu_mxl(env); | |
575 | 576 | |
576 | 577 | /* flush tlb on mstatus fields that affect VM */ |
577 | 578 | if ((val ^ mstatus) & (MSTATUS_MXR | MSTATUS_MPP | MSTATUS_MPV | |
@@ -583,21 +584,22 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno, | ||
583 | 584 | MSTATUS_MPP | MSTATUS_MXR | MSTATUS_TVM | MSTATUS_TSR | |
584 | 585 | MSTATUS_TW | MSTATUS_VS; |
585 | 586 | |
586 | - if (riscv_cpu_mxl(env) != MXL_RV32) { | |
587 | + if (xl != MXL_RV32) { | |
587 | 588 | /* |
588 | 589 | * RV32: MPV and GVA are not in mstatus. The current plan is to |
589 | 590 | * add them to mstatush. For now, we just don't support it. |
590 | 591 | */ |
591 | 592 | mask |= MSTATUS_MPV | MSTATUS_GVA; |
593 | + if ((val & MSTATUS64_UXL) != 0) { | |
594 | + mask |= MSTATUS64_UXL; | |
595 | + } | |
592 | 596 | } |
593 | 597 | |
594 | 598 | mstatus = (mstatus & ~mask) | (val & mask); |
595 | 599 | |
596 | - RISCVMXL xl = riscv_cpu_mxl(env); | |
597 | 600 | if (xl > MXL_RV32) { |
598 | - /* SXL and UXL fields are for now read only */ | |
601 | + /* SXL field is for now read only */ | |
599 | 602 | mstatus = set_field(mstatus, MSTATUS64_SXL, xl); |
600 | - mstatus = set_field(mstatus, MSTATUS64_UXL, xl); | |
601 | 603 | } |
602 | 604 | env->mstatus = mstatus; |
603 | 605 | env->xl = cpu_recompute_xl(env); |
@@ -898,6 +900,9 @@ static RISCVException read_sstatus_i128(CPURISCVState *env, int csrno, | ||
898 | 900 | { |
899 | 901 | uint64_t mask = sstatus_v1_10_mask; |
900 | 902 | uint64_t sstatus = env->mstatus & mask; |
903 | + if (env->xl != MXL_RV32) { | |
904 | + mask |= SSTATUS64_UXL; | |
905 | + } | |
901 | 906 | |
902 | 907 | *val = int128_make128(sstatus, add_status_sd(MXL_RV128, sstatus)); |
903 | 908 | return RISCV_EXCP_NONE; |
@@ -907,7 +912,9 @@ static RISCVException read_sstatus(CPURISCVState *env, int csrno, | ||
907 | 912 | target_ulong *val) |
908 | 913 | { |
909 | 914 | target_ulong mask = (sstatus_v1_10_mask); |
910 | - | |
915 | + if (env->xl != MXL_RV32) { | |
916 | + mask |= SSTATUS64_UXL; | |
917 | + } | |
911 | 918 | /* TODO: Use SXL not MXL. */ |
912 | 919 | *val = add_status_sd(riscv_cpu_mxl(env), env->mstatus & mask); |
913 | 920 | return RISCV_EXCP_NONE; |
@@ -917,6 +924,12 @@ static RISCVException write_sstatus(CPURISCVState *env, int csrno, | ||
917 | 924 | target_ulong val) |
918 | 925 | { |
919 | 926 | 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 | + } | |
920 | 933 | target_ulong newval = (env->mstatus & ~mask) | (val & mask); |
921 | 934 | return write_mstatus(env, CSR_MSTATUS, newval); |
922 | 935 | } |
@@ -1380,6 +1393,9 @@ static RISCVException write_vsstatus(CPURISCVState *env, int csrno, | ||
1380 | 1393 | target_ulong val) |
1381 | 1394 | { |
1382 | 1395 | uint64_t mask = (target_ulong)-1; |
1396 | + if ((val & VSSTATUS64_UXL) == 0) { | |
1397 | + mask &= ~VSSTATUS64_UXL; | |
1398 | + } | |
1383 | 1399 | env->vsstatus = (env->vsstatus & ~mask) | (uint64_t)val; |
1384 | 1400 | return RISCV_EXCP_NONE; |
1385 | 1401 | } |