From d922922bab61740de2d7283ededf028eff540cdf Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 09:43:43 +0900 Subject: [PATCH 01/12] arch: armv7-a: Fix style warnings in smp.h Signed-off-by: Masayuki Ishikawa --- arch/arm/src/armv7-a/smp.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm/src/armv7-a/smp.h b/arch/arm/src/armv7-a/smp.h index 7f3e37539b61f..a94170c7646e1 100644 --- a/arch/arm/src/armv7-a/smp.h +++ b/arch/arm/src/armv7-a/smp.h @@ -122,9 +122,9 @@ void __cpu3_start(void); * * Description: * Continues the C-level initialization started by the assembly language - * __cpu[n]_start function. At a minimum, this function needs to initialize - * interrupt handling and, perhaps, wait on WFI for arm_cpu_start() to - * issue an SGI. + * __cpu[n]_start function. At a minimum, this function needs to + * initialize interrupt handling and, perhaps, wait on WFI for + * arm_cpu_start() to issue an SGI. * * This function must be provided by the each ARMv7-A MCU and implement * MCU-specific initialization logic. From d427a3e6019d51faa4fb5a0107bf0e096e7711fb Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Fri, 23 Oct 2020 14:18:43 +0900 Subject: [PATCH 02/12] arch: armv7-a: Fix style warnings in arm_cpuidlestack.c Signed-off-by: Masayuki Ishikawa --- arch/arm/src/armv7-a/arm_cpuidlestack.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/arm/src/armv7-a/arm_cpuidlestack.c b/arch/arm/src/armv7-a/arm_cpuidlestack.c index d389622d63ca3..7059e806eb997 100644 --- a/arch/arm/src/armv7-a/arm_cpuidlestack.c +++ b/arch/arm/src/armv7-a/arm_cpuidlestack.c @@ -133,7 +133,6 @@ int up_cpu_idlestack(int cpu, FAR struct tcb_s *tcb, size_t stack_size) /* Get the top of the stack */ - stack_alloc = (uintptr_t)g_cpu_stackalloc[cpu]; DEBUGASSERT(stack_alloc != 0 && STACK_ISALIGNED(stack_alloc)); top_of_stack = stack_alloc + SMP_STACK_TOP; From 0cdd055c21e674f3174e90a31064532bc2efa09c Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 09:46:07 +0900 Subject: [PATCH 03/12] arch: armv7-a: Fix CPUx IDLE stack top for SMP Summary: - This commit fixes CPUx IDLE stack top for SMP - Also removes SMP_STACK_TOP from smp.h Impact: - Affects armv7-a SMP only Testing: - Tested with sabre-6quad:smp (QEMU) Signed-off-by: Masayuki Ishikawa --- arch/arm/src/armv7-a/arm_cpuidlestack.c | 2 +- arch/arm/src/armv7-a/smp.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/arm/src/armv7-a/arm_cpuidlestack.c b/arch/arm/src/armv7-a/arm_cpuidlestack.c index 7059e806eb997..1acdeae7177ca 100644 --- a/arch/arm/src/armv7-a/arm_cpuidlestack.c +++ b/arch/arm/src/armv7-a/arm_cpuidlestack.c @@ -135,7 +135,7 @@ int up_cpu_idlestack(int cpu, FAR struct tcb_s *tcb, size_t stack_size) stack_alloc = (uintptr_t)g_cpu_stackalloc[cpu]; DEBUGASSERT(stack_alloc != 0 && STACK_ISALIGNED(stack_alloc)); - top_of_stack = stack_alloc + SMP_STACK_TOP; + top_of_stack = stack_alloc + SMP_STACK_SIZE; tcb->adj_stack_size = SMP_STACK_SIZE; tcb->stack_alloc_ptr = (FAR uint32_t *)stack_alloc; diff --git a/arch/arm/src/armv7-a/smp.h b/arch/arm/src/armv7-a/smp.h index a94170c7646e1..e168ce680556d 100644 --- a/arch/arm/src/armv7-a/smp.h +++ b/arch/arm/src/armv7-a/smp.h @@ -58,7 +58,6 @@ #define SMP_STACK_MASK 7 #define SMP_STACK_SIZE ((CONFIG_SMP_IDLETHREAD_STACKSIZE + 7) & ~7) #define SMP_STACK_WORDS (SMP_STACK_SIZE >> 2) -#define SMP_STACK_TOP (SMP_STACK_SIZE - 8) /**************************************************************************** * Public Data From 7a7999c19bd09a8e2436a3b8f4ead21aede389b1 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 12:49:25 +0900 Subject: [PATCH 04/12] boards: sabre-6quad: Update nsh/defconfig Summary: - Add CONFIG_DEBUG_FULLOPT=y - Add CONFIG_DEBUG_SYMBOLS=y - Remove CONFIG_HOST_WINDOWS=y - Add CONFIG_READLINE_CMD_HISTORY=y - Add CONFIG_STACK_COLORATION=y Impact: - Affects sabre-6quad:nsh only Testing: - Tested with QEMU Signed-off-by: Masayuki Ishikawa --- boards/arm/imx6/sabre-6quad/configs/nsh/defconfig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/boards/arm/imx6/sabre-6quad/configs/nsh/defconfig b/boards/arm/imx6/sabre-6quad/configs/nsh/defconfig index c42ae64c05b59..30aa9a25a8b34 100644 --- a/boards/arm/imx6/sabre-6quad/configs/nsh/defconfig +++ b/boards/arm/imx6/sabre-6quad/configs/nsh/defconfig @@ -20,11 +20,12 @@ CONFIG_ARCH_STACKDUMP=y CONFIG_BOARD_LOOPSPERMSEC=99369 CONFIG_BOOT_RUNFROMSDRAM=y CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y CONFIG_DEV_ZERO=y CONFIG_FS_PROCFS=y CONFIG_HAVE_CXX=y CONFIG_HAVE_CXXINITIALIZE=y -CONFIG_HOST_WINDOWS=y CONFIG_IMX6_UART1=y CONFIG_IMX_DDR_SIZE=1073741824 CONFIG_INTELHEX_BINARY=y @@ -42,10 +43,12 @@ CONFIG_RAM_SIZE=1073741824 CONFIG_RAM_START=0x10000000 CONFIG_RAM_VSTART=0x10000000 CONFIG_RAW_BINARY=y +CONFIG_READLINE_CMD_HISTORY=y CONFIG_RR_INTERVAL=200 CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORKPRIORITY=192 CONFIG_SCHED_WAITPID=y +CONFIG_STACK_COLORATION=y CONFIG_START_MONTH=3 CONFIG_START_YEAR=2016 CONFIG_SYMTAB_ORDEREDBYNAME=y From ca08968a0c79cc8ab7c12917a91af9153f5bff28 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 10:06:05 +0900 Subject: [PATCH 05/12] armv7-a, imx6: Refactor interrupt stack related code Summary: - Remove -4/-8 offset coding in imx_irq.c and arm_vectors.S - Instead, add SP adjustment after calling setirqstack/setfiqstack - Fix off-by-one irq/fiq stack allocation in 8-byte aligned arch - Fix comments on the user stack pointer in arm_vectors.S - Also, fix up_dumpstate() to extract the user stack pointer - NOTE: stack pointer alignment is 8-byte Impact: - Affects armv7-a with interrupt stack enabled Testing: - Tested with sabre-6quad:smp with QEMU - Tested with sabre-6quad:nsh with QEMU Signed-off-by: Masayuki Ishikawa --- arch/arm/src/armv7-a/arm_assert.c | 25 +++++++++++-------------- arch/arm/src/armv7-a/arm_vectors.S | 10 +++++----- arch/arm/src/imx6/imx_irq.c | 10 +++++----- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/arch/arm/src/armv7-a/arm_assert.c b/arch/arm/src/armv7-a/arm_assert.c index 07a2decbf7f97..f04eaa001243e 100644 --- a/arch/arm/src/armv7-a/arm_assert.c +++ b/arch/arm/src/armv7-a/arm_assert.c @@ -265,24 +265,10 @@ static void up_dumpstate(void) if (sp > istackbase - istacksize && sp < istackbase) { - uint32_t *stackbase; - /* Yes.. dump the interrupt stack */ _alert("Interrupt Stack\n", sp); up_stackdump(sp, istackbase); - - /* Extract the user stack pointer which should lie - * at the base of the interrupt stack. - */ - -#ifdef CONFIG_SMP - stackbase = (uint32_t *)arm_intstack_base(); -#else - stackbase = (uint32_t *)&g_intstackbase; -#endif - sp = *stackbase; - _alert("User sp: %08x\n", sp); } else if (CURRENT_REGS) { @@ -291,6 +277,17 @@ static void up_dumpstate(void) } #endif + /* Extract the user stack pointer if we are in an interrupt handler. + * If we are not in an interrupt handler. Then sp is the user stack + * pointer (and the above range check should have failed). + */ + + if (CURRENT_REGS) + { + sp = CURRENT_REGS[REG_R13]; + _alert("User sp: %08x\n", sp); + } + /* Dump the user stack if the stack pointer lies within the allocated user * stack memory. */ diff --git a/arch/arm/src/armv7-a/arm_vectors.S b/arch/arm/src/armv7-a/arm_vectors.S index 6df8755c4c946..e0559048164dc 100644 --- a/arch/arm/src/armv7-a/arm_vectors.S +++ b/arch/arm/src/armv7-a/arm_vectors.S @@ -261,7 +261,7 @@ arm_vectorirq: /* Call arm_decodeirq() on the interrupt stack */ setirqstack r1, r3 /* SP = IRQ stack top */ - str r0, [sp] /* Save the user stack pointer */ + str r0, [sp, #-4]! /* Save the xcp address at SP-4 then update SP */ mov r4, sp /* Save the SP in a preserved register */ bic sp, sp, #7 /* Force 8-byte alignment */ bl arm_decodeirq /* Call the handler */ @@ -1004,7 +1004,7 @@ arm_vectorfiq: #if CONFIG_ARCH_INTERRUPTSTACK > 7 setfiqstack r1, r4 /* SP = FIQ stack top */ - str r0, [sp] /* Save the user stack pointer */ + str r0, [sp, #-4]! /* Save the xcp address at SP-4 then update SP */ mov r4, sp /* Save the SP in a preserved register */ bic sp, sp, #7 /* Force 8-byte alignment */ bl arm_decodefiq /* Call the handler */ @@ -1072,7 +1072,7 @@ arm_vectorfiq: #if !defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 .bss - .align 4 + .balign 8 .globl g_intstackalloc .type g_intstackalloc, object @@ -1080,7 +1080,7 @@ arm_vectorfiq: .type g_intstackbase, object g_intstackalloc: - .skip ((CONFIG_ARCH_INTERRUPTSTACK & ~7) - 4) + .skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7) g_intstackbase: .skip 4 .size g_intstackbase, 4 @@ -1096,7 +1096,7 @@ g_intstackbase: .type g_fiqstackbase, object g_fiqstackalloc: - .skip ((CONFIG_ARCH_INTERRUPTSTACK & ~7) - 4) + .skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7) g_fiqstackbase: .skip 4 .size g_fiqstackbase, 4 diff --git a/arch/arm/src/imx6/imx_irq.c b/arch/arm/src/imx6/imx_irq.c index 1f7738f9a042d..7d3b76033e576 100644 --- a/arch/arm/src/imx6/imx_irq.c +++ b/arch/arm/src/imx6/imx_irq.c @@ -88,15 +88,15 @@ uint64_t g_fiqstack_alloc[INTSTACK_ALLOC >> 3]; uintptr_t g_irqstack_top[CONFIG_SMP_NCPUS] = { - (uintptr_t)g_irqstack_alloc + INTSTACK_SIZE - 8, + (uintptr_t)g_irqstack_alloc + INTSTACK_SIZE, #if CONFIG_SMP_NCPUS > 1 - (uintptr_t)g_irqstack_alloc + (2 * INTSTACK_SIZE) - 8, + (uintptr_t)g_irqstack_alloc + (2 * INTSTACK_SIZE), #endif #if CONFIG_SMP_NCPUS > 2 - (uintptr_t)g_irqstack_alloc + (3 * INTSTACK_SIZE) - 8, + (uintptr_t)g_irqstack_alloc + (3 * INTSTACK_SIZE), #endif #if CONFIG_SMP_NCPUS > 3 - (uintptr_t)g_irqstack_alloc + (4 * INTSTACK_SIZE) - 8 + (uintptr_t)g_irqstack_alloc + (4 * INTSTACK_SIZE) #endif }; @@ -215,6 +215,6 @@ uintptr_t arm_intstack_base(void) #if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 uintptr_t arm_intstack_alloc(void) { - return g_irqstack_top[up_cpu_index()] - (INTSTACK_SIZE - 8); + return g_irqstack_top[up_cpu_index()] - INTSTACK_SIZE; } #endif From 3777889146ce598ae99eec9b3528a5d96902ae64 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 11:57:14 +0900 Subject: [PATCH 06/12] arm, c5471: Refactor interrupt stack related code Summary: - Apply the same logic for armv7-a - NOTE: stack pointer alignment is 4-byte Impact: - Affects arm (arm7/9) and c5471 with interrupt stack enabled Testing: - Built with c5471evm.nsh (CONFIG_ARCH_INTERRUPTSTACK=2048) - Built with ea3131:nsh (CONFIG_ARCH_INTERRUPTSTACK=2048) - Not tested but should work Signed-off-by: Masayuki Ishikawa --- arch/arm/src/arm/arm_assert.c | 21 +++++++++++++-------- arch/arm/src/arm/arm_vectors.S | 6 +++--- arch/arm/src/c5471/c5471_vectors.S | 6 +++--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/arch/arm/src/arm/arm_assert.c b/arch/arm/src/arm/arm_assert.c index e4f445bb8069e..4957af560b9eb 100644 --- a/arch/arm/src/arm/arm_assert.c +++ b/arch/arm/src/arm/arm_assert.c @@ -210,18 +210,12 @@ static void up_dumpstate(void) * stack? */ - if (sp <= istackbase && sp > istackbase - istacksize) + if (sp < istackbase && sp > istackbase - istacksize) { /* Yes.. dump the interrupt stack */ + _alert("Interrupt Stack\n", sp); up_stackdump(sp, istackbase); - - /* Extract the user stack pointer which should lie - * at the base of the interrupt stack. - */ - - sp = g_intstackbase; - _alert("sp: %08x\n", sp); } else if (CURRENT_REGS) { @@ -229,6 +223,17 @@ static void up_dumpstate(void) up_stackdump(istackbase - istacksize, istackbase); } + /* Extract the user stack pointer if we are in an interrupt handler. + * If we are not in an interrupt handler. Then sp is the user stack + * pointer (and the above range check should have failed). + */ + + if (CURRENT_REGS) + { + sp = CURRENT_REGS[REG_R13]; + _alert("User sp: %08x\n", sp); + } + /* Show user stack info */ _alert("User stack:\n"); diff --git a/arch/arm/src/arm/arm_vectors.S b/arch/arm/src/arm/arm_vectors.S index c03f091edad5e..9606131192af4 100644 --- a/arch/arm/src/arm/arm_vectors.S +++ b/arch/arm/src/arm/arm_vectors.S @@ -132,7 +132,7 @@ arm_vectorirq: #if CONFIG_ARCH_INTERRUPTSTACK > 3 ldr sp, .Lirqstackbase /* SP = interrupt stack base */ - str r0, [sp] /* Save the user stack pointer */ + str r0, [sp, #-4]! /* Save the xcp address at SP-4 then update SP */ bl arm_decodeirq /* Call the handler */ ldr sp, [sp] /* Restore the user stack pointer */ #else @@ -432,13 +432,13 @@ arm_vectorfiq: #if CONFIG_ARCH_INTERRUPTSTACK > 3 .bss - .align 4 + .balign 4 .globl g_intstackalloc .type g_intstackalloc, object .globl g_intstackbase .type g_intstackbase, object g_intstackalloc: - .skip ((CONFIG_ARCH_INTERRUPTSTACK & ~3) - 4) + .skip (CONFIG_ARCH_INTERRUPTSTACK & ~3) g_intstackbase: .skip 4 .size g_intstackbase, 4 diff --git a/arch/arm/src/c5471/c5471_vectors.S b/arch/arm/src/c5471/c5471_vectors.S index 95f4357a771a7..813e0534edc4a 100644 --- a/arch/arm/src/c5471/c5471_vectors.S +++ b/arch/arm/src/c5471/c5471_vectors.S @@ -162,7 +162,7 @@ arm_vectorirq: #if CONFIG_ARCH_INTERRUPTSTACK > 3 ldr sp, .Lirqstackbase /* SP = interrupt stack base */ - str r1, [sp] /* Save the user stack pointer */ + str r1, [sp, #-4]! /* Save the xcp address at SP-4 then update SP */ bl arm_doirq /* Call the handler */ ldr sp, [sp] /* Restore the user stack pointer */ #else @@ -471,13 +471,13 @@ arm_vectoraddrexcptn: #if CONFIG_ARCH_INTERRUPTSTACK > 3 .bss - .align 4 + .balign 4 .global g_intstackalloc .global g_intstackbase .type g_intstackalloc, object .type g_intstackbase, object g_intstackalloc: - .skip ((CONFIG_ARCH_INTERRUPTSTACK & ~3) - 4) + .skip (CONFIG_ARCH_INTERRUPTSTACK & ~3) g_intstackbase: .skip 4 .size g_intstackbase, 4 From cffcb791e12c7e071a5ab0d3fa6ab0480b4b0e8f Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 11:13:38 +0900 Subject: [PATCH 07/12] arch: armv7-r: Refactor interrupt stack related code Summary: - Apply the same logic for armv7-a - NOTE: stack pointer alignment is 8-byte Impact: - Affects armv7-r with interrupt stack enabled Testing: - Not tested but should work Signed-off-by: Masayuki Ishikawa --- arch/arm/src/armv7-r/arm_assert.c | 26 +++++++++++++++----------- arch/arm/src/armv7-r/arm_vectors.S | 22 +++++++++++----------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/arch/arm/src/armv7-r/arm_assert.c b/arch/arm/src/armv7-r/arm_assert.c index c91e2ca1d33bc..ed516c750bee1 100644 --- a/arch/arm/src/armv7-r/arm_assert.c +++ b/arch/arm/src/armv7-r/arm_assert.c @@ -195,7 +195,7 @@ static void up_dumpstate(void) uint32_t sp = arm_getsp(); uint32_t ustackbase; uint32_t ustacksize; -#if CONFIG_ARCH_INTERRUPTSTACK > 3 +#if CONFIG_ARCH_INTERRUPTSTACK > 7 uint32_t istackbase; uint32_t istacksize; #endif @@ -214,11 +214,11 @@ static void up_dumpstate(void) _alert("Current sp: %08x\n", sp); -#if CONFIG_ARCH_INTERRUPTSTACK > 3 +#if CONFIG_ARCH_INTERRUPTSTACK > 7 /* Get the limits on the interrupt stack memory */ istackbase = (uint32_t)&g_intstackbase; - istacksize = (CONFIG_ARCH_INTERRUPTSTACK & ~3); + istacksize = (CONFIG_ARCH_INTERRUPTSTACK & ~7); /* Show interrupt stack info */ @@ -253,7 +253,7 @@ static void up_dumpstate(void) } #endif -#if CONFIG_ARCH_INTERRUPTSTACK > 3 +#if CONFIG_ARCH_INTERRUPTSTACK > 7 /* Does the current stack pointer lie within the interrupt stack? */ if (sp > istackbase - istacksize && sp < istackbase) @@ -262,13 +262,6 @@ static void up_dumpstate(void) _alert("Interrupt Stack\n", sp); up_stackdump(sp, istackbase); - - /* Extract the user stack pointer which should lie - * at the base of the interrupt stack. - */ - - sp = g_intstackbase; - _alert("User sp: %08x\n", sp); } else if (CURRENT_REGS) { @@ -277,6 +270,17 @@ static void up_dumpstate(void) } #endif + /* Extract the user stack pointer if we are in an interrupt handler. + * If we are not in an interrupt handler. Then sp is the user stack + * pointer (and the above range check should have failed). + */ + + if (CURRENT_REGS) + { + sp = CURRENT_REGS[REG_R13]; + _alert("User sp: %08x\n", sp); + } + /* Dump the user stack if the stack pointer lies within the allocated user * stack memory. */ diff --git a/arch/arm/src/armv7-r/arm_vectors.S b/arch/arm/src/armv7-r/arm_vectors.S index bea7c927bcebf..f3064ad219987 100644 --- a/arch/arm/src/armv7-r/arm_vectors.S +++ b/arch/arm/src/armv7-r/arm_vectors.S @@ -179,9 +179,9 @@ arm_vectorirq: mov fp, #0 /* Init frame pointer */ mov r0, sp /* Get r0=xcp */ -#if CONFIG_ARCH_INTERRUPTSTACK > 3 +#if CONFIG_ARCH_INTERRUPTSTACK > 7 ldr sp, .Lirqstackbase /* SP = interrupt stack base */ - str r0, [sp] /* Save the user stack pointer */ + str r0, [sp, #-4]! /* Save the xcp address at SP-4 then update SP */ mov r4, sp /* Save the SP in a preserved register */ bic sp, sp, #7 /* Force 8-byte alignment */ bl arm_decodeirq /* Call the handler */ @@ -232,7 +232,7 @@ arm_vectorirq: .Lirqtmp: .word g_irqtmp -#if CONFIG_ARCH_INTERRUPTSTACK > 3 +#if CONFIG_ARCH_INTERRUPTSTACK > 7 .Lirqstackbase: .word g_intstackbase #endif @@ -890,9 +890,9 @@ arm_vectorfiq: mov fp, #0 /* Init frame pointer */ mov r0, sp /* Get r0=xcp */ -#if CONFIG_ARCH_INTERRUPTSTACK > 3 +#if CONFIG_ARCH_INTERRUPTSTACK > 7 ldr sp, .Lfiqstackbase /* SP = interrupt stack base */ - str r0, [sp] /* Save the user stack pointer */ + str r0, [sp, #-4]! /* Save the xcp address at SP-4 then update SP */ mov r4, sp /* Save the SP in a preserved register */ bic sp, sp, #7 /* Force 8-byte alignment */ bl arm_decodefiq /* Call the handler */ @@ -943,7 +943,7 @@ arm_vectorfiq: .Lfiqtmp: .word g_fiqtmp -#if CONFIG_ARCH_INTERRUPTSTACK > 3 +#if CONFIG_ARCH_INTERRUPTSTACK > 7 .Lfiqstackbase: .word g_intstackbase #endif @@ -957,9 +957,9 @@ arm_vectorfiq: * Name: g_intstackalloc/g_intstackbase ************************************************************************************/ -#if CONFIG_ARCH_INTERRUPTSTACK > 3 +#if CONFIG_ARCH_INTERRUPTSTACK > 7 .bss - .align 4 + .balign 8 .globl g_intstackalloc .type g_intstackalloc, object @@ -967,11 +967,11 @@ arm_vectorfiq: .type g_intstackbase, object g_intstackalloc: - .skip ((CONFIG_ARCH_INTERRUPTSTACK & ~3) - 4) + .skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7) g_intstackbase: .skip 4 .size g_intstackbase, 4 - .size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~3) + .size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~7) -#endif /* CONFIG_ARCH_INTERRUPTSTACK > 3 */ +#endif /* CONFIG_ARCH_INTERRUPTSTACK > 7 */ .end From cefa7050c1c4519f96fae1d76b72a18f1f6dcc6f Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 14:50:50 +0900 Subject: [PATCH 08/12] boards: stm32f4discovery: Update wifi/defconfig Summary: - Add CONFIG_ARCH_INTERRUPTSTACK=2048 - Add CONFIG_ARMV7M_LAZYFPU=y - Add CONFIG_TESTING_OSTEST_FPUSIZE=132 Impact: - Affects stm32f4discovery:wifi only Testing: - Tested with ostest, uSD card, Wi-Fi Signed-off-by: Masayuki Ishikawa --- boards/arm/stm32/stm32f4discovery/configs/wifi/defconfig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/boards/arm/stm32/stm32f4discovery/configs/wifi/defconfig b/boards/arm/stm32/stm32f4discovery/configs/wifi/defconfig index 54912f275dc5f..9f48660c75bb2 100644 --- a/boards/arm/stm32/stm32f4discovery/configs/wifi/defconfig +++ b/boards/arm/stm32/stm32f4discovery/configs/wifi/defconfig @@ -5,7 +5,6 @@ # You can then do "make savedefconfig" to generate a new defconfig file that includes your # modifications. # -# CONFIG_ARCH_FPU is not set # CONFIG_MMCSD_HAVE_CARDDETECT is not set # CONFIG_MMCSD_HAVE_WRITEPROTECT is not set # CONFIG_NSH_ARGCAT is not set @@ -19,7 +18,9 @@ CONFIG_ARCH_BUTTONS=y CONFIG_ARCH_CHIP="stm32" CONFIG_ARCH_CHIP_STM32=y CONFIG_ARCH_CHIP_STM32F407VG=y +CONFIG_ARCH_INTERRUPTSTACK=2048 CONFIG_ARCH_STACKDUMP=y +CONFIG_ARMV7M_LAZYFPU=y CONFIG_BOARDCTL_RESET=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y @@ -101,6 +102,7 @@ CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME="g_symtab" CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME="g_nsymbols" CONFIG_SYSTEM_NTPC=y CONFIG_TESTING_OSTEST=y +CONFIG_TESTING_OSTEST_FPUSIZE=132 CONFIG_USART2_RXBUFSIZE=128 CONFIG_USART2_SERIAL_CONSOLE=y CONFIG_USART2_TXBUFSIZE=128 From e074e8705170f0cb1c18351f1466c36dc53604ba Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 14:06:31 +0900 Subject: [PATCH 09/12] armv7-m, cxd56xx, lc823450: Refactor interrupt stack related code Summary: - Remove +4/-8 offset coding - Also, fix alignments for g_intstackalloc - NOTE: stack pointer alignment is 8-byte Impact: - Affects armv7-m with interrupt stack enabled Testing: - Tested with spresense:wifi_smp - Tested with lc823450:smp - Tested with stm32f4discovery:wifi Signed-off-by: Masayuki Ishikawa --- arch/arm/src/armv7-m/arm_assert.c | 2 +- arch/arm/src/armv7-m/gnu/arm_exception.S | 6 +++--- arch/arm/src/armv7-m/gnu/arm_lazyexception.S | 6 +++--- arch/arm/src/cxd56xx/cxd56_irq.c | 14 +++++++------- arch/arm/src/lc823450/lc823450_irq.c | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/arch/arm/src/armv7-m/arm_assert.c b/arch/arm/src/armv7-m/arm_assert.c index 382297f202bdb..c1a29cdd60b2e 100644 --- a/arch/arm/src/armv7-m/arm_assert.c +++ b/arch/arm/src/armv7-m/arm_assert.c @@ -244,7 +244,7 @@ static void up_dumpstate(void) * stack? */ - if (sp <= istackbase && sp > istackbase - istacksize) + if (sp < istackbase && sp > istackbase - istacksize) { /* Yes.. dump the interrupt stack */ diff --git a/arch/arm/src/armv7-m/gnu/arm_exception.S b/arch/arm/src/armv7-m/gnu/arm_exception.S index b9580eeec5732..34e5031264c39 100644 --- a/arch/arm/src/armv7-m/gnu/arm_exception.S +++ b/arch/arm/src/armv7-m/gnu/arm_exception.S @@ -67,7 +67,7 @@ * no privileged task has run. */ -# if defined(CONFIG_BUILD_PROTECTED) && CONFIG_ARCH_INTERRUPTSTACK < 4 +# if defined(CONFIG_BUILD_PROTECTED) && CONFIG_ARCH_INTERRUPTSTACK < 8 # error Interrupt stack must be used with high priority interrupts in kernel mode # endif @@ -197,7 +197,7 @@ exception_common: * here prohibits nested interrupts without some additional logic! */ - setintstack r2, r3 + setintstack r2, r3 /* SP = IRQ stack top */ #else /* Otherwise, we will re-use the interrupted thread's stack. That may @@ -321,7 +321,7 @@ exception_common: .bss .global g_intstackalloc .global g_intstackbase - .align 8 + .balign 8 g_intstackalloc: .skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7) g_intstackbase: diff --git a/arch/arm/src/armv7-m/gnu/arm_lazyexception.S b/arch/arm/src/armv7-m/gnu/arm_lazyexception.S index 57ee25096ff8b..9d15f901eeb1a 100644 --- a/arch/arm/src/armv7-m/gnu/arm_lazyexception.S +++ b/arch/arm/src/armv7-m/gnu/arm_lazyexception.S @@ -50,7 +50,7 @@ * nested interrupt, the interrupt stack if no privileged task has run. */ -# if defined(CONFIG_BUILD_PROTECTED) && CONFIG_ARCH_INTERRUPTSTACK < 4 +# if defined(CONFIG_BUILD_PROTECTED) && CONFIG_ARCH_INTERRUPTSTACK < 8 # error Interrupt stack must be used with high priority interrupts in kernel mode # endif @@ -192,7 +192,7 @@ exception_common: * here prohibits nested interrupts without some additional logic! */ - setintstack r2, r3 + setintstack r2, r3 /* SP = IRQ stack top */ #else /* Otherwise, we will re-use the interrupted thread's stack. That may @@ -340,7 +340,7 @@ exception_common: .bss .global g_intstackalloc .global g_intstackbase - .align 8 + .balign 8 g_intstackalloc: .skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7) g_intstackbase: diff --git a/arch/arm/src/cxd56xx/cxd56_irq.c b/arch/arm/src/cxd56xx/cxd56_irq.c index f113dcef06f9e..d59872e61576e 100644 --- a/arch/arm/src/cxd56xx/cxd56_irq.c +++ b/arch/arm/src/cxd56xx/cxd56_irq.c @@ -112,17 +112,17 @@ static uint64_t g_intstack_alloc[INTSTACK_ALLOC >> 3]; const uint32_t g_cpu_intstack_top[CONFIG_SMP_NCPUS] = { - (uint32_t)g_intstack_alloc + INTSTACK_SIZE - 8, + (uint32_t)g_intstack_alloc + INTSTACK_SIZE, #if CONFIG_SMP_NCPUS > 1 - (uint32_t)g_intstack_alloc + (2 * INTSTACK_SIZE) - 8, + (uint32_t)g_intstack_alloc + (2 * INTSTACK_SIZE), #if CONFIG_SMP_NCPUS > 2 - (uint32_t)g_intstack_alloc + (3 * INTSTACK_SIZE) - 8, + (uint32_t)g_intstack_alloc + (3 * INTSTACK_SIZE), #if CONFIG_SMP_NCPUS > 3 - (uint32_t)g_intstack_alloc + (4 * INTSTACK_SIZE) - 8, + (uint32_t)g_intstack_alloc + (4 * INTSTACK_SIZE), #if CONFIG_SMP_NCPUS > 4 - (uint32_t)g_intstack_alloc + (5 * INTSTACK_SIZE) - 8, + (uint32_t)g_intstack_alloc + (5 * INTSTACK_SIZE), #if CONFIG_SMP_NCPUS > 5 - (uint32_t)g_intstack_alloc + (6 * INTSTACK_SIZE) - 8, + (uint32_t)g_intstack_alloc + (6 * INTSTACK_SIZE), #endif /* CONFIG_SMP_NCPUS > 5 */ #endif /* CONFIG_SMP_NCPUS > 4 */ #endif /* CONFIG_SMP_NCPUS > 3 */ @@ -667,6 +667,6 @@ uintptr_t arm_intstack_base(void) #if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 uintptr_t arm_intstack_alloc(void) { - return g_cpu_intstack_top[up_cpu_index()] - (INTSTACK_SIZE - 8); + return g_cpu_intstack_top[up_cpu_index()] - INTSTACK_SIZE; } #endif diff --git a/arch/arm/src/lc823450/lc823450_irq.c b/arch/arm/src/lc823450/lc823450_irq.c index 4e0beaa0715b1..4583ae95f5e80 100644 --- a/arch/arm/src/lc823450/lc823450_irq.c +++ b/arch/arm/src/lc823450/lc823450_irq.c @@ -95,9 +95,9 @@ uint64_t g_intstack_alloc[INTSTACK_ALLOC >> 3]; const uint32_t g_cpu_intstack_top[CONFIG_SMP_NCPUS] = { - (uint32_t)g_intstack_alloc + INTSTACK_SIZE - 8, + (uint32_t)g_intstack_alloc + INTSTACK_SIZE, #if CONFIG_SMP_NCPUS > 1 - (uint32_t)g_intstack_alloc + (2 * INTSTACK_SIZE) - 8, + (uint32_t)g_intstack_alloc + (2 * INTSTACK_SIZE), #endif /* CONFIG_SMP_NCPUS > 1 */ }; #endif @@ -888,6 +888,6 @@ uintptr_t arm_intstack_base(void) #if defined(CONFIG_SMP) && CONFIG_ARCH_INTERRUPTSTACK > 7 uintptr_t arm_intstack_alloc(void) { - return g_cpu_intstack_top[up_cpu_index()] - (INTSTACK_SIZE - 8); + return g_cpu_intstack_top[up_cpu_index()] - INTSTACK_SIZE; } #endif From c575a46db47d0edbb342e2b88c36ed3edc9c4ad0 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 15:20:39 +0900 Subject: [PATCH 10/12] arch: armv8-m: Refactor interrupt stack related code Summary: - Apply the same logic for armv7-m - NOTE: stack pointer alignment is 8-byte Impact: - Affects armv8-m with interrupt stack enabled Testing: - Not tested but should work Signed-off-by: Masayuki Ishikawa --- arch/arm/src/armv8-m/arm_assert.c | 2 +- arch/arm/src/armv8-m/arm_exception.S | 4 ++-- arch/arm/src/armv8-m/arm_lazyexception.S | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm/src/armv8-m/arm_assert.c b/arch/arm/src/armv8-m/arm_assert.c index ac0b9b7215113..bc6cb3a1d9356 100644 --- a/arch/arm/src/armv8-m/arm_assert.c +++ b/arch/arm/src/armv8-m/arm_assert.c @@ -244,7 +244,7 @@ static void up_dumpstate(void) * stack? */ - if (sp <= istackbase && sp > istackbase - istacksize) + if (sp < istackbase && sp > istackbase - istacksize) { /* Yes.. dump the interrupt stack */ diff --git a/arch/arm/src/armv8-m/arm_exception.S b/arch/arm/src/armv8-m/arm_exception.S index c7dc5af6e097e..9a3c434e0a92d 100644 --- a/arch/arm/src/armv8-m/arm_exception.S +++ b/arch/arm/src/armv8-m/arm_exception.S @@ -67,7 +67,7 @@ * no privileged task has run. */ -# if defined(CONFIG_BUILD_PROTECTED) && CONFIG_ARCH_INTERRUPTSTACK < 4 +# if defined(CONFIG_BUILD_PROTECTED) && CONFIG_ARCH_INTERRUPTSTACK < 8 # error Interrupt stack must be used with high priority interrupts in kernel mode # endif @@ -355,7 +355,7 @@ exception_common: .bss .global g_intstackalloc .global g_intstackbase - .align 8 + .balign 8 g_intstackalloc: .skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7) g_intstackbase: diff --git a/arch/arm/src/armv8-m/arm_lazyexception.S b/arch/arm/src/armv8-m/arm_lazyexception.S index ade51c1adbac1..fe89b3206331e 100644 --- a/arch/arm/src/armv8-m/arm_lazyexception.S +++ b/arch/arm/src/armv8-m/arm_lazyexception.S @@ -50,7 +50,7 @@ * nested interrupt, the interrupt stack if no privileged task has run. */ -# if defined(CONFIG_BUILD_PROTECTED) && CONFIG_ARCH_INTERRUPTSTACK < 4 +# if defined(CONFIG_BUILD_PROTECTED) && CONFIG_ARCH_INTERRUPTSTACK < 8 # error Interrupt stack must be used with high priority interrupts in kernel mode # endif @@ -373,7 +373,7 @@ exception_common: .bss .global g_intstackalloc .global g_intstackbase - .align 8 + .balign 8 g_intstackalloc: .skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7) g_intstackbase: From bcf7d94944f451a9f5f5609707b9042595aa068c Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 22 Oct 2020 15:46:31 +0900 Subject: [PATCH 11/12] arch: armv6-m: Refactor interrupt stack related code Summary: - Apply the same logic for armv7-m - NOTE: stack pointer alignment is 4-byte Impact: - Affects armv6-m with interrupt stack enabled Testing: - Built with freedom-kl25z:nsh (CONFIG_ARCH_INTERRUPTSTACK=2048) - Not tested but should work Signed-off-by: Masayuki Ishikawa --- arch/arm/src/armv6-m/arm_assert.c | 2 +- arch/arm/src/armv6-m/arm_exception.S | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/armv6-m/arm_assert.c b/arch/arm/src/armv6-m/arm_assert.c index 382a039a3943d..11c97ba1e72c4 100644 --- a/arch/arm/src/armv6-m/arm_assert.c +++ b/arch/arm/src/armv6-m/arm_assert.c @@ -247,7 +247,7 @@ static void up_dumpstate(void) * stack? */ - if (sp <= istackbase && sp > istackbase - istacksize) + if (sp < istackbase && sp > istackbase - istacksize) { /* Yes.. dump the interrupt stack */ diff --git a/arch/arm/src/armv6-m/arm_exception.S b/arch/arm/src/armv6-m/arm_exception.S index c70c57a2eb969..ecc6c04df29ea 100644 --- a/arch/arm/src/armv6-m/arm_exception.S +++ b/arch/arm/src/armv6-m/arm_exception.S @@ -270,7 +270,7 @@ exception_common: .bss .global g_intstackalloc .global g_intstackbase - .align 4 + .balign 4 g_intstackalloc: .skip (CONFIG_ARCH_INTERRUPTSTACK & ~3) g_intstackbase: From df8c32307f57fb1921e4c747333322b4d3490de9 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Fri, 23 Oct 2020 14:35:41 +0900 Subject: [PATCH 12/12] arm: armv7-a: Fix kernel stack dump in arm_assert.c Summary: - This commit fixes kernel stack dump information Impact: - Affects armv7-a with kernel build Testing: - Built with sama5d4-ek:knsh - Not tested Signed-off-by: Masayuki Ishikawa --- arch/arm/src/armv7-a/arm_assert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/src/armv7-a/arm_assert.c b/arch/arm/src/armv7-a/arm_assert.c index f04eaa001243e..015aa83578267 100644 --- a/arch/arm/src/armv7-a/arm_assert.c +++ b/arch/arm/src/armv7-a/arm_assert.c @@ -252,7 +252,7 @@ static void up_dumpstate(void) if (rtcb->xcp.kstack) { kstackbase = (uint32_t)rtcb->xcp.kstack + - CONFIG_ARCH_KERNEL_STACKSIZE - 4; + CONFIG_ARCH_KERNEL_STACKSIZE; _alert("Kernel stack:\n"); _alert(" base: %08x\n", kstackbase);