summaryrefslogtreecommitdiff
path: root/startup
diff options
context:
space:
mode:
Diffstat (limited to 'startup')
-rw-r--r--startup/SConscript12
-rw-r--r--startup/riscv_reset_handler.cpp11
2 files changed, 23 insertions, 0 deletions
diff --git a/startup/SConscript b/startup/SConscript
new file mode 100644
index 0000000..971f9fa
--- /dev/null
+++ b/startup/SConscript
@@ -0,0 +1,12 @@
+Import('env')
+
+sources = [
+ File('entry.cpp'),
+]
+
+startup = env['PLATFORM_SPEC'].get('startup', [])
+
+for file in startup:
+ sources.append(File(f'{file}.cpp'))
+
+Return('sources')
diff --git a/startup/riscv_reset_handler.cpp b/startup/riscv_reset_handler.cpp
new file mode 100644
index 0000000..0eed06d
--- /dev/null
+++ b/startup/riscv_reset_handler.cpp
@@ -0,0 +1,11 @@
+void entry();
+extern int _ram_end;
+
+[[gnu::naked]]
+[[gnu::section(".vectors")]]
+void _reset_handler() {
+ // Initialize stack pointer.
+ asm volatile("lui sp, %%hi(%0); add sp, sp, %%lo(%0)" :: "i"(&_ram_end));
+ // Absolute jump to entry function.
+ asm volatile("jr %0" :: "m"(entry));
+}