Skip to content

Commit

Permalink
arch/arm64: syscall SYS_switch_context and SYS_restore_context use tc…
Browse files Browse the repository at this point in the history
…b as

parm

sys_call2(SYS_switch_context, (uintptr_t)rtcb, (uintptr_t)tcb)
sys_call1(SYS_restore_context, (uintptr_t)next)

Signed-off-by: lipengfei28 <[email protected]>
  • Loading branch information
lipengfei28 authored and xiaoxiang781216 committed Nov 13, 2024
1 parent 6847eb0 commit daab676
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
17 changes: 9 additions & 8 deletions arch/arm64/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,15 @@ static inline void up_irq_restore(irqstate_t flags)
#define up_update_task(t) modify_sysreg(t, ~1ul, tpidr_el1)
#define up_interrupt_context() (read_sysreg(tpidr_el1) & 1)

#define up_switch_context(tcb, rtcb) \
do { \
if (!up_interrupt_context()) \
{ \
sys_call2(SYS_switch_context, (uintptr_t)&rtcb->xcp.regs, \
(uintptr_t)tcb->xcp.regs); \
} \
} while (0)
#define up_switch_context(tcb, rtcb) \
do \
{ \
if (!up_interrupt_context()) \
{ \
sys_call2(SYS_switch_context, (uintptr_t)rtcb, (uintptr_t)tcb); \
} \
} \
while (0)

/****************************************************************************
* Name: up_getusrpc
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/src/common/arm64_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ void up_exit(int status)

/* Then switch contexts */

arm64_fullcontextrestore(tcb->xcp.regs);
arm64_fullcontextrestore(tcb);
}
4 changes: 2 additions & 2 deletions arch/arm64/src/common/arm64_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@

/* Context switching */

#define arm64_fullcontextrestore(restoreregs) \
#define arm64_fullcontextrestore(next) \
do \
{ \
sys_call1(SYS_restore_context, (uintptr_t)restoreregs); \
sys_call1(SYS_restore_context, (uintptr_t)next); \
} \
while (1)

Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/src/common/arm64_sigdeliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ void arm64_sigdeliver(void)
leave_critical_section(flags);
rtcb->irqcount--;
#endif
arm64_fullcontextrestore(rtcb->xcp.regs);
arm64_fullcontextrestore(rtcb);
}
19 changes: 11 additions & 8 deletions arch/arm64/src/common/arm64_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ uint64_t *arm64_syscall(uint64_t *regs)
* At this point, the following values are saved in context:
*
* x0 = SYS_restore_context
* x1 = restoreregs( xcp->regs, callee saved register save area)
* x1 = next
*/

case SYS_restore_context:
Expand All @@ -192,22 +192,22 @@ uint64_t *arm64_syscall(uint64_t *regs)
* set will determine the restored context.
*/

ret_regs = (uint64_t *)regs[REG_X1];
regs[REG_X1] = 0; /* set the saveregs = 0 */
tcb = (struct tcb_s *)regs[REG_X1];
ret_regs = tcb->xcp.regs;

DEBUGASSERT(ret_regs);
}
break;

/* x0 = SYS_switch_context: This a switch context command:
*
* void arm64_switchcontext(uint64_t *saveregs, uint64_t *restoreregs);
* void arm64_switchcontext(struct tcb_s *prev, struct tcb_s *next);
*
* At this point, the following values are saved in context:
*
* x0 = SYS_switch_context
* x1 = saveregs (xcp->regs, callee saved register save area)
* x2 = restoreregs (xcp->regs, callee saved register save area)
* x1 = prev
* x2 = next
*
* In this case, we do both: We save the context registers to the save
* register area reference by the saved contents of x1 and then set
Expand All @@ -217,10 +217,13 @@ uint64_t *arm64_syscall(uint64_t *regs)

case SYS_switch_context:
{
struct tcb_s *rtcb = (struct tcb_s *)regs[REG_X1];
tcb = (struct tcb_s *)regs[REG_X2];

DEBUGASSERT(regs[REG_X1] != 0 && regs[REG_X2] != 0);
*(uint64_t **)regs[REG_X1] = regs;
rtcb->xcp.regs = regs;

ret_regs = (uint64_t *)regs[REG_X2];
ret_regs = tcb->xcp.regs;
}
break;

Expand Down

0 comments on commit daab676

Please sign in to comment.