From cbcbaa0efe3d252cf3e6ec33b9c617d738aee565 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 9 Aug 2011 08:12:47 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3213 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/ports/GCC/ARMCMx/crt0.c | 84 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 16 deletions(-) (limited to 'os/ports/GCC/ARMCMx') diff --git a/os/ports/GCC/ARMCMx/crt0.c b/os/ports/GCC/ARMCMx/crt0.c index 73dca119e..6e4524fa9 100644 --- a/os/ports/GCC/ARMCMx/crt0.c +++ b/os/ports/GCC/ARMCMx/crt0.c @@ -25,7 +25,7 @@ * @{ */ -#include "chtypes.h" +#include #define FALSE 0 #define TRUE (!FALSE) @@ -39,45 +39,80 @@ typedef funcp_t * funcpp_t; * stack (dual stack mode). */ #if !defined(CRT0_CONTROL_INIT) || defined(__DOXYGEN__) -#define CRT0_CONTROL_INIT 0x00000002 +#define CRT0_CONTROL_INIT 0x00000002 +#endif + +/** + * @brief Stack segments initialization switch. + */ +#if !defined(CRT0_STACKS_FILL_PATTERN) || defined(__DOXYGEN__) +#define CRT0_STACKS_FILL_PATTERN 0x55555555 +#endif + +/** + * @brief Stack segments initialization switch. + */ +#if !defined(CRT0_INIT_STACKS) || defined(__DOXYGEN__) +#define CRT0_INIT_STACKS TRUE #endif /** * @brief DATA segment initialization switch. */ #if !defined(CRT0_INIT_DATA) || defined(__DOXYGEN__) -#define CRT0_INIT_DATA TRUE +#define CRT0_INIT_DATA TRUE #endif /** * @brief BSS segment initialization switch. */ #if !defined(CRT0_INIT_BSS) || defined(__DOXYGEN__) -#define CRT0_INIT_BSS TRUE +#define CRT0_INIT_BSS TRUE #endif /** * @brief Constructors invocation switch. */ #if !defined(CRT0_CALL_CONSTRUCTORS) || defined(__DOXYGEN__) -#define CRT0_CALL_CONSTRUCTORS TRUE +#define CRT0_CALL_CONSTRUCTORS TRUE #endif /** * @brief Destructors invocation switch. */ #if !defined(CRT0_CALL_DESTRUCTORS) || defined(__DOXYGEN__) -#define CRT0_CALL_DESTRUCTORS TRUE +#define CRT0_CALL_DESTRUCTORS TRUE #endif #define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0)) /** - * @brief Main thread stack initial position. + * @brief Main stack lower boundary. + * @details This symbol must be exported by the linker script and represents + * the main stack lower boundary. + */ +extern uint32_t __main_stack_base__; + +/** + * @brief Main stack initial position. + * @details This symbol must be exported by the linker script and represents + * the main stack initial position. + */ +extern uint32_t __main_stack_end__; + +/** + * @brief Process stack lower boundary. * @details This symbol must be exported by the linker script and represents - * the main thread stack initial position. + * the process stack lower boundary. */ -extern uint8_t __process_stack_end__; +extern uint32_t __process_stack_base__; + +/** + * @brief Process stack initial position. + * @details This symbol must be exported by the linker script and represents + * the process stack initial position. + */ +extern uint32_t __process_stack_end__; /** * @brief ROM image of the data segment start. @@ -176,6 +211,19 @@ void _default_exit(void) { ; } +/** + * @brief Memory fill. + * + * @param[in] start fill area start + * @param[in] end fill area end + * @param[in] filler filler pattern + */ +static void fill32(uint32_t *start, uint32_t *end, uint32_t filler) { + + while (start < end) + *start++ = filler; +} + /** * @brief Reset vector. */ @@ -199,6 +247,16 @@ void ResetHandler(void) { /* Early initialization hook invocation.*/ __early_init(); +#if CRT0_INIT_STACKS + /* Main and Process stacks initialization.*/ + fill32(&__main_stack_base__, + &__main_stack_end__, + CRT0_STACKS_FILL_PATTERN); + fill32(&__process_stack_base__, + &__process_stack_end__, + CRT0_STACKS_FILL_PATTERN); +#endif + #if CRT0_INIT_DATA /* DATA segment initialization.*/ { @@ -213,13 +271,7 @@ void ResetHandler(void) { #if CRT0_INIT_BSS /* BSS segment initialization.*/ - { - uint32_t *bp; - - bp = &_bss_start; - while (bp < &_bss_end) - *bp++ = 0; - } + fill32(&_bss_start, &_bss_end, 0); #endif /* Late initialization hook invocation.*/ -- cgit v1.2.3