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```
9const REVISION: u64 = 4;
10
11#[used]
12#[unsafe(link_section = ".limine_reqs")]
13static LIMINE_BASE_REVISION: [u64; 4] = use_base_revision(4);
14
15#[used]
16#[unsafe(link_section = ".limine_req_start")]
17static LIMINE_REQUEST_START_MARKER: [u64; 4] = REQUEST_START_MARKER;
18
19#[used]
20#[unsafe(link_section = ".limine_reqs")]
21pub static MEMORY_MAP_REQUEST: MemoryMapRequest = MemoryMapRequest::new(REVISION);
22
23#[used]
24#[unsafe(link_section = ".limine_reqs")]
25pub static FRAMEBUFFER_REQUEST: FramebufferRequest = FramebufferRequest::new(REVISION);
26
27#[used]
28#[unsafe(link_section = ".limine_reqs")]
29pub static BOOTLOADER_INFO_REQUEST: BootloaderInfoRequest = BootloaderInfoRequest::new(REVISION);
30
31#[used]
32#[unsafe(link_section = ".limine_req_end")]
33static LIMINE_REQUEST_END_MARKER: [u64; 2] = REQUEST_END_MARKER;
34
35pub 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
50mod util;
51mod requests;
52
53pub const REQUEST_START_MARKER: [u64; 4] = [ 0xf6b8f4b39de7d1ae, 0xfab91a6940fcb9cf, 0x785c6ed015d3e316, 0x181e920a7852b9d9 ];
54pub const REQUEST_END_MARKER: [u64; 2] = [ 0xadc0e0531bb10d03, 0x9572709f31764c62 ];
55
56
57///Wrapper for the Limine Base Revision magic number
58pub const fn use_base_revision(revision: u64) -> [u64; 4]{
59    [ 0xf9562b2d5c95a6c8, 0x6a7b384944536bdc, revision, 0 ]
60}
61
62#[repr(C, align(8))]
63struct LimineReqId {
64    common_magic: [u64; 2],
65    other: [u64; 2]
66}
67
68impl LimineReqId {
69    const fn new(other: [u64; 2]) -> Self {
70        Self {
71            common_magic: [0xc7b1dd30df4c8b88, 0x0a82e883a194f07b],
72            other
73        }
74    }
75}
76