@@ -55,11 +55,10 @@ extern void __main(void);
5555void __iar_program_start (void );
5656#elif defined(__GNUC__ )
5757extern uint32_t __StackTop ;
58- extern uint32_t __etext ;
59- extern uint32_t __data_start__ ;
60- extern uint32_t __data_end__ ;
61- extern uint32_t __bss_start__ ;
62- extern uint32_t __bss_end__ ;
58+ extern uint32_t __copy_table_start__ ;
59+ extern uint32_t __copy_table_end__ ;
60+ extern uint32_t __zero_table_start__ ;
61+ extern uint32_t __zero_table_end__ ;
6362
6463#if defined(TOOLCHAIN_GCC_ARM )
6564extern void _start (void );
@@ -350,26 +349,51 @@ void Reset_Handler(void)
350349 __iar_program_start ();
351350
352351#elif defined(__GNUC__ )
353- uint32_t * src_ind = (uint32_t * ) & __etext ;
354- uint32_t * dst_ind = (uint32_t * ) & __data_start__ ;
355- uint32_t * dst_end = (uint32_t * ) & __data_end__ ;
356-
357- /* Move .data section from ROM to RAM */
358- if (src_ind != dst_ind ) {
359- for (; dst_ind < dst_end ;) {
360- * dst_ind ++ = * src_ind ++ ;
352+ /* Move (multiple) .data section(s) from ROM to RAM */
353+ {
354+ /* Struct of copy table entry which must match linker script */
355+ typedef struct copy_table_entry_ {
356+ uint32_t src ; // Address to copy from
357+ uint32_t dst ; // Address to copy to
358+ uint32_t size ; // Copy size in bytes
359+ } copy_table_entry ;
360+
361+ copy_table_entry * copy_table_ind = (copy_table_entry * ) & __copy_table_start__ ;
362+ copy_table_entry * copy_table_end = (copy_table_entry * ) & __copy_table_end__ ;
363+
364+ for (; copy_table_ind != copy_table_end ; copy_table_ind ++ ) {
365+ uint32_t * src_ind = (uint32_t * ) copy_table_ind -> src ;
366+ uint32_t * src_end = (uint32_t * ) (copy_table_ind -> src + copy_table_ind -> size );
367+ uint32_t * dst_ind = (uint32_t * ) copy_table_ind -> dst ;
368+ if (src_ind != dst_ind ) {
369+ for (; src_ind < src_end ;) {
370+ * dst_ind ++ = * src_ind ++ ;
371+ }
372+ }
361373 }
362374 }
363-
364- /* Initialize .bss section to zero */
365- dst_ind = (uint32_t * ) & __bss_start__ ;
366- dst_end = (uint32_t * ) & __bss_end__ ;
367- if (dst_ind != dst_end ) {
368- for (; dst_ind < dst_end ;) {
369- * dst_ind ++ = 0 ;
375+
376+ /* Initialize (multiple) .bss sections to zero */
377+ {
378+ /* Struct of zero table entry which must match linker script */
379+ typedef struct zero_table_entry_ {
380+ uint32_t start ; // Address to start zero'ing
381+ uint32_t size ; // Zero size in bytes
382+ } zero_table_entry ;
383+
384+ zero_table_entry * zero_table_ind = (zero_table_entry * ) & __zero_table_start__ ;
385+ zero_table_entry * zero_table_end = (zero_table_entry * ) & __zero_table_end__ ;
386+
387+ for (; zero_table_ind != zero_table_end ; zero_table_ind ++ ) {
388+ uint32_t * dst_ind = (uint32_t * ) zero_table_ind -> start ;
389+ uint32_t * dst_end = (uint32_t * ) (zero_table_ind -> start + zero_table_ind -> size );
390+
391+ for (; dst_ind < dst_end ; ) {
392+ * dst_ind ++ = 0 ;
393+ }
370394 }
371395 }
372-
396+
373397 _start ();
374398
375399#endif
0 commit comments