From 76a029e88dc247887427adec31cceb591baedddf Mon Sep 17 00:00:00 2001 From: ccli8 Date: Wed, 16 Jan 2019 13:18:35 +0800 Subject: [PATCH] [M2351] Support initializing multiple .data/.bss sections with GCC_ARM --- .../device/TOOLCHAIN_GCC_ARM/M2351.ld | 17 +++++ .../TARGET_M2351/device/startup_M2351.c | 64 +++++++++++++------ 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/device/TOOLCHAIN_GCC_ARM/M2351.ld b/targets/TARGET_NUVOTON/TARGET_M2351/device/TOOLCHAIN_GCC_ARM/M2351.ld index 602937ed2c..a2cabacb6c 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/device/TOOLCHAIN_GCC_ARM/M2351.ld +++ b/targets/TARGET_NUVOTON/TARGET_M2351/device/TOOLCHAIN_GCC_ARM/M2351.ld @@ -150,6 +150,23 @@ SECTIONS . = ALIGN(8); } > VECTORS + .copy.table : ALIGN(4) + { + __copy_table_start__ = .; + LONG (LOADADDR(.data)) + LONG (ADDR(.data)) + LONG (SIZEOF(.data)) + __copy_table_end__ = .; + } > FLASH + + .zero.table : ALIGN(4) + { + __zero_table_start__ = .; + LONG (ADDR(.bss)) + LONG (SIZEOF(.bss)) + __zero_table_end__ = .; + } > FLASH + .text : { *(.text*) diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c b/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c index 59d06bc78c..eed259956f 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c @@ -55,11 +55,10 @@ extern void __main(void); void __iar_program_start(void); #elif defined(__GNUC__) extern uint32_t __StackTop; -extern uint32_t __etext; -extern uint32_t __data_start__; -extern uint32_t __data_end__; -extern uint32_t __bss_start__; -extern uint32_t __bss_end__; +extern uint32_t __copy_table_start__; +extern uint32_t __copy_table_end__; +extern uint32_t __zero_table_start__; +extern uint32_t __zero_table_end__; #if defined(TOOLCHAIN_GCC_ARM) extern void _start(void); @@ -350,26 +349,51 @@ void Reset_Handler(void) __iar_program_start(); #elif defined(__GNUC__) - uint32_t *src_ind = (uint32_t *) &__etext; - uint32_t *dst_ind = (uint32_t *) &__data_start__; - uint32_t *dst_end = (uint32_t *) &__data_end__; + /* Move (multiple) .data section(s) from ROM to RAM */ + { + /* Struct of copy table entry which must match linker script */ + typedef struct copy_table_entry_ { + uint32_t src; // Address to copy from + uint32_t dst; // Address to copy to + uint32_t size; // Copy size in bytes + } copy_table_entry; - /* Move .data section from ROM to RAM */ - if (src_ind != dst_ind) { - for (; dst_ind < dst_end;) { - *dst_ind ++ = *src_ind ++; + copy_table_entry *copy_table_ind = (copy_table_entry *) &__copy_table_start__; + copy_table_entry *copy_table_end = (copy_table_entry *) &__copy_table_end__; + + for (; copy_table_ind != copy_table_end; copy_table_ind ++) { + uint32_t *src_ind = (uint32_t *) copy_table_ind->src; + uint32_t *src_end = (uint32_t *) (copy_table_ind->src + copy_table_ind->size); + uint32_t *dst_ind = (uint32_t *) copy_table_ind->dst; + if (src_ind != dst_ind) { + for (; src_ind < src_end;) { + *dst_ind ++ = *src_ind ++; + } + } } } - - /* Initialize .bss section to zero */ - dst_ind = (uint32_t *) &__bss_start__; - dst_end = (uint32_t *) &__bss_end__; - if (dst_ind != dst_end) { - for (; dst_ind < dst_end;) { - *dst_ind ++ = 0; + + /* Initialize (multiple) .bss sections to zero */ + { + /* Struct of zero table entry which must match linker script */ + typedef struct zero_table_entry_ { + uint32_t start; // Address to start zero'ing + uint32_t size; // Zero size in bytes + } zero_table_entry; + + zero_table_entry *zero_table_ind = (zero_table_entry *) &__zero_table_start__; + zero_table_entry *zero_table_end = (zero_table_entry *) &__zero_table_end__; + + for (; zero_table_ind != zero_table_end; zero_table_ind ++) { + uint32_t *dst_ind = (uint32_t *) zero_table_ind->start; + uint32_t *dst_end = (uint32_t *) (zero_table_ind->start + zero_table_ind->size); + + for (; dst_ind < dst_end; ) { + *dst_ind ++ = 0; + } } } - + _start(); #endif