Merge pull request #1075 from bthebaudeau/cc2538-data-bss-init

cc2538: Fix and improve .data/.bss initialization
This commit is contained in:
George Oikonomou 2015-05-23 18:50:57 +01:00
commit deb3ea4e9c
2 changed files with 16 additions and 22 deletions

View file

@ -85,12 +85,13 @@ SECTIONS
*(.udma_channel_control_table) *(.udma_channel_control_table)
} > SRAM } > SRAM
.data : .data : ALIGN(4)
{ {
_data = .; _data = .;
*(.data*) *(.data*)
_edata = .; _edata = .;
} > SRAM AT > FLASH } > SRAM AT > FLASH
_ldata = LOADADDR(.data);
.ARM.exidx : .ARM.exidx :
{ {
@ -105,6 +106,11 @@ SECTIONS
_ebss = .; _ebss = .;
} > SRAM } > SRAM
.stack (NOLOAD) :
{
*(.stack)
} > SRAM
#if (LPM_CONF_MAX_PM==2) && (LPM_CONF_ENABLE != 0) #if (LPM_CONF_MAX_PM==2) && (LPM_CONF_ENABLE != 0)
.nrdata (NOLOAD) : .nrdata (NOLOAD) :
{ {

View file

@ -40,6 +40,7 @@
#include "reg.h" #include "reg.h"
#include "flash-cca.h" #include "flash-cca.h"
#include "sys-ctrl.h" #include "sys-ctrl.h"
#include "rom-util.h"
#include <stdint.h> #include <stdint.h>
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -89,7 +90,7 @@ void uart1_isr(void) WEAK_ALIAS(default_handler);
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Allocate stack space */ /* Allocate stack space */
static unsigned long stack[512]; static unsigned long stack[512] __attribute__ ((section(".stack")));
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Linker construct indicating .text section location */ /* Linker construct indicating .text section location */
extern uint8_t _text[0]; extern uint8_t _text[0];
@ -275,11 +276,11 @@ void(*const vectors[])(void) =
}; };
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Linker constructs indicating .data and .bss segment locations */ /* Linker constructs indicating .data and .bss segment locations */
extern unsigned long _etext; extern uint8_t _ldata;
extern unsigned long _data; extern uint8_t _data;
extern unsigned long _edata; extern uint8_t _edata;
extern unsigned long _bss; extern uint8_t _bss;
extern unsigned long _ebss; extern uint8_t _ebss;
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Weak interrupt handlers. */ /* Weak interrupt handlers. */
void void
@ -298,26 +299,13 @@ default_handler(void)
void void
reset_handler(void) reset_handler(void)
{ {
unsigned long *pul_src, *pul_dst;
REG(SYS_CTRL_EMUOVR) = 0xFF; REG(SYS_CTRL_EMUOVR) = 0xFF;
/* Copy the data segment initializers from flash to SRAM. */ /* Copy the data segment initializers from flash to SRAM. */
pul_src = &_etext; rom_util_memcpy(&_data, &_ldata, &_edata - &_data);
for(pul_dst = &_data; pul_dst < &_edata;) {
*pul_dst++ = *pul_src++;
}
/* Zero-fill the bss segment. */ /* Zero-fill the bss segment. */
__asm(" ldr r0, =_bss\n" rom_util_memset(&_bss, 0, &_ebss - &_bss);
" ldr r1, =_ebss\n"
" mov r2, #0\n"
" .thumb_func\n"
"zero_loop:\n"
" cmp r0, r1\n"
" it lt\n"
" strlt r2, [r0], #4\n" " blt zero_loop");
/* call the application's entry point. */ /* call the application's entry point. */
main(); main();