kernel/initcall/
early.rs

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