This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7e9eccc5bfc5f7196d07c73187fecf0aac4a9e5f Author: zhangyu117 <[email protected]> AuthorDate: Mon May 12 20:17:04 2025 +0800 arch/tricore: support independent interrupt stack Dispatch syscalls on a dedicated kernel context and preserve the original CSA chain across nested calls. Clear PSW.IS in newly created task and signal contexts so they can use the independent interrupt stack. Signed-off-by: zhangyu117 <[email protected]> --- arch/tricore/src/common/tricore_initialstate.c | 2 +- .../tricore/src/common/tricore_schedulesigaction.c | 2 +- arch/tricore/src/common/tricore_svcall.c | 121 +++++++++++++++------ 3 files changed, 88 insertions(+), 37 deletions(-) diff --git a/arch/tricore/src/common/tricore_initialstate.c b/arch/tricore/src/common/tricore_initialstate.c index 05ac76ca960..3c0baf997f2 100644 --- a/arch/tricore/src/common/tricore_initialstate.c +++ b/arch/tricore/src/common/tricore_initialstate.c @@ -94,5 +94,5 @@ void up_initial_state(struct tcb_s *tcb) xcp->regs = tricore_alloc_csa((uintptr_t)tcb->start, (uintptr_t)tcb->stack_base_ptr + tcb->adj_stack_size, - PSW_IO_SUPERVISOR | PSW_IS | PSW_CDE, false); + PSW_IO_SUPERVISOR | PSW_CDE, false); } diff --git a/arch/tricore/src/common/tricore_schedulesigaction.c b/arch/tricore/src/common/tricore_schedulesigaction.c index ad1e46cbd53..ddefb43bb7b 100644 --- a/arch/tricore/src/common/tricore_schedulesigaction.c +++ b/arch/tricore/src/common/tricore_schedulesigaction.c @@ -94,6 +94,6 @@ void up_schedule_sigaction(struct tcb_s *tcb) tcb->xcp.regs = tricore_alloc_csa((uintptr_t)tricore_sigdeliver, STACKFRAME_ALIGN_DOWN (up_getusrsp(tcb->xcp.regs)), - PSW_IO_SUPERVISOR | PSW_IS | PSW_CDE, + PSW_IO_SUPERVISOR | PSW_CDE, true); } diff --git a/arch/tricore/src/common/tricore_svcall.c b/arch/tricore/src/common/tricore_svcall.c index 0f65de36099..9ee53e3e634 100644 --- a/arch/tricore/src/common/tricore_svcall.c +++ b/arch/tricore/src/common/tricore_svcall.c @@ -29,7 +29,6 @@ #include <stdint.h> #include <string.h> #include <assert.h> -#include <errno.h> #include <nuttx/debug.h> #include <nuttx/userspace.h> #include <syscall.h> @@ -42,19 +41,42 @@ #include "tricore_internal.h" /**************************************************************************** - * Private Types + * Private Functions ****************************************************************************/ #ifdef CONFIG_LIB_SYSCALL -typedef uintptr_t (*syscall_stub_t)(int nbr, - uintptr_t parm1, uintptr_t parm2, - uintptr_t parm3, uintptr_t parm4, - uintptr_t parm5, uintptr_t parm6); +static void dispatch_syscall(void) +{ + __asm__ __volatile__ ( +#ifdef CONFIG_TRICORE_TOOLCHAIN_TASKING + "mov.aa a14, %0\n\t" + "sh d15, d4, #2\n\t" + "addsc.a a14, a14, d15, #0\n\t" + "sub.a sp, #12\n\t" + "st.w [sp]8, d10\n\t" + "st.w [sp]4, d9\n\t" + "st.w [sp]0, d8\n\t" + "ld.a a15, [a14]0\n\t" + "calli a15\n\t" + "addih.a sp, sp, #12\n\t" +#else + "mov.aa %%a14, %0\n\t" + "sh %%d15, %%d4, 2\n\t" + "addsc.a %%a14, %%a14, %%d15, 0\n\t" + "sub.a %%sp, 12\n\t" + "st.w [%%sp]8, %%d10\n\t" + "st.w [%%sp]4, %%d9\n\t" + "st.w [%%sp]0, %%d8\n\t" + "ld.a %%a15, [%%a14]0\n\t" + "calli %%a15\n\t" + "addih.a %%sp, %%sp, 12\n\t" +#endif + ::"a"(g_stublookup) + : "memory" + ); + sys_call0(SYS_syscall_return); +} #endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ /**************************************************************************** * Public Functions @@ -107,6 +129,28 @@ void tricore_svcall(volatile void *trap) UP_ISB(); break; +#ifdef CONFIG_LIB_SYSCALL + case SYS_syscall_return: + { + struct tcb_s *rtcb = this_task(); + int index = rtcb->xcp.nsyscalls - 1; + int ret = plregs[REG_D2]; + + puregs[REG_UPCXI] = 0; + tricore_reclaim_csa(tricore_addr2csa(plregs)); + + plregs = rtcb->xcp.syscall_regs[index]; + puregs = tricore_csa2addr(plregs[REG_LPCXI]); + puregs[REG_D8] = ret; + rtcb->xcp.nsyscalls = index; + rtcb->xcp.regs = plregs; + tricore_mtcr(TRICORE_CPU_PCXI, + tricore_addr2csa(rtcb->xcp.regs)); + UP_ISB(); + } + break; +#endif + /* REG_D8 = SYS_task_start: This a user task start * * void up_task_start(main_t taskentry, int argc, char *argv[]) @@ -272,39 +316,46 @@ void tricore_svcall(volatile void *trap) default: { #ifdef CONFIG_LIB_SYSCALL - uintptr_t ret; - int nbr = cmd - CONFIG_SYS_RESERVED; struct tcb_s *rtcb = nxsched_self(); - syscall_stub_t stub; + uintptr_t *regs = plregs; + int index = rtcb->xcp.nsyscalls; - if (cmd < CONFIG_SYS_RESERVED || cmd >= SYS_maxsyscall || - rtcb->xcp.nsyscalls >= CONFIG_SYS_NNEST) - { - puregs[REG_D8] = -ENOSYS; - break; - } + /* Verify that the SYS call number is within range */ - stub = (syscall_stub_t)g_stublookup[nbr]; + DEBUGASSERT(cmd >= CONFIG_SYS_RESERVED && cmd < SYS_maxsyscall); - /* Setup nested syscall */ + DEBUGASSERT(index < CONFIG_SYS_NNEST); - rtcb->xcp.nsyscalls += 1; + /* Setup to return to dispatch_syscall in privileged mode. */ - up_set_interrupt_context(false); + rtcb->xcp.syscall_regs[index] = plregs; + rtcb->xcp.nsyscalls = index + 1; - /* Call syscall function */ + /* New plregs and puregs to dispatch_syscall */ - ret = stub(nbr, puregs[REG_D9], puregs[REG_D10], - puregs[REG_D11], puregs[REG_D12], - puregs[REG_D13], puregs[REG_D14]); - - /* Setup return from nested syscall */ - - rtcb->xcp.nsyscalls -= 1; - - /* Assign the return value to the D8 register. */ - - puregs[REG_D8] = ret; + plregs = tricore_alloc_csa( + (uintptr_t)dispatch_syscall, + STACK_ALIGN_DOWN(puregs[REG_SP]), + (puregs[REG_PSW] & (~PSW_MODE_MASK) & (~PSW_PRS_MASK)) | + (PSW_IO_SUPERVISOR), + !(plregs[REG_LPCXI] & PCXI_PIE)); + puregs = tricore_csa2addr(plregs[REG_LPCXI]); + + /* Args passed to dispatch_syscall */ + + puregs[REG_UPCXI] = tricore_addr2csa(regs); + regs = tricore_csa2addr(regs[REG_LPCXI]); + plregs[REG_D4] = regs[REG_D8] - CONFIG_SYS_RESERVED; + plregs[REG_D5] = regs[REG_D9]; + plregs[REG_D6] = regs[REG_D10]; + plregs[REG_D7] = regs[REG_D11]; + puregs[REG_D8] = regs[REG_D12]; + puregs[REG_D9] = regs[REG_D13]; + puregs[REG_D10] = regs[REG_D14]; + + rtcb->xcp.regs = plregs; + tricore_mtcr(TRICORE_CPU_PCXI, tricore_addr2csa(plregs)); + UP_ISB(); #else svcerr("ERROR: Bad SYS call: %d\n", (int)puregs[REG_D8]); #endif
