riscv_syscall.S: Remove duplicated code
Return from exception is common code for both system calls and exceptions
This commit is contained in:
parent
394de18316
commit
6bad48e4c7
@ -72,6 +72,7 @@
|
|||||||
|
|
||||||
.section EXCEPTION_SECTION
|
.section EXCEPTION_SECTION
|
||||||
.global exception_common
|
.global exception_common
|
||||||
|
.global return_from_exception
|
||||||
.align 8
|
.align 8
|
||||||
|
|
||||||
exception_common:
|
exception_common:
|
||||||
@ -142,6 +143,8 @@ exception_common:
|
|||||||
addi sp, sp, XCPTCONTEXT_SIZE
|
addi sp, sp, XCPTCONTEXT_SIZE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return_from_exception:
|
||||||
|
|
||||||
/* If context switch is needed, return a new sp */
|
/* If context switch is needed, return a new sp */
|
||||||
|
|
||||||
mv sp, a0
|
mv sp, a0
|
||||||
|
@ -119,52 +119,8 @@ sys_call6:
|
|||||||
|
|
||||||
/* Run the handler */
|
/* Run the handler */
|
||||||
|
|
||||||
jal x1, riscv_perform_syscall
|
la x1, return_from_exception
|
||||||
|
tail riscv_perform_syscall
|
||||||
/* Restore (potentially new) context */
|
|
||||||
|
|
||||||
mv sp, a0 /* use sp, as a0 gets wiped */
|
|
||||||
|
|
||||||
REGLOAD s0, REG_EPC(sp) /* restore epc */
|
|
||||||
csrw CSR_EPC, s0
|
|
||||||
|
|
||||||
/* Restore status register, but don't enable interrupts yet */
|
|
||||||
|
|
||||||
REGLOAD s0, REG_INT_CTX(sp) /* restore status */
|
|
||||||
li s1, STATUS_IE /* move IE -> PIE */
|
|
||||||
and s1, s0, s1 /* if (STATUS & IE) */
|
|
||||||
beqz s1, 1f
|
|
||||||
li s1, ~STATUS_IE /* clear IE */
|
|
||||||
and s0, s0, s1
|
|
||||||
li s1, STATUS_PIE /* set PIE */
|
|
||||||
or s0, s0, s1
|
|
||||||
|
|
||||||
1:
|
|
||||||
csrw CSR_STATUS, s0
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_KERNEL_STACK
|
|
||||||
/* Returning to userspace ? */
|
|
||||||
|
|
||||||
li s1, STATUS_PPP
|
|
||||||
and s0, s0, s1
|
|
||||||
bnez s0, 1f
|
|
||||||
|
|
||||||
/* Set the next task's kernel stack to the scratch area */
|
|
||||||
|
|
||||||
jal x1, riscv_current_ksp
|
|
||||||
csrr s0, CSR_SCRATCH
|
|
||||||
REGSTORE a0, RISCV_PERCPU_KSP(s0)
|
|
||||||
|
|
||||||
1:
|
|
||||||
#endif
|
|
||||||
|
|
||||||
load_ctx sp
|
|
||||||
|
|
||||||
REGLOAD sp, REG_SP(sp) /* restore original sp */
|
|
||||||
|
|
||||||
/* return from exception, which updates the status register */
|
|
||||||
|
|
||||||
ERET
|
|
||||||
|
|
||||||
.size sys_call0, .-sys_call0
|
.size sys_call0, .-sys_call0
|
||||||
.size sys_call1, .-sys_call1
|
.size sys_call1, .-sys_call1
|
||||||
|
Loading…
Reference in New Issue
Block a user