Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riscv/context_switch: Set tp when a context switch occurs #15652

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions arch/risc-v/src/common/riscv_exception_common.S
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ exception_common:
REGSTORE s3, REG_SP(sp)

#ifdef CONFIG_LIB_SYSCALL
csrr tp, CSR_SCRATCH /* Load kernel TP */
REGLOAD tp, RISCV_PERCPU_TCB(tp)

/* Check whether it is an exception or interrupt */

blt s2, x0, handle_irq /* If cause < 0 it is interrupt */
Expand All @@ -177,9 +180,6 @@ exception_common:
addi s1, s1, 0x4 /* Must move EPC forward by +4 */
REGSTORE s1, REG_EPC(sp) /* Updated EPC to user context */

csrr tp, CSR_SCRATCH /* Load kernel TP */
REGLOAD tp, RISCV_PERCPU_TCB(tp)

mv a7, sp /* a7 = context */
call x1, dispatch_syscall /* Dispatch the system call */

Expand Down Expand Up @@ -246,9 +246,8 @@ return_from_exception:
#ifdef CONFIG_LIB_SYSCALL
/* Store tcb to scratch register */

call x1, nxsched_self
csrr s1, CSR_SCRATCH
REGSTORE a0, RISCV_PERCPU_TCB(s1)
REGSTORE tp, RISCV_PERCPU_TCB(s1)
#endif

#ifdef CONFIG_ARCH_KERNEL_STACK
Expand Down
6 changes: 6 additions & 0 deletions arch/risc-v/src/common/riscv_initialstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ void up_initial_state(struct tcb_s *tcb)
/* Set idle process' initial interrupt context */

riscv_set_idleintctx();

#ifdef CONFIG_LIB_SYSCALL
/* Update current thread pointer */

__asm__ __volatile__("mv tp, %0" : : "r"(tcb));
#endif
return;
}

Expand Down
6 changes: 6 additions & 0 deletions arch/risc-v/src/common/riscv_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ static inline void riscv_restorecontext(struct tcb_s *tcb)

riscv_restorevpu(tcb->xcp.regs, riscv_vpuregs(tcb));
#endif

#ifdef CONFIG_LIB_SYSCALL
/* Update current thread pointer */

__asm__ __volatile__("mv tp, %0" : : "r"(tcb));
#endif
}

#ifdef CONFIG_ARCH_RISCV_INTXCPT_EXTENSIONS
Expand Down
Loading