I successfully wrote a bare metal C program which is running on my STM32F4. It's nothing fancy, just the usual led-blinky-program. In this project I have written the initialization routines which is clearing the .bss
section and initializing the .data
section myself.
This wasn't really complicated. In the linker script, I just instructed the linker to create some symbols which are marking the start and the end of the .data
and .bss
section.
.data 0x20001000 :
ALIGN(4)
{
__etext = LOADADDR(.data);
__data_start__ = ADDR(.data) ;
*(.data*) ;
__data_end__ = ADDR(.data) + SIZEOF(.data) ;
} >RAM AT>ROM
.bss :
ALIGN(4)
{
__bss_start__ = ADDR(.bss) ;
*(.bss*) ;
__bss_end__ = ADDR(.bss) + SIZEOF(.bss) ;
} >RAM
Then I was using these symbols in my code:
extern unsigned int __etext;
extern unsigned int __data_start__;
extern unsigned int __data_end__;
extern unsigned int __bss_start__;
extern unsigned int __bss_end__;
void Reset_Handler()
{
unsigned int * src;
unsigned int * dest;
src = &__etext;
dest = &__data_start__;
/* copy .data */
while (dest < &__data_end__)
*(dest++) = *(src++);
/* Zero bss. */
for (dest = &__bss_start__; dest < &__bss_end__; dest++)
*dest = 0;
}
Now I would like to use the crt0
for the purpose of setting-up .bss
and .data
. (I heard setting up things is the main purpose of crt0
.)
How can I do that? Is the basic principle of defining symbols in the linker script and using the in the code the same?
TL;DR
How can I use crt0
to setup my .bss
and .data
section?