diff --git a/arch/arm/include/armv6-m/syscall.h b/arch/arm/include/armv6-m/syscall.h index 75b9c4f8a2c..812e863a58d 100644 --- a/arch/arm/include/armv6-m/syscall.h +++ b/arch/arm/include/armv6-m/syscall.h @@ -241,25 +241,6 @@ static inline uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1, return reg0; } -/* This inline function is used by user-space code in order to return from - * a signal handler. - */ - -#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) -static inline void signal_handler_return(void) noreturn_function; -static inline void signal_handler_return(void) -{ - __asm__ __volatile__ - ( - " mov r0, %0\n" - " svc %1\n" - : - : "i" (SYS_signal_handler_return), "i"(SYS_syscall) - : "memory" - ); -} -#endif - /**************************************************************************** * Public Variables ****************************************************************************/ diff --git a/arch/arm/include/armv7-m/syscall.h b/arch/arm/include/armv7-m/syscall.h index 62bd5c324c1..6d3928a17b9 100644 --- a/arch/arm/include/armv7-m/syscall.h +++ b/arch/arm/include/armv7-m/syscall.h @@ -241,25 +241,6 @@ static inline uintptr_t sys_call6(unsigned int nbr, uintptr_t parm1, return reg0; } -/* This inline function is used by user-space code in order to return from - * a signal handler. - */ - -#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) -static inline void signal_handler_return(void) noreturn_function; -static inline void signal_handler_return(void) -{ - __asm__ __volatile__ - ( - " mov r0, %0\n" - " svc %1\n" - : - : "i" (SYS_signal_handler_return), "i"(SYS_syscall) - : "memory" - ); -} -#endif - /**************************************************************************** * Public Variables ****************************************************************************/ diff --git a/arch/arm/src/Makefile b/arch/arm/src/Makefile index 01061212424..f9b0ac93300 100644 --- a/arch/arm/src/Makefile +++ b/arch/arm/src/Makefile @@ -74,8 +74,12 @@ else endif endif +# The "head" object + HEAD_OBJ = $(HEAD_ASRC:.S=$(OBJEXT)) +# Flat build or kernel-mode objects + ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS) AOBJS = $(ASRCS:.S=$(OBJEXT)) @@ -85,6 +89,21 @@ COBJS = $(CSRCS:.c=$(OBJEXT)) SRCS = $(ASRCS) $(CSRCS) OBJS = $(AOBJS) $(COBJS) +# User-mode objects + +UASRCS = $(CHIP_UASRCS) $(CMN_UASRCS) +UAOBJS = $(UASRCS:.S=$(OBJEXT)) + +UCSRCS = $(CHIP_UCSRCS) $(CMN_UCSRCS) +UCOBJS = $(UCSRCS:.c=$(OBJEXT)) + +USRCS = $(UASRCS) $(UCSRCS) +UOBJS = $(UAOBJS) $(UCOBJS) + +KBIN = libkarch$(LIBEXT) +UBIN = libuarch$(LIBEXT) +BIN = libarch$(LIBEXT) + LDFLAGS += $(ARCHSCRIPT) EXTRA_LIBS ?= @@ -125,19 +144,22 @@ GCC_LIBDIR := ${shell dirname $(LIBGCC)} VPATH = chip:common:$(ARCH_SUBDIR) -all: $(HEAD_OBJ) libarch$(LIBEXT) +all: $(HEAD_OBJ) $(BIN) .PHONY: board/libboard$(LIBEXT) -$(AOBJS) $(HEAD_OBJ): %$(OBJEXT): %.S +$(AOBJS) $(UAOBJS) $(HEAD_OBJ): %$(OBJEXT): %.S $(call ASSEMBLE, $<, $@) -$(COBJS): %$(OBJEXT): %.c +$(COBJS) $(UCOBJS): %$(OBJEXT): %.c $(call COMPILE, $<, $@) -libarch$(LIBEXT): $(OBJS) +$(BIN): $(OBJS) $(call ARCHIVE, $@, $(OBJS)) +$(UBIN): $(UOBJS) + $(call ARCHIVE, $@, $(UOBJS)) + board/libboard$(LIBEXT): $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" libboard$(LIBEXT) EXTRADEFINES=$(EXTRADEFINES) @@ -182,7 +204,9 @@ clean: ifeq ($(BOARDMAKE),y) $(Q) $(MAKE) -C board TOPDIR="$(TOPDIR)" clean endif - $(call DELFILE, libarch$(LIBEXT)) + $(call DELFILE, $(KBIN)) + $(call DELFILE, $(UBIN)) + $(call DELFILE, $(BIN)) $(call CLEAN) distclean: clean diff --git a/arch/arm/src/armv6-m/up_signal_handler.S b/arch/arm/src/armv6-m/up_signal_handler.S new file mode 100644 index 00000000000..559b8c6d705 --- /dev/null +++ b/arch/arm/src/armv6-m/up_signal_handler.S @@ -0,0 +1,115 @@ +/**************************************************************************** + * arch/arm/srcm/armv6-m/up_signal_handler.S + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) + +/**************************************************************************** + * File info + ****************************************************************************/ + + .cpu cortex-m0 + .file "up_signal_handler.S" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_signal_handler + * + * Description: + * This function is the user-space, signal handler trampoline function. It + * is called from up_signal_dispatch() in user-mode. + * + * Inputs: + * R0 = sighand + * The address user-space signal handling function + * R1-R3 = signo, info, and ucontext + * Standard arguments to be passed to the signal handling function. + * + * Return: + * None. This function does not return in the normal sense. It returns + * via the SYS_signal_handler_return (see svcall.h) + * + ****************************************************************************/ + + .text + .align 2 + .code 16 + .thumb_func + .globl up_signal_handler + .type up_signal_handler, function +up_signal_handler: + + /* Save some register */ + + push {r4, r5 /* Save R4 and R5 on the stack */ + mov r5, lr /* Save LR in R5 */ + + /* Call the signal handler */ + + mov r4, r0 /* R4=sighand */ + mov r0, r1 /* R0=signo */ + mov r1, r2 /* R1=info */ + mov r2, r3 /* R2=ucontext */ + blx r4 /* Call the signal handler */ + + /* Restore the registers */ + + mov lr, r5 /* Restore LR */ + pop {r4, r5} /* Restore R4 and R5 */ + + /* Execute the SYS_signal_handler_return SVCall (will not return) */ + + mov r0, #SYS_signal_handler_return + svc 0 + nop + + .size up_signal_handler, .-up_signal_handler + .end + +#endif /* CONFIG_NUTTX_KERNEL && !__KERNEL__ */ diff --git a/arch/arm/src/armv7-m/up_saveusercontext.S b/arch/arm/src/armv7-m/up_saveusercontext.S index 06eb183d217..d3136d507f4 100644 --- a/arch/arm/src/armv7-m/up_saveusercontext.S +++ b/arch/arm/src/armv7-m/up_saveusercontext.S @@ -101,4 +101,3 @@ up_saveusercontext: * context switch with r0=1 */ .size up_saveusercontext, .-up_saveusercontext .end - diff --git a/arch/arm/src/armv7-m/up_signal_handler.S b/arch/arm/src/armv7-m/up_signal_handler.S new file mode 100644 index 00000000000..f19dcdaa76a --- /dev/null +++ b/arch/arm/src/armv7-m/up_signal_handler.S @@ -0,0 +1,118 @@ +/**************************************************************************** + * arch/arm/srcm/armv7-m/up_signal_handler.S + * + * Copyright (C) 2013 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__) + +/**************************************************************************** + * File info + ****************************************************************************/ + + .syntax unified + .thumb + .cpu cortex-m3 + .file "up_signal_handler.S" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_signal_handler + * + * Description: + * This function is the user-space, signal handler trampoline function. It + * is called from up_signal_dispatch() in user-mode. + * + * R0-R3, R11 - volatile registers need not be preserved. + * R4-R10 - static registers must be preserved + * R12-R14 - LR and SP must be preserved + * + * Inputs: + * R0 = sighand + * The address user-space signal handling function + * R1-R3 = signo, info, and ucontext + * Standard arguments to be passed to the signal handling function. + * + * Return: + * None. This function does not return in the normal sense. It returns + * via the SYS_signal_handler_return (see svcall.h) + * + ****************************************************************************/ + + .text + .thumb_func + .globl up_signal_handler + .type up_signal_handler, function +up_signal_handler: + + /* Save some register */ + + push {lr} /* Save LR on the stack */ + + /* Call the signal handler */ + + mov ip, r0 /* IP=sighand */ + mov r0, r1 /* R0=signo */ + mov r1, r2 /* R1=info */ + mov r2, r3 /* R2=ucontext */ + blx ip /* Call the signal handler */ + + /* Restore the registers */ + + pop {r2} /* Recover LR in R2 */ + mov lr, r2 /* Restore LR */ + + /* Execute the SYS_signal_handler_return SVCall (will not return) */ + + mov r0, #SYS_signal_handler_return + svc 0 + nop + + .size up_signal_handler, .-up_signal_handler + .end + +#endif /* CONFIG_NUTTX_KERNEL && !__KERNEL__ */ diff --git a/arch/arm/src/common/up_signal_handler.c b/arch/arm/src/common/up_signal_dispatch.c similarity index 88% rename from arch/arm/src/common/up_signal_handler.c rename to arch/arm/src/common/up_signal_dispatch.c index b2a828479b4..7755ca7e4cf 100644 --- a/arch/arm/src/common/up_signal_handler.c +++ b/arch/arm/src/common/up_signal_dispatch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/arm/src/common/up_task_start.c + * arch/arm/src/common/up_signal_dispatch.c * * Copyright (C) 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: up_signal_handler + * Name: up_signal_dispatch * * Description: * In this kernel mode build, this function will be called to execute a @@ -73,9 +73,9 @@ * * Normally the a user-mode signalling handling stub will also execute * before the ultimate signal handler is called. See - * libc/signal/signal_handler.c This function is the user-space, signal - * handler trampoline function. It is called from up_signal_handler() in - * user-mode. + * arch/arm/src/armv[6\7]/up_signal_handler. This function is the + * user-space, signal handler trampoline function. It is called from + * up_signal_dispatch() in user-mode. * * Inputs: * sighand - The address user-space signal handling function @@ -84,12 +84,14 @@ * * Return: * None. This function does not return in the normal sense. It returns - * via signal_handler_return (below) + * via an architecture specific system call made by up_signal_handler(). + * However, this will look like a normal return by the caller of + * up_signal_dispatch. * ****************************************************************************/ -void up_signal_handler(_sa_sigaction_t sighand, int signo, - FAR siginfo_t *info, FAR void *ucontext) +void up_signal_dispatch(_sa_sigaction_t sighand, int signo, + FAR siginfo_t *info, FAR void *ucontext) { /* Let sys_call4() do all of the work */ diff --git a/arch/arm/src/lpc17xx/Make.defs b/arch/arm/src/lpc17xx/Make.defs index 0fec22d124c..b1b455cf5c7 100644 --- a/arch/arm/src/lpc17xx/Make.defs +++ b/arch/arm/src/lpc17xx/Make.defs @@ -43,6 +43,9 @@ endif # Common ARM and Cortex-M3 files +CMN_UASRCS = +CMN_UCSRCS = + CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += vfork.S @@ -70,7 +73,8 @@ endif ifeq ($(CONFIG_NUTTX_KERNEL),y) CMN_CSRCS += up_mpu.c up_task_start.c up_pthread_start.c up_stackframe.c ifneq ($(CONFIG_DISABLE_SIGNALS),y) -CMN_CSRCS += up_signal_handler.c +CMN_CSRCS += up_signal_dispatch.c +CMN_UASRCS += up_signal_handler.S endif endif diff --git a/arch/arm/src/sam3u/Make.defs b/arch/arm/src/sam3u/Make.defs index 4abca3b2c81..b2b3bf3b536 100644 --- a/arch/arm/src/sam3u/Make.defs +++ b/arch/arm/src/sam3u/Make.defs @@ -39,6 +39,9 @@ HEAD_ASRC = sam3u_vectors.S # Common ARM and Cortex-M3 files +CMN_UASRCS = +CMN_UCSRCS = + CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += vfork.S CMN_CSRCS = up_assert.c up_blocktask.c up_copystate.c up_createstack.c @@ -62,7 +65,8 @@ endif ifeq ($(CONFIG_NUTTX_KERNEL),y) CMN_CSRCS += up_mpu.c up_task_start.c up_pthread_start.c up_stackframe.c ifneq ($(CONFIG_DISABLE_SIGNALS),y) -CMN_CSRCS += up_signal_handler.c +CMN_CSRCS += up_signal_dispatch.c +CMN_UASRCS += up_signal_handler.S endif endif diff --git a/arch/arm/src/stm32/Make.defs b/arch/arm/src/stm32/Make.defs index c2684303921..15b87ca9e85 100644 --- a/arch/arm/src/stm32/Make.defs +++ b/arch/arm/src/stm32/Make.defs @@ -39,6 +39,9 @@ else HEAD_ASRC = stm32_vectors.S endif +CMN_UASRCS = +CMN_UCSRCS = + CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += vfork.S @@ -67,7 +70,8 @@ endif ifeq ($(CONFIG_NUTTX_KERNEL),y) CMN_CSRCS += up_mpu.c up_task_start.c up_pthread_start.c up_stackframe.c ifneq ($(CONFIG_DISABLE_SIGNALS),y) -CMN_CSRCS += up_signal_handler.c +CMN_CSRCS += up_signal_dispatch.c +CMN_UASRCS += up_signal_handler.S endif endif