diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2022-09-10 20:18:42 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2022-09-10 20:18:42 +0200 |
commit | 23a2994e051488561294050993f16162f24a85e7 (patch) | |
tree | 521ca72c19d7db7ee65beb2051b9843b3deb5a0c | |
parent | 51c91e98efc5a6ae1ee59f3fff44971a60c7f94d (diff) |
startup: Add RISC-V reset handler.
-rw-r--r-- | SConscript | 2 | ||||
-rw-r--r-- | platforms/riscv.yaml | 5 | ||||
-rw-r--r-- | startup/SConscript | 12 | ||||
-rw-r--r-- | startup/riscv_reset_handler.cpp | 11 |
4 files changed, 28 insertions, 2 deletions
@@ -22,7 +22,7 @@ env.Append( env.SConscript('usb/SConscript'), env.SConscript('display/SConscript'), env.SConscript('wpan/SConscript'), - Glob('startup/*.cpp'), + env.SConscript('startup/SConscript'), Glob('os/*.cpp'), ], ) diff --git a/platforms/riscv.yaml b/platforms/riscv.yaml index 16db64b..f66a3ef 100644 --- a/platforms/riscv.yaml +++ b/platforms/riscv.yaml @@ -33,7 +33,10 @@ 8: UEI 9: SEI 11: MEI - + + startup: + - riscv_reset_handler + toolchains: - riscv64-unknown-elf 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)); +} |