diff options
author | xengineering <me@xengineering.eu> | 2021-09-25 15:47:25 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2021-09-26 12:33:08 +0200 |
commit | 7211bd49452e67e0b53ea06ca474f4e54af991ae (patch) | |
tree | 2de4b48926830ea29b8ba1f670aedbb4945f4e1d /src/startup.c | |
parent | 3eaf47ee2144f2abf781c10194f920a799aebb3a (diff) | |
download | ledcontrol-7211bd49452e67e0b53ea06ca474f4e54af991ae.tar ledcontrol-7211bd49452e67e0b53ea06ca474f4e54af991ae.tar.zst ledcontrol-7211bd49452e67e0b53ea06ca474f4e54af991ae.zip |
Implement Linker Script and Startup File
Diffstat (limited to 'src/startup.c')
-rw-r--r-- | src/startup.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/startup.c b/src/startup.c new file mode 100644 index 0000000..b71a805 --- /dev/null +++ b/src/startup.c @@ -0,0 +1,50 @@ + + +#define STACK_TOP 0x20005000 + + +extern unsigned int _BSS_START; +extern unsigned int _BSS_END; +extern unsigned int _DATA_ROM_START; +extern unsigned int _DATA_RAM_START; +extern unsigned int _DATA_RAM_END; + +void startup(); +void main(); + +// Define the vector table +unsigned int * myvectors[2] +__attribute__ ((section("vectors")))= { + (unsigned int *) STACK_TOP, // stack pointer + (unsigned int *) startup // code entry point +}; + +void startup() +{ + /* Set memory in bss segment to zeros */ + unsigned int * bss_start_p = &_BSS_START; + unsigned int * bss_end_p = &_BSS_END; + + while(bss_start_p != bss_end_p) + { + *bss_start_p = 0; + bss_start_p++; + } + + /* Copy memory in data segment from its position + * in the flash image to its position in the + * read/write memory */ + unsigned int * data_rom_start_p = &_DATA_ROM_START; + unsigned int * data_ram_start_p = &_DATA_RAM_START; + unsigned int * data_ram_end_p = &_DATA_RAM_END; + + while(data_ram_start_p != data_ram_end_p) + { + *data_ram_start_p = *data_rom_start_p; + data_ram_start_p++; + data_rom_start_p++; + } + + /* Now we are ready to start the main function */ + main(); +} |