From 25268e9c6a21906ece7cdeefd2ae473499a0fede Mon Sep 17 00:00:00 2001 From: Zhang Ze Date: Wed, 3 Aug 2022 13:42:53 +0800 Subject: [PATCH] Fix satp reg write bug to support linux 5.1.x kernel Signed-off-by: Zhang Ze --- src/isa/riscv64/system/priv.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/isa/riscv64/system/priv.c b/src/isa/riscv64/system/priv.c index 71ab47ada..fcbec0001 100644 --- a/src/isa/riscv64/system/priv.c +++ b/src/isa/riscv64/system/priv.c @@ -270,7 +270,19 @@ static inline void csr_write(word_t *dest, word_t src) { mmu_tlb_flush(0); #endif } else if (is_write(satp)) { - *dest = MASKED_SATP(src); + +#define SATP_MODE_BARE 0 +#define SATP_MODE_SV39 8 + + word_t mode; + + mode = (src >> SATP_PADDR_MAX_LEN) >> SATP_ASID_MAX_LEN; + + if (mode == SATP_MODE_BARE || mode == SATP_MODE_SV39) + { + *dest = MASKED_SATP(src); + } + } else { *dest = src; } bool need_update_mstatus_sd = false;