diff options
| author | Vivian Wang <[email protected]> | 2022-08-04 22:32:30 +0800 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2022-08-22 08:50:04 +0530 |
| commit | 5a0ca098f176fd5b84d311e82543a05aaab8cafb (patch) | |
| tree | 57b4b6c2377cb9b1cca0453f305c06680340b918 | |
| parent | 1c4ce74f5128b7e1094ad253c9bc5fd732e3d82b (diff) | |
lib: sbi_trap: Set hypervisor CSRs for HS-mode
The hypervisor CSRs hstatus, htval, htinst should always be set if the
trap is to be taken in HS-mode, regardless of which mode it came from.
Signed-off-by: Vivian Wang <[email protected]>
Reviewed-by: Andrew Jones <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
| -rw-r--r-- | lib/sbi/sbi_trap.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index db70c26d..1cf2e6fc 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -118,12 +118,14 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, regs->mstatus |= (next_virt) ? MSTATUS_MPV : 0UL; #endif - /* Update HSTATUS for VS/VU-mode to HS-mode transition */ - if (misa_extension('H') && prev_virt && !next_virt) { - /* Update HSTATUS SPVP and SPV bits */ + /* Update hypervisor CSRs if going to HS-mode */ + if (misa_extension('H') && !next_virt) { hstatus = csr_read(CSR_HSTATUS); - hstatus &= ~HSTATUS_SPVP; - hstatus |= (prev_mode == PRV_S) ? HSTATUS_SPVP : 0; + if (prev_virt) { + /* hstatus.SPVP is only updated if coming from VS/VU-mode */ + hstatus &= ~HSTATUS_SPVP; + hstatus |= (prev_mode == PRV_S) ? HSTATUS_SPVP : 0; + } hstatus &= ~HSTATUS_SPV; hstatus |= (prev_virt) ? HSTATUS_SPV : 0; csr_write(CSR_HSTATUS, hstatus); |
