mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Rework of kernel build signal dispatch to user-space handlers
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5778 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -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
|
||||
****************************************************************************/
|
||||
|
||||
@@ -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
|
||||
****************************************************************************/
|
||||
|
||||
+29
-5
@@ -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
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/srcm/armv6-m/up_signal_handler.S
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <arch/syscall.h>
|
||||
|
||||
#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__ */
|
||||
@@ -101,4 +101,3 @@ up_saveusercontext:
|
||||
* context switch with r0=1 */
|
||||
.size up_saveusercontext, .-up_saveusercontext
|
||||
.end
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/srcm/armv7-m/up_signal_handler.S
|
||||
*
|
||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <arch/syscall.h>
|
||||
|
||||
#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__ */
|
||||
@@ -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 <gnutt@nuttx.org>
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user