This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new daab676db9 arch/arm64: syscall SYS_switch_context and
SYS_restore_context use tcb as parm
daab676db9 is described below
commit daab676db97bbf2690e9011cbed1a0d45b2112f6
Author: lipengfei28 <[email protected]>
AuthorDate: Tue Nov 12 12:08:33 2024 +0800
arch/arm64: syscall SYS_switch_context and SYS_restore_context use tcb 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]>
---
arch/arm64/include/irq.h | 17 +++++++++--------
arch/arm64/src/common/arm64_exit.c | 2 +-
arch/arm64/src/common/arm64_internal.h | 4 ++--
arch/arm64/src/common/arm64_sigdeliver.c | 2 +-
arch/arm64/src/common/arm64_syscall.c | 19 +++++++++++--------
5 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/arch/arm64/include/irq.h b/arch/arm64/include/irq.h
index a47544d7f2..f4c91fdd0d 100644
--- a/arch/arm64/include/irq.h
+++ b/arch/arm64/include/irq.h
@@ -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
diff --git a/arch/arm64/src/common/arm64_exit.c
b/arch/arm64/src/common/arm64_exit.c
index ba81dbb97f..793533f76e 100644
--- a/arch/arm64/src/common/arm64_exit.c
+++ b/arch/arm64/src/common/arm64_exit.c
@@ -76,5 +76,5 @@ void up_exit(int status)
/* Then switch contexts */
- arm64_fullcontextrestore(tcb->xcp.regs);
+ arm64_fullcontextrestore(tcb);
}
diff --git a/arch/arm64/src/common/arm64_internal.h
b/arch/arm64/src/common/arm64_internal.h
index de5bc20980..5badadb9af 100644
--- a/arch/arm64/src/common/arm64_internal.h
+++ b/arch/arm64/src/common/arm64_internal.h
@@ -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)
diff --git a/arch/arm64/src/common/arm64_sigdeliver.c
b/arch/arm64/src/common/arm64_sigdeliver.c
index fff7e1ccee..5ef6b592cd 100644
--- a/arch/arm64/src/common/arm64_sigdeliver.c
+++ b/arch/arm64/src/common/arm64_sigdeliver.c
@@ -160,5 +160,5 @@ retry:
leave_critical_section(flags);
rtcb->irqcount--;
#endif
- arm64_fullcontextrestore(rtcb->xcp.regs);
+ arm64_fullcontextrestore(rtcb);
}
diff --git a/arch/arm64/src/common/arm64_syscall.c
b/arch/arm64/src/common/arm64_syscall.c
index a192cabafb..780286892f 100644
--- a/arch/arm64/src/common/arm64_syscall.c
+++ b/arch/arm64/src/common/arm64_syscall.c
@@ -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:
@@ -192,8 +192,8 @@ 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);
}
@@ -201,13 +201,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
@@ -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;