1use core::ptr::read_volatile;
2
3use crate::early_println;
4
5#[macro_export]
6macro_rules! early_initcall {
7 ($func:ident) => {
8 #[unsafe(link_section = ".initcall.early")]
9 #[used(linker)]
10 static __EARLY_INITCALL__: fn() = $func;
11 };
12}
13
14unsafe extern "C" {
15 static __INITCALL_EARLY_START: usize;
16 static __INITCALL_EARLY_END: usize;
17}
18
19pub fn early_initcall_call() {
20 unsafe {
21 let size = core::mem::size_of::<fn()>();
22
23 early_println!("Running early initcalls... ");
24 let mut func_addr = &__INITCALL_EARLY_START as *const usize as usize;
25 let end_addr = &__INITCALL_EARLY_END as *const usize as usize;
26
27 while func_addr < end_addr {
28 let initcall = read_volatile(func_addr as *const fn());
29
30 initcall();
31
32 func_addr += size;
33 }
34 }
35}