diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-12-12 21:41:55 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-12-12 21:41:55 -0700 |
commit | 8bb2d168044213ce9bd31a19efb6bab90f5c9722 (patch) | |
tree | 737ba66cd1405fb4aa9ac5df9415b2ea5d88ab20 /src/init/core.rs | |
parent | ef3a1919ce5c87179e8f1d7a3b1b835151fdf50f (diff) | |
download | stm32l4-rust-8bb2d168044213ce9bd31a19efb6bab90f5c9722.tar.gz stm32l4-rust-8bb2d168044213ce9bd31a19efb6bab90f5c9722.tar.bz2 stm32l4-rust-8bb2d168044213ce9bd31a19efb6bab90f5c9722.zip |
Create an init system.
Diffstat (limited to 'src/init/core.rs')
-rw-r--r-- | src/init/core.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/init/core.rs b/src/init/core.rs new file mode 100644 index 0000000..51f1e6a --- /dev/null +++ b/src/init/core.rs @@ -0,0 +1,29 @@ +#[link_section = ".on_reset"] +#[no_mangle] +pub static __RESET_VECTOR: fn() -> ! = on_reset; + +/** + * The init sections are run. The order in which they are run is deterined by the name of the + * section the pointer to the function is located in. By convention the section name is 'inits.nnn' + * where 'nnn' is a number from 000-999. + */ +fn run_init_sections() -> () { + extern "C" { + static mut _sinits: extern "C" fn() -> (); + static mut _einits: extern "C" fn() -> (); + } + unsafe { + let mut cursor: *mut extern "C" fn() -> () = &mut _sinits; + let einits_end: *mut extern "C" fn() -> () = &mut _einits; + + while cursor < einits_end { + cursor.read()(); + cursor = cursor.offset(1); + } + } +} + +fn on_reset() -> ! { + run_init_sections(); + loop {} +} |