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 committed Nov 13, 2024
1 parent 46f3eb7 commit ccf433b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
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: 12 additions & 7 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,7 +192,9 @@ uint64_t *arm64_syscall(uint64_t *regs)
* set will determine the restored context.
*/

ret_regs = (uint64_t *)regs[REG_X1];
struct tcb_s *tcb = regs[REG_X1];

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

DEBUGASSERT(ret_regs);
Expand All @@ -201,13 +203,13 @@ uint64_t *arm64_syscall(uint64_t *regs)

/* 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 +219,13 @@ uint64_t *arm64_syscall(uint64_t *regs)

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

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

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

Expand Down

0 comments on commit ccf433b

Please sign in to comment.