From 0382b63f5d925dd56ec306e1dc9b036a8914d4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E6=98=95?= Date: Wed, 7 Dec 2022 12:27:56 +0800 Subject: [PATCH] move common assert logic together. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 田昕 --- arch/arm/src/common/arm_assert.c | 128 -------------------- arch/arm64/src/common/arm64_assert.c | 133 --------------------- arch/arm64/src/common/arm64_initialize.c | 32 +++++ arch/avr/src/common/avr_assert.c | 119 ------------------- arch/ceva/src/common/ceva_assert.c | 123 -------------------- arch/hc/src/m9s12/m9s12_assert.c | 112 ------------------ arch/mips/src/mips32/mips_assert.c | 118 ------------------- arch/misoc/src/lm32/lm32_assert.c | 123 -------------------- arch/misoc/src/minerva/minerva_assert.c | 122 ------------------- arch/or1k/src/common/or1k_assert.c | 113 ------------------ arch/renesas/src/common/renesas_assert.c | 121 ------------------- arch/risc-v/src/common/riscv_assert.c | 138 ---------------------- arch/sim/src/sim/sim_assert.c | 34 ------ arch/sparc/src/common/sparc_assert.c | 127 -------------------- arch/x86/src/common/x86_assert.c | 113 ------------------ arch/x86_64/src/common/x86_64_assert.c | 116 ------------------ arch/xtensa/src/common/xtensa_assert.c | 101 ---------------- arch/z16/src/common/z16_assert.c | 123 -------------------- arch/z80/src/common/z80_assert.c | 124 -------------------- include/nuttx/panic_notifier.h | 87 ++++++++++++++ sched/misc/Make.defs | 2 +- sched/misc/assert.c | 142 +++++++++++++++++++++++ sched/misc/panic.c | 88 ++++++++++++++ 23 files changed, 350 insertions(+), 2089 deletions(-) create mode 100644 include/nuttx/panic_notifier.h create mode 100644 sched/misc/panic.c diff --git a/arch/arm/src/common/arm_assert.c b/arch/arm/src/common/arm_assert.c index 881d412118..9f1ee94885 100644 --- a/arch/arm/src/common/arm_assert.c +++ b/arch/arm/src/common/arm_assert.c @@ -26,37 +26,17 @@ #include #include -#include -#include #include -#include #include #include #include -#include -#include #include #include "sched/sched.h" -#include "irq/irq.h" #include "arm_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - #ifdef CONFIG_ARCH_STACKDUMP /**************************************************************************** @@ -77,10 +57,6 @@ static void arm_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; - /* Flush any buffered SYSLOG data to avoid overwrite */ - - syslog_flush(); - for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; @@ -313,30 +289,6 @@ static void arm_showtasks(void) #endif } -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Name: arm_dump_stack ****************************************************************************/ @@ -460,54 +412,6 @@ static void arm_dumpstate(void) } #endif /* CONFIG_ARCH_STACKDUMP */ -/**************************************************************************** - * Name: arm_assert - ****************************************************************************/ - -static void arm_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (CURRENT_REGS || (running_task())->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - /* Disable interrupts on this CPU */ - - up_irq_save(); - -#ifdef CONFIG_SMP - /* Try (again) to stop activity on other CPUs */ - - spin_trylock(&g_cpu_irqlock); -#endif - - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - /* FLASH LEDs a 2Hz */ - - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -520,39 +424,7 @@ void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - /* Flush any buffered SYSLOG data (prior to the assertion) */ - - syslog_flush(); - - _alert("Assertion failed " -#ifdef CONFIG_SMP - "CPU%d " -#endif - "at file:%s line: %d" -#if CONFIG_TASK_NAME_SIZE > 0 - " task: %s" -#endif - "\n", -#ifdef CONFIG_SMP - up_cpu_index(), -#endif - filename, lineno -#if CONFIG_TASK_NAME_SIZE > 0 - , running_task()->name -#endif - ); - #ifdef CONFIG_ARCH_STACKDUMP arm_dumpstate(); #endif - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - arm_assert(); } diff --git a/arch/arm64/src/common/arm64_assert.c b/arch/arm64/src/common/arm64_assert.c index 7544357c9c..b7c7346012 100644 --- a/arch/arm64/src/common/arm64_assert.c +++ b/arch/arm64/src/common/arm64_assert.c @@ -26,18 +26,10 @@ #include #include -#include -#include #include -#include #include -#include -#include -#include -#include "sched/sched.h" -#include "irq/irq.h" #include "arm64_arch.h" #include "arm64_internal.h" #include "chip.h" @@ -46,20 +38,6 @@ #include "arm64_fpu.h" #endif -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - /**************************************************************************** * Name: arm_registerdump ****************************************************************************/ @@ -124,10 +102,6 @@ static void arm64_stackdump(uint64_t sp, uint64_t stack_top) { uint64_t stack; - /* Flush any buffered SYSLOG data to avoid overwrite */ - - syslog_flush(); - for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 64) { uint64_t *ptr = (uint64_t *)stack; @@ -333,30 +307,6 @@ static void arm64_showtasks(void) #endif } -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Name: arm_dump_stack ****************************************************************************/ @@ -458,12 +408,6 @@ static void arm64_dumpstate_assert(void) /* Dump the state of all tasks (if available) */ arm64_showtasks(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif } #endif /* CONFIG_ARCH_STACKDUMP */ @@ -500,47 +444,6 @@ void up_mdelay(unsigned int milliseconds) } } -/**************************************************************************** - * Name: arm64_assert - ****************************************************************************/ - -static void arm64_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (CURRENT_REGS || (running_task())->flink == NULL) - { - #if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - /* Disable interrupts on this CPU */ - - up_irq_save(); - -#ifdef CONFIG_SMP - /* Try (again) to stop activity on other CPUs */ - - spin_trylock(&g_cpu_irqlock); -#endif - - for (; ; ) - { - up_mdelay(250); - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -551,43 +454,7 @@ static void arm64_assert(void) void up_assert(const char *filename, int lineno) { -#ifdef CONFIG_ARCH_FPU - arm64_fpu_disable(); -#endif - - /* Flush any buffered SYSLOG data (prior to the assertion) */ - - syslog_flush(); - - _alert("Assertion failed " -#ifdef CONFIG_SMP - "CPU%d " -#endif - "at file:%s line: %d" -#if CONFIG_TASK_NAME_SIZE > 0 - " task: %s" -#endif - "\n", -#ifdef CONFIG_SMP - up_cpu_index(), -#endif - filename, lineno -#if CONFIG_TASK_NAME_SIZE > 0 - , running_task()->name -#endif - ); - #ifdef CONFIG_ARCH_STACKDUMP arm64_dumpstate_assert(); #endif - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - arm64_assert(); } diff --git a/arch/arm64/src/common/arm64_initialize.c b/arch/arm64/src/common/arm64_initialize.c index af3047af24..25179a8ce3 100644 --- a/arch/arm64/src/common/arm64_initialize.c +++ b/arch/arm64/src/common/arm64_initialize.c @@ -34,10 +34,15 @@ #include #include #include +#include #include #include #include "arm64_arch.h" + +#ifdef CONFIG_ARCH_FPU +#include "arm64_fpu.h" +#endif #include "arm64_internal.h" #include "chip.h" @@ -57,6 +62,10 @@ volatile uint64_t *g_current_regs[CONFIG_SMP_NCPUS]; +#ifdef CONFIG_ARCH_FPU +static struct notifier_block g_fpu_panic_block; +#endif + #ifdef CONFIG_SMP INIT_STACK_ARRAY_DEFINE(g_cpu_idlestackalloc, CONFIG_SMP_NCPUS, SMP_STACK_SIZE); @@ -127,6 +136,23 @@ static void up_color_intstack(void) # define up_color_intstack() #endif +/**************************************************************************** + * Name: arm64_panic_disable_fpu + * + * Description: + * This is called when panic to close fpu. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_FPU +int arm64_panic_disable_fpu(struct notifier_block *this, + unsigned long action, void *data) +{ + arm64_fpu_disable(); + return 0; +} +#endif + /**************************************************************************** * Name: up_initialize * @@ -187,4 +213,10 @@ void up_initialize(void) arm64_usbinitialize(); #endif + +#ifdef CONFIG_ARCH_FPU + g_fpu_panic_block.notifier_call = arm64_panic_disable_fpu; + g_fpu_panic_block.priority = INT_MAX; + panic_notifier_chain_register(&g_fpu_panic_block); +#endif } diff --git a/arch/avr/src/common/avr_assert.c b/arch/avr/src/common/avr_assert.c index 61b9393551..a23dce264e 100644 --- a/arch/avr/src/common/avr_assert.c +++ b/arch/avr/src/common/avr_assert.c @@ -23,102 +23,12 @@ ****************************************************************************/ #include - -#include -#include -#include -#include - -#include -#include #include -#include -#include #include -#include "sched/sched.h" #include "avr_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (g_current_regs || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(FAR const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -130,34 +40,5 @@ static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - avr_dumpstate(); - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - - _up_assert(); } diff --git a/arch/ceva/src/common/ceva_assert.c b/arch/ceva/src/common/ceva_assert.c index 1eda27c3ac..daf304a6f6 100644 --- a/arch/ceva/src/common/ceva_assert.c +++ b/arch/ceva/src/common/ceva_assert.c @@ -24,31 +24,13 @@ #include -#include #include #include -#include -#include #include "sched/sched.h" -#include "irq/irq.h" #include "ceva_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - /**************************************************************************** * Private Data ****************************************************************************/ @@ -151,30 +133,6 @@ static inline void up_registerdump(void) # define up_registerdump() #endif -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, &ap); - va_end(ap); - return 0; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Name: up_dumpstate ****************************************************************************/ @@ -272,56 +230,11 @@ static void up_dumpstate(void) /* Dump the state of all tasks (if available) */ up_showtasks(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif } #else # define up_dumpstate() #endif -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(int errorcode) noreturn_function; -static void _up_assert(int errorcode) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (up_interrupt_context() || sched_idletask()) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - -#ifdef CONFIG_SMP - /* Try (again) to stop activity on other CPUs */ - - spin_trylock(&g_cpu_irqlock); -#endif - - for (; ; ) - { - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -332,41 +245,5 @@ static void _up_assert(int errorcode) void up_assert(const uint8_t *filename, int lineno) { -#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_DEBUG_ALERT) - struct tcb_s *rtcb = running_task(); -#endif - - /* Flush any buffered SYSLOG data (prior to the assertion) */ - - syslog_flush(); - -#ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed CPU%d at file:%s line: %d task: %s\n", - up_cpu_index(), filename, lineno, rtcb->name); -#else - _alert("Assertion failed CPU%d at file:%s line: %d\n", - up_cpu_index(), filename, lineno); -#endif -#else -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, rtcb->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif -#endif - up_dumpstate(); - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - _up_assert(EXIT_FAILURE); } diff --git a/arch/hc/src/m9s12/m9s12_assert.c b/arch/hc/src/m9s12/m9s12_assert.c index b328353db8..4afe9297ab 100644 --- a/arch/hc/src/m9s12/m9s12_assert.c +++ b/arch/hc/src/m9s12/m9s12_assert.c @@ -25,35 +25,17 @@ #include #include -#include -#include #include #include #include #include -#include -#include #include #include "sched/sched.h" #include "hc_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - /**************************************************************************** * Private Data ****************************************************************************/ @@ -75,10 +57,6 @@ static void hc_stackdump(uint16_t sp, uint16_t stack_top) { uint16_t stack; - /* Flush any buffered SYSLOG data to avoid overwrite */ - - syslog_flush(); - for (stack = sp & ~0x7; stack < (stack_top & ~0x7); stack += 8) { uint8_t *ptr = (uint8_t *)stack; @@ -134,30 +112,6 @@ static inline void hc_registerdump(void) } #endif -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(FAR const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Name: up_dumpstate ****************************************************************************/ @@ -243,54 +197,11 @@ static void up_dumpstate(void) _alert("ERROR: Stack pointer is not within allocated stack\n"); hc_stackdump(ustackbase, ustackbase + ustacksize); } - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif } #else # define up_dumpstate() #endif -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (g_current_regs || (running_task())->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -302,28 +213,5 @@ static void _up_assert(void) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - up_dumpstate(); - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - _up_assert(); } diff --git a/arch/mips/src/mips32/mips_assert.c b/arch/mips/src/mips32/mips_assert.c index d88cf31d86..1e9ec7fe92 100644 --- a/arch/mips/src/mips32/mips_assert.c +++ b/arch/mips/src/mips32/mips_assert.c @@ -24,101 +24,12 @@ #include -#include -#include -#include -#include - -#include -#include #include -#include -#include #include -#include "sched/sched.h" #include "mips_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (CURRENT_REGS || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -130,34 +41,5 @@ static int assert_tracecallback(struct usbtrace_s *trace, void *arg) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - mips_dumpstate(); - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#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, lineno); -#endif - - _up_assert(); } diff --git a/arch/misoc/src/lm32/lm32_assert.c b/arch/misoc/src/lm32/lm32_assert.c index 1f6035078e..f570529885 100644 --- a/arch/misoc/src/lm32/lm32_assert.c +++ b/arch/misoc/src/lm32/lm32_assert.c @@ -24,106 +24,12 @@ #include -#include -#include -#include -#include - -#include -#include #include -#include -#include #include -#include "sched/sched.h" #include "lm32.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? - * NOTE: You cannot use the PID to determine if this is an IDLE task. In - * the SMP case, there may be multiple IDLE tasks with different PIDs. The - * only consistent way to test for the IDLE task is to check it is at the - * end of the list (flink == NULL) - */ - - if (g_current_regs || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -135,34 +41,5 @@ static int assert_tracecallback(struct usbtrace_s *trace, void *arg) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - lm32_dumpstate(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - _up_assert(); } diff --git a/arch/misoc/src/minerva/minerva_assert.c b/arch/misoc/src/minerva/minerva_assert.c index 61e520ed93..e427abe919 100644 --- a/arch/misoc/src/minerva/minerva_assert.c +++ b/arch/misoc/src/minerva/minerva_assert.c @@ -24,106 +24,12 @@ #include -#include -#include -#include -#include - -#include -#include #include -#include -#include #include -#include "sched/sched.h" #include "minerva.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? NOTE: You cannot use - * the PID to determine if this is an IDLE task. In the SMP case, there - * may be multiple IDLE tasks with different PIDs. The only consistent - * way to test for the IDLE task is to check it is at the end of the list - * (flink == NULL) - */ - - if (g_current_regs || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -135,33 +41,5 @@ static int assert_tracecallback(struct usbtrace_s *trace, void *arg) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", filename, lineno); -#endif - minerva_dumpstate(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - _up_assert(); } diff --git a/arch/or1k/src/common/or1k_assert.c b/arch/or1k/src/common/or1k_assert.c index 3b6d9782c6..068a8f9763 100644 --- a/arch/or1k/src/common/or1k_assert.c +++ b/arch/or1k/src/common/or1k_assert.c @@ -25,35 +25,17 @@ #include #include -#include -#include #include #include #include #include -#include -#include #include #include "sched/sched.h" #include "or1k_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - /**************************************************************************** * Private Data ****************************************************************************/ @@ -75,10 +57,6 @@ static void or1k_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; - /* Flush any buffered SYSLOG data to avoid overwrite */ - - syslog_flush(); - for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; @@ -162,31 +140,6 @@ static inline void or1k_registerdump(void) } #endif -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - int ret; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - ret = vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return ret; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Name: up_dumpstate ****************************************************************************/ @@ -287,54 +240,11 @@ static void up_dumpstate(void) /* Dump the state of all tasks (if available) */ up_showtasks(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif } #else # define up_dumpstate() #endif -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (CURRENT_REGS || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -346,28 +256,5 @@ static void _up_assert(void) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - up_dumpstate(); - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - _up_assert(); } diff --git a/arch/renesas/src/common/renesas_assert.c b/arch/renesas/src/common/renesas_assert.c index ea776412d6..919b3cb884 100644 --- a/arch/renesas/src/common/renesas_assert.c +++ b/arch/renesas/src/common/renesas_assert.c @@ -24,103 +24,11 @@ #include -#include -#include -#include -#include - -#include -#include #include #include -#include -#include - -#include - -#include "sched/sched.h" #include "renesas_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (g_current_regs || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(FAR const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -132,34 +40,5 @@ static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - renesas_dumpstate(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - _up_assert(); } diff --git a/arch/risc-v/src/common/riscv_assert.c b/arch/risc-v/src/common/riscv_assert.c index f0a72bf849..b684fc1419 100644 --- a/arch/risc-v/src/common/riscv_assert.c +++ b/arch/risc-v/src/common/riscv_assert.c @@ -26,39 +26,17 @@ #include #include -#include -#include #include -#include - -#include #include #include #include -#include -#include #include #include "sched/sched.h" -#include "irq/irq.h" #include "riscv_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -83,10 +61,6 @@ static void riscv_stackdump(uintptr_t sp, uintptr_t stack_top) { uintptr_t stack; - /* Flush any buffered SYSLOG data to avoid overwrite */ - - syslog_flush(); - for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; @@ -422,73 +396,6 @@ static void riscv_dumpstate(void) # define riscv_dumpstate() #endif /* CONFIG_ARCH_STACKDUMP */ -/**************************************************************************** - * Name: riscv_assert - ****************************************************************************/ - -static void riscv_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (CURRENT_REGS || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - -#ifdef CONFIG_SMP - /* Try (again) to stop activity on other CPUs */ - - spin_trylock(&g_cpu_irqlock); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -500,54 +407,9 @@ static int assert_tracecallback(struct usbtrace_s *trace, void *arg) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed CPU%d at file:%s line: %d task: %s\n", - up_cpu_index(), filename, lineno, running_task()->name); -#else - _alert("Assertion failed CPU%d at file:%s line: %d\n", - up_cpu_index(), filename, lineno); -#endif -#else -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif -#endif - riscv_dumpstate(); -#ifdef CONFIG_SMP - /* Show the CPU number */ - - _alert("CPU%d:\n", up_cpu_index()); -#endif - /* Dump the state of all tasks (if available) */ riscv_showtasks(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - riscv_assert(); } diff --git a/arch/sim/src/sim/sim_assert.c b/arch/sim/src/sim/sim_assert.c index a9be25ba5f..fb498918f3 100644 --- a/arch/sim/src/sim/sim_assert.c +++ b/arch/sim/src/sim/sim_assert.c @@ -75,30 +75,6 @@ void up_assert(const char *filename, int lineno) { struct tcb_s *rtcb = running_task(); - /* Flush any buffered SYSLOG data (prior to the assertion) */ - - syslog_flush(); - - /* Show the location of the failed assertion */ - -#ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed CPU%d at file:%s line: %d task: %s\n", - up_cpu_index(), filename, lineno, rtcb->name); -#else - _alert("Assertion failed CPU%d at file:%s line: %d\n", - up_cpu_index(), filename, lineno); -#endif -#else -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, rtcb->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif -#endif - /* Show back trace */ #ifdef CONFIG_SCHED_BACKTRACE @@ -109,16 +85,6 @@ void up_assert(const char *filename, int lineno) syslog_flush(); - /* Allow for any board/configuration specific crash information */ - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), rtcb, filename, lineno); -#endif - - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - if (CURRENT_REGS || is_idle_task(rtcb)) { /* Exit the simulation */ diff --git a/arch/sparc/src/common/sparc_assert.c b/arch/sparc/src/common/sparc_assert.c index b0b2826312..c86e8e587b 100644 --- a/arch/sparc/src/common/sparc_assert.c +++ b/arch/sparc/src/common/sparc_assert.c @@ -24,103 +24,8 @@ #include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include "sched/sched.h" #include "sparc_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(int errorcode) noreturn_function; -static void _up_assert(int errorcode) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (CURRENT_REGS || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - exit(errorcode); - } -} - -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, &ap); - va_end(ap); - return 0; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -131,37 +36,5 @@ static int assert_tracecallback(struct usbtrace_s *trace, void *arg) void up_assert(const char *filename, int lineno) { -#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_DEBUG_ALERT) - struct tcb_s *rtcb = running_task(); -#endif - - /* Flush any buffered SYSLOG data (prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, rtcb->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - sparc_dumpstate(); - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - - _up_assert(EXIT_FAILURE); } diff --git a/arch/x86/src/common/x86_assert.c b/arch/x86/src/common/x86_assert.c index d20d3b7f7c..982515353b 100644 --- a/arch/x86/src/common/x86_assert.c +++ b/arch/x86/src/common/x86_assert.c @@ -25,36 +25,17 @@ #include #include -#include -#include #include #include #include #include -#include -#include -#include #include #include "sched/sched.h" #include "x86_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - /**************************************************************************** * Private Data ****************************************************************************/ @@ -76,10 +57,6 @@ static void x86_stackdump(uint32_t sp, uint32_t stack_top) { uint32_t stack; - /* Flush any buffered SYSLOG data to avoid overwrite */ - - syslog_flush(); - for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; @@ -90,30 +67,6 @@ static void x86_stackdump(uint32_t sp, uint32_t stack_top) } #endif -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Name: x86_dumpstate ****************************************************************************/ @@ -209,54 +162,11 @@ static void x86_dumpstate(void) _alert("ERROR: Stack pointer is not within allocated stack\n"); x86_stackdump(ustackbase, ustackbase + ustacksize); } - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif } #else # define x86_dumpstate() #endif -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (g_current_regs || (running_task())->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -268,28 +178,5 @@ static void _up_assert(void) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - x86_dumpstate(); - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - _up_assert(); } diff --git a/arch/x86_64/src/common/x86_64_assert.c b/arch/x86_64/src/common/x86_64_assert.c index 92de529b69..e6602dc6cb 100644 --- a/arch/x86_64/src/common/x86_64_assert.c +++ b/arch/x86_64/src/common/x86_64_assert.c @@ -25,36 +25,16 @@ #include #include -#include -#include #include #include -#include #include -#include -#include -#include #include #include "sched/sched.h" #include "x86_64_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -68,10 +48,6 @@ static void x86_64_stackdump(uint64_t sp, uint64_t stack_top) { uint64_t stack; - /* Flush any buffered SYSLOG data to avoid overwrite */ - - syslog_flush(); - for (stack = sp & ~0x1f; stack < (stack_top & ~0x1f); stack += 32) { uint32_t *ptr = (uint32_t *)stack; @@ -84,30 +60,6 @@ static void x86_64_stackdump(uint64_t sp, uint64_t stack_top) } #endif -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Name: x86_64_dumpstate ****************************************************************************/ @@ -196,56 +148,11 @@ static void x86_64_dumpstate(void) { x86_64_registerdump((uint64_t *)g_current_regs); } - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif } #else # define x86_64_dumpstate() #endif -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (g_current_regs || (running_task())->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { - /* Assertions in other contexts only cause the thread to exit */ - -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -257,28 +164,5 @@ static void _up_assert(void) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - x86_64_dumpstate(); - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), this_task(), filename, lineno); -#endif - - _up_assert(); } diff --git a/arch/xtensa/src/common/xtensa_assert.c b/arch/xtensa/src/common/xtensa_assert.c index 9c46dd50b8..6034cdc9ae 100644 --- a/arch/xtensa/src/common/xtensa_assert.c +++ b/arch/xtensa/src/common/xtensa_assert.c @@ -25,63 +25,21 @@ #include #include -#include -#include #include #include -#include #include #include -#include #include #include "sched/sched.h" #include "xtensa.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Name: xtensa_assert ****************************************************************************/ @@ -91,52 +49,6 @@ static void xtensa_assert(void) /* Dump the processor state */ xtensa_dumpstate(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - -#ifdef CONFIG_BOARD_CRASHDUMP - /* Perform board-specific crash dump */ - - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (CURRENT_REGS || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - /* Blink the LEDs forever */ - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { - /* Assertions in other contexts only cause the thread to exit */ - -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } } /**************************************************************************** @@ -150,19 +62,6 @@ static void xtensa_assert(void) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - xtensa_assert(); } diff --git a/arch/z16/src/common/z16_assert.c b/arch/z16/src/common/z16_assert.c index ffe6081157..0554c17fcd 100644 --- a/arch/z16/src/common/z16_assert.c +++ b/arch/z16/src/common/z16_assert.c @@ -24,102 +24,8 @@ #include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -#include "chip.h" -#include "sched/sched.h" #include "z16_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (up_interrupt_context() || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(FAR const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) -{ - usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); - return 0; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -131,35 +37,6 @@ static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) void up_assert(const char *filename, int lineno) { board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - z16_registerdump(); z16_stackdump(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - _up_assert(); } diff --git a/arch/z80/src/common/z80_assert.c b/arch/z80/src/common/z80_assert.c index 8312e0fb6d..b9b1069157 100644 --- a/arch/z80/src/common/z80_assert.c +++ b/arch/z80/src/common/z80_assert.c @@ -24,100 +24,8 @@ #include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "chip.h" -#include "sched/sched.h" #include "z80_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* USB trace dumping */ - -#ifndef CONFIG_USBDEV_TRACE -# undef CONFIG_ARCH_USBDUMP -#endif - -#ifndef CONFIG_BOARD_RESET_ON_ASSERT -# define CONFIG_BOARD_RESET_ON_ASSERT 0 -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: _up_assert - ****************************************************************************/ - -static void _up_assert(void) -{ - /* Flush any buffered SYSLOG data */ - - syslog_flush(); - - /* Are we in an interrupt handler or the idle task? */ - - if (up_interrupt_context() || running_task()->flink == NULL) - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - - up_irq_save(); - for (; ; ) - { -#ifdef CONFIG_ARCH_LEDS - board_autoled_on(LED_PANIC); - up_mdelay(250); - board_autoled_off(LED_PANIC); - up_mdelay(250); -#endif - } - } - else - { -#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 - board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); -#endif - } -} - -/**************************************************************************** - * Name: assert_tracecallback - ****************************************************************************/ - -#ifdef CONFIG_ARCH_USBDUMP -static int usbtrace_syslog(FAR const char *fmt, ...) -{ - va_list ap; - - /* Let vsyslog do the real work */ - - va_start(ap, fmt); - vsyslog(LOG_EMERG, fmt, ap); - va_end(ap); - return OK; -} - -static int assert_tracecallback(struct usbtrace_s *trace, void *arg) -{ - usbtrace_trprintf(FAR usbtrace_syslog, trace->event, FAR trace->value); - return 0; -} -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -128,38 +36,6 @@ static int assert_tracecallback(struct usbtrace_s *trace, void *arg) void up_assert(const char *filename, int lineno) { - board_autoled_on(LED_ASSERTION); - - /* Flush any buffered SYSLOG data (from prior to the assertion) */ - - syslog_flush(); - -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Assertion failed at file:%s line: %d task: %s\n", - filename, lineno, running_task()->name); -#else - _alert("Assertion failed at file:%s line: %d\n", - filename, lineno); -#endif - Z80_REGISTER_DUMP(); z80_stackdump(); - -#ifdef CONFIG_ARCH_USBDUMP - /* Dump USB trace data */ - - usbtrace_enumerate(assert_tracecallback, NULL); -#endif - - /* Flush any buffered SYSLOG data (from the above) */ - - syslog_flush(); - -#ifdef CONFIG_BOARD_CRASHDUMP - /* Execute board-specific crash dump logic */ - - board_crashdump(up_getsp(), running_task(), filename, lineno); -#endif - - _up_assert(); } diff --git a/include/nuttx/panic_notifier.h b/include/nuttx/panic_notifier.h new file mode 100644 index 0000000000..b2e4e131de --- /dev/null +++ b/include/nuttx/panic_notifier.h @@ -0,0 +1,87 @@ +/**************************************************************************** + * include/nuttx/panic_notifier.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_PANIC_NOTIFIER_H +#define __INCLUDE_NUTTX_PANIC_NOTIFIER_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +enum panic_type_e +{ + PANIC_KERNEL = 0, + PANIC_TASK = 1, +}; + +/**************************************************************************** + * Public Function + ****************************************************************************/ + +/**************************************************************************** + * Name: panic_notifier_chain_register + * + * Description: + * Add notifier to the panic notifier chain + * + * Input Parameters: + * nb - New entry in notifier chain + * + ****************************************************************************/ + +void panic_notifier_chain_register(FAR struct notifier_block *nb); + +/**************************************************************************** + * Name: panic_notifier_chain_unregister + * + * Description: + * Remove notifier from the panic notifier chain + * + * Input Parameters: + * nb - Entry to remove from notifier chain + * + ****************************************************************************/ + +void panic_notifier_chain_unregister(FAR struct notifier_block *nb); + +/**************************************************************************** + * Name: panic_notifier_call_chain + * + * Description: + * Call functions in the panic notifier chain. + * + * Input Parameters: + * action - Value passed unmodified to notifier function + * data - Pointer passed unmodified to notifier function + * + ****************************************************************************/ + +void panic_notifier_call_chain(unsigned long action, FAR void *data); + +#endif /* __INCLUDE_NUTTX_PANIC_NOTIFIER_H */ diff --git a/sched/misc/Make.defs b/sched/misc/Make.defs index 82436c8e52..b781dd3332 100644 --- a/sched/misc/Make.defs +++ b/sched/misc/Make.defs @@ -18,7 +18,7 @@ # ############################################################################ -CSRCS += assert.c +CSRCS += assert.c panic.c # Include init build support diff --git a/sched/misc/assert.c b/sched/misc/assert.c index f1d9999849..e9865a7738 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -22,17 +22,159 @@ * Included Files ****************************************************************************/ +#include + #include +#include +#include +#include +#include +#include #include +#include #include +#include "irq/irq.h" +#include "sched/sched.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_BOARD_RESET_ON_ASSERT +# define CONFIG_BOARD_RESET_ON_ASSERT 0 +#endif + +/* USB trace dumping */ + +#ifndef CONFIG_USBDEV_TRACE +# undef CONFIG_ARCH_USBDUMP +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: assert_tracecallback + ****************************************************************************/ + +#ifdef CONFIG_ARCH_USBDUMP +static int usbtrace_syslog(FAR const char *fmt, ...) +{ + va_list ap; + + /* Let vsyslog do the real work */ + + va_start(ap, fmt); + vsyslog(LOG_EMERG, fmt, ap); + va_end(ap); + return OK; +} + +static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) +{ + usbtrace_trprintf(usbtrace_syslog, trace->event, trace->value); + return 0; +} +#endif + +/**************************************************************************** + * Name: assert_end + ****************************************************************************/ + +static void assert_end(void) +{ + /* Flush any buffered SYSLOG data */ + + syslog_flush(); + + /* Are we in an interrupt handler or the idle task? */ + + if (up_interrupt_context() || running_task()->flink == NULL) + { +#if CONFIG_BOARD_RESET_ON_ASSERT >= 1 + board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); +#endif + + /* Disable interrupts on this CPU */ + + up_irq_save(); + +#ifdef CONFIG_SMP + /* Try (again) to stop activity on other CPUs */ + + spin_trylock(&g_cpu_irqlock); +#endif + + for (; ; ) + { + up_mdelay(250); + } + } + else + { +#if CONFIG_BOARD_RESET_ON_ASSERT >= 2 + board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); +#endif + } +} + /**************************************************************************** * Public Functions ****************************************************************************/ void _assert(FAR const char *filename, int linenum) { + /* 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) + { + panic_notifier_call_chain(PANIC_TASK, NULL); + } + else +#endif + { + panic_notifier_call_chain(PANIC_KERNEL, NULL); + } + +#ifdef CONFIG_SMP +# if CONFIG_TASK_NAME_SIZE > 0 + _alert("Assertion failed CPU%d at file:%s line: %d task: %s\n", + up_cpu_index(), filename, linenum, running_task()->name); +# else + _alert("Assertion failed CPU%d at file:%s line: %d\n", + up_cpu_index(), filename, linenum); +# endif +#else +# if CONFIG_TASK_NAME_SIZE > 0 + _alert("Assertion failed at file:%s line: %d task: %s\n", + filename, linenum, running_task()->name); +# else + _alert("Assertion failed at file:%s line: %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(); + up_assert(filename, linenum); + assert_end(); exit(EXIT_FAILURE); } diff --git a/sched/misc/panic.c b/sched/misc/panic.c new file mode 100644 index 0000000000..31c02ed96f --- /dev/null +++ b/sched/misc/panic.c @@ -0,0 +1,88 @@ +/**************************************************************************** + * sched/misc/panic.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 + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static ATOMIC_NOTIFIER_HEAD(g_panic_notifier_list); + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: panic_notifier_chain_register + * + * Description: + * Add notifier to the panic notifier chain + * + * Input Parameters: + * nb - New entry in notifier chain + * + ****************************************************************************/ + +void panic_notifier_chain_register(FAR struct notifier_block *nb) +{ + atomic_notifier_chain_register(&g_panic_notifier_list, nb); +} + +/**************************************************************************** + * Name: panic_notifier_chain_unregister + * + * Description: + * Remove notifier from the panic notifier chain + * + * Input Parameters: + * nb - Entry to remove from notifier chain + * + ****************************************************************************/ + +void panic_notifier_chain_unregister(FAR struct notifier_block *nb) +{ + atomic_notifier_chain_unregister(&g_panic_notifier_list, nb); +} + +/**************************************************************************** + * Name: panic_notifier_call_chain + * + * Description: + * Call functions in the panic notifier chain. + * + * Input Parameters: + * action - Value passed unmodified to notifier function + * data - Pointer passed unmodified to notifier function + * + ****************************************************************************/ + +void panic_notifier_call_chain(unsigned long action, FAR void *data) +{ + atomic_notifier_call_chain(&g_panic_notifier_list, action, data); +} +