aboutsummaryrefslogtreecommitdiff
path: root/prog/src/startup.c
diff options
context:
space:
mode:
authorFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-20 16:48:55 +0200
committerFlavian Kaufmann <flavian@flaviankaufmann.ch>2024-05-20 16:48:55 +0200
commite945c80a6ceaef501350de49bf647ae8539d1cbb (patch)
tree9e698d839e5f6221af523b49be04b809648efeb9 /prog/src/startup.c
parent142510b8325b9ef89bd3e22463f36c3caa2815de (diff)
downloadriscv_cpu-e945c80a6ceaef501350de49bf647ae8539d1cbb.tar.gz
riscv_cpu-e945c80a6ceaef501350de49bf647ae8539d1cbb.zip
reset synchronizer
Diffstat (limited to 'prog/src/startup.c')
-rw-r--r--prog/src/startup.c39
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);
+}