This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit b1736ddd973711376c46a22b4630aa792b43c2bd Author: hujun5 <[email protected]> AuthorDate: Tue Dec 2 19:27:13 2025 +0800 arm_a_r: merge arm_dispatch_syscall.S to arm_a_r merge arm_dispatch_syscall.S to arm_a_r Signed-off-by: hujun5 <[email protected]> --- arch/arm/src/arm_a_r/CMakeLists.txt | 4 ++ arch/arm/src/arm_a_r/Make.defs | 4 ++ arch/arm/src/arm_a_r/arm_dispatch_syscall.S | 107 ++++++++++++++++++++++++++++ arch/arm/src/armv7-a/arm_syscall.c | 62 +--------------- arch/arm/src/common/arm_internal.h | 10 +-- 5 files changed, 122 insertions(+), 65 deletions(-) diff --git a/arch/arm/src/arm_a_r/CMakeLists.txt b/arch/arm/src/arm_a_r/CMakeLists.txt index 664d46bb6f9..9c71db5b182 100644 --- a/arch/arm/src/arm_a_r/CMakeLists.txt +++ b/arch/arm/src/arm_a_r/CMakeLists.txt @@ -28,6 +28,10 @@ if(CONFIG_ARCH_HAVE_DEBUG) list(APPEND CSRCS arm_hwdebug.c) endif() +if(CONFIG_LIB_SYSCALL) + list(APPEND CSRCS arm_dispatch_syscall.S) +endif() + list(APPEND CSRCS arm_tcbinfo.c arm_doirq.c arm_dataabort.c) target_sources(arch PRIVATE ${CSRCS}) diff --git a/arch/arm/src/arm_a_r/Make.defs b/arch/arm/src/arm_a_r/Make.defs index b21218a969f..b0f47bc2d5f 100644 --- a/arch/arm/src/arm_a_r/Make.defs +++ b/arch/arm/src/arm_a_r/Make.defs @@ -28,6 +28,10 @@ ifeq ($(CONFIG_ENABLE_ALL_SIGNALS),y) CMN_CSRCS += arm_schedulesigaction.c arm_sigdeliver.c endif +ifeq ($(CONFIG_LIB_SYSCALL),y) + CMN_ASRCS += arm_dispatch_syscall.S +endif + ifeq ($(CONFIG_ARCH_HAVE_DEBUG),y) CMN_CSRCS += arm_hwdebug.c endif diff --git a/arch/arm/src/arm_a_r/arm_dispatch_syscall.S b/arch/arm/src/arm_a_r/arm_dispatch_syscall.S new file mode 100644 index 00000000000..525a6fa330c --- /dev/null +++ b/arch/arm/src/arm_a_r/arm_dispatch_syscall.S @@ -0,0 +1,107 @@ +/*************************************************************************** + * arch/arm/src/arm_a_r/arm_dispatch_syscall.S + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <syscall.h> + +#include "arm_internal.h" + +/**************************************************************************** + * Public Symbols + ****************************************************************************/ + + .globl arm_dispatch_syscall + .file "arm_dispatch_syscall.S" + +/**************************************************************************** + * .text + ****************************************************************************/ + +/**************************************************************************** + * Call the stub function corresponding to the system call. NOTE the non- + * standard parameter passing: + * + * R0 = SYS_ call number + * R1 = parm0 + * R2 = parm1 + * R3 = parm2 + * R4 = parm3 + * R5 = parm4 + * R6 = parm5 + * + * The values of R4-R5 may be preserved in the proxy called by the user + * code if they are used (but otherwise will not be). + * + * Register usage: + * + * R0 - Need not be preserved. + * R1-R3 - Need to be preserved until the stub is called. The values of + * R0 and R1 returned by the stub must be preserved. + * R4-R11 must be preserved to support the expectations of the user-space + * callee. R4-R6 may have been preserved by the proxy, but don't know + * for sure. + * R12 - Need not be preserved + * R13 - (stack pointer) + * R14 - Need not be preserved + * R15 - (PC) + * + ****************************************************************************/ + + .text + .syntax unified +#ifdef CONFIG_ARM_THUMB + .thumb +#else + .arm +#endif + .type arm_dispatch_syscall, function +arm_dispatch_syscall: + .cfi_sections .debug_frame + .cfi_startproc + sub sp, sp, #32 + .cfi_def_cfa_offset 32 + str r4, [sp, #0] + .cfi_offset r4, -32 + str r5, [sp, #4] + .cfi_offset r5, -28 + str r6, [sp, #8] + .cfi_offset r6, -24 + str lr, [sp, #12] + .cfi_offset lr, -20 + str ip, [sp, #16] + .cfi_offset pc, -16 + ldr ip, =g_stublookup + ldr ip, [ip, r0, lsl #2] + blx ip + ldr lr, [sp, #12] + add sp, sp, #32 + mov r2, r0 + mov r0, SYS_syscall_return + svc SYS_syscall + .cfi_endproc + .size arm_dispatch_syscall, .-arm_dispatch_syscall + .end diff --git a/arch/arm/src/armv7-a/arm_syscall.c b/arch/arm/src/armv7-a/arm_syscall.c index bd3a430555a..8053f9d1f2f 100644 --- a/arch/arm/src/armv7-a/arm_syscall.c +++ b/arch/arm/src/armv7-a/arm_syscall.c @@ -86,66 +86,6 @@ static void dump_syscall(const char *tag, uint32_t cmd, const uint32_t *regs) svcinfo("CPSR: %08" PRIx32 "\n", regs[REG_CPSR]); } -/**************************************************************************** - * Name: dispatch_syscall - * - * Description: - * Call the stub function corresponding to the system call. NOTE the non- - * standard parameter passing: - * - * R0 = SYS_ call number - * R1 = parm0 - * R2 = parm1 - * R3 = parm2 - * R4 = parm3 - * R5 = parm4 - * R6 = parm5 - * - * The values of R4-R5 may be preserved in the proxy called by the user - * code if they are used (but otherwise will not be). - * - * WARNING: There are hard-coded values in this logic! - * - * Register usage: - * - * R0 - Need not be preserved. - * R1-R3 - Need to be preserved until the stub is called. The values of - * R0 and R1 returned by the stub must be preserved. - * R4-R11 must be preserved to support the expectations of the user-space - * callee. R4-R6 may have been preserved by the proxy, but don't know - * for sure. - * R12 - Need not be preserved - * R13 - (stack pointer) - * R14 - Need not be preserved - * R15 - (PC) - * - ****************************************************************************/ - -#ifdef CONFIG_LIB_SYSCALL -static void dispatch_syscall(void) naked_function; -static void dispatch_syscall(void) -{ - __asm__ __volatile__ - ( - " sub sp, sp, #16\n" /* Create a stack frame to hold 3 parms + lr */ - " str r4, [sp, #0]\n" /* Move parameter 4 (if any) into position */ - " str r5, [sp, #4]\n" /* Move parameter 5 (if any) into position */ - " str r6, [sp, #8]\n" /* Move parameter 6 (if any) into position */ - " str lr, [sp, #12]\n" /* Save lr in the stack frame */ - " ldr ip, =%c0\n" /* R12=The base of the stub lookup table */ - " ldr ip, [ip, r0, lsl #2]\n" /* R12=The address of the stub for this SYSCALL */ - " blx ip\n" /* Call the stub (modifies lr) */ - " ldr lr, [sp, #12]\n" /* Restore lr */ - " add sp, sp, #16\n" /* Destroy the stack frame */ - " mov r2, r0\n" /* R2=Save return value in R2 */ - " mov r0, #" STRINGIFY(SYS_syscall_return) "\n" /* R0=SYS_syscall_return */ - " svc #" STRINGIFY(SYS_syscall) "\n" /* Return from the SYSCALL */ - : - : "i"(g_stublookup) - ); -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -527,7 +467,7 @@ uint32_t *arm_syscall(uint32_t *regs) rtcb->xcp.sregs = regs; } - regs[REG_PC] = (uint32_t)dispatch_syscall; + regs[REG_PC] = (uint32_t)arm_dispatch_syscall; #ifdef CONFIG_BUILD_KERNEL cpsr = regs[REG_CPSR] & ~PSR_MODE_MASK; regs[REG_CPSR] = cpsr | PSR_MODE_SYS; diff --git a/arch/arm/src/common/arm_internal.h b/arch/arm/src/common/arm_internal.h index 5466a605532..4a37188df80 100644 --- a/arch/arm/src/common/arm_internal.h +++ b/arch/arm/src/common/arm_internal.h @@ -304,6 +304,12 @@ void arm_ack_irq(int irq); uint32_t *arm_doirq(int irq, uint32_t *regs); +/* System call handling */ + +#ifdef CONFIG_LIB_SYSCALL +void arm_dispatch_syscall(void); +#endif + /* Exception handling logic unique to the Cortex-M family */ #if defined(CONFIG_ARCH_ARMV6M) || defined(CONFIG_ARCH_ARMV7M) || \ @@ -321,10 +327,6 @@ extern const void *__vector_table[]; extern const void * const _vectors[]; #endif -#ifdef CONFIG_LIB_SYSCALL -void arm_dispatch_syscall(void); -#endif - /* Exception Handlers */ int arm_svcall(int irq, void *context, void *arg);
