From ced0dc1e16517f31c10eff62e99f72929d045dd0 Mon Sep 17 00:00:00 2001 From: "David S. Alessio" Date: Tue, 6 Aug 2019 15:59:19 -0600 Subject: [PATCH] arch/arm/src/armv7-m: Add ARMv7-M setjmp/longjump functions. --- Kconfig | 34 +++++- arch/arm/Kconfig | 1 + arch/arm/include/setjmp.h | 98 ++++++++++++++++ arch/arm/src/armv7-m/gnu/up_setjmp.S | 162 +++++++++++++++++++++++++++ arch/arm/src/cxd56xx/Make.defs | 6 + arch/arm/src/efm32/Make.defs | 6 + arch/arm/src/imxrt/Make.defs | 6 + arch/arm/src/kinetis/Make.defs | 6 + arch/arm/src/lc823450/Make.defs | 6 + arch/arm/src/lpc17xx_40xx/Make.defs | 6 + arch/arm/src/lpc43xx/Make.defs | 6 + arch/arm/src/lpc54xx/Make.defs | 6 + arch/arm/src/max326xx/Make.defs | 6 + arch/arm/src/nrf52/Make.defs | 6 + arch/arm/src/sam34/Make.defs | 6 + arch/arm/src/samd5e5/Make.defs | 6 + arch/arm/src/samv7/Make.defs | 6 + arch/arm/src/stm32/Make.defs | 6 + arch/arm/src/stm32f7/Make.defs | 6 + arch/arm/src/stm32h7/Make.defs | 6 + arch/arm/src/stm32l4/Make.defs | 6 + arch/arm/src/tiva/Make.defs | 6 + arch/arm/src/xmc4/Make.defs | 6 + include/.gitignore | 1 + include/nuttx/lib/setjmp.h | 64 +++++++++++ tools/Makefile.unix | 15 ++- tools/Makefile.win | 15 ++- 27 files changed, 497 insertions(+), 7 deletions(-) create mode 100644 arch/arm/include/setjmp.h create mode 100644 arch/arm/src/armv7-m/gnu/up_setjmp.S create mode 100644 include/nuttx/lib/setjmp.h diff --git a/Kconfig b/Kconfig index dd031d969b..25cb6f9616 100644 --- a/Kconfig +++ b/Kconfig @@ -425,11 +425,11 @@ config ARCH_STDARG_H bool "stdarg.h" default n ---help--- - There is also a redirecting version of stdarg.h in the source tree - as well. It also resides out-of-the-way at include/nuttx/lib/stdarg.h. - This is because you should normally use your toolchain's stdarg.h - file. But sometimes, your toolchain's stdarg.h file may have other - header file dependencies and so may not be usable in the NuttX build + There is a redirecting version of stdarg.h in the source tree. It + resides out-of-the-way at include/nuttx/lib/stdarg.h. This is + because you should normally use your toolchain's stdarg.h file. But + sometimes, your toolchain's stdarg.h file may have other header + file dependencies and so may not be usable in the NuttX build environment. In those cases, you may have to create a architecture- specific stdarg.h header file at nuttx/arch//include/stdarg.h @@ -440,6 +440,30 @@ config ARCH_STDARG_H ARCH_STDARG_H=y and providing. If ARCH_STDARG_H, is not defined, then the stdarg.h header file will stay out-of-the-way in include/nuttx/. +config ARCH_HAVE_SETJMP + bool + default n + +config ARCH_SETJMP_H + bool "setjmp.h" + default n + depends on ARCH_HAVE_SETJMP + ---help--- + There is a redirecting version of setjmp.h in the source tree. It + resides out-of-the-way at include/nuttx/lib/setjmp.h. This is + because you should normally use your toolchain's setjmp.h file. But + sometimes, your toolchain's setjmp.h file may have other header + file dependencies and so may not be usable in the NuttX build + environment. In those cases, you may have to create a architecture- + specific setjmp.h header file at nuttx/arch//include/setjmp.h + + If ARCH_SETJMP_H=y is defined, the top-level makefile will copy the + re-directing setjmp.h header file from include/nuttx/lib/setjmp.h to + include/setjmp.h. So for the architectures that cannot use their + toolchain's setjmp.h file, they can use this alternative by defining + ARCH_SETJMP_H=y and providing. If ARCH_SETJMP_H, is not defined, then + the setjmp.h header file will stay out-of-the-way in include/nuttx/. + config ARCH_DEBUG_H bool "debug.h" default n diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 9132794f1b..93860bfcd2 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -514,6 +514,7 @@ config ARCH_CORTEXM23 config ARCH_ARMV7M bool default n + select ARCH_HAVE_SETJMP if ARCH_TOOLCHAIN_GNU config ARCH_CORTEXM3 bool diff --git a/arch/arm/include/setjmp.h b/arch/arm/include/setjmp.h new file mode 100644 index 0000000000..c90bdd78fb --- /dev/null +++ b/arch/arm/include/setjmp.h @@ -0,0 +1,98 @@ +/**************************************************************************** + * arch/arm/include/setjmp.h + * + * Copyright (C) 2019 Gregory Nutt. All rights reserved. + * Author: David S. Alessio + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_INCLUDE_SETJUMP_H +#define __ARCH_ARM_INCLUDE_SETJUMP_H 1 + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_ARCH_ARMV7M + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct setjmp_buf_s +{ + /* Note: core registers r0-r3 are caller-saved */ + + unsigned r4; + unsigned r5; + unsigned r6; + unsigned r7; + unsigned r8; + unsigned r9; + unsigned r10; + unsigned r11; + unsigned ip; /* this is really sp */ + unsigned lr; + +#ifdef CONFIG_ARCH_FPU + /* note: FPU registers s0-s15 are caller-saved */ + + float s16; + float s17; + float s18; + float s19; + float s20; + float s21; + float s22; + float s23; + float s24; + float s25; + float s26; + float s27; + float s28; + float s29; + float s30; + float s31; + + unsigned fpscr; +#endif +}; + +/* Traditional typedef for setjmp_buf */ + +typedef struct setjmp_buf_s jmp_buf[1]; + +#else +# error "setjmp() not compiled!" +#endif /* CONFIG_ARCH_ARMV7M */ + +#endif /* __ARCH_ARM_INCLUDE_SETJUMP_H */ diff --git a/arch/arm/src/armv7-m/gnu/up_setjmp.S b/arch/arm/src/armv7-m/gnu/up_setjmp.S new file mode 100644 index 0000000000..0f6b6f7cab --- /dev/null +++ b/arch/arm/src/armv7-m/gnu/up_setjmp.S @@ -0,0 +1,162 @@ +/************************************************************************************ + * arch/arm/src/armv7-m/gnu/up_setjmp.S + * + * Copyright (C) 2019 Gregory Nutt. All rights reserved. + * Author: David S. Alessio + * + * 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. + * + ************************************************************************************/ + +/* When this file is assembled, it will require the following GCC options: + * + * -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -meabi=5 -mthumb + */ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/************************************************************************************ + * Public Symbols + ************************************************************************************/ + + .globl setjmp + .globl longjmp + + .syntax unified + .thumb + .file "setjmp.S" + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: setjmp + * + * Description: + * Given the pointer to a register save area (in R0), save the state of the + * all callee-saved registers + * + * C Function Prototype: + * int setjmp(jmp_buf env); + * + * Input Parameters: + * env - A pointer to the register save area in which to save the floating point + * registers and core registers. Since setjmp() can not be inlined, we + * only need to save the ABI-specified callee-saved registers. + * + * Returned Value: + * 0 setjmp called directly + * non-0 we justed returned from a longjmp() + * + ************************************************************************************/ + + .thumb_func + .type setjmp, function +setjmp: + + /* Store callee-saved Core registers */ + + mov ip, sp /* move sp to ip so we can save it */ + stmia r0!, {r4-r11, ip, lr} + +#ifdef CONFIG_ARCH_FPU + vstmia r0!, {s16-s31} /* Save the callee-saved FP registers */ + + /* Store the floating point control and status register. At the end of the + * vstmia, r0 will point to the FPCSR storage location. + */ + + vmrs r1, fpscr /* Fetch the FPCSR */ + str r1, [r0], #4 /* Save the floating point control and status register */ + // DSA: don't need to inc r0 +#endif /* CONFIG_ARCH_FPU */ + + /* we're done, we're out of here */ + + mov r0, #0 + bx lr + + .size setjmp, .-setjmp + +/************************************************************************************ + * Name: longjmp + * + * Description: + * The longjmp() function used the information saved in env to transfer control + * control back to the point where setjmp() was called and to restore ("rewind") + * the stack to its state at the time of the setjmp() call. When control is + * passed back to where setjmp() had been called, setjmp() will return with + * 'val', the second paramater passed to longjmp(). + * + * C Function Prototype: + * void longjmp(jmp_buf env, int val); + * + * Input Parameters: + * jmp_buf env + * int val + * + * Returned Value: + * This function does not return anything explicitly. + * + ************************************************************************************/ + + .thumb_func + .type longjmp, function +longjmp: + + /* Load callee-saved Core registers */ + + ldmia r0!, {r4-r11, ip, lr} + mov sp, ip /* restore sp */ + +#ifdef CONFIG_ARCH_FPU + /* Load callee-saved floating point registers. */ + + vldmia r0!, {s16-s31} /* Restore FP context */ + + /* Load the floating point control and status register. */ + + ldr r2, [r0], #4 /* Fetch the floating point control and status register */ + /* DSA: don't need to inc r0 */ + vmsr fpscr, r2 /* Restore the FPCSR */ +#endif /* CONFIG_ARCH_FPU */ + + mov r0, r1 /* return val */ + bx lr + + .size longjmp, .-longjmp + .end diff --git a/arch/arm/src/cxd56xx/Make.defs b/arch/arm/src/cxd56xx/Make.defs index 65a79318df..fff61e0645 100644 --- a/arch/arm/src/cxd56xx/Make.defs +++ b/arch/arm/src/cxd56xx/Make.defs @@ -40,6 +40,12 @@ HEAD_ASRC = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c CMN_CSRCS += up_createstack.c up_mdelay.c up_udelay.c up_exit.c CMN_CSRCS += up_initialize.c up_initialstate.c up_interruptcontext.c diff --git a/arch/arm/src/efm32/Make.defs b/arch/arm/src/efm32/Make.defs index 9cc149ae7e..7c289df6af 100644 --- a/arch/arm/src/efm32/Make.defs +++ b/arch/arm/src/efm32/Make.defs @@ -41,6 +41,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_allocateheap.c up_assert.c up_blocktask.c up_copyfullstate.c CMN_CSRCS += up_createstack.c up_doirq.c up_exit.c up_hardfault.c CMN_CSRCS += up_initialize.c up_initialstate.c up_interruptcontext.c diff --git a/arch/arm/src/imxrt/Make.defs b/arch/arm/src/imxrt/Make.defs index 0c9e7cea92..735be891b2 100644 --- a/arch/arm/src/imxrt/Make.defs +++ b/arch/arm/src/imxrt/Make.defs @@ -41,6 +41,12 @@ HEAD_ASRC = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c CMN_CSRCS += up_createstack.c up_mdelay.c up_udelay.c up_exit.c CMN_CSRCS += up_initialize.c up_initialstate.c up_interruptcontext.c diff --git a/arch/arm/src/kinetis/Make.defs b/arch/arm/src/kinetis/Make.defs index ec049fc15d..22f13dea3f 100644 --- a/arch/arm/src/kinetis/Make.defs +++ b/arch/arm/src/kinetis/Make.defs @@ -41,6 +41,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_mdelay.c up_udelay.c up_exit.c up_initialize.c up_memfault.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_modifyreg8.c diff --git a/arch/arm/src/lc823450/Make.defs b/arch/arm/src/lc823450/Make.defs index f0861a815a..c195a2e0ce 100644 --- a/arch/arm/src/lc823450/Make.defs +++ b/arch/arm/src/lc823450/Make.defs @@ -43,6 +43,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c CMN_CSRCS += up_createstack.c up_mdelay.c up_udelay.c up_exit.c CMN_CSRCS += up_initialize.c up_initialstate.c up_interruptcontext.c diff --git a/arch/arm/src/lpc17xx_40xx/Make.defs b/arch/arm/src/lpc17xx_40xx/Make.defs index b4004d03a5..dac8b63e94 100644 --- a/arch/arm/src/lpc17xx_40xx/Make.defs +++ b/arch/arm/src/lpc17xx_40xx/Make.defs @@ -45,6 +45,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_mdelay.c up_udelay.c up_exit.c up_initialize.c up_memfault.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_modifyreg8.c diff --git a/arch/arm/src/lpc43xx/Make.defs b/arch/arm/src/lpc43xx/Make.defs index b083bc3bdf..eb62cd2870 100644 --- a/arch/arm/src/lpc43xx/Make.defs +++ b/arch/arm/src/lpc43xx/Make.defs @@ -38,6 +38,12 @@ HEAD_ASRC = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_doirq.c up_exit.c up_hardfault.c up_initialize.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_mdelay.c diff --git a/arch/arm/src/lpc54xx/Make.defs b/arch/arm/src/lpc54xx/Make.defs index c589874054..56e5b2c32e 100644 --- a/arch/arm/src/lpc54xx/Make.defs +++ b/arch/arm/src/lpc54xx/Make.defs @@ -38,6 +38,12 @@ HEAD_ASRC = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_doirq.c up_exit.c up_hardfault.c up_initialize.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_mdelay.c diff --git a/arch/arm/src/max326xx/Make.defs b/arch/arm/src/max326xx/Make.defs index fcb164e44e..75aab22f5d 100644 --- a/arch/arm/src/max326xx/Make.defs +++ b/arch/arm/src/max326xx/Make.defs @@ -40,6 +40,12 @@ HEAD_ASRC = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_allocateheap.c up_assert.c up_blocktask.c up_copyfullstate.c CMN_CSRCS += up_createstack.c up_doirq.c up_exit.c up_hardfault.c CMN_CSRCS += up_initialize.c up_initialstate.c up_interruptcontext.c diff --git a/arch/arm/src/nrf52/Make.defs b/arch/arm/src/nrf52/Make.defs index 96b992f4de..51ca78d553 100644 --- a/arch/arm/src/nrf52/Make.defs +++ b/arch/arm/src/nrf52/Make.defs @@ -38,6 +38,12 @@ HEAD_ASRC = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c CMN_CSRCS += up_createstack.c up_doirq.c up_exit.c up_hardfault.c CMN_CSRCS += up_initialize.c up_initialstate.c up_interruptcontext.c diff --git a/arch/arm/src/sam34/Make.defs b/arch/arm/src/sam34/Make.defs index c88098722b..0aee624ed3 100644 --- a/arch/arm/src/sam34/Make.defs +++ b/arch/arm/src/sam34/Make.defs @@ -46,6 +46,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_doirq.c up_exit.c up_hardfault.c up_initialize.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_mdelay.c diff --git a/arch/arm/src/samd5e5/Make.defs b/arch/arm/src/samd5e5/Make.defs index 40d9654f7a..82722da2ff 100644 --- a/arch/arm/src/samd5e5/Make.defs +++ b/arch/arm/src/samd5e5/Make.defs @@ -45,6 +45,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_allocateheap.c up_assert.c up_blocktask.c up_copyfullstate.c CMN_CSRCS += up_createstack.c up_exit.c up_initialize.c up_initialstate.c CMN_CSRCS += up_interruptcontext.c up_mdelay.c up_memfault.c up_modifyreg8.c diff --git a/arch/arm/src/samv7/Make.defs b/arch/arm/src/samv7/Make.defs index a1fd93883a..b0e7a21863 100644 --- a/arch/arm/src/samv7/Make.defs +++ b/arch/arm/src/samv7/Make.defs @@ -46,6 +46,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_doirq.c up_exit.c up_hardfault.c up_initialize.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_mdelay.c diff --git a/arch/arm/src/stm32/Make.defs b/arch/arm/src/stm32/Make.defs index 45a182cb7a..4656d054d0 100644 --- a/arch/arm/src/stm32/Make.defs +++ b/arch/arm/src/stm32/Make.defs @@ -41,6 +41,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_exit.c up_hardfault.c up_initialize.c up_initialstate.c CMN_CSRCS += up_interruptcontext.c up_mdelay.c up_memfault.c up_modifyreg8.c diff --git a/arch/arm/src/stm32f7/Make.defs b/arch/arm/src/stm32f7/Make.defs index 387dcda7d1..506d830d58 100644 --- a/arch/arm/src/stm32f7/Make.defs +++ b/arch/arm/src/stm32f7/Make.defs @@ -46,6 +46,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_doirq.c up_exit.c up_hardfault.c up_initialize.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_mdelay.c diff --git a/arch/arm/src/stm32h7/Make.defs b/arch/arm/src/stm32h7/Make.defs index efaaac71e5..8a3b2671d7 100644 --- a/arch/arm/src/stm32h7/Make.defs +++ b/arch/arm/src/stm32h7/Make.defs @@ -46,6 +46,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_doirq.c up_exit.c up_hardfault.c up_initialize.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_mdelay.c up_memfault.c diff --git a/arch/arm/src/stm32l4/Make.defs b/arch/arm/src/stm32l4/Make.defs index 20f5f6f509..7656637c79 100644 --- a/arch/arm/src/stm32l4/Make.defs +++ b/arch/arm/src/stm32l4/Make.defs @@ -47,6 +47,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_doirq.c up_exit.c up_hardfault.c up_initialize.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_mdelay.c up_memfault.c diff --git a/arch/arm/src/tiva/Make.defs b/arch/arm/src/tiva/Make.defs index b92fcc0df8..6a802eda51 100644 --- a/arch/arm/src/tiva/Make.defs +++ b/arch/arm/src/tiva/Make.defs @@ -39,6 +39,12 @@ HEAD_ASRC = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_doirq.c up_exit.c up_hardfault.c up_initialize.c CMN_CSRCS += up_initialstate.c up_interruptcontext.c up_mdelay.c diff --git a/arch/arm/src/xmc4/Make.defs b/arch/arm/src/xmc4/Make.defs index ffbccadb03..af7025f116 100644 --- a/arch/arm/src/xmc4/Make.defs +++ b/arch/arm/src/xmc4/Make.defs @@ -41,6 +41,12 @@ CMN_UCSRCS = CMN_ASRCS = up_saveusercontext.S up_fullcontextrestore.S up_switchcontext.S CMN_ASRCS += up_testset.S up_fetchadd.S vfork.S +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +ifeq ($(CONFIG_ARCH_TOOLCHAIN_GNU),y) +CMN_ASRCS += up_setjmp.S +endif +endif + CMN_CSRCS = up_assert.c up_blocktask.c up_copyfullstate.c up_createstack.c CMN_CSRCS += up_doirq.c up_exit.c up_initialize.c up_initialstate.c CMN_CSRCS += up_hardfault.c up_interruptcontext.c up_memfault.c up_mdelay.c diff --git a/include/.gitignore b/include/.gitignore index 7f05406205..bb0a48a3be 100644 --- a/include/.gitignore +++ b/include/.gitignore @@ -4,6 +4,7 @@ /math.h /float.h /stdarg.h +/setjmp.h /features.h /uClibc++ /libcxx diff --git a/include/nuttx/lib/setjmp.h b/include/nuttx/lib/setjmp.h new file mode 100644 index 0000000000..498e58a026 --- /dev/null +++ b/include/nuttx/lib/setjmp.h @@ -0,0 +1,64 @@ +/**************************************************************************** + * include/nuttx/lib/setjmp.h + * + * Copyright (C) 2019 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_LIB_SETJMP_H +#define __INCLUDE_NUTTX_LIB_SETJMP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/* If CONFIG_ARCH_SETJMP_H is defined, then the top-level Makefile will copy + * this header file to include/setjmp.h where it will become the system + * setjmp.h header file. In this case, the architecture specific code must + * provide an arch//include/setjmp.h file which will be + * included below: + */ + +#ifdef CONFIG_ARCH_SETJMP_H +# include +#endif + +/**************************************************************************** + * Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* __INCLUDE_NUTTX_LIB_SETJMP_H */ diff --git a/tools/Makefile.unix b/tools/Makefile.unix index 552d137f29..fcaabf5f58 100644 --- a/tools/Makefile.unix +++ b/tools/Makefile.unix @@ -240,6 +240,18 @@ else include/stdarg.h: endif +# Target used to copy include/nuttx/lib/setjmp.h. If CONFIG_ARCH_SETJMP_H is +# defined, then there is an architecture specific setjmp.h header file +# that will be included indirectly from include/lib/setjmp.h. But first, we +# have to copy setjmp.h from include/nuttx/. to include/. + +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +include/setjmp.h: include/nuttx/lib/setjmp.h + $(Q) cp -f include/nuttx/lib/setjmp.h include/setjmp.h +else +include/setjmp.h: +endif + # Targets used to build include/nuttx/version.h. Creation of version.h is # part of the overall NuttX configuration sequence. Notice that the # tools/mkversion tool is built and used to create include/nuttx/version.h @@ -341,7 +353,7 @@ dirlinks: include/arch include/arch/board include/arch/chip $(ARCH_SRC)/board $( # the config.h and version.h header files in the include/nuttx directory and # the establishment of symbolic links to configured directories. -context: check_context staging include/nuttx/config.h include/nuttx/version.h include/math.h include/float.h include/stdarg.h dirlinks +context: check_context staging include/nuttx/config.h include/nuttx/version.h include/math.h include/float.h include/stdarg.h include/setjmp.h dirlinks $(Q) for dir in $(CONTEXTDIRS) ; do \ $(MAKE) -C $$dir TOPDIR="$(TOPDIR)" context; \ done @@ -358,6 +370,7 @@ clean_context: $(call DELFILE, include/nuttx/version.h) $(call DELFILE, include/math.h) $(call DELFILE, include/stdarg.h) + $(call DELFILE, include/setjmp.h) $(Q) $(DIRUNLINK) include/arch/board $(Q) $(DIRUNLINK) include/arch/chip $(Q) $(DIRUNLINK) include/arch diff --git a/tools/Makefile.win b/tools/Makefile.win index 48376534b9..96306588c5 100644 --- a/tools/Makefile.win +++ b/tools/Makefile.win @@ -235,6 +235,18 @@ else include\stdarg.h: endif +# Target used to copy include\nuttx\setjmp.h. If CONFIG_ARCH_SETJMP_H is +# defined, then there is an architecture specific setjmp.h header file +# that will be included indirectly from include\setjmp.h. But first, we +# have to copy setjmp.h from include\nuttx\. to include\. + +ifeq ($(CONFIG_ARCH_SETJMP_H),y) +include\setjmp.h: include\nuttx\setjmp.h + $(Q) cp -f include\nuttx\setjmp.h include\setjmp.h +else +include\setjmp.h: +endif + # Targets used to build include\nuttx\version.h. Creation of version.h is # part of the overall NuttX configuration sequence. Notice that the # tools\mkversion tool is built and used to create include\nuttx\version.h @@ -363,7 +375,7 @@ dirlinks: include\arch include\arch\board include\arch\chip $(ARCH_SRC)\board $( # the config.h and version.h header files in the include\nuttx directory and # the establishment of symbolic links to configured directories. -context: check_context staging include\nuttx\config.h include\nuttx\version.h include\math.h include\float.h include\stdarg.h dirlinks +context: check_context staging include\nuttx\config.h include\nuttx\version.h include\math.h include\float.h include\stdarg.h include\setjmp.h dirlinks $(Q) for %%G in ($(CONTEXTDIRS)) do ( $(MAKE) -C %%G TOPDIR="$(TOPDIR)" context ) # clean_context @@ -378,6 +390,7 @@ clean_context: $(call DELFILE, include\nuttx\version.h) $(call DELFILE, include\math.h) $(call DELFILE, include\stdarg.h) + $(call DELFILE, include\setjmp.h) $(call DELDIR, include\arch\board) $(call DELDIR, include\arch\chip) $(call DELDIR, include\arch)