arm64_task/pthread_start: Set sp_el0 upon starting user process
As the handling of sp_el0 was moved from the context switch routine to exception entry/exit, we must set sp_el0 explicitly when the user process is first started.
This commit is contained in:
parent
7975c94d88
commit
192dde1b58
@ -264,7 +264,7 @@ EXTERN uint8_t g_idle_topstack[]; /* End+1 of heap */
|
||||
|
||||
void arm64_new_task(struct tcb_s *tak_new);
|
||||
void arm64_jump_to_user(uint64_t entry, uint64_t x0, uint64_t x1,
|
||||
uint64_t *regs) noreturn_function;
|
||||
uint64_t sp_el0, uint64_t *regs) noreturn_function;
|
||||
|
||||
/* Low level initialization provided by chip logic */
|
||||
|
||||
|
@ -68,6 +68,8 @@
|
||||
void up_pthread_start(pthread_trampoline_t startup,
|
||||
pthread_startroutine_t entrypt, pthread_addr_t arg)
|
||||
{
|
||||
struct tcb_s *rtcb = this_task();
|
||||
|
||||
/* Set up to enter the user-space pthread start-up function in
|
||||
* unprivileged mode. We need:
|
||||
*
|
||||
@ -78,7 +80,7 @@ void up_pthread_start(pthread_trampoline_t startup,
|
||||
*/
|
||||
|
||||
arm64_jump_to_user((uint64_t)startup, (uint64_t)entrypt, (uint64_t)arg,
|
||||
this_task()->xcp.initregs);
|
||||
(uint64_t)rtcb->xcp.ustkptr, rtcb->xcp.initregs);
|
||||
}
|
||||
|
||||
#endif /* !CONFIG_BUILD_FLAT && __KERNEL__ && !CONFIG_DISABLE_PTHREAD */
|
||||
|
@ -65,6 +65,8 @@
|
||||
|
||||
void up_task_start(main_t taskentry, int argc, char *argv[])
|
||||
{
|
||||
struct tcb_s *rtcb = this_task();
|
||||
|
||||
/* Set up to return to the user-space _start function in
|
||||
* unprivileged mode. We need:
|
||||
*
|
||||
@ -75,7 +77,7 @@ void up_task_start(main_t taskentry, int argc, char *argv[])
|
||||
*/
|
||||
|
||||
arm64_jump_to_user((uint64_t)taskentry, (uint64_t)argc, (uint64_t)argv,
|
||||
this_task()->xcp.initregs);
|
||||
(uint64_t)rtcb->xcp.ustkptr, rtcb->xcp.initregs);
|
||||
}
|
||||
|
||||
#endif /* !CONFIG_BUILD_FLAT */
|
||||
|
@ -107,10 +107,11 @@ SECTION_FUNC(text, up_saveusercontext)
|
||||
* the kernel is ready to give control to the user task in user space.
|
||||
*
|
||||
* arm64_jump_to_user(entry, x0, x1, regs)
|
||||
* entry: process entry point
|
||||
* x0: parameter 0 for process
|
||||
* x1: parameter 1 for process
|
||||
* regs: integer register save area to use
|
||||
* entry: process entry point
|
||||
* x0: parameter 0 for process
|
||||
* x1: parameter 1 for process
|
||||
* sp_el0: user stack pointer
|
||||
* regs: integer register save area to use
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@ -118,10 +119,11 @@ SECTION_FUNC(text, up_saveusercontext)
|
||||
GTEXT(arm64_jump_to_user)
|
||||
SECTION_FUNC(text, arm64_jump_to_user)
|
||||
msr daifset, #IRQ_DAIF_MASK
|
||||
mov sp, x3
|
||||
mov sp, x4
|
||||
str x0, [sp, #8 * REG_ELR]
|
||||
str x1, [sp, #8 * REG_X0]
|
||||
str x2, [sp, #8 * REG_X1]
|
||||
str x3, [sp, #8 * REG_SP_EL0]
|
||||
mrs x0, spsr_el1
|
||||
and x0, x0, #~SPSR_MODE_MASK
|
||||
#orr x0, x0, #SPSR_MODE_EL0T # EL0T=0x00, out of range for orr
|
||||
|
Loading…
Reference in New Issue
Block a user