From c41976f23ce5b7c9d81ef3c3159b5b3cc37859d2 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 23 Mar 2014 10:09:53 -0600 Subject: [PATCH] Clean-up AVR stack colorization logic --- arch/avr/Kconfig | 1 + arch/avr/src/avr/up_createstack.c | 2 +- arch/avr/src/avr/up_usestack.c | 2 +- arch/avr/src/avr32/up_createstack.c | 2 +- arch/avr/src/avr32/up_usestack.c | 8 ++++++++ arch/avr/src/common/up_internal.h | 8 ++++++++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/avr/Kconfig b/arch/avr/Kconfig index 7e4b74a54c..917653fdce 100644 --- a/arch/avr/Kconfig +++ b/arch/avr/Kconfig @@ -32,6 +32,7 @@ endchoice config ARCH_FAMILY_AVR bool default n + select ARCH_HAVE_STACKCHECK config ARCH_FAMILY_AVR32 bool diff --git a/arch/avr/src/avr/up_createstack.c b/arch/avr/src/avr/up_createstack.c index e82473ef09..5212131261 100644 --- a/arch/avr/src/avr/up_createstack.c +++ b/arch/avr/src/avr/up_createstack.c @@ -170,7 +170,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) */ #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) - memset(tcb->stack_alloc_ptr, 0xaa, stack_size); + memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size); #endif /* The AVR uses a push-down stack: the stack grows toward lower diff --git a/arch/avr/src/avr/up_usestack.c b/arch/avr/src/avr/up_usestack.c index 629ad6cf02..cb19ed241b 100644 --- a/arch/avr/src/avr/up_usestack.c +++ b/arch/avr/src/avr/up_usestack.c @@ -112,7 +112,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) */ #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) - memset(tcb->stack_alloc_ptr, 0xaa, stack_size); + memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size); #endif /* The AVR uses a push-down stack: the stack grows toward loweraddresses in diff --git a/arch/avr/src/avr32/up_createstack.c b/arch/avr/src/avr32/up_createstack.c index f6e1ab635c..f9968d5551 100644 --- a/arch/avr/src/avr32/up_createstack.c +++ b/arch/avr/src/avr32/up_createstack.c @@ -170,7 +170,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) */ #if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) - memset(tcb->stack_alloc_ptr, 0xaa, stack_size); + memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size); #endif /* The AVR32 uses a push-down stack: the stack grows toward lower diff --git a/arch/avr/src/avr32/up_usestack.c b/arch/avr/src/avr32/up_usestack.c index e71be16e7e..f606ff3857 100644 --- a/arch/avr/src/avr32/up_usestack.c +++ b/arch/avr/src/avr32/up_usestack.c @@ -107,6 +107,14 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) tcb->stack_alloc_ptr = stack; + /* If stack debug is enabled, then fill the stack with a recognizable value + * that we can use later to test for high water marks. + */ + +#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_STACK) + memset(tcb->stack_alloc_ptr, STACK_COLOR, stack_size); +#endif + /* The AVR32 uses a push-down stack: the stack grows * toward loweraddresses in memory. The stack pointer * register, points to the lowest, valid work address diff --git a/arch/avr/src/common/up_internal.h b/arch/avr/src/common/up_internal.h index 77d75afeb8..75c9e5cb17 100644 --- a/arch/avr/src/common/up_internal.h +++ b/arch/avr/src/common/up_internal.h @@ -73,6 +73,14 @@ # define CONFIG_ARCH_INTERRUPTSTACK 0 #endif +/* This is the value used to mark the stack for subsequent stack monitoring + * logic. + */ + +#define STACK_COLOR 's' +#define INTSTACK_COLOR 's' +#define HEAP_COLOR 'h' + /**************************************************************************** * Public Types ****************************************************************************/