limine_protocol_for_rust/
lib.rs

1/*!
2This crate implements a couple of utilities for making something compatible with the Limine Boot Protocol.
3It serves as an equivalent to the *'limine.h'* file, along with some extra utilities for making response retrieval and reading provided data easier.
4
5For more information read [The Limine Boot Protocol](https://codeberg.org/Limine/limine-protocol/src/branch/trunk/PROTOCOL.md).
6
7Example Usage:
8```
9* const REVISION: u64 = 4;
10* 
11* #[used]
12* #[unsafe(link_section = ".limine_reqs")]
13* static LIMINE_BASE_REVISION: [u64; 4] = use_base_revision(REVISION);
14* 
15* #[used]
16* #[unsafe(link_section = ".limine_req_start")]
17* static LIMINE_REQUEST_START_MARKER: [u64; 4] = REQUEST_START_MARKER;
18* 
19* #[used]
20* #[unsafe(link_section = ".limine_reqs")]
21* pub static MEMORY_MAP_REQUEST: MemoryMapRequest = MemoryMapRequest::new(REVISION);
22* 
23* #[used]
24* #[unsafe(link_section = ".limine_reqs")]
25* pub static HHDM_REQUEST: HigherHalfDirectMapRequest = HigherHalfDirectMapRequest::new(REVISION);
26* 
27* #[used]
28* #[unsafe(link_section = ".limine_reqs")]
29* pub static FRAMEBUFFER_REQUEST: FramebufferRequest = FramebufferRequest::new(REVISION);
30* 
31* #[used]
32* #[unsafe(link_section = ".limine_req_end")]
33* static LIMINE_REQUEST_END_MARKER: [u64; 2] = REQUEST_END_MARKER;
34* 
35* pub fn kernel_main() -> ! {
36*     let bootloader_info_resp = BOOTLOADER_INFO_REQUEST.get_response().expect("BootloaderInfo request had no response");
37*     kprint!("Bootloader: {} {}",bootloader_info_resp.get_name(), bootloader_info_resp.get_version());
38* 
39*     let memory_map_resp = MEMORY_MAP_REQUEST.get_response().expect("Memory map request had no response");
40*     let memory_map = memory_map_resp.get_entries();
41* }
42* ```
43
44*/
45
46
47
48#![no_std]
49
50pub mod util;
51pub mod requests;
52pub mod file;
53
54pub const REQUEST_START_MARKER: [u64; 4] = [ 0xf6b8f4b39de7d1ae, 0xfab91a6940fcb9cf, 0x785c6ed015d3e316, 0x181e920a7852b9d9 ];
55pub const REQUEST_END_MARKER: [u64; 2] = [ 0xadc0e0531bb10d03, 0x9572709f31764c62 ];
56
57
58///Wrapper for the Limine Base Revision magic number
59pub const fn use_base_revision(revision: u64) -> [u64; 4]{
60    [ 0xf9562b2d5c95a6c8, 0x6a7b384944536bdc, revision, 0 ]
61}
62
63#[repr(C, align(8))]
64struct LimineReqId {
65    common_magic: [u64; 2],
66    other: [u64; 2]
67}
68
69impl LimineReqId {
70    const fn new(other: [u64; 2]) -> Self {
71        Self {
72            common_magic: [0xc7b1dd30df4c8b88, 0x0a82e883a194f07b],
73            other
74        }
75    }
76}
77