RISC-V: Access CSRs using CSR numbers
We should prefer accessing CSRs using their CSR numbers because: 1. It compiles fine with older toolchains. 2. We can use latest CSR names in #define macro names of CSR numbers as-per RISC-V spec. 3. We can access newly added CSRs even if toolchain does not recognize newly addes CSRs by name. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
This commit is contained in:
+11
-11
@@ -37,11 +37,11 @@
|
||||
* the kernel thread pointer. If we came from the kernel, sscratch
|
||||
* will contain 0, and we should continue on the current TP.
|
||||
*/
|
||||
csrrw tp, sscratch, tp
|
||||
csrrw tp, CSR_SSCRATCH, tp
|
||||
bnez tp, _save_context
|
||||
|
||||
_restore_kernel_tpsp:
|
||||
csrr tp, sscratch
|
||||
csrr tp, CSR_SSCRATCH
|
||||
REG_S sp, TASK_TI_KERNEL_SP(tp)
|
||||
_save_context:
|
||||
REG_S sp, TASK_TI_USER_SP(tp)
|
||||
@@ -87,11 +87,11 @@ _save_context:
|
||||
li t0, SR_SUM | SR_FS
|
||||
|
||||
REG_L s0, TASK_TI_USER_SP(tp)
|
||||
csrrc s1, sstatus, t0
|
||||
csrr s2, sepc
|
||||
csrr s3, sbadaddr
|
||||
csrr s4, scause
|
||||
csrr s5, sscratch
|
||||
csrrc s1, CSR_SSTATUS, t0
|
||||
csrr s2, CSR_SEPC
|
||||
csrr s3, CSR_STVAL
|
||||
csrr s4, CSR_SCAUSE
|
||||
csrr s5, CSR_SSCRATCH
|
||||
REG_S s0, PT_SP(sp)
|
||||
REG_S s1, PT_SSTATUS(sp)
|
||||
REG_S s2, PT_SEPC(sp)
|
||||
@@ -107,8 +107,8 @@ _save_context:
|
||||
.macro RESTORE_ALL
|
||||
REG_L a0, PT_SSTATUS(sp)
|
||||
REG_L a2, PT_SEPC(sp)
|
||||
csrw sstatus, a0
|
||||
csrw sepc, a2
|
||||
csrw CSR_SSTATUS, a0
|
||||
csrw CSR_SEPC, a2
|
||||
|
||||
REG_L x1, PT_RA(sp)
|
||||
REG_L x3, PT_GP(sp)
|
||||
@@ -155,7 +155,7 @@ ENTRY(handle_exception)
|
||||
* Set sscratch register to 0, so that if a recursive exception
|
||||
* occurs, the exception vector knows it came from the kernel
|
||||
*/
|
||||
csrw sscratch, x0
|
||||
csrw CSR_SSCRATCH, x0
|
||||
|
||||
/* Load the global pointer */
|
||||
.option push
|
||||
@@ -248,7 +248,7 @@ resume_userspace:
|
||||
* Save TP into sscratch, so we can find the kernel data structures
|
||||
* again.
|
||||
*/
|
||||
csrw sscratch, tp
|
||||
csrw CSR_SSCRATCH, tp
|
||||
|
||||
restore_all:
|
||||
RESTORE_ALL
|
||||
|
||||
Reference in New Issue
Block a user