Skip to main content

somehal_macros/
lib.rs

1use proc_macro::TokenStream;
2
3mod _entry;
4
5/// Attribute to declare the entry point of the program
6///
7/// **IMPORTANT**: This attribute must appear exactly *once* in the dependency graph. Also, if you
8/// are using Rust 1.30 the attribute must be used on a reachable item (i.e. there must be no
9/// private modules between the item and the root of the crate); if the item is in the root of the
10/// crate you'll be fine. This reachability restriction doesn't apply to Rust 1.31 and newer releases.
11///
12/// The specified function will be called by the reset handler *after* RAM has been initialized.
13/// If present, the FPU will also be enabled before the function is called.
14///
15/// The type of the specified function must be `[unsafe] fn() -> !` (never ending function)
16///
17/// # 属性参数
18///
19/// 此宏**必需**接受一个内核类型参数:
20///
21/// - **参数**: 指定实现 `somehal::KernelOp` trait 的类型标识符
22/// - **行为**: 自动在函数开头插入 `somehal::init(&<type>)` 调用
23///
24/// # Properties
25///
26/// The entry point will be called by the reset handler. The program can't reference to the entry
27/// point, much less invoke it.
28///
29/// # Examples
30///
31/// - Entry point with kernel initialization
32///
33/// ```ignore
34/// # #![no_main]
35/// # use pie_boot::entry;
36/// # struct Kernel;
37/// # impl somehal::KernelOp for Kernel {
38/// #     fn ioremap(&self, paddr: usize, size: usize) -> somehal::PagingResult<*mut u8> {
39/// #         Ok(std::ptr::null_mut())
40/// #     }
41/// # }
42/// #[entry(Kernel)]
43/// fn main() -> ! {
44///     // somehal::init(&Kernel) 已自动生成
45///     loop { /* .. */ }
46/// }
47/// ```
48#[proc_macro_attribute]
49pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
50    _entry::entry(args, input, "__someboot_main")
51}
52
53/// Attribute to declare the secondary entry point of the program
54///
55/// # Examples
56///
57/// - Simple entry point
58///
59/// ```ignore
60/// # #![no_main]
61/// # use pie_boot::secondary_entry;
62/// #[entry]
63/// fn secondary(cpu_id: usize) -> ! {
64///     loop { /* .. */ }
65/// }
66/// ```
67#[proc_macro_attribute]
68pub fn someboot_secondary_entry(args: TokenStream, input: TokenStream) -> TokenStream {
69    _entry::entry_secondary(args, input, true)
70}
71
72/// Attribute to declare the secondary entry point of the program
73///
74/// # Examples
75///
76/// - Simple entry point
77///
78/// ```ignore
79/// # #![no_main]
80/// # use pie_boot::secondary_entry;
81/// #[entry]
82/// fn secondary(cpu_id: usize) -> ! {
83///     loop { /* .. */ }
84/// }
85/// ```
86#[proc_macro_attribute]
87pub fn somehal_secondary_entry(args: TokenStream, input: TokenStream) -> TokenStream {
88    _entry::entry_secondary(args, input, false)
89}