From eb2422ed76ebb3076f9006ea6ed7df471c2ed749 Mon Sep 17 00:00:00 2001 From: Wayne Ren Date: Thu, 26 Sep 2019 21:40:42 +0800 Subject: [PATCH] arch: arc: enlarge the exception handling stack after recent changes in zephyr's fault handling, e.g. use log to repace printk, it requires more stack to exception handling, or the stack overflow may happen and crash the system. this commit adds a kconfig option for exception stack size with a larger default size. Signed-off-by: Wayne Ren --- arch/arc/Kconfig | 9 +++++++++ arch/arc/core/fault_s.S | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index 243605e0cd0..99dfa552e9d 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -280,6 +280,15 @@ config CACHE_FLUSHING If the d-cache is present, set this to y. If the d-cache is NOT present, set this to n. +config ARC_EXCEPTION_STACK_SIZE + int "ARC exception handling stack size" + default 768 + help + Size in bytes of exception handling stack which is at the top of + interrupt stack to get smaller memory footprint because exception + is not frequent. To reduce the impact on interrupt handling, + especially nested interrupt, it cannot be too large. + endmenu config ARC_EXCEPTION_DEBUG diff --git a/arch/arc/core/fault_s.S b/arch/arc/core/fault_s.S index 1f537129f3e..e3e719498d8 100644 --- a/arch/arc/core/fault_s.S +++ b/arch/arc/core/fault_s.S @@ -38,8 +38,17 @@ GTEXT(__ev_maligned) GTEXT(z_irq_do_offload); #endif -/* the necessary stack size for exception handling */ -#define EXCEPTION_STACK_SIZE 384 + +/* + * The exception handling will use top part of interrupt stack to + * get smaller memory footprint, because exception is not frequent. + * To reduce the impact on interrupt handling, especially nested interrupt + * the top part of interrupt stack cannot be too large, so add a check + * here + */ +#if CONFIG_ARC_EXCEPTION_STACK_SIZE > (CONFIG_ISR_STACK_SIZE >> 1) +#error "interrupt stack size is too small" +#endif /* * @brief Fault handler installed in the fault and reserved vectors @@ -67,7 +76,7 @@ _exc_entry: */ mov_s ilink, sp _get_curr_cpu_irq_stack sp - sub sp, sp, (CONFIG_ISR_STACK_SIZE - EXCEPTION_STACK_SIZE) + sub sp, sp, (CONFIG_ISR_STACK_SIZE - CONFIG_ARC_EXCEPTION_STACK_SIZE) /* * save caller saved registers