From 8bb2d168044213ce9bd31a19efb6bab90f5c9722 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Mon, 12 Dec 2022 21:41:55 -0700 Subject: Create an init system. --- src/init/core.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/init/core.rs (limited to 'src/init/core.rs') 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 {} +} -- cgit