limine_proc/lib.rs
1extern crate proc_macro;
2
3use proc_macro::TokenStream;
4
5/// Adds the limine request to the `.limine_reqs` section.
6///
7/// ## Note
8/// If the executable kernel file contains a `.limine_reqs` section, the bootloader
9/// will, instead of scanning the executable for requests, fetch the requests from
10/// a NULL-terminated array of pointers to the provided requests, contained inside
11/// said section.
12#[proc_macro_attribute]
13pub fn limine_tag(_: TokenStream, item: TokenStream) -> TokenStream {
14 let input = syn::parse_macro_input!(item as syn::ItemStatic);
15
16 let typ = input.ty.clone();
17 let name = input.ident.clone();
18 let ptr_name = quote::format_ident!("{name}_PTR");
19
20 quote::quote! {
21 #input
22
23 const _: () = {
24 // Limine expects a NULL-terminated array of pointers to the provided requests.
25 #[used]
26 #[link_section = ".limine_reqs"]
27 static #ptr_name: &#typ = &#name;
28 };
29 }
30 .into()
31}