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