From 6c7922e23b85bef624ef84a8b05ed89495e1eb20 Mon Sep 17 00:00:00 2001 From: Atish Patra Date: Thu, 16 Apr 2020 18:56:30 -0700 Subject: [PATCH] lib: Support vector extension Enable vector context in mstatus by updating the corresponding bits in mstatus if vector extension is supported by the hart. Signed-off-by: Atish Patra Reviewed-by: Bin Meng Reviewed-by: Anup Patel --- include/sbi/riscv_encoding.h | 2 ++ lib/sbi/sbi_hart.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 1cf624bf..8c3e6f16 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -25,6 +25,7 @@ #define MSTATUS_MPP (_UL(3) << MSTATUS_MPP_SHIFT) #define MSTATUS_FS _UL(0x00006000) #define MSTATUS_XS _UL(0x00018000) +#define MSTATUS_VS _UL(0x01800000) #define MSTATUS_MPRV _UL(0x00020000) #define MSTATUS_SUM _UL(0x00040000) #define MSTATUS_MXR _UL(0x00080000) @@ -53,6 +54,7 @@ #define SSTATUS_SPP MSTATUS_SPP #define SSTATUS_FS MSTATUS_FS #define SSTATUS_XS MSTATUS_XS +#define SSTATUS_VS MSTATUS_VS #define SSTATUS_SUM MSTATUS_SUM #define SSTATUS_MXR MSTATUS_MXR #define SSTATUS32_SD MSTATUS32_SD diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index b0f9919b..b5df7c4f 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -25,10 +25,17 @@ void (*sbi_hart_unpriv_trap)(void) = &__sbi_unpriv_trap; static void mstatus_init(struct sbi_scratch *scratch, u32 hartid) { const struct sbi_platform *plat = sbi_platform_ptr(scratch); + unsigned long mstatus_val = 0; /* Enable FPU */ if (misa_extension('D') || misa_extension('F')) - csr_write(CSR_MSTATUS, MSTATUS_FS); + mstatus_val |= MSTATUS_FS; + + /* Enable Vector context */ + if (misa_extension('V')) + mstatus_val |= MSTATUS_VS; + + csr_write(CSR_MSTATUS, mstatus_val); /* Enable user/supervisor use of perf counters */ if (misa_extension('S') && sbi_platform_has_scounteren(plat))