summaryrefslogtreecommitdiff
path: root/src/init/core.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/init/core.rs')
-rw-r--r--src/init/core.rs29
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 {}
+}