8000 Add an entry_point macro · rust-osdev/bootloader@15f8699 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 15f8699

Browse files
committed
Add an entry_point macro
1 parent 0a41cf2 commit 15f8699
8000

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
#![no_std]
22

33
pub extern crate os_bootinfo as bootinfo;
4+
5+
/// Defines the entry point function.
6+
///
7+
/// The function must have the signature `fn(&'static BootInfo) -> !`.
8+
///
9+
/// This macro just creates a function named `_start`, which the linker will use as the entry
10+
/// point. The advantage of using this macro instead of providing an own `_start` function is
11+
/// that the macro ensures that the function and argument types are correct.
12+
#[macro_export]
13+
macro_rules! entry_point {
14+
($path:path) => {
15+
#[export_name = "_start"]
16+
pub extern "C" fn __impl_start(boot_info: &'static $crate::bootinfo::BootInfo) -> ! {
17+
// validate the signature of the program entry point
18+
let f: fn(&'static $crate::bootinfo::BootInfo) -> ! = $path;
19+
20+
f(boot_info)
21+
}
22+
};
23+
}

0 commit comments

Comments
 (0)
0