Skip to content

Commit

Permalink
core: riscv: Simplify SP setup in setup_unwind_user_mode()
Browse files Browse the repository at this point in the history
The parameter "regs" is the stack pointer which is allocated to store
system call registers when calling thread_scall_handler(). Thus, we can
simply get the original stack pointer by "regs + 1" equation, and use it
to exit user mode.

The code is referenced from ARM's setup_unwind_user_mode().

Signed-off-by: Alvin Chang <alvinga@andestech.com>
  • Loading branch information
gagachang committed Aug 14, 2024
1 parent eadb6be commit 0875dea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/arch/riscv/kernel/thread_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ static void setup_unwind_user_mode(struct thread_scall_regs *regs)
{
regs->ra = (uintptr_t)thread_unwind_user_mode;
regs->status = xstatus_for_xret(true, PRV_S);
regs->sp = thread_get_saved_thread_sp();
/*
* We are going to exit user mode because we handled an errored scall.
* The stack pointer must be set as the original value it had before
* allocating space of scall "regs" and calling thread_scall_handler().
* Thus, we can simply set stack pointer as (regs + 1) value.
*/
regs->sp = (unsigned long)(regs + 1);
}

static void thread_unhandled_trap(unsigned long cause __unused,
Expand Down

0 comments on commit 0875dea

Please sign in to comment.