diff options
Diffstat (limited to 'prog/src/startup.c')
-rw-r--r-- | prog/src/startup.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/prog/src/startup.c b/prog/src/startup.c new file mode 100644 index 0000000..32aa131 --- /dev/null +++ b/prog/src/startup.c @@ -0,0 +1,39 @@ +extern unsigned int _sidata; /* Start address for the .data section in ROM */ +extern unsigned int _sdata; /* Start address for the .data section in RAM */ +extern unsigned int _edata; /* End address for the .data section in RAM */ +extern unsigned int _sbss; /* Start address for the .bss section */ +extern unsigned int _ebss; /* End address for the .bss section */ +extern unsigned int _estack; /* End address for the stack section */ + +void main(void); /* The main function declaration */ +void _start(void) __attribute__((section(".text.startup"), naked)); /* The entry point */ + +void _start(void) +{ + unsigned int *src, *dest; + + /* Copy .data section from ROM to RAM */ + src = &_sidata; /* ROM address of the .data section */ + for (dest = &_sdata; dest < &_edata;) + { + *dest++ = *src++; + } + + //while(1); + + /* Zero initialize .bss section */ + for (dest = &_sbss; dest < &_ebss;) + { + *dest++ = 0; + } + + + /* Initialize stack pointer */ + asm volatile ("la sp, _estack"); + + /* Call the main function */ + main(); + + /* If main returns, loop forever */ + while (1); +} |