diff --git a/Documentation/reference/os/arch.rst b/Documentation/reference/os/arch.rst index b9b5c1e393..1fd49f1fc4 100644 --- a/Documentation/reference/os/arch.rst +++ b/Documentation/reference/os/arch.rst @@ -198,9 +198,9 @@ APIs Exported by Architecture-Specific Logic to NuttX function should disable interrupts before performing scheduling operations. -.. c:function:: void up_assert(FAR const char *filename, int linenum) +.. c:function:: void up_dump_register(FAR void *dumpregs) - Assertions may be handled in an + Register dump may be handled in an architecture-specific way. .. c:function:: void up_schedule_sigaction(FAR struct tcb_s *tcb, sig_deliver_t sigdeliver) diff --git a/arch/arm/src/armv7-a/arm_cpustart.c b/arch/arm/src/armv7-a/arm_cpustart.c index e77d408a11..a7dd56c7a5 100644 --- a/arch/arm/src/armv7-a/arm_cpustart.c +++ b/arch/arm/src/armv7-a/arm_cpustart.c @@ -82,7 +82,7 @@ int arm_start_handler(int irq, void *context, void *arg) /* Dump registers so that we can see what is going to happen on return */ #if 0 - arm_registerdump(tcb->xcp.regs); + up_dump_register(tcb->xcp.regs); #endif /* Then switch contexts. This instantiates the exception context of the diff --git a/arch/arm/src/common/Make.defs b/arch/arm/src/common/Make.defs index a90af8c3ad..1377b80b4a 100644 --- a/arch/arm/src/common/Make.defs +++ b/arch/arm/src/common/Make.defs @@ -20,14 +20,12 @@ # Common ARM files -CMN_CSRCS += arm_allocateheap.c arm_assert.c -CMN_CSRCS += arm_createstack.c arm_exit.c -CMN_CSRCS += arm_initialize.c arm_lowputs.c -CMN_CSRCS += arm_modifyreg16.c arm_modifyreg32.c -CMN_CSRCS += arm_modifyreg8.c arm_nputs.c -CMN_CSRCS += arm_releasestack.c arm_saveusercontext.c -CMN_CSRCS += arm_stackframe.c arm_registerdump.c arm_getintstack.c -CMN_CSRCS += arm_vfork.c arm_switchcontext.c arm_usestack.c +CMN_CSRCS += arm_allocateheap.c arm_createstack.c arm_exit.c +CMN_CSRCS += arm_getintstack.c arm_initialize.c arm_lowputs.c +CMN_CSRCS += arm_modifyreg8.c arm_modifyreg16.c arm_modifyreg32.c +CMN_CSRCS += arm_nputs.c arm_releasestack.c arm_registerdump.c +CMN_CSRCS += arm_stackframe.c arm_saveusercontext.c +CMN_CSRCS += arm_switchcontext.c arm_usestack.c arm_vfork.c ifneq ($(CONFIG_ALARM_ARCH),y) ifneq ($(CONFIG_TIMER_ARCH),y) diff --git a/arch/arm/src/common/arm_assert.c b/arch/arm/src/common/arm_assert.c deleted file mode 100644 index 01498fe232..0000000000 --- a/arch/arm/src/common/arm_assert.c +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * arch/arm/src/common/arm_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include - -#include -#include - -#include - -#include "sched/sched.h" -#include "arm_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint8_t s_last_regs[XCPTCONTEXT_SIZE]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - struct tcb_s *rtcb = running_task(); - - board_autoled_on(LED_ASSERTION); - - /* Update the xcp context */ - - if (CURRENT_REGS) - { - rtcb->xcp.regs = (uint32_t *)CURRENT_REGS; - } - else - { - up_saveusercontext(s_last_regs); - rtcb->xcp.regs = (uint32_t *)s_last_regs; - } - - /* Dump the interrupt registers */ - - arm_registerdump(rtcb->xcp.regs); -} diff --git a/arch/arm/src/common/arm_internal.h b/arch/arm/src/common/arm_internal.h index f46abb6b89..a1dbcfb904 100644 --- a/arch/arm/src/common/arm_internal.h +++ b/arch/arm/src/common/arm_internal.h @@ -480,8 +480,6 @@ size_t arm_stack_check(void *stackbase, size_t nbytes); void arm_stack_color(void *stackbase, size_t nbytes); #endif -void arm_registerdump(volatile uint32_t *regs); - #undef EXTERN #ifdef __cplusplus } diff --git a/arch/arm/src/common/arm_registerdump.c b/arch/arm/src/common/arm_registerdump.c index 99c2632fe6..e5fb4bd647 100644 --- a/arch/arm/src/common/arm_registerdump.c +++ b/arch/arm/src/common/arm_registerdump.c @@ -51,11 +51,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: arm_registerdump + * Name: up_dump_register ****************************************************************************/ -void arm_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : CURRENT_REGS; + /* Dump the interrupt registers */ _alert("R0: %08" PRIx32 " R1: %08" PRIx32 diff --git a/arch/arm64/src/common/Make.defs b/arch/arm64/src/common/Make.defs index bf731b424e..507e8e57dd 100644 --- a/arch/arm64/src/common/Make.defs +++ b/arch/arm64/src/common/Make.defs @@ -43,12 +43,11 @@ endif # Common C source files ( OS call up_xxx) CMN_CSRCS = arm64_initialize.c arm64_initialstate.c arm64_boot.c -CMN_CSRCS += arm64_nputs.c arm64_idle.c arm64_copystate.c -CMN_CSRCS += arm64_createstack.c arm64_releasestack.c arm64_stackframe.c arm64_usestack.c +CMN_CSRCS += arm64_nputs.c arm64_idle.c arm64_copystate.c arm64_createstack.c +CMN_CSRCS += arm64_releasestack.c arm64_stackframe.c arm64_usestack.c CMN_CSRCS += arm64_task_sched.c arm64_exit.c arm64_vfork.c arm64_switchcontext.c -CMN_CSRCS += arm64_assert.c arm64_schedulesigaction.c arm64_backtrace.c -CMN_CSRCS += arm64_sigdeliver.c arm64_systemreset.c -CMN_CSRCS += arm64_getintstack.c arm64_registerdump.c +CMN_CSRCS += arm64_schedulesigaction.c arm64_sigdeliver.c arm64_systemreset.c +CMN_CSRCS += arm64_backtrace.c arm64_getintstack.c arm64_registerdump.c # Common C source files ( hardware BSP ) CMN_CSRCS += arm64_mmu.c arm64_arch_timer.c arm64_cache.c diff --git a/arch/arm64/src/common/arm64_assert.c b/arch/arm64/src/common/arm64_assert.c deleted file mode 100644 index 1a14e98e02..0000000000 --- a/arch/arm64/src/common/arm64_assert.c +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** - * arch/arm64/src/common/arm64_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include - -#include "arm64_arch.h" -#include "arm64_internal.h" -#include "chip.h" - -#ifdef CONFIG_ARCH_FPU -#include "arm64_fpu.h" -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: arm64_dump_fatal - ****************************************************************************/ - -void arm64_dump_fatal(struct regs_context *regs) -{ -#ifdef CONFIG_SCHED_BACKTRACE - struct tcb_s *rtcb = (struct tcb_s *)regs->tpidr_el1; - - /* Show back trace */ - - sched_dumpstack(rtcb->pid); -#endif - - /* Dump the registers */ - - arm64_registerdump(regs); -} - -void up_mdelay(unsigned int milliseconds) -{ - volatile unsigned int i; - volatile unsigned int j; - - for (i = 0; i < milliseconds; i++) - { - for (j = 0; j < CONFIG_BOARD_LOOPSPERMSEC; j++) - { - } - } -} - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - struct tcb_s *rtcb = (struct tcb_s *)arch_get_current_tcb(); - - /* Update the xcp context */ - - if (CURRENT_REGS) - { - /* in interrupt */ - - rtcb->xcp.regs = (uint64_t *)CURRENT_REGS; - } - else - { - up_saveusercontext(rtcb->xcp.regs); - } - - /* Dump the registers */ - - arm64_registerdump((struct regs_context *)rtcb->xcp.regs); -} diff --git a/arch/arm64/src/common/arm64_fatal.c b/arch/arm64/src/common/arm64_fatal.c index fac6db9082..36321ec828 100644 --- a/arch/arm64/src/common/arm64_fatal.c +++ b/arch/arm64/src/common/arm64_fatal.c @@ -284,6 +284,42 @@ static void print_ec_cause(uint64_t esr) * Public Functions ****************************************************************************/ +/**************************************************************************** + * Name: up_mdelay + ****************************************************************************/ + +void up_mdelay(unsigned int milliseconds) +{ + volatile unsigned int i; + volatile unsigned int j; + + for (i = 0; i < milliseconds; i++) + { + for (j = 0; j < CONFIG_BOARD_LOOPSPERMSEC; j++) + { + } + } +} + +/**************************************************************************** + * Name: arm64_dump_fatal + ****************************************************************************/ + +void arm64_dump_fatal(struct regs_context *regs) +{ +#ifdef CONFIG_SCHED_BACKTRACE + struct tcb_s *rtcb = (struct tcb_s *)regs->tpidr_el1; + + /* Show back trace */ + + sched_dumpstack(rtcb->pid); +#endif + + /* Dump the registers */ + + up_dump_register(regs); +} + /**************************************************************************** * Name: arm64_fatal_error * diff --git a/arch/arm64/src/common/arm64_internal.h b/arch/arm64/src/common/arm64_internal.h index 211a3f175b..1b4d3af8e8 100644 --- a/arch/arm64/src/common/arm64_internal.h +++ b/arch/arm64/src/common/arm64_internal.h @@ -347,8 +347,6 @@ size_t arm64_stack_check(void *stackbase, size_t nbytes); void arm64_stack_color(void *stackbase, size_t nbytes); #endif -void arm64_registerdump(struct regs_context * regs); - #undef EXTERN #ifdef __cplusplus } diff --git a/arch/arm64/src/common/arm64_registerdump.c b/arch/arm64/src/common/arm64_registerdump.c index b7973adff8..1776b9eba7 100644 --- a/arch/arm64/src/common/arm64_registerdump.c +++ b/arch/arm64/src/common/arm64_registerdump.c @@ -53,11 +53,14 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: arm64_registerdump + * Name: up_dump_register ****************************************************************************/ -void arm64_registerdump(struct regs_context * regs) +void up_dump_register(void *dumpregs) { + volatile struct regs_context *regs = dumpregs ? dumpregs : + (struct regs_context *)CURRENT_REGS; + _alert("stack = %p\n", regs); _alert("x0: 0x%-16"PRIx64" x1: 0x%"PRIx64"\n", regs->regs[REG_X0], regs->regs[REG_X1]); diff --git a/arch/avr/include/avr/irq.h b/arch/avr/include/avr/irq.h index 67671b87db..c63d776ae7 100644 --- a/arch/avr/include/avr/irq.h +++ b/arch/avr/include/avr/irq.h @@ -82,6 +82,8 @@ # define REG_PC2 37 #endif +#define XCPTCONTEXT_SIZE XCPTCONTEXT_REGS + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/avr/include/avr32/irq.h b/arch/avr/include/avr32/irq.h index 67847fc270..755d9086ce 100644 --- a/arch/avr/include/avr32/irq.h +++ b/arch/avr/include/avr32/irq.h @@ -82,6 +82,7 @@ #define INTCONTEXT_REGS 8 /* r8-r12, lr, pc, sr */ #define XCPTCONTEXT_REGS 17 /* Plus r0-r7, sp */ +#define XCPTCONTEXT_SIZE (4 * XCPTCONTEXT_REGS) /**************************************************************************** * Public Types diff --git a/arch/avr/src/at32uc3/Make.defs b/arch/avr/src/at32uc3/Make.defs index deeb192d5a..4b0f23fb57 100644 --- a/arch/avr/src/at32uc3/Make.defs +++ b/arch/avr/src/at32uc3/Make.defs @@ -24,14 +24,12 @@ HEAD_ASRC = avr_nommuhead.S # Common AVR/AVR32 files -CMN_ASRCS = avr_exceptions.S avr_fullcontextrestore.S avr_doswitch.S -CMN_CSRCS = avr_assert.c avr_allocateheap.c avr_copystate.c -CMN_CSRCS += avr_createstack.c avr_mdelay.c avr_udelay.c avr_exit.c avr_idle.c -CMN_CSRCS += avr_initialize.c avr_initialstate.c +CMN_ASRCS = avr_exceptions.S avr_fullcontextrestore.S avr_doswitch.S avr_saveusercontext.S +CMN_CSRCS = avr_allocateheap.c avr_copystate.c avr_createstack.c avr_exit.c +CMN_CSRCS += avr_mdelay.c avr_udelay.c avr_initialize.c avr_initialstate.c avr_idle.c CMN_CSRCS += avr_modifyreg8.c avr_modifyreg16.c avr_modifyreg32.c avr_releasestack.c -CMN_CSRCS += avr_schedulesigaction.c avr_sigdeliver.c avr_stackframe.c -CMN_CSRCS += avr_switchcontext.c avr_usestack.c avr_doirq.c avr_nputs.c -CMN_CSRCS += avr_registerdump.c avr_getintstack.c +CMN_CSRCS += avr_schedulesigaction.c avr_sigdeliver.c avr_stackframe.c avr_switchcontext.c +CMN_CSRCS += avr_usestack.c avr_doirq.c avr_nputs.c avr_registerdump.c avr_getintstack.c # Required AT32UC3 files diff --git a/arch/avr/src/at90usb/Make.defs b/arch/avr/src/at90usb/Make.defs index 5d04bc3711..eac2d88f67 100644 --- a/arch/avr/src/at90usb/Make.defs +++ b/arch/avr/src/at90usb/Make.defs @@ -24,15 +24,14 @@ HEAD_ASRC = at90usb_head.S # Common AVR files -CMN_ASRCS = avr_doswitch.S -CMN_CSRCS = avr_allocateheap.c avr_assert.c avr_copystate.c -CMN_CSRCS += avr_createstack.c avr_doirq.c avr_exit.c avr_idle.c avr_initialize.c -CMN_CSRCS += avr_initialstate.c avr_irq.c avr_lowputs.c -CMN_CSRCS += avr_mdelay.c avr_modifyreg8.c avr_modifyreg16.c avr_modifyreg32.c -CMN_CSRCS += avr_nputs.c avr_releasestack.c -CMN_CSRCS += avr_schedulesigaction.c avr_sigdeliver.c -CMN_CSRCS += avr_stackframe.c avr_udelay.c avr_switchcontext.c avr_usestack.c -CMN_CSRCS += avr_registerdump.c avr_getintstack.c +CMN_ASRCS = avr_doswitch.S avr_saveusercontext.S +CMN_CSRCS = avr_allocateheap.c avr_copystate.c avr_createstack.c +CMN_CSRCS += avr_doirq.c avr_exit.c avr_idle.c avr_irq.c avr_udelay.c +CMN_CSRCS += avr_initialize.c avr_initialstate.c avr_lowputs.c avr_mdelay.c +CMN_CSRCS += avr_modifyreg8.c avr_modifyreg16.c avr_modifyreg32.c +CMN_CSRCS += avr_nputs.c avr_releasestack.c avr_registerdump.c +CMN_CSRCS += avr_schedulesigaction.c avr_sigdeliver.c avr_getintstack.c +CMN_CSRCS += avr_stackframe.c avr_switchcontext.c avr_usestack.c # Configuration-dependent common files diff --git a/arch/avr/src/atmega/Make.defs b/arch/avr/src/atmega/Make.defs index 9b0131957f..9fa3569f11 100644 --- a/arch/avr/src/atmega/Make.defs +++ b/arch/avr/src/atmega/Make.defs @@ -24,15 +24,14 @@ HEAD_ASRC = atmega_head.S # Common AVR files -CMN_ASRCS = avr_doswitch.S -CMN_CSRCS = avr_allocateheap.c avr_assert.c avr_copystate.c -CMN_CSRCS += avr_createstack.c avr_doirq.c avr_exit.c avr_idle.c avr_initialize.c -CMN_CSRCS += avr_initialstate.c avr_irq.c avr_lowputs.c -CMN_CSRCS += avr_mdelay.c avr_modifyreg8.c avr_modifyreg16.c avr_modifyreg32.c -CMN_CSRCS += avr_nputs.c avr_releasestack.c -CMN_CSRCS += avr_schedulesigaction.c avr_sigdeliver.c +CMN_ASRCS = avr_doswitch.S avr_saveusercontext.S +CMN_CSRCS = avr_allocateheap.c avr_copystate.c avr_createstack.c +CMN_CSRCS += avr_doirq.c avr_exit.c avr_idle.c avr_initialize.c +CMN_CSRCS += avr_initialstate.c avr_irq.c avr_lowputs.c avr_mdelay.c +CMN_CSRCS += avr_modifyreg8.c avr_modifyreg16.c avr_modifyreg32.c +CMN_CSRCS += avr_nputs.c avr_releasestack.c avr_registerdump.c +CMN_CSRCS += avr_schedulesigaction.c avr_sigdeliver.c avr_getintstack.c CMN_CSRCS += avr_stackframe.c avr_udelay.c avr_switchcontext.c avr_usestack.c -CMN_CSRCS += avr_registerdump.c avr_getintstack.c # Configuration-dependent common files diff --git a/arch/avr/src/avr/avr_registerdump.c b/arch/avr/src/avr/avr_registerdump.c index 9410dd99e0..422236ecd1 100644 --- a/arch/avr/src/avr/avr_registerdump.c +++ b/arch/avr/src/avr/avr_registerdump.c @@ -48,11 +48,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: avr_registerdump + * Name: up_dump_register ****************************************************************************/ -void avr_registerdump(volatile uint8_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint8_t *regs = dumpregs ? dumpregs : g_current_regs; + /* Are user registers available from interrupt processing? */ if (regs) @@ -98,4 +100,3 @@ void avr_registerdump(volatile uint8_t *regs) #endif } } - diff --git a/arch/risc-v/src/common/riscv_assert.c b/arch/avr/src/avr/avr_saveusercontext.S similarity index 65% rename from arch/risc-v/src/common/riscv_assert.c rename to arch/avr/src/avr/avr_saveusercontext.S index cd8a1dfac5..8734cf7b26 100644 --- a/arch/risc-v/src/common/riscv_assert.c +++ b/arch/avr/src/avr/avr_saveusercontext.S @@ -1,5 +1,5 @@ -/**************************************************************************** - * arch/risc-v/src/common/riscv_assert.c +/************************************************************************************ + * arch/avr/src/avr/avr_saveusercontext.S * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -16,61 +16,55 @@ * License for the specific language governing permissions and limitations * under the License. * - ****************************************************************************/ + ************************************************************************************/ -/**************************************************************************** +/************************************************************************************ * Included Files - ****************************************************************************/ + ************************************************************************************/ #include -#include -#include -#include +#include -#include -#include +#include "excptmacros.h" -#include +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ -#include "sched/sched.h" -#include "riscv_internal.h" +/************************************************************************************ + * Public Symbols + ************************************************************************************/ -/**************************************************************************** - * Private Functions - ****************************************************************************/ + .file "avr_saveusercontext.S" -/**************************************************************************** - * Private Data - ****************************************************************************/ +/************************************************************************************ + * Macros + ************************************************************************************/ -static uint8_t s_last_regs[XCPTCONTEXT_SIZE]; - -/**************************************************************************** +/************************************************************************************ * Public Functions - ****************************************************************************/ + ************************************************************************************/ /**************************************************************************** - * Name: up_assert + * Name: up_saveusercontext + * + * Description: + * Save the current thread context + * ****************************************************************************/ -void up_assert(void) -{ - struct tcb_s *rtcb = running_task(); + .text + .globl up_saveusercontext + .func up_saveusercontext +up_saveusercontext: + /* Use X [r26:r27] to reference the save structure. (X is Call-used) */ - board_autoled_on(LED_ASSERTION); + movw r26, r24 - /* Update the xcp context */ + /* Save the context to saveregs */ - if (CURRENT_REGS) - { - rtcb->xcp.regs = (uintptr_t *)CURRENT_REGS; - } - else - { - up_saveusercontext(s_last_regs); - rtcb->xcp.regs = (uintptr_t *)s_last_regs; - } + USER_SAVE - riscv_registerdump(rtcb->xcp.regs); -} + .endfunc + .end diff --git a/arch/avr/src/avr32/avr_registerdump.c b/arch/avr/src/avr32/avr_registerdump.c index 9fc5da1a31..ac6c7f675c 100644 --- a/arch/avr/src/avr32/avr_registerdump.c +++ b/arch/avr/src/avr32/avr_registerdump.c @@ -48,11 +48,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: avr_registerdump + * Name: up_dump_register ****************************************************************************/ -void avr_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : g_current_regs; + /* Are user registers available from interrupt processing? */ if (regs) @@ -74,4 +76,3 @@ void avr_registerdump(volatile uint32_t *regs) _alert("SR: %08x\n", regs[REG_SR]); } } - diff --git a/arch/avr/src/avr32/avr_saveusercontext.S b/arch/avr/src/avr32/avr_saveusercontext.S new file mode 100644 index 0000000000..9be38b80e7 --- /dev/null +++ b/arch/avr/src/avr32/avr_saveusercontext.S @@ -0,0 +1,86 @@ +/************************************************************************************ + * arch/avr/src/avr32/avr_saveusercontext.S + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include +#include +#include + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +/************************************************************************************ + * Public Symbols + ************************************************************************************/ + + .file "avr_saveusercontext.S" + +/************************************************************************************ + * Macros + ************************************************************************************/ + +/************************************************************************************ + * Public Functions + ************************************************************************************/ + +/**************************************************************************** + * Name: up_saveusercontext + * + * Description: + * Save the current thread context + * + ****************************************************************************/ + + .text + .globl up_saveusercontext + .type up_saveusercontext, @function +up_saveusercontext: + /* "Pickle" the current thread context in the saveregs "can." r12=saveregs. */ + /* xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx */ + /* ^r12 */ + /* Sample SR and set r12 to just after the LR storage location. */ + /* xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx */ + /* ^r12 */ + + mfsr r10, AVR32_SR + sub r12, -4*(REG_LR+1) + + /* Then "push" PC=LR, LR, SR, and SP as they are on entry. */ + /* xx xx xx xx xx xx xx xx SP SR PC LR xx xx xx xx xx */ + /* ^r12 */ + + st.w --r12, lr + st.w --r12, lr + st.w --r12, r10 + st.w --r12, sp + + /* Save the preserved/static registers, r0-r7. There is no reason to save the */ + /* scratch/volatile registers, r8-r12, in this context. */ + /* 07 06 05 04 03 02 01 00 SP SR PC LR xx xx xx xx xx */ + /* ^r12 */ + + stm --r12, r0-r7 + + .size up_saveusercontext, .-up_saveusercontext + .end diff --git a/arch/avr/src/common/avr_internal.h b/arch/avr/src/common/avr_internal.h index 2a0ad93058..e7d208233e 100644 --- a/arch/avr/src/common/avr_internal.h +++ b/arch/avr/src/common/avr_internal.h @@ -119,11 +119,6 @@ void weak_function avr_dma_initialize(void); void avr_sigdeliver(void); void avr_lowputc(char ch); void avr_lowputs(const char *str); -#ifdef CONFIG_ARCH_FAMILY_AVR32 -void avr_registerdump(volatile uint32_t *regs); -#else -void avr_registerdump(volatile uint8_t *regs); -#endif /* Defined in common/avr_allocateheap.c or chip/xxx_allocateheap.c */ diff --git a/arch/ceva/src/common/ceva_assert.c b/arch/ceva/src/common/ceva_assert.c deleted file mode 100644 index 92d523ab08..0000000000 --- a/arch/ceva/src/common/ceva_assert.c +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** - * arch/ceva/src/common/ceva_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include - -#include "sched/sched.h" -#include "ceva_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint32_t s_last_regs[XCPTCONTEXT_REGS]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - volatile uint32_t *regs = CURRENT_REGS; - - /* Are user registers available from interrupt processing? */ - - if (regs == NULL) - { - /* No.. capture user registers by hand */ - - up_saveusercontext(s_last_regs); - regs = s_last_regs; - } - - ceva_registerdump(regs); -} diff --git a/arch/ceva/src/common/ceva_internal.h b/arch/ceva/src/common/ceva_internal.h index f7fefc0885..8a2de7647e 100644 --- a/arch/ceva/src/common/ceva_internal.h +++ b/arch/ceva/src/common/ceva_internal.h @@ -305,8 +305,6 @@ size_t ceva_stack_check(uintptr_t alloc, size_t size); void ceva_stack_color(void *stackbase, size_t nbytes); #endif -void ceva_registerdump(volatile uint32_t *regs); - #undef EXTERN #ifdef __cplusplus } diff --git a/arch/ceva/src/common/ceva_registerdump.c b/arch/ceva/src/common/ceva_registerdump.c index a301f7a32c..2d944b11a3 100644 --- a/arch/ceva/src/common/ceva_registerdump.c +++ b/arch/ceva/src/common/ceva_registerdump.c @@ -45,11 +45,12 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: ceva_registerdump + * Name: up_dump_register ****************************************************************************/ -void ceva_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : CURRENT_REGS; int rx; /* Dump the interrupt registers */ diff --git a/arch/hc/src/common/hc_internal.h b/arch/hc/src/common/hc_internal.h index 62fee6d98e..a493daccda 100644 --- a/arch/hc/src/common/hc_internal.h +++ b/arch/hc/src/common/hc_internal.h @@ -195,8 +195,6 @@ void hc_usbuninitialize(void); # define hc_usbuninitialize() #endif -void hc_registerdump(volatile uint8_t *regs); - #endif /* __ASSEMBLY__ */ #endif /* __ARCH_HC_SRC_COMMON_UP_INTERNAL_H */ diff --git a/arch/hc/src/m9s12/Make.defs b/arch/hc/src/m9s12/Make.defs index 3d22989579..be6f1e1919 100644 --- a/arch/hc/src/m9s12/Make.defs +++ b/arch/hc/src/m9s12/Make.defs @@ -20,14 +20,14 @@ HEAD_ASRC = m9s12_vectors.S -CMN_CSRCS = hc_allocateheap.c hc_copystate.c hc_createstack.c -CMN_CSRCS += hc_doirq.c hc_exit.c hc_idle.c hc_initialize.c +CMN_CSRCS = hc_allocateheap.c hc_copystate.c hc_createstack.c hc_doirq.c +CMN_CSRCS += hc_exit.c hc_getintstack.c hc_idle.c hc_initialize.c CMN_CSRCS += hc_mdelay.c hc_modifyreg16.c hc_modifyreg32.c hc_modifyreg8.c -CMN_CSRCS += hc_nputs.c hc_releasestack.c hc_getintstack.c -CMN_CSRCS += hc_stackframe.c hc_udelay.c hc_switchcontext.c hc_usestack.c +CMN_CSRCS += hc_nputs.c hc_releasestack.c hc_stackframe.c hc_switchcontext.c +CMN_CSRCS += hc_udelay.c hc_usestack.c CHIP_ASRCS = m9s12_start.S m9s12_lowputc.S m9s12_saveusercontext.S -CHIP_CSRCS = m9s12_assert.c m9s12_gpio.c m9s12_gpioirq.c m9s12_initialstate.c +CHIP_CSRCS = m9s12_gpio.c m9s12_gpioirq.c m9s12_initialstate.c CHIP_CSRCS += m9s12_irq.c m9s12_serial.c m9s12_registerdump.c ifneq ($(CONFIG_SCHED_TICKLESS),y) diff --git a/arch/hc/src/m9s12/m9s12_assert.c b/arch/hc/src/m9s12/m9s12_assert.c deleted file mode 100644 index e7cf5b9e53..0000000000 --- a/arch/hc/src/m9s12/m9s12_assert.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * arch/hc/src/m9s12/m9s12_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include -#include - -#include - -#include "sched/sched.h" -#include "hc_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint8_t s_last_regs[XCPTCONTEXT_REGS]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - volatile uint8_t *regs = g_current_regs; - - board_autoled_on(LED_ASSERTION); - - /* Are user registers available from interrupt processing? */ - - if (regs == NULL) - { - /* No.. capture user registers by hand */ - - up_saveusercontext(s_last_regs); - regs = s_last_regs; - } - - hc_registerdump(regs); -} diff --git a/arch/hc/src/m9s12/m9s12_registerdump.c b/arch/hc/src/m9s12/m9s12_registerdump.c index 332e9fcd15..9b9b47dcfa 100644 --- a/arch/hc/src/m9s12/m9s12_registerdump.c +++ b/arch/hc/src/m9s12/m9s12_registerdump.c @@ -47,11 +47,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: hc_registerdump + * Name: up_dump_register ****************************************************************************/ -void hc_registerdump(volatile uint8_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint8_t *regs = dumpregs ? dumpregs : (uint8_t *)g_current_regs; + _alert("A:%02x B:%02x X:%02x%02x Y:%02x%02x PC:%02x%02x CCR:%02x\n", regs[REG_A], regs[REG_B], regs[REG_XH], regs[REG_XL], regs[REG_YH], regs[REG_YL], regs[REG_PCH], regs[REG_PCL], diff --git a/arch/mips/include/syscall.h b/arch/mips/include/syscall.h index d459dcf281..9d2d80f6b7 100644 --- a/arch/mips/include/syscall.h +++ b/arch/mips/include/syscall.h @@ -136,7 +136,12 @@ /* Context switching system calls *******************************************/ -/* SYS call 0: (not used) */ +/* SYS call 0: + * + * int up_saveusercontext(void *saveregs); + */ + +#define SYS_save_context (0) /* SYS call 1: * diff --git a/arch/mips/src/common/mips_internal.h b/arch/mips/src/common/mips_internal.h index badf12cad3..16bbc1c3de 100644 --- a/arch/mips/src/common/mips_internal.h +++ b/arch/mips/src/common/mips_internal.h @@ -176,10 +176,6 @@ void mips_copystate(uint32_t *dest, uint32_t *src); void mips_lowputs(const char *str); -/* Debug */ - -void mips_registerdump(volatile uint32_t *regs); - /* Common MIPS32 functions defined in arch/mips/src/MIPS32 */ /* IRQs */ diff --git a/arch/mips/src/mips32/mips_registerdump.c b/arch/mips/src/mips32/mips_registerdump.c index 9ce3fa7ee1..f94f537216 100644 --- a/arch/mips/src/mips32/mips_registerdump.c +++ b/arch/mips/src/mips32/mips_registerdump.c @@ -48,11 +48,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: mips_registerdump + * Name: up_dump_register ****************************************************************************/ -void mips_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : CURRENT_REGS; + /* Are user registers available from interrupt processing? */ if (regs) diff --git a/arch/avr/src/common/avr_assert.c b/arch/mips/src/mips32/mips_saveusercontext.c similarity index 78% rename from arch/avr/src/common/avr_assert.c rename to arch/mips/src/mips32/mips_saveusercontext.c index a10f0f61ee..19b9b30900 100644 --- a/arch/avr/src/common/avr_assert.c +++ b/arch/mips/src/mips32/mips_saveusercontext.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/avr/src/common/avr_assert.c + * arch/mips/src/mips32/mips_saveusercontext.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,22 +23,28 @@ ****************************************************************************/ #include -#include -#include - -#include "avr_internal.h" +#include /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: up_assert + * Name: up_saveusercontext + * + * Description: + * Save the current thread context. Full prototype is: + * + * int up_saveusercontext(void *saveregs); + * + * Returned Value: + * 0: Normal return + * 1: Context switch return + * ****************************************************************************/ -void up_assert(void) +int up_saveusercontext(void *saveregs) { - board_autoled_on(LED_ASSERTION); - avr_registerdump(g_current_regs); + return sys_call1(SYS_save_context, (uintptr_t)saveregs); } diff --git a/arch/mips/src/mips32/mips_swint0.c b/arch/mips/src/mips32/mips_swint0.c index 6d15e61000..b7aa091d0e 100644 --- a/arch/mips/src/mips32/mips_swint0.c +++ b/arch/mips/src/mips32/mips_swint0.c @@ -109,13 +109,33 @@ int mips_swint0(int irq, void *context, void *arg) #ifdef CONFIG_DEBUG_SYSCALL_INFO svcinfo("Entry: regs: %p cmd: %d\n", regs, regs[REG_R4]); - mips_registerdump(regs); + up_dump_register(regs); #endif /* Handle the SWInt according to the command in $4 */ switch (regs[REG_R4]) { + /* R4=SYS_save_context: This is a save context command: + * + * int up_saveusercontext(void *saveregs); + * + * At this point, the following values are saved in context: + * + * R4 = SYS_save_context + * R5 = saveregs + * + * In this case, we simply need to copy the current registers to the + * save register space references in the saved R1 and return. + */ + + case SYS_save_context: + { + DEBUGASSERT(regs[REG_A1] != 0); + mips_copystate((uint32_t *)regs[REG_A1], regs); + } + break; + /* R4=SYS_restore_context: This a restore context command: * * void up_fullcontextrestore(uint32_t *restoreregs) noreturn_function; @@ -256,7 +276,7 @@ int mips_swint0(int irq, void *context, void *arg) if (regs != CURRENT_REGS) { svcinfo("SWInt Return: Context switch!\n"); - mips_registerdump(CURRENT_REGS); + up_dump_register(CURRENT_REGS); } else { diff --git a/arch/mips/src/pic32mx/Make.defs b/arch/mips/src/pic32mx/Make.defs index fc6d74044d..c5293a0439 100644 --- a/arch/mips/src/pic32mx/Make.defs +++ b/arch/mips/src/pic32mx/Make.defs @@ -25,15 +25,14 @@ HEAD_ASRC = pic32mx_head.S # Common MIPS files CMN_ASRCS = mips_syscall0.S vfork.S -CMN_CSRCS = mips_allocateheap.c mips_assert.c mips_copystate.c -CMN_CSRCS += mips_createstack.c mips_doirq.c mips_exit.c mips_initialize.c -CMN_CSRCS += mips_initialstate.c mips_irq.c mips_lowputs.c -CMN_CSRCS += mips_mdelay.c mips_modifyreg8.c mips_modifyreg16.c mips_modifyreg32.c -CMN_CSRCS += mips_nputs.c mips_releasestack.c -CMN_CSRCS += mips_schedulesigaction.c mips_sigdeliver.c -CMN_CSRCS += mips_stackframe.c mips_swint0.c mips_udelay.c mips_switchcontext.c -CMN_CSRCS += mips_usestack.c mips_vfork.c -CMN_CSRCS += mips_registerdump.c mips_getintstack.c +CMN_CSRCS = mips_allocateheap.c mips_copystate.c mips_createstack.c +CMN_CSRCS += mips_doirq.c mips_exit.c mips_getintstack.c mips_initialize.c +CMN_CSRCS += mips_initialstate.c mips_irq.c mips_lowputs.c mips_mdelay.c +CMN_CSRCS += mips_modifyreg8.c mips_modifyreg16.c mips_modifyreg32.c +CMN_CSRCS += mips_nputs.c mips_releasestack.c mips_registerdump.c +CMN_CSRCS += mips_schedulesigaction.c mips_sigdeliver.c mips_swint0.c +CMN_CSRCS += mips_stackframe.c mips_switchcontext.c mips_saveusercontext.c +CMN_CSRCS += mips_udelay.c mips_usestack.c mips_vfork.c # Configuration dependent common files diff --git a/arch/mips/src/pic32mz/Make.defs b/arch/mips/src/pic32mz/Make.defs index 348a3b942a..08f7099a63 100644 --- a/arch/mips/src/pic32mz/Make.defs +++ b/arch/mips/src/pic32mz/Make.defs @@ -25,15 +25,14 @@ HEAD_ASRC = pic32mz_head.S # Common MIPS files CMN_ASRCS = mips_syscall0.S vfork.S mips_cache.S -CMN_CSRCS = mips_allocateheap.c mips_assert.c mips_copystate.c -CMN_CSRCS += mips_createstack.c mips_doirq.c mips_exit.c mips_initialize.c -CMN_CSRCS += mips_initialstate.c mips_irq.c mips_lowputs.c -CMN_CSRCS += mips_mdelay.c mips_modifyreg8.c mips_modifyreg16.c mips_modifyreg32.c -CMN_CSRCS += mips_nputs.c mips_releasestack.c -CMN_CSRCS += mips_schedulesigaction.c mips_sigdeliver.c -CMN_CSRCS += mips_stackframe.c mips_swint0.c mips_udelay.c mips_switchcontext.c -CMN_CSRCS += mips_usestack.c mips_vfork.c -CMN_CSRCS += mips_registerdump.c mips_getintstack.c +CMN_CSRCS = mips_allocateheap.c mips_copystate.c mips_createstack.c +CMN_CSRCS += mips_doirq.c mips_exit.c mips_getintstack.c mips_initialize.c +CMN_CSRCS += mips_initialstate.c mips_irq.c mips_lowputs.c mips_mdelay.c +CMN_CSRCS += mips_modifyreg8.c mips_modifyreg16.c mips_modifyreg32.c +CMN_CSRCS += mips_nputs.c mips_releasestack.c mips_registerdump.c +CMN_CSRCS += mips_schedulesigaction.c mips_sigdeliver.c mips_swint0.c +CMN_CSRCS += mips_stackframe.c mips_switchcontext.c mips_saveusercontext.c +CMN_CSRCS += mips_udelay.c mips_usestack.c mips_vfork.c # Configuration dependent common files diff --git a/arch/misoc/include/syscall.h b/arch/misoc/include/syscall.h index b3f7e40171..06f978aeb1 100644 --- a/arch/misoc/include/syscall.h +++ b/arch/misoc/include/syscall.h @@ -61,7 +61,12 @@ /* Context switching system calls *******************************************/ -/* SYS call 0: (not used) */ +/* SYS call 0: + * + * int up_saveusercontext(void *saveregs); + */ + +#define SYS_save_context (0) /* SYS call 1: * diff --git a/arch/misoc/src/lm32/Make.defs b/arch/misoc/src/lm32/Make.defs index 234549f451..8c1f112177 100644 --- a/arch/misoc/src/lm32/Make.defs +++ b/arch/misoc/src/lm32/Make.defs @@ -27,11 +27,9 @@ CMN_CSRCS += misoc_timerisr.c misoc_net.c misoc_flushcache.c CHIP_ASRCS = lm32_syscall.S -CHIP_CSRCS = lm32_allocateheap.c lm32_assert.c -CHIP_CSRCS += lm32_copystate.c lm32_createstack.c lm32_decodeirq.c -CHIP_CSRCS += lm32_doirq.c lm32_registerdump.c lm32_exit.c lm32_idle.c -CHIP_CSRCS += lm32_initialstate.c lm32_irq.c -CHIP_CSRCS += lm32_releasestack.c lm32_stackframe.c lm32_swint.c -CHIP_CSRCS += lm32_switchcontext.c -CHIP_CSRCS += lm32_schedulesigaction.c lm32_sigdeliver.c -CHIP_CSRCS += lm32_flushcache.c lm32_usetack.c +CHIP_CSRCS = lm32_allocateheap.c lm32_copystate.c lm32_createstack.c +CHIP_CSRCS += lm32_decodeirq.c lm32_doirq.c lm32_exit.c lm32_flushcache.c +CHIP_CSRCS += lm32_idle.c lm32_initialstate.c lm32_irq.c lm32_usetack.c +CHIP_CSRCS += lm32_registerdump.c lm32_releasestack.c lm32_swint.c +CHIP_CSRCS += lm32_stackframe.c lm32_switchcontext.c lm32_sigdeliver.c +CHIP_CSRCS += lm32_schedulesigaction.c lm32_saveusercontext.c diff --git a/arch/misoc/src/lm32/lm32.h b/arch/misoc/src/lm32/lm32.h index 395799c2d3..68939d9708 100644 --- a/arch/misoc/src/lm32/lm32.h +++ b/arch/misoc/src/lm32/lm32.h @@ -126,9 +126,5 @@ void lm32_sigdeliver(void); void lm32_flush_dcache(void); void lm32_flush_icache(void); -/* Debug ********************************************************************/ - -void lm32_registerdump(volatile uint32_t *regs); - #endif /* __ASSEMBLY__ */ #endif /* __ARCH_MISOC_SRC_LM32_LM32_H */ diff --git a/arch/misoc/src/lm32/lm32_registerdump.c b/arch/misoc/src/lm32/lm32_registerdump.c index 7e5e34b708..fdd3f85687 100644 --- a/arch/misoc/src/lm32/lm32_registerdump.c +++ b/arch/misoc/src/lm32/lm32_registerdump.c @@ -47,11 +47,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: lm32_registerdump + * Name: up_dump_register ****************************************************************************/ -void lm32_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : g_current_regs; + /* Are user registers available from interrupt processing? */ if (regs) @@ -85,4 +87,3 @@ void lm32_registerdump(volatile uint32_t *regs) _alert(" IE:%08x\n", regs[REG_X32_NDX]); } } - diff --git a/arch/misoc/src/lm32/lm32_assert.c b/arch/misoc/src/lm32/lm32_saveusercontext.c similarity index 78% rename from arch/misoc/src/lm32/lm32_assert.c rename to arch/misoc/src/lm32/lm32_saveusercontext.c index 7b934061c8..110e770543 100644 --- a/arch/misoc/src/lm32/lm32_assert.c +++ b/arch/misoc/src/lm32/lm32_saveusercontext.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/misoc/src/lm32/lm32_assert.c + * arch/misoc/src/lm32/lm32_saveusercontext.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,22 +24,27 @@ #include -#include - -#include - -#include "lm32.h" +#include /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: up_assert + * Name: up_saveusercontext + * + * Description: + * Save the current thread context. Full prototype is: + * + * int up_saveusercontext(void *saveregs); + * + * Returned Value: + * 0: Normal return + * 1: Context switch return + * ****************************************************************************/ -void up_assert(void) +int up_saveusercontext(void *saveregs) { - board_autoled_on(LED_ASSERTION); - lm32_registerdump(g_current_regs); + return sys_call1(SYS_save_context, (uintptr_t)saveregs); } diff --git a/arch/misoc/src/lm32/lm32_swint.c b/arch/misoc/src/lm32/lm32_swint.c index 353caa23f3..a42ab9ffdf 100644 --- a/arch/misoc/src/lm32/lm32_swint.c +++ b/arch/misoc/src/lm32/lm32_swint.c @@ -106,13 +106,33 @@ int lm32_swint(int irq, void *context, void *arg) #ifdef CONFIG_DEBUG_SYSCALL_INFO svcinfo("Entry: regs: %p cmd: %d\n", regs, regs[REG_A0]); - lm32_registerdump(regs); + up_dump_register(regs); #endif /* Handle the SWInt according to the command in $a0 */ switch (regs[REG_A0]) { + /* A0=SYS_save_context: This is a save context command: + * + * int up_saveusercontext(void *saveregs); + * + * At this point, the following values are saved in context: + * + * A0 = SYS_save_context + * A1 = saveregs + * + * In this case, we simply need to copy the current registers to the + * save register space references in the saved R1 and return. + */ + + case SYS_save_context: + { + DEBUGASSERT(regs[REG_A1] != 0); + lm32_copystate((uint32_t *)regs[REG_A1], regs); + } + break; + /* A0=SYS_restore_context: This a restore context command: * * void up_fullcontextrestore(uint32_t *restoreregs) @@ -254,7 +274,7 @@ int lm32_swint(int irq, void *context, void *arg) if (regs != g_current_regs) { svcinfo("SWInt Return: Context switch!\n"); - lm32_registerdump(g_current_regs); + up_dump_register(g_current_regs); } else { diff --git a/arch/misoc/src/minerva/Make.defs b/arch/misoc/src/minerva/Make.defs index 9a409ee6b1..3aa34aea07 100644 --- a/arch/misoc/src/minerva/Make.defs +++ b/arch/misoc/src/minerva/Make.defs @@ -27,11 +27,10 @@ CMN_CSRCS += misoc_timerisr.c misoc_net.c misoc_flushcache.c CHIP_ASRCS = minerva_syscall.S -CHIP_CSRCS = minerva_allocateheap.c minerva_assert.c -CHIP_CSRCS += minerva_copystate.c minerva_createstack.c minerva_decodeirq.c -CHIP_CSRCS += minerva_doirq.c minerva_registerdump.c minerva_exit.c minerva_idle.c -CHIP_CSRCS += minerva_initialstate.c minerva_irq.c -CHIP_CSRCS += minerva_releasestack.c minerva_stackframe.c minerva_swint.c -CHIP_CSRCS += minerva_switchcontext.c -CHIP_CSRCS += minerva_schedulesigaction.c minerva_sigdeliver.c -CHIP_CSRCS += minerva_flushcache.c minerva_doexceptions.c minerva_usetack.c +CHIP_CSRCS = minerva_allocateheap.c minerva_copystate.c minerva_createstack.c +CHIP_CSRCS += minerva_decodeirq.c minerva_doirq.c minerva_doexceptions.c +CHIP_CSRCS += minerva_exit.c minerva_flushcache.c minerva_idle.c minerva_irq.c +CHIP_CSRCS += minerva_initialstate.c minerva_registerdump.c minerva_releasestack.c +CHIP_CSRCS += minerva_stackframe.c minerva_swint.c minerva_saveusercontext.c +CHIP_CSRCS += minerva_switchcontext.c minerva_schedulesigaction.c minerva_sigdeliver.c +CHIP_CSRCS += minerva_usetack.c diff --git a/arch/misoc/src/minerva/minerva.h b/arch/misoc/src/minerva/minerva.h index 20b8124c4e..21995d4f70 100644 --- a/arch/misoc/src/minerva/minerva.h +++ b/arch/misoc/src/minerva/minerva.h @@ -125,9 +125,5 @@ void minerva_sigdeliver(void); void minerva_flush_dcache(void); void minerva_flush_icache(void); -/* Debug ********************************************************************/ - -void mineva_registerdump(volatile uint32_t *regs); - #endif /* __ASSEMBLY__ */ #endif /* __ARCH_MISOC_SRC_MINERVA_MINERVA_H */ diff --git a/arch/misoc/src/minerva/minerva_registerdump.c b/arch/misoc/src/minerva/minerva_registerdump.c index 98a95998da..453c25a2d5 100644 --- a/arch/misoc/src/minerva/minerva_registerdump.c +++ b/arch/misoc/src/minerva/minerva_registerdump.c @@ -47,11 +47,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: mineva_registerdump + * Name: up_dump_register ****************************************************************************/ -void mineva_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : g_current_regs; + /* Are user registers available from interrupt processing? */ if (regs) @@ -84,4 +86,3 @@ void mineva_registerdump(volatile uint32_t *regs) _alert(" IE:%08x\n", regs[REG_CSR_MSTATUS]); } } - diff --git a/arch/misoc/src/minerva/minerva_assert.c b/arch/misoc/src/minerva/minerva_saveusercontext.c similarity index 78% rename from arch/misoc/src/minerva/minerva_assert.c rename to arch/misoc/src/minerva/minerva_saveusercontext.c index 86ade9ba5f..a35b998bcc 100644 --- a/arch/misoc/src/minerva/minerva_assert.c +++ b/arch/misoc/src/minerva/minerva_saveusercontext.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/misoc/src/minerva/minerva_assert.c + * arch/misoc/src/minerva/minerva_saveusercontext.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,22 +24,27 @@ #include -#include - -#include - -#include "minerva.h" +#include /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: up_assert + * Name: up_saveusercontext + * + * Description: + * Save the current thread context. Full prototype is: + * + * int up_saveusercontext(void *saveregs); + * + * Returned Value: + * 0: Normal return + * 1: Context switch return + * ****************************************************************************/ -void up_assert(void) +int up_saveusercontext(void *saveregs) { - board_autoled_on(LED_ASSERTION); - mineva_registerdump(g_current_regs); + return sys_call1(SYS_save_context, (uintptr_t)saveregs); } diff --git a/arch/misoc/src/minerva/minerva_swint.c b/arch/misoc/src/minerva/minerva_swint.c index d46f2dca0b..ac54d992d0 100644 --- a/arch/misoc/src/minerva/minerva_swint.c +++ b/arch/misoc/src/minerva/minerva_swint.c @@ -109,6 +109,21 @@ int minerva_swint(int irq, void *context, void *arg) switch (regs[REG_A0]) { + /* A0=SYS_save_context: This a save context command: void + * int up_saveusercontext(void *saveregs); + * At this point, the following values are saved in context: A0 = + * SYS_save_context A1 = saveregs A2 = saveregs. In this case, we + * save the context registers to the save register area referenced by + * the saved contents of R5. + */ + + case SYS_save_context: + { + DEBUGASSERT(regs[REG_A1] != 0); + minerva_copystate((uint32_t *) regs[REG_A1], regs); + } + break; + /* A0=SYS_restore_context: This a restore context command: void * up_fullcontextrestore(uint32_t *restoreregs) noreturn_function; At * this point, the following values are saved in context: A0 = diff --git a/arch/or1k/src/common/or1k_assert.c b/arch/or1k/src/common/or1k_assert.c deleted file mode 100644 index 88824d1c05..0000000000 --- a/arch/or1k/src/common/or1k_assert.c +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * arch/or1k/src/common/or1k_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include -#include - -#include - -#include "sched/sched.h" -#include "or1k_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint32_t s_last_regs[XCPTCONTEXT_REGS]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - volatile uint32_t *regs = CURRENT_REGS; - - board_autoled_on(LED_ASSERTION); - - /* Are user registers available from interrupt processing? */ - - if (regs == NULL) - { - /* No.. capture user registers by hand */ - - up_saveusercontext(s_last_regs); - regs = s_last_regs; - } - - or1k_registerdump(regs); -} diff --git a/arch/or1k/src/common/or1k_internal.h b/arch/or1k/src/common/or1k_internal.h index 925ca1d57b..6ea0c9fb2e 100644 --- a/arch/or1k/src/common/or1k_internal.h +++ b/arch/or1k/src/common/or1k_internal.h @@ -323,8 +323,6 @@ size_t or1k_stack_check(uintptr_t alloc, size_t size); void or1k_stack_color(void *stackbase, size_t nbytes); #endif -void or1k_registerdump(volatile uint32_t *regs); - #undef EXTERN #ifdef __cplusplus } diff --git a/arch/or1k/src/common/or1k_registerdump.c b/arch/or1k/src/common/or1k_registerdump.c index 14a6263966..aeca101da0 100644 --- a/arch/or1k/src/common/or1k_registerdump.c +++ b/arch/or1k/src/common/or1k_registerdump.c @@ -46,11 +46,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: or1k_registerdump + * Name: up_dump_register ****************************************************************************/ -void or1k_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : CURRENT_REGS; + /* Dump the interrupt registers */ _alert("R0: %08x %08x %08x %08x %08x %08x %08x %08x\n", diff --git a/arch/or1k/src/mor1kx/Make.defs b/arch/or1k/src/mor1kx/Make.defs index 0e217ccbeb..5f87c7dfd6 100644 --- a/arch/or1k/src/mor1kx/Make.defs +++ b/arch/or1k/src/mor1kx/Make.defs @@ -34,7 +34,6 @@ CMN_CSRCS = or1k_initialize.c \ or1k_copyfullstate.c \ or1k_registerdump.c \ or1k_getintstack.c \ - or1k_assert.c \ or1k_exit.c \ or1k_udelay.c \ or1k_mdelay.c \ diff --git a/arch/renesas/src/common/renesas_assert.c b/arch/renesas/src/common/renesas_assert.c deleted file mode 100644 index 28b8b66db9..0000000000 --- a/arch/renesas/src/common/renesas_assert.c +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * arch/renesas/src/common/renesas_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include - -#include "renesas_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint32_t s_last_regs[XCPTCONTEXT_REGS]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - volatile uint32_t *regs = g_current_regs; - - board_autoled_on(LED_ASSERTION); - - /* Are user registers available from interrupt processing? */ - - if (regs == NULL) - { - /* No.. capture user registers by hand */ - - up_saveusercontext(s_last_regs); - regs = s_last_regs; - } - - renesas_registerdump(regs); -} diff --git a/arch/renesas/src/common/renesas_internal.h b/arch/renesas/src/common/renesas_internal.h index 472edc4639..ca8e9f021d 100644 --- a/arch/renesas/src/common/renesas_internal.h +++ b/arch/renesas/src/common/renesas_internal.h @@ -200,9 +200,5 @@ void renesas_usbuninitialize(void); # define renesas_usbuninitialize() #endif -/* Defined in chip-specific logic */ - -void renesas_registerdump(volatile uint32_t *regs); - #endif /* __ASSEMBLY__ */ #endif /* ___ARCH_RENESAS_SRC_COMMON_UP_INTERNAL_H */ diff --git a/arch/renesas/src/m16c/Make.defs b/arch/renesas/src/m16c/Make.defs index 264d2d1087..94b0992140 100644 --- a/arch/renesas/src/m16c/Make.defs +++ b/arch/renesas/src/m16c/Make.defs @@ -20,11 +20,11 @@ HEAD_ASRC = m16c_head.S -CMN_CSRCS = renesas_allocateheap.c renesas_assert.c -CMN_CSRCS += renesas_createstack.c renesas_doirq.c renesas_exit.c renesas_idle.c renesas_initialize.c -CMN_CSRCS += renesas_lowputs.c renesas_mdelay.c renesas_nputs.c -CMN_CSRCS += renesas_releasestack.c renesas_getintstack.c -CMN_CSRCS += renesas_stackframe.c renesas_udelay.c renesas_switchcontext.c renesas_usestack.c +CMN_CSRCS = renesas_allocateheap.c renesas_createstack.c renesas_doirq.c +CMN_CSRCS += renesas_exit.c renesas_getintstack.c renesas_idle.c +CMN_CSRCS += renesas_initialize.c renesas_lowputs.c renesas_mdelay.c +CMN_CSRCS += renesas_nputs.c renesas_releasestack.c renesas_stackframe.c +CMN_CSRCS += renesas_switchcontext.c renesas_udelay.c renesas_usestack.c CHIP_ASRCS = m16c_vectors.S CHIP_CSRCS = m16c_initialstate.c m16c_copystate.c m16c_lowputc.c m16c_irq.c diff --git a/arch/renesas/src/m16c/m16c_registerdump.c b/arch/renesas/src/m16c/m16c_registerdump.c index 5566fc2e53..d36f002453 100644 --- a/arch/renesas/src/m16c/m16c_registerdump.c +++ b/arch/renesas/src/m16c/m16c_registerdump.c @@ -48,12 +48,12 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: renesas_registerdump + * Name: up_dump_register ****************************************************************************/ -void renesas_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { - uint8_t *ptr = (uint8_t *)regs; + volatile uint8_t *ptr = dumpregs ? dumpregs : (uint8_t *)g_current_regs; /* Dump the interrupt registers */ diff --git a/arch/renesas/src/rx65n/Make.defs b/arch/renesas/src/rx65n/Make.defs index 6ffd59f111..e73e5451d9 100644 --- a/arch/renesas/src/rx65n/Make.defs +++ b/arch/renesas/src/rx65n/Make.defs @@ -20,11 +20,11 @@ HEAD_ASRC = rx65n_head.S -CMN_CSRCS = renesas_allocateheap.c renesas_assert.c -CMN_CSRCS += renesas_createstack.c renesas_doirq.c renesas_exit.c renesas_idle.c renesas_initialize.c -CMN_CSRCS += renesas_lowputs.c renesas_mdelay.c renesas_nputs.c -CMN_CSRCS += renesas_releasestack.c renesas_getintstack.c -CMN_CSRCS += renesas_stackframe.c renesas_udelay.c renesas_switchcontext.c renesas_usestack.c +CMN_CSRCS = renesas_allocateheap.c renesas_createstack.c renesas_doirq.c +CMN_CSRCS += renesas_exit.c renesas_getintstack.c renesas_initialize.c +CMN_CSRCS += renesas_idle.c renesas_lowputs.c renesas_mdelay.c renesas_nputs.c +CMN_CSRCS += renesas_releasestack.c renesas_switchcontext.c renesas_stackframe.c +CMN_CSRCS += renesas_udelay.c renesas_usestack.c CHIP_ASRCS = rx65n_vector.S CHIP_CSRCS = rx65n_lowputc.c rx65n_serial.c rx65n_copystate.c rx65n_irq.c diff --git a/arch/renesas/src/rx65n/rx65n_registerdump.c b/arch/renesas/src/rx65n/rx65n_registerdump.c index a816bd6ebf..288fba6392 100644 --- a/arch/renesas/src/rx65n/rx65n_registerdump.c +++ b/arch/renesas/src/rx65n/rx65n_registerdump.c @@ -49,11 +49,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: rx65n_registerdump + * Name: up_dump_register ****************************************************************************/ -void renesas_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : g_current_regs; + /* Dump the interrupt registers */ _alert("PC: %08" PRIx32 " PSW=%08" PRIx32 "\n", diff --git a/arch/renesas/src/sh1/Make.defs b/arch/renesas/src/sh1/Make.defs index 7cc7a92919..f346e87a8b 100644 --- a/arch/renesas/src/sh1/Make.defs +++ b/arch/renesas/src/sh1/Make.defs @@ -20,13 +20,12 @@ HEAD_ASRC = sh1_head.S -CMN_CSRCS = renesas_allocateheap.c renesas_assert.c -CMN_CSRCS += renesas_createstack.c renesas_doirq.c renesas_exit.c renesas_idle.c renesas_initialize.c -CMN_CSRCS += renesas_initialstate.c renesas_lowputs.c +CMN_CSRCS = renesas_allocateheap.c renesas_createstack.c renesas_doirq.c +CMN_CSRCS += renesas_exit.c renesas_getintstack.c renesas_initialize.c +CMN_CSRCS += renesas_idle.c renesas_initialstate.c renesas_lowputs.c CMN_CSRCS += renesas_mdelay.c renesas_nputs.c renesas_releasestack.c -CMN_CSRCS += renesas_stackframe.c renesas_udelay.c renesas_getintstack.c -CMN_CSRCS += sh1_schedulesigaction.c sh1_sigdeliver.c -CMN_CSRCS += renesas_switchcontext.c renesas_usestack.c +CMN_CSRCS += renesas_stackframe.c renesas_switchcontext.c renesas_udelay.c +CMN_CSRCS += renesas_usestack.c sh1_schedulesigaction.c sh1_sigdeliver.c CHIP_ASRCS = sh1_vector.S sh1_saveusercontext.S CHIP_CSRCS = sh1_lowputc.c sh1_irq.c sh1_serial.c sh1_initialstate.c diff --git a/arch/renesas/src/sh1/sh1_registerdump.c b/arch/renesas/src/sh1/sh1_registerdump.c index 888d6a75c5..0d436890de 100644 --- a/arch/renesas/src/sh1/sh1_registerdump.c +++ b/arch/renesas/src/sh1/sh1_registerdump.c @@ -46,11 +46,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: renesas_registerdump + * Name: up_dump_register ****************************************************************************/ -void renesas_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : g_current_regs; + /* Dump the interrupt registers */ _alert("PC: %08x SR=%08x\n", @@ -67,4 +69,3 @@ void renesas_registerdump(volatile uint32_t *regs) regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11], regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]); } - diff --git a/arch/risc-v/src/common/Make.defs b/arch/risc-v/src/common/Make.defs index 19517ec0e6..fde6828710 100644 --- a/arch/risc-v/src/common/Make.defs +++ b/arch/risc-v/src/common/Make.defs @@ -27,14 +27,13 @@ CMN_ASRCS += riscv_vectors.S riscv_exception_common.S riscv_mhartid.S # Specify C code within the common directory to be included CMN_CSRCS += riscv_initialize.c riscv_swint.c riscv_mtimer.c -CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c riscv_exit.c -CMN_CSRCS += riscv_assert.c riscv_copystate.c riscv_initialstate.c -CMN_CSRCS += riscv_modifyreg32.c riscv_nputs.c -CMN_CSRCS += riscv_releasestack.c riscv_stackframe.c riscv_schedulesigaction.c -CMN_CSRCS += riscv_sigdeliver.c riscv_switchcontext.c riscv_usestack.c -CMN_CSRCS += riscv_idle.c riscv_tcbinfo.c riscv_cpuidlestack.c -CMN_CSRCS += riscv_exception.c riscv_getnewintctx.c riscv_doirq.c -CMN_CSRCS += riscv_saveusercontext.c riscv_getintstack.c riscv_registerdump.c +CMN_CSRCS += riscv_allocateheap.c riscv_createstack.c riscv_copystate.c +CMN_CSRCS += riscv_cpuidlestack.c riscv_doirq.c riscv_exit.c riscv_exception.c +CMN_CSRCS += riscv_getnewintctx.c riscv_getintstack.c riscv_initialstate.c +CMN_CSRCS += riscv_idle.c riscv_modifyreg32.c riscv_nputs.c riscv_releasestack.c +CMN_CSRCS += riscv_registerdump.c riscv_stackframe.c riscv_schedulesigaction.c +CMN_CSRCS += riscv_sigdeliver.c riscv_switchcontext.c riscv_saveusercontext.c +CMN_CSRCS += riscv_usestack.c riscv_tcbinfo.c ifneq ($(CONFIG_ALARM_ARCH),y) ifneq ($(CONFIG_TIMER_ARCH),y) diff --git a/arch/risc-v/src/common/riscv_internal.h b/arch/risc-v/src/common/riscv_internal.h index a7aa360838..fbfa3f12fa 100644 --- a/arch/risc-v/src/common/riscv_internal.h +++ b/arch/risc-v/src/common/riscv_internal.h @@ -277,8 +277,6 @@ size_t riscv_stack_check(uintptr_t alloc, size_t size); void riscv_stack_color(void *stackbase, size_t nbytes); #endif -void riscv_registerdump(volatile uintptr_t *regs); - #ifdef CONFIG_SMP void riscv_cpu_boot(int cpu); int riscv_pause_handler(int irq, void *c, void *arg); diff --git a/arch/risc-v/src/common/riscv_registerdump.c b/arch/risc-v/src/common/riscv_registerdump.c index 6364828406..2bb4dd2ac5 100644 --- a/arch/risc-v/src/common/riscv_registerdump.c +++ b/arch/risc-v/src/common/riscv_registerdump.c @@ -47,11 +47,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: riscv_registerdump + * Name: up_dump_register ****************************************************************************/ -void riscv_registerdump(volatile uintptr_t *regs) +void up_dump_register(void *dumpregs) { + volatile uintptr_t *regs = dumpregs ? dumpregs : CURRENT_REGS; + /* Are user registers available from interrupt processing? */ _alert("EPC: %" PRIxREG "\n", regs[REG_EPC]); @@ -86,4 +88,3 @@ void riscv_registerdump(volatile uintptr_t *regs) regs[REG_SP], regs[REG_FP], regs[REG_TP], regs[REG_RA]); #endif } - diff --git a/arch/risc-v/src/common/riscv_swint.c b/arch/risc-v/src/common/riscv_swint.c index a66f133067..b20c25341c 100644 --- a/arch/risc-v/src/common/riscv_swint.c +++ b/arch/risc-v/src/common/riscv_swint.c @@ -125,7 +125,7 @@ int riscv_swint(int irq, void *context, void *arg) #ifdef CONFIG_DEBUG_SYSCALL_INFO svcinfo("Entry: regs: %p cmd: %d\n", regs, regs[REG_A0]); - riscv_registerdump(regs); + up_dump_register(regs); #endif /* Handle the SWInt according to the command in $a0 */ @@ -513,7 +513,7 @@ int riscv_swint(int irq, void *context, void *arg) if (regs != CURRENT_REGS) { svcinfo("SWInt Return: Context switch!\n"); - riscv_registerdump(CURRENT_REGS); + up_dump_register(CURRENT_REGS); } else { diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index 93a12e8426..b4a38d4026 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -60,7 +60,8 @@ AOBJS = $(ASRCS:.S=$(OBJEXT)) CSRCS = sim_initialize.c sim_idle.c sim_doirq.c sim_initialstate.c CSRCS += sim_createstack.c sim_usestack.c sim_releasestack.c sim_stackframe.c CSRCS += sim_exit.c sim_schedulesigaction.c sim_switchcontext.c sim_heap.c -CSRCS += sim_uart.c sim_assert.c sim_copyfullstate.c sim_sigdeliver.c +CSRCS += sim_uart.c sim_copyfullstate.c sim_sigdeliver.c +CSRCS += sim_registerdump.c sim_saveusercontext.c ifeq ($(CONFIG_SCHED_BACKTRACE),y) CSRCS += sim_backtrace.c diff --git a/arch/sim/src/sim/sim_assert.c b/arch/sim/src/sim/sim_assert.c deleted file mode 100644 index 9105feab37..0000000000 --- a/arch/sim/src/sim/sim_assert.c +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** - * arch/sim/src/sim/sim_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include - -#ifdef CONFIG_BOARD_CRASHDUMP -# include -#endif - -#include "sim_internal.h" - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - * - * Description: - * Called to terminate the simulation abnormally in the event of a failed - * assertion. - * - ****************************************************************************/ - -void up_assert(void) -{ - struct tcb_s *rtcb = running_task(); - - if (CURRENT_REGS || is_idle_task(rtcb)) - { - /* Exit the simulation */ - - host_abort(EXIT_FAILURE); - } -} diff --git a/arch/z80/src/common/z80_assert.c b/arch/sim/src/sim/sim_registerdump.c similarity index 90% rename from arch/z80/src/common/z80_assert.c rename to arch/sim/src/sim/sim_registerdump.c index eae6bf0318..4b7a1f5641 100644 --- a/arch/z80/src/common/z80_assert.c +++ b/arch/sim/src/sim/sim_registerdump.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/z80/src/common/z80_assert.c + * arch/sim/src/sim/sim_registerdump.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,17 +24,18 @@ #include -#include "z80_internal.h" +#include + +#include "sim_internal.h" /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: up_assert + * Name: up_dump_register ****************************************************************************/ -void up_assert(void) +void up_dump_register(void *dumpregs) { - Z80_REGISTER_DUMP(); } diff --git a/arch/mips/src/mips32/mips_assert.c b/arch/sim/src/sim/sim_saveusercontext.c similarity index 79% rename from arch/mips/src/mips32/mips_assert.c rename to arch/sim/src/sim/sim_saveusercontext.c index 7f9f72b34d..df99e8a157 100644 --- a/arch/mips/src/mips32/mips_assert.c +++ b/arch/sim/src/sim/sim_saveusercontext.c @@ -1,5 +1,5 @@ /**************************************************************************** - * arch/mips/src/mips32/mips_assert.c + * arch/sim/src/sim/sim_saveusercontext.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,22 +24,29 @@ #include -#include +#include -#include - -#include "mips_internal.h" +#include "sim_internal.h" /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: up_assert + * Name: up_saveusercontext + * + * Description: + * Save the current thread context. Full prototype is: + * + * int up_saveusercontext(void *saveregs); + * + * Return: + * 0: Normal return + * 1: Context switch return + * ****************************************************************************/ -void up_assert(void) +int up_saveusercontext(void *saveregs) { - board_autoled_on(LED_ASSERTION); - mips_registerdump(CURRENT_REGS); + return sim_saveusercontext(saveregs); } diff --git a/arch/sparc/include/sparc_v8/irq.h b/arch/sparc/include/sparc_v8/irq.h index de77b50199..ae3de3eac8 100644 --- a/arch/sparc/include/sparc_v8/irq.h +++ b/arch/sparc/include/sparc_v8/irq.h @@ -95,10 +95,11 @@ #define REG_R33 (1) /* R33 */ #define REG_R34 (2) /* R34 */ -#define REG_R35 (18) /* R35 */ -#define REG_R36 (19) /* R36 */ +#define REG_R35 (18) /* R35 */ +#define REG_R36 (19) /* R36 */ -#define XCPTCONTEXT_REGS (52) +#define XCPTCONTEXT_REGS (68) +#define XCPTCONTEXT_SIZE (4 * XCPTCONTEXT_REGS) /* Alternate register names *************************************************/ /* %psr: processor status register */ diff --git a/arch/sparc/include/syscall.h b/arch/sparc/include/syscall.h index b50b33804e..5662aba509 100644 --- a/arch/sparc/include/syscall.h +++ b/arch/sparc/include/syscall.h @@ -61,7 +61,12 @@ /* Context switching system calls *******************************************/ -/* SYS call 0: (not used) */ +/* SYS call 0: + * + * int up_saveusercontext(void *saveregs); + */ + +#define SYS_save_context (0) /* SYS call 1: * diff --git a/arch/sparc/src/common/Make.defs b/arch/sparc/src/common/Make.defs index cf320a245a..7d3d13b242 100644 --- a/arch/sparc/src/common/Make.defs +++ b/arch/sparc/src/common/Make.defs @@ -20,12 +20,12 @@ # Common Sparc files (arch/sparc/src/common) -CMN_CSRCS += sparc_allocateheap.c sparc_assert.c -CMN_CSRCS += sparc_createstack.c sparc_exit.c sparc_idle.c sparc_initialize.c -CMN_CSRCS += sparc_lowputs.c sparc_mdelay.c -CMN_CSRCS += sparc_modifyreg8.c sparc_modifyreg16.c sparc_modifyreg32.c -CMN_CSRCS += sparc_nputs.c sparc_releasestack.c sparc_getintstack.c -CMN_CSRCS += sparc_stackframe.c sparc_udelay.c sparc_usestack.c +CMN_CSRCS += sparc_allocateheap.c sparc_createstack.c sparc_exit.c +CMN_CSRCS += sparc_getintstack.c sparc_idle.c sparc_initialize.c +CMN_CSRCS += sparc_lowputs.c sparc_mdelay.c sparc_modifyreg8.c +CMN_CSRCS += sparc_modifyreg16.c sparc_modifyreg32.c sparc_nputs.c +CMN_CSRCS += sparc_releasestack.c sparc_stackframe.c +CMN_CSRCS += sparc_udelay.c sparc_usestack.c # Configuration-dependent common files diff --git a/arch/sparc/src/common/sparc_assert.c b/arch/sparc/src/common/sparc_assert.c deleted file mode 100644 index e146904c8c..0000000000 --- a/arch/sparc/src/common/sparc_assert.c +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * arch/sparc/src/common/sparc_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "sparc_internal.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - sparc_registerdump(CURRENT_REGS); -} diff --git a/arch/sparc/src/common/sparc_internal.h b/arch/sparc/src/common/sparc_internal.h index 4ed19b8d73..23b7a29111 100644 --- a/arch/sparc/src/common/sparc_internal.h +++ b/arch/sparc/src/common/sparc_internal.h @@ -183,10 +183,6 @@ void sparc_copystate(uint32_t *dest, uint32_t *src); void sparc_lowputs(const char *str); -/* Debug */ - -void sparc_registerdump(volatile uint32_t *regs); - /* Software interrupt 0 handler */ int sparc_swint0(int irq, void *context, void *arg); diff --git a/arch/sparc/src/sparc_v8/Make.defs b/arch/sparc/src/sparc_v8/Make.defs index d37bb41b56..c46ad158bd 100644 --- a/arch/sparc/src/sparc_v8/Make.defs +++ b/arch/sparc/src/sparc_v8/Make.defs @@ -25,6 +25,6 @@ include common/Make.defs CMN_ASRCS += sparc_v8_syscall.S CMN_CSRCS += sparc_v8_copystate.c sparc_v8_doirq.c CMN_CSRCS += sparc_v8_initialstate.c sparc_v8_irq.c -CMN_CSRCS += sparc_v8_schedulesigaction.c +CMN_CSRCS += sparc_v8_schedulesigaction.c sparc_v8_saveusercontext.c CMN_CSRCS += sparc_v8_sigdeliver.c sparc_v8_swint1.c sparc_v8_systemreset.c CMN_CSRCS += sparc_v8_switchcontext.c sparc_v8_registerdump.c diff --git a/arch/sparc/src/sparc_v8/sparc_v8_registerdump.c b/arch/sparc/src/sparc_v8/sparc_v8_registerdump.c index df77801ad9..2b43487994 100644 --- a/arch/sparc/src/sparc_v8/sparc_v8_registerdump.c +++ b/arch/sparc/src/sparc_v8/sparc_v8_registerdump.c @@ -47,11 +47,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: sparc_registerdump + * Name: up_dump_register ****************************************************************************/ -void sparc_registerdump(volatile uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : CURRENT_REGS; + /* Are user registers available from interrupt processing? */ if (regs) diff --git a/arch/sparc/src/sparc_v8/sparc_v8_saveusercontext.c b/arch/sparc/src/sparc_v8/sparc_v8_saveusercontext.c new file mode 100644 index 0000000000..14bfbfa15d --- /dev/null +++ b/arch/sparc/src/sparc_v8/sparc_v8_saveusercontext.c @@ -0,0 +1,50 @@ +/**************************************************************************** + * arch/sparc/src/sparc_v8/sparc_v8_saveusercontext.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_saveusercontext + * + * Description: + * Save the current thread context. Full prototype is: + * + * int up_saveusercontext(void *saveregs); + * + * Returned Value: + * 0: Normal return + * 1: Context switch return + * + ****************************************************************************/ + +int up_saveusercontext(void *saveregs) +{ + return sys_call1(SYS_save_context, (uintptr_t)saveregs); +} diff --git a/arch/sparc/src/sparc_v8/sparc_v8_swint1.c b/arch/sparc/src/sparc_v8/sparc_v8_swint1.c index 9d6b0650de..1a76f29b63 100644 --- a/arch/sparc/src/sparc_v8/sparc_v8_swint1.c +++ b/arch/sparc/src/sparc_v8/sparc_v8_swint1.c @@ -82,13 +82,33 @@ int sparc_swint1(int irq, void *context, void *arg) #ifdef CONFIG_DEBUG_SYSCALL_INFO svcinfo("Entry: regs: %p cmd: %d\n", regs, regs[REG_I0]); - up_registerdump(regs); + up_dump_register(regs); #endif /* Handle the SWInt according to the command in $4 */ switch (regs[REG_I0]) { + /* A0=SYS_save_context: This is a save context command: + * + * int up_saveusercontext(void *saveregs); + * + * At this point, the following values are saved in context: + * + * A0 = SYS_save_context + * A1 = saveregs + * + * In this case, we simply need to copy the current registers to the + * save register space references in the saved R1 and return. + */ + + case SYS_save_context: + { + DEBUGASSERT(regs[REG_I1] != 0); + trap_flush_task((uint32_t *)regs[REG_I1], regs); + } + break; + /* A0=SYS_restore_context: This a restore context command: * * void sparc_fullcontextrestore @@ -217,7 +237,7 @@ int sparc_swint1(int irq, void *context, void *arg) if (regs != CURRENT_REGS) { svcinfo("SWInt Return: Context switch!\n"); - up_registerdump(CURRENT_REGS); + up_dump_register(CURRENT_REGS); } else { diff --git a/arch/x86/src/common/x86_assert.c b/arch/x86/src/common/x86_assert.c deleted file mode 100644 index c7a631e27c..0000000000 --- a/arch/x86/src/common/x86_assert.c +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * arch/x86/src/common/x86_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include -#include - -#include - -#include "sched/sched.h" -#include "x86_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint32_t s_last_regs[XCPTCONTEXT_REGS]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - board_autoled_on(LED_ASSERTION); - - if (g_current_regs != NULL) - { - x86_registerdump((uint32_t *)g_current_regs); - } - else - { - /* Capture and dump user registers by hand */ - - up_saveusercontext(s_last_regs); - x86_registerdump(s_last_regs); - } -} diff --git a/arch/x86/src/common/x86_internal.h b/arch/x86/src/common/x86_internal.h index 0d81692be8..cfaf5cccfa 100644 --- a/arch/x86/src/common/x86_internal.h +++ b/arch/x86/src/common/x86_internal.h @@ -177,7 +177,6 @@ void x86_lowputc(char ch); void x86_lowputs(const char *str); void x86_syscall(uint32_t *regs); -void x86_registerdump(uint32_t *regs); /* Defined in up_allocateheap.c */ diff --git a/arch/x86/src/i486/i486_regdump.c b/arch/x86/src/i486/i486_regdump.c index f73bfc6684..4d724e7329 100644 --- a/arch/x86/src/i486/i486_regdump.c +++ b/arch/x86/src/i486/i486_regdump.c @@ -43,11 +43,13 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: x86_registerdump + * Name: up_dump_register ****************************************************************************/ -void x86_registerdump(uint32_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint32_t *regs = dumpregs ? dumpregs : g_current_regs; + _alert(" ds:%08x irq:%08x err:%08x\n", regs[REG_DS], regs[REG_IRQNO], regs[REG_ERRCODE]); _alert("edi:%08x esi:%08x ebp:%08x esp:%08x\n", diff --git a/arch/x86/src/qemu/Make.defs b/arch/x86/src/qemu/Make.defs index e2dc8960a5..ffa06f1b38 100644 --- a/arch/x86/src/qemu/Make.defs +++ b/arch/x86/src/qemu/Make.defs @@ -27,14 +27,13 @@ HEAD_ASRC = qemu_head.S CMN_ASRCS = i486_utils.S i486_syscall6.S CMN_CSRCS += i486_createstack.c i486_initialstate.c -CMN_CSRCS += x86_allocateheap.c x86_assert.c x86_copystate.c -CMN_CSRCS += x86_exit.c x86_initialize.c x86_mdelay.c x86_udelay.c +CMN_CSRCS += x86_allocateheap.c x86_copystate.c x86_exit.c +CMN_CSRCS += x86_getintstack.c x86_initialize.c x86_mdelay.c CMN_CSRCS += x86_modifyreg8.c x86_modifyreg16.c x86_modifyreg32.c -CMN_CSRCS += x86_nputs.c x86_switchcontext.c x86_getintstack.c +CMN_CSRCS += x86_nputs.c x86_switchcontext.c x86_udelay.c CMN_CSRCS += i486_irq.c i486_regdump.c i486_releasestack.c -CMN_CSRCS += i486_savestate.c i486_sigdeliver.c -CMN_CSRCS += i486_schedulesigaction.c i486_stackframe.c -CMN_CSRCS += i486_usestack.c +CMN_CSRCS += i486_savestate.c i486_sigdeliver.c i486_stackframe.c +CMN_CSRCS += i486_schedulesigaction.c i486_usestack.c # Required QEMU files diff --git a/arch/x86_64/src/common/x86_64_assert.c b/arch/x86_64/src/common/x86_64_assert.c deleted file mode 100644 index b551aa6552..0000000000 --- a/arch/x86_64/src/common/x86_64_assert.c +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * arch/x86_64/src/common/x86_64_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include -#include - -#include - -#include "sched/sched.h" -#include "x86_64_internal.h" - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - board_autoled_on(LED_ASSERTION); - - if (g_current_regs != NULL) - { - x86_64_registerdump((uint64_t *)g_current_regs); - } -} diff --git a/arch/x86_64/src/common/x86_64_internal.h b/arch/x86_64/src/common/x86_64_internal.h index 7046c0a9aa..ec4b22769f 100644 --- a/arch/x86_64/src/common/x86_64_internal.h +++ b/arch/x86_64/src/common/x86_64_internal.h @@ -199,7 +199,6 @@ void x86_64_restore_auxstate(struct tcb_s *rtcb); void x86_64_checktasks(void); void x86_64_syscall(uint64_t *regs); -void x86_64_registerdump(uint64_t *regs); /* Defined in up_allocateheap.c */ diff --git a/arch/x86_64/src/intel64/Make.defs b/arch/x86_64/src/intel64/Make.defs index 411181f0b2..820d2dfbbc 100644 --- a/arch/x86_64/src/intel64/Make.defs +++ b/arch/x86_64/src/intel64/Make.defs @@ -20,15 +20,15 @@ # Common x86_64 and intel64 files -CMN_CSRCS += x86_64_allocateheap.c x86_64_assert.c x86_64_copystate.c -CMN_CSRCS += x86_64_mdelay.c x86_64_udelay.c x86_64_exit.c x86_64_initialize.c -CMN_CSRCS += x86_64_modifyreg8.c x86_64_modifyreg16.c x86_64_modifyreg32.c x86_64_nputs.c -CMN_CSRCS += x86_64_switchcontext.c x86_64_getintstack.c -CMN_CSRCS += intel64_restore_auxstate.c intel64_createstack.c intel64_initialstate.c -CMN_CSRCS += intel64_regdump.c intel64_releasestack.c intel64_map_region.c -CMN_CSRCS += intel64_savestate.c intel64_sigdeliver.c -CMN_CSRCS += intel64_schedulesigaction.c intel64_stackframe.c -CMN_CSRCS += intel64_usestack.c intel64_irq.c intel64_rtc.c +CMN_CSRCS += x86_64_allocateheap.c x86_64_copystate.c x86_64_exit.c +CMN_CSRCS += x86_64_getintstack.c x86_64_mdelay.c x86_64_initialize.c +CMN_CSRCS += x86_64_modifyreg8.c x86_64_modifyreg16.c x86_64_modifyreg32.c +CMN_CSRCS += x86_64_nputs.c x86_64_switchcontext.c x86_64_udelay.c +CMN_CSRCS += intel64_createstack.c intel64_initialstate.c intel64_irq.c +CMN_CSRCS += intel64_map_region.c intel64_regdump.c intel64_releasestack.c +CMN_CSRCS += intel64_rtc.c intel64_restore_auxstate.c intel64_savestate.c +CMN_CSRCS += intel64_stackframe.c intel64_schedulesigaction.c +CMN_CSRCS += intel64_sigdeliver.c intel64_usestack.c # Required Intel64 files diff --git a/arch/x86_64/src/intel64/intel64_handlers.c b/arch/x86_64/src/intel64/intel64_handlers.c index 0acc90ce87..4e5295a61f 100644 --- a/arch/x86_64/src/intel64/intel64_handlers.c +++ b/arch/x86_64/src/intel64/intel64_handlers.c @@ -170,7 +170,7 @@ uint64_t *isr_handler(uint64_t *regs, uint64_t irq) "with error code %" PRId64 ":\n", irq, regs[REG_ERRCODE]); - x86_64_registerdump(regs); + up_dump_register(regs); up_trash_cpu(); break; diff --git a/arch/x86_64/src/intel64/intel64_regdump.c b/arch/x86_64/src/intel64/intel64_regdump.c index 64ff453e19..d12acc8924 100644 --- a/arch/x86_64/src/intel64/intel64_regdump.c +++ b/arch/x86_64/src/intel64/intel64_regdump.c @@ -108,8 +108,9 @@ void backtrace(uint64_t rbp) } } -void x86_64_registerdump(uint64_t *regs) +void up_dump_register(void *dumpregs) { + volatile uint64_t *regs = dumpregs ? dumpregs : g_current_regs; uint64_t mxcsr; uint64_t cr2; diff --git a/arch/xtensa/src/common/Make.defs b/arch/xtensa/src/common/Make.defs index 9776a26645..31e2e61b6c 100644 --- a/arch/xtensa/src/common/Make.defs +++ b/arch/xtensa/src/common/Make.defs @@ -27,16 +27,14 @@ HEAD_ASRC += xtensa_int_handlers.S xtensa_user_handler.S CMN_ASRCS = xtensa_context.S xtensa_cpuint.S xtensa_panic.S -CMN_CSRCS = xtensa_assert.c -CMN_CSRCS += xtensa_cpenable.c xtensa_createstack.c xtensa_exit.c -CMN_CSRCS += xtensa_initialize.c xtensa_initialstate.c -CMN_CSRCS += xtensa_irqdispatch.c xtensa_lowputs.c xtensa_mdelay.c +CMN_CSRCS = xtensa_assert.c xtensa_cpenable.c xtensa_createstack.c +CMN_CSRCS += xtensa_exit.c xtensa_getintstack.c xtensa_initialize.c +CMN_CSRCS += xtensa_initialstate.c xtensa_irqdispatch.c xtensa_lowputs.c CMN_CSRCS += xtensa_modifyreg8.c xtensa_modifyreg16.c xtensa_modifyreg32.c -CMN_CSRCS += xtensa_nputs.c xtensa_releasestack.c -CMN_CSRCS += xtensa_schedsigaction.c -CMN_CSRCS += xtensa_sigdeliver.c xtensa_stackframe.c xtensa_udelay.c -CMN_CSRCS += xtensa_switchcontext.c xtensa_usestack.c xtensa_swint.c -CMN_CSRCS += xtensa_saveusercontext.c xtensa_getintstack.c xtensa_registerdump.c +CMN_CSRCS += xtensa_mdelay.c xtensa_nputs.c xtensa_releasestack.c +CMN_CSRCS += xtensa_registerdump.c xtensa_sigdeliver.c xtensa_switchcontext.c +CMN_CSRCS += xtensa_swint.c xtensa_stackframe.c xtensa_saveusercontext.c +CMN_CSRCS += xtensa_schedsigaction.c xtensa_udelay.c xtensa_usestack.c # Configuration-dependent common Xtensa files diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h index 7f28fed94b..fc88bfab33 100644 --- a/arch/xtensa/src/common/xtensa.h +++ b/arch/xtensa/src/common/xtensa.h @@ -214,10 +214,6 @@ void modifyreg32(unsigned int addr, uint32_t clearbits, uint32_t setbits); void xtensa_lowputs(const char *str); -/* Debug */ - -void xtensa_registerdump(uintptr_t *regs); - /* Common XTENSA functions */ /* Initialization */ diff --git a/arch/xtensa/src/common/xtensa_assert.c b/arch/xtensa/src/common/xtensa_assert.c index 002d071d8b..6490dd4555 100644 --- a/arch/xtensa/src/common/xtensa_assert.c +++ b/arch/xtensa/src/common/xtensa_assert.c @@ -37,43 +37,10 @@ #include "sched/sched.h" #include "xtensa.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint8_t s_last_regs[XCPTCONTEXT_SIZE]; - /**************************************************************************** * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - struct tcb_s *rtcb = running_task(); - - board_autoled_on(LED_ASSERTION); - - /* Update the xcp context */ - - if (CURRENT_REGS) - { - rtcb->xcp.regs = (uint32_t *)CURRENT_REGS; - } - else - { - up_saveusercontext(s_last_regs); - rtcb->xcp.regs = (uint32_t *)s_last_regs; - } - - /* Dump the registers (if available) */ - - xtensa_registerdump(rtcb->xcp.regs); -} - /**************************************************************************** * Name: xtensa_panic * diff --git a/arch/xtensa/src/common/xtensa_registerdump.c b/arch/xtensa/src/common/xtensa_registerdump.c index 4470141fd5..2b43ab3431 100644 --- a/arch/xtensa/src/common/xtensa_registerdump.c +++ b/arch/xtensa/src/common/xtensa_registerdump.c @@ -47,11 +47,14 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: xtensa_registerdump + * Name: up_dump_register ****************************************************************************/ -void xtensa_registerdump(uintptr_t *regs) +void up_dump_register(void *dumpregs) { + volatile uintptr_t *regs = dumpregs ? dumpregs : + (uintptr_t *)CURRENT_REGS; + _alert(" PC: %08lx PS: %08lx\n", (unsigned long)regs[REG_PC], (unsigned long)regs[REG_PS]); _alert(" A0: %08lx A1: %08lx A2: %08lx A3: %08lx\n", @@ -75,4 +78,3 @@ void xtensa_registerdump(uintptr_t *regs) (unsigned long)regs[REG_LCOUNT]); #endif } - diff --git a/arch/xtensa/src/common/xtensa_swint.c b/arch/xtensa/src/common/xtensa_swint.c index 3ae0c5bbb8..51bf2c1b79 100644 --- a/arch/xtensa/src/common/xtensa_swint.c +++ b/arch/xtensa/src/common/xtensa_swint.c @@ -68,7 +68,7 @@ int xtensa_swint(int irq, void *context, void *arg) #ifdef CONFIG_DEBUG_SYSCALL_INFO svcinfo("SYSCALL Entry: regs: %p cmd: %" PRIu32 "\n", regs, cmd); - xtensa_registerdump(regs); + up_dump_register(regs); #endif /* Handle the syscall according to the command in A2 */ @@ -431,7 +431,7 @@ int xtensa_swint(int irq, void *context, void *arg) if (regs != CURRENT_REGS) { svcinfo("SYSCALL Return: Context switch!\n"); - xtensa_registerdump(CURRENT_REGS); + up_dump_register(CURRENT_REGS); } else { diff --git a/arch/xtensa/src/esp32/esp32_cpustart.c b/arch/xtensa/src/esp32/esp32_cpustart.c index 7d69c6c191..10925430ca 100644 --- a/arch/xtensa/src/esp32/esp32_cpustart.c +++ b/arch/xtensa/src/esp32/esp32_cpustart.c @@ -166,7 +166,7 @@ void IRAM_ATTR xtensa_appcpu_start(void) /* Dump registers so that we can see what is going to happen on return */ #if 0 - xtensa_registerdump(tcb->xcp.regs); + up_dump_register(tcb->xcp.regs); #endif #ifdef CONFIG_ESP32_GPIO_IRQ diff --git a/arch/z16/src/common/z16_assert.c b/arch/z16/src/common/z16_assert.c deleted file mode 100644 index 1064e55e63..0000000000 --- a/arch/z16/src/common/z16_assert.c +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** - * arch/z16/src/common/z16_assert.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include - -#include "z16_internal.h" - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static chipreg_t s_last_regs[XCPTCONTEXT_REGS]; - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_assert - ****************************************************************************/ - -void up_assert(void) -{ - FAR volatile uint32_t *regs32 = (FAR volatile uint32_t *)g_current_regs; - - board_autoled_on(LED_ASSERTION); - - if (regs32 == NULL) - { - up_saveusercontext(s_last_regs); - regs32 = (FAR volatile uint32_t *)s_last_regs; - } - - z16_registerdump(regs32); -} diff --git a/arch/z16/src/common/z16_internal.h b/arch/z16/src/common/z16_internal.h index ffe81aaade..d0bd733544 100644 --- a/arch/z16/src/common/z16_internal.h +++ b/arch/z16/src/common/z16_internal.h @@ -155,10 +155,6 @@ void z16_netinitialize(void); # define z16_netinitialize() #endif -/* Dump stack and registers */ - -void z16_registerdump(FAR volatile uint32_t *regs); - #endif /* __ASSEMBLY__ */ #endif /* __ARCH_Z16_SRC_COMMON_Z16_INTERNAL_H */ diff --git a/arch/z16/src/common/z16_registerdump.c b/arch/z16/src/common/z16_registerdump.c index 56d0c38b13..33c2a2b641 100644 --- a/arch/z16/src/common/z16_registerdump.c +++ b/arch/z16/src/common/z16_registerdump.c @@ -43,12 +43,14 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: z16_registerdump + * Name: up_dump_register ****************************************************************************/ -void z16_registerdump(FAR volatile uint32_t *regs) +void up_dump_register(FAR void *dumpregs) { #ifdef CONFIG_DEBUG_INFO + FAR uint32_t *regs = dumpregs ? dumpregs : g_current_regs; + _alert("R0 :%08x R1 :%08x R2 :%08x R3 :%08x " "R4 :%08x R5 :%08x R6 :%08x R7 :%08x\n" regs[REG_R0 / 2], regs[REG_R1 / 2], regs[REG_R2 / 2], @@ -56,7 +58,7 @@ void z16_registerdump(FAR volatile uint32_t *regs) regs[REG_R6 / 2], regs[REG_R7 / 2]); _alert("R8 :%08x R9 :%08x R10:%08x R11:%08x R12:%08x R13:%08x\n" regs[REG_R8 / 2], regs[REG_R9 / 2], regs[REG_R10 / 2], - regs3[REG_R11 / 2], regs[REG_R12 / 2], regs[REG_R13 / 2]); + regs[REG_R11 / 2], regs[REG_R12 / 2], regs[REG_R13 / 2]); _alert("FP :%08x SP :%08x FLG:%04x\n" regs[REG_R14 / 2], regs[REG_R15 / 2], regs[REG_FLAGS]); #endif diff --git a/arch/z16/src/z16f/Make.defs b/arch/z16/src/z16f/Make.defs index 0e7a089360..be6288f0f6 100644 --- a/arch/z16/src/z16f/Make.defs +++ b/arch/z16/src/z16f/Make.defs @@ -20,12 +20,11 @@ HEAD_SSRC = z16f_head.S -CMN_CSRCS = z16_allocateheap.c z16_initialize.c z16_schedulesigaction.c -CMN_CSRCS += z16_assert.c z16_initialstate.c z16_sigdeliver.c z16_copystate.c -CMN_CSRCS += z16_mdelay.c z16_udelay.c z16_createstack.c z16_registerdump.c -CMN_CSRCS += z16_switchcontext.c z16_doirq.c z16_usestack.c -CMN_CSRCS += z16_exit.c z16_releasestack.c z16_stackframe.c z16_idle.c -CMN_CSRCS += z16_nputs.c +CMN_CSRCS = z16_allocateheap.c z16_copystate.c z16_createstack.c z16_doirq.c +CMN_CSRCS += z16_exit.c z16_initialstate.c z16_initialize.c z16_idle.c +CMN_CSRCS += z16_mdelay.c z16_nputs.c z16_registerdump.c z16_releasestack.c +CMN_CSRCS += z16_schedulesigaction.c z16_sigdeliver.c z16_switchcontext.c +CMN_CSRCS += z16_stackframe.c z16_udelay.c z16_usestack.c CHIP_SSRCS = z16f_lowuart.S z16f_saveusercontext.S z16f_restoreusercontext.S CHIP_CSRCS = z16f_clkinit.c z16f_sysexec.c z16f_irq.c z16f_serial.c diff --git a/arch/z80/src/common/z80_internal.h b/arch/z80/src/common/z80_internal.h index 566b1a6f3c..ff6e5cb1d3 100644 --- a/arch/z80/src/common/z80_internal.h +++ b/arch/z80/src/common/z80_internal.h @@ -143,14 +143,6 @@ int z80_multicastfilter(FAR struct net_driver_s *dev, FAR uint8_t *mac, # define z80_multicastfilter(dev, mac, enable) #endif -/* Dump stack and registers */ - -#ifdef CONFIG_ARCH_STACKDUMP -# define Z80_REGISTER_DUMP() _REGISTER_DUMP() -#else -# define Z80_REGISTER_DUMP() -#endif - #ifdef __cplusplus } #endif diff --git a/arch/z80/src/ez80/Make.defs b/arch/z80/src/ez80/Make.defs index 00e19b1daa..249325b2c3 100644 --- a/arch/z80/src/ez80/Make.defs +++ b/arch/z80/src/ez80/Make.defs @@ -18,12 +18,11 @@ # ############################################################################ -CMN_CSRCS = z80_initialize.c z80_allocateheap.c z80_createstack.c -CMN_CSRCS += z80_releasestack.c z80_interruptcontext.c -CMN_CSRCS += z80_switchcontext.c z80_exit.c -CMN_CSRCS += z80_idle.c z80_assert.c z80_doirq.c -CMN_CSRCS += z80_mdelay.c z80_stackframe.c z80_udelay.c z80_usestack.c -CMN_CSRCS += z80_nputs.c +CMN_CSRCS = z80_allocateheap.c z80_createstack.c z80_doirq.c +CMN_CSRCS += z80_exit.c z80_interruptcontext.c z80_idle.c +CMN_CSRCS += z80_initialize.c z80_mdelay.c z80_nputs.c +CMN_CSRCS += z80_releasestack.c z80_switchcontext.c +CMN_CSRCS += z80_stackframe.c z80_udelay.c z80_usestack.c CHIP_ASRCS = ez80_startup.asm ez80_io.asm ez80_irqsave.asm CHIP_ASRCS += ez80_irqcommon.asm diff --git a/arch/z80/src/ez80/ez80_registerdump.c b/arch/z80/src/ez80/ez80_registerdump.c index 184dc57bca..fb958f69e5 100644 --- a/arch/z80/src/ez80/ez80_registerdump.c +++ b/arch/z80/src/ez80/ez80_registerdump.c @@ -32,14 +32,6 @@ #include "chip/switch.h" #include "z80_internal.h" -#ifdef CONFIG_ARCH_STACKDUMP - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static chipreg_t s_last_regs[XCPTCONTEXT_REGS]; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -55,18 +47,12 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: z80_registerdump + * Name: up_dump_register ****************************************************************************/ -void ez80_registerdump(void) +void up_dump_register(FAR void *dumpregs) { - volatile chipreg_t *regs = g_current_regs; - - if (regs == NULL) - { - up_saveusercontext(s_last_regs); - regs = s_last_regs; - } + FAR chipreg_t *regs = dumpregs ? dumpregs : g_current_regs; #ifdef CONFIG_EZ80_Z80MODE _alert("AF: %04x I: %04x\n", @@ -88,5 +74,3 @@ void ez80_registerdump(void) regs[XCPT_SP], regs[XCPT_PC]); #endif } - -#endif /* CONFIG_ARCH_STACKDUMP */ diff --git a/arch/z80/src/ez80/switch.h b/arch/z80/src/ez80/switch.h index 4d4a3051e3..41e0b65f47 100644 --- a/arch/z80/src/ez80/switch.h +++ b/arch/z80/src/ez80/switch.h @@ -97,10 +97,6 @@ #define RESTORE_USERCONTEXT(tcb) ez80_restorecontext((tcb)->xcp.regs) -/* Dump the current machine registers */ - -#define _REGISTER_DUMP() ez80_registerdump() - /************************************************************************************ * Public Types ************************************************************************************/ @@ -139,10 +135,6 @@ int up_saveusercontext(FAR chipreg_t *regs); void ez80_restorecontext(FAR chipreg_t *regs); -/* Defined in ez80_registerdump.c */ - -void ez80_registerdump(void); - #ifdef __cplusplus } #endif diff --git a/arch/z80/src/z180/Make.defs b/arch/z80/src/z180/Make.defs index 4898f3ae35..339bfa24f8 100644 --- a/arch/z80/src/z180/Make.defs +++ b/arch/z80/src/z180/Make.defs @@ -26,11 +26,11 @@ HEAD_ASRC = z180_head.asm endif endif -CMN_CSRCS = z80_allocateheap.c z80_assert.c z80_createstack.c -CMN_CSRCS += z80_doirq.c z80_exit.c z80_idle.c z80_initialize.c -CMN_CSRCS += z80_interruptcontext.c z80_mdelay.c -CMN_CSRCS += z80_releasestack.c z80_stackframe.c -CMN_CSRCS += z80_switchcontext.c z80_udelay.c z80_usestack.c z80_nputs.c +CMN_CSRCS = z80_allocateheap.c z80_createstack.c z80_doirq.c +CMN_CSRCS += z80_exit.c z80_interruptcontext.c z80_idle.c +CMN_CSRCS += z80_initialize.c z80_mdelay.c z80_nputs.c +CMN_CSRCS += z80_releasestack.c z80_stackframe.c z80_switchcontext.c +CMN_CSRCS += z80_udelay.c z80_usestack.c CHIP_ASRCS = z180_restoreusercontext.asm z180_saveusercontext.asm CHIP_ASRCS += z180_vectcommon.asm diff --git a/arch/z80/src/z180/switch.h b/arch/z80/src/z180/switch.h index 14ab93e6a2..2209c97f3c 100644 --- a/arch/z80/src/z180/switch.h +++ b/arch/z80/src/z180/switch.h @@ -154,11 +154,6 @@ } \ while (0) -/* Dump the current machine registers */ - -#define _REGISTER_DUMP() \ - z180_registerdump() - /************************************************************************************ * Public Types ************************************************************************************/ @@ -210,10 +205,6 @@ void z180_restoreusercontext(FAR chipreg_t *regs); void z180_sigsetup(FAR struct tcb_s *tcb, sig_deliver_t sigdeliver, FAR chipreg_t *regs); -/* Defined in z180_registerdump.c */ - -void z180_registerdump(void); - #ifdef __cplusplus } #endif diff --git a/arch/z80/src/z180/z180_registerdump.c b/arch/z80/src/z180/z180_registerdump.c index 87f11ab995..a76d83a8ef 100644 --- a/arch/z80/src/z180/z180_registerdump.c +++ b/arch/z80/src/z180/z180_registerdump.c @@ -32,14 +32,6 @@ #include "chip/switch.h" #include "z80_internal.h" -#ifdef CONFIG_ARCH_STACKDUMP - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static chipreg_t s_last_regs[XCPTCONTEXT_REGS]; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -55,18 +47,12 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: z180_registerdump + * Name: up_dump_register ****************************************************************************/ -void z180_registerdump(void) +void up_dump_register(FAR void *dumpregs) { - volatile chipreg_t *regs = g_current_regs; - - if (regs == NULL) - { - up_saveusercontext(s_last_regs); - regs = s_last_regs; - } + FAR chipreg_t *regs = dumpregs ? dumpregs : g_current_regs; _alert("AF: %04x I: %04x\n", regs[XCPT_AF], regs[XCPT_I]); @@ -79,5 +65,3 @@ void z180_registerdump(void) _alert("CBAR: %02x BBR: %02x CBR: %02x\n" inp(Z180_MMU_CBAR), inp(Z180_MMU_BBR), inp(Z180_MMU_CBR)); } - -#endif /* CONFIG_ARCH_STACKDUMP */ diff --git a/arch/z80/src/z8/Make.defs b/arch/z80/src/z8/Make.defs index 076a0eb9f7..67ad5f8708 100644 --- a/arch/z80/src/z8/Make.defs +++ b/arch/z80/src/z8/Make.defs @@ -20,12 +20,11 @@ HEAD_SSRC = z8_head.S -CMN_CSRCS = z80_initialize.c z80_allocateheap.c z80_createstack.c -CMN_CSRCS += z80_releasestack.c z80_interruptcontext.c -CMN_CSRCS += z80_switchcontext.c z80_exit.c -CMN_CSRCS += z80_idle.c z80_assert.c z80_doirq.c -CMN_CSRCS += z80_mdelay.c z80_stackframe.c z80_udelay.c z80_usestack.c -CMN_CSRCS += z80_nputs.c +CMN_CSRCS = z80_allocateheap.c z80_createstack.c z80_doirq.c +CMN_CSRCS += z80_exit.c z80_idle.c z80_interruptcontext.c +CMN_CSRCS += z80_initialize.c z80_mdelay.c z80_nputs.c +CMN_CSRCS += z80_releasestack.c z80_switchcontext.c +CMN_CSRCS += z80_stackframe.c z80_udelay.c z80_usestack.c CHIP_SSRCS = z8_vector.S z8_saveusercontext.S z8_restorecontext.S CHIP_CSRCS = z8_initialstate.c z8_irq.c z8_saveirqcontext.c diff --git a/arch/z80/src/z8/switch.h b/arch/z80/src/z8/switch.h index 0f8b778fe6..8513f4a7ea 100644 --- a/arch/z80/src/z8/switch.h +++ b/arch/z80/src/z8/switch.h @@ -158,11 +158,6 @@ #define RESTORE_USERCONTEXT(tcb) \ z8_restorecontext((tcb)->xcp.regs) -/* Dump the current machine registers */ - -#define _REGISTER_DUMP() \ - z8_registerdump() - /************************************************************************************ * Public Types ************************************************************************************/ @@ -232,10 +227,6 @@ void z8_restorecontext(FAR chipreg_t *regs); void z8_sigsetup(FAR struct tcb_s *tcb, sig_deliver_t sigdeliver, FAR chipreg_t *regs); -/* Defined in z8_registerdump.c */ - -void z8_registerdump(void); - #ifdef __cplusplus } #endif diff --git a/arch/z80/src/z8/z8_registerdump.c b/arch/z80/src/z8/z8_registerdump.c index d5fa77d35b..26da6c6d8c 100644 --- a/arch/z80/src/z8/z8_registerdump.c +++ b/arch/z80/src/z8/z8_registerdump.c @@ -33,14 +33,6 @@ #include "chip/switch.h" #include "z80_internal.h" -#ifdef CONFIG_ARCH_STACKDUMP - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static chipreg_t s_last_regs[XCPTCONTEXT_REGS]; - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -74,10 +66,10 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: z8_registerdump + * Name: up_dump_register ****************************************************************************/ -void z8_registerdump(void) +void up_dump_register(FAR void *dumpregs) { FAR chipret_t *regs; chipreg_t sp; @@ -124,5 +116,3 @@ void z8_registerdump(void) break; } } - -#endif /* CONFIG_ARCH_STACKDUMP */ diff --git a/arch/z80/src/z80/Make.defs b/arch/z80/src/z80/Make.defs index 06467846e5..75cb102307 100644 --- a/arch/z80/src/z80/Make.defs +++ b/arch/z80/src/z80/Make.defs @@ -26,11 +26,11 @@ HEAD_ASRC = z80_head.asm endif endif -CMN_CSRCS = z80_initialize.c z80_allocateheap.c z80_createstack.c -CMN_CSRCS += z80_releasestack.c z80_interruptcontext.c -CMN_CSRCS += z80_switchcontext.c z80_exit.c -CMN_CSRCS += z80_idle.c z80_assert.c z80_doirq.c -CMN_CSRCS += z80_mdelay.c z80_stackframe.c z80_udelay.c z80_usestack.c +CMN_CSRCS = z80_allocateheap.c z80_createstack.c z80_doirq.c +CMN_CSRCS += z80_exit.c z80_initialize.c z80_interruptcontext.c +CMN_CSRCS += z80_idle.c z80_mdelay.c z80_releasestack.c +CMN_CSRCS += z80_switchcontext.c z80_stackframe.c +CMN_CSRCS += z80_udelay.c z80_usestack.c CHIP_ASRCS = z80_saveusercontext.asm z80_restoreusercontext.asm diff --git a/arch/z80/src/z80/switch.h b/arch/z80/src/z80/switch.h index aaf37dcd6c..7bb25bec42 100644 --- a/arch/z80/src/z80/switch.h +++ b/arch/z80/src/z80/switch.h @@ -96,10 +96,6 @@ #define RESTORE_USERCONTEXT(tcb) z80_restoreusercontext((tcb)->xcp.regs) -/* Dump the current machine registers */ - -#define _REGISTER_DUMP() z80_registerdump() - /************************************************************************************ * Public Types ************************************************************************************/ @@ -138,10 +134,6 @@ int up_saveusercontext(FAR chipreg_t *regs); void z80_restoreusercontext(FAR chipreg_t *regs); -/* Defined in z80_registerdump.c */ - -void z80_registerdump(void); - #ifdef __cplusplus } #endif diff --git a/arch/z80/src/z80/z80_registerdump.c b/arch/z80/src/z80/z80_registerdump.c index 05e049b6d6..3357420c7d 100644 --- a/arch/z80/src/z80/z80_registerdump.c +++ b/arch/z80/src/z80/z80_registerdump.c @@ -32,14 +32,6 @@ #include "chip/switch.h" #include "z80_internal.h" -#ifdef CONFIG_ARCH_STACKDUMP - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static chipreg_t s_last_regs[XCPTCONTEXT_REGS]; - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -55,18 +47,12 @@ uintptr_t up_getusrsp(void) } /**************************************************************************** - * Name: z80_registerdump + * Name: up_dump_register ****************************************************************************/ -void z80_registerdump(void) +void up_dump_register(FAR void *dumpregs) { - volatile chipreg_t *regs = g_current_regs; - - if (regs == NULL) - { - up_saveusercontext(s_last_regs); - regs = s_last_regs; - } + FAR chipreg_t *regs = dumpregs ? dumpregs : g_current_regs; _alert("AF: %04x I: %04x\n", regs[XCPT_AF], regs[XCPT_I]); @@ -77,5 +63,3 @@ void z80_registerdump(void) _alert("SP: %04x PC: %04x\n" regs[XCPT_SP], regs[XCPT_PC]); } - -#endif /* CONFIG_ARCH_STACKDUMP */ diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h index 7fd4b5a185..35d6520ad6 100644 --- a/include/nuttx/arch.h +++ b/include/nuttx/arch.h @@ -423,14 +423,14 @@ void up_exit(int status) noreturn_function; /* Prototype is in unistd.h */ /**************************************************************************** - * Name: up_assert + * Name: up_dump_register * * Description: - * Assertions may be handled in an architecture-specific way. + * Register dump may be handled in an architecture-specific way. * ****************************************************************************/ -void up_assert(void); +void up_dump_register(FAR void *regs); #ifdef CONFIG_ARCH_HAVE_BACKTRACE diff --git a/sched/misc/assert.c b/sched/misc/assert.c index 3a74e18380..95a00b7925 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -34,6 +34,7 @@ #include #include +#include #include #include "irq/irq.h" @@ -59,6 +60,12 @@ # undef CONFIG_ARCH_USBDUMP #endif +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static uint8_t g_last_regs[XCPTCONTEXT_SIZE]; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -480,12 +487,14 @@ static void assert_end(void) void _assert(FAR const char *filename, int linenum) { + FAR struct tcb_s *rtcb = running_task(); + /* Flush any buffered SYSLOG data (from prior to the assertion) */ syslog_flush(); #if CONFIG_BOARD_RESET_ON_ASSERT < 2 - if (!up_interrupt_context() && running_task()->flink != NULL) + if (!up_interrupt_context() && rtcb->flink != NULL) { panic_notifier_call_chain(PANIC_TASK, NULL); } @@ -498,8 +507,8 @@ void _assert(FAR const char *filename, int linenum) #ifdef CONFIG_SMP # if CONFIG_TASK_NAME_SIZE > 0 _alert("Assertion failed CPU%d at file: %s:%d task: %s %p\n", - up_cpu_index(), filename, linenum, running_task()->name, - running_task()->entry.main); + up_cpu_index(), filename, linenum, rtcb->name, + rtcb->entry.main); # else _alert("Assertion failed CPU%d at file: %s:%d\n", up_cpu_index(), filename, linenum); @@ -507,24 +516,13 @@ void _assert(FAR const char *filename, int linenum) #else # if CONFIG_TASK_NAME_SIZE > 0 _alert("Assertion failed at file: %s:%d task: %s %p\n", - filename, linenum, running_task()->name, - running_task()->entry.main); + filename, linenum, rtcb->name, rtcb->entry.main); # else _alert("Assertion failed at file: %s:%d\n", filename, linenum); # endif #endif -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, linenum); -#endif - /* Flush any buffered SYSLOG data (from the above) */ syslog_flush(); @@ -532,10 +530,20 @@ void _assert(FAR const char *filename, int linenum) /* Show back trace */ #ifdef CONFIG_SCHED_BACKTRACE - sched_dumpstack(running_task()->pid); + sched_dumpstack(rtcb->pid); #endif - up_assert(); + /* Register dump */ + + if (up_interrupt_context()) + { + up_dump_register(NULL); + } + else + { + up_saveusercontext(g_last_regs); + up_dump_register(g_last_regs); + } #ifdef CONFIG_ARCH_STACKDUMP showstacks(); @@ -543,5 +551,15 @@ void _assert(FAR const char *filename, int linenum) showtasks(); +#ifdef CONFIG_ARCH_USBDUMP + /* Dump USB trace data */ + + usbtrace_enumerate(assert_tracecallback, NULL); +#endif + +#ifdef CONFIG_BOARD_CRASHDUMP + board_crashdump(up_getsp(), rtcb, filename, linenum); +#endif + assert_end(); } diff --git a/tools/minidumpserver.py b/tools/minidumpserver.py index 091c58e2c4..96102034c9 100755 --- a/tools/minidumpserver.py +++ b/tools/minidumpserver.py @@ -214,7 +214,7 @@ class dump_log_file: if line == "": break - tmp = re.search(r"([^ ]*)_registerdump:?", line) + tmp = re.search("up_dump_register:", line) if tmp is not None: # find arch self.arch = tmp.group(1)