kernel_info/
boot.rs

1//! # Kerrnel Boot Information
2
3/// Kernel function pointer.
4///
5/// # ABI
6/// The ABI is defined as `win64` since the kernel is called from a UEFI
7/// (PE/COFF) application.
8pub type KernelEntryFn = extern "win64" fn(*const KernelBootInfo) -> !;
9
10/// Information the kernel needs right after `ExitBootServices`.
11/// Keep this `#[repr(C)]` and prefer fixed-size integers over `u64` at the ABI boundary.
12#[repr(C)]
13#[derive(Clone)]
14pub struct KernelBootInfo {
15    /// Memory map information.
16    pub mmap: MemoryMapInfo,
17
18    /// RSDP (ACPI 2.0+) physical address, or 0 if not provided.
19    pub rsdp_addr: u64,
20
21    /// Framebuffer information, passed from UEFI GOP.
22    pub fb: FramebufferInfo,
23}
24
25#[repr(C)]
26#[derive(Clone)]
27pub struct MemoryMapInfo {
28    /// Pointer to the raw UEFI memory map buffer (array of `EFI_MEMORY_DESCRIPTOR` bytes).
29    /// Pass 0 if you’re not handing the map to the kernel yet.
30    pub mmap_ptr: u64,
31
32    /// Length of the memory map buffer in **bytes**.
33    pub mmap_len: u64,
34
35    /// Size of a single memory descriptor in bytes (`EFI_MEMORY_DESCRIPTOR_VERSION` dependent).
36    pub mmap_desc_size: u64,
37
38    /// Descriptor version (from UEFI). Kernel can check it matches expectations.
39    pub mmap_desc_version: u32,
40}
41
42#[repr(C)]
43#[derive(Clone)]
44pub struct FramebufferInfo {
45    /// Linear framebuffer base address (CPU physical address). Valid to write after `ExitBootServices`.
46    pub framebuffer_ptr: u64,
47
48    /// Total framebuffer size in **bytes**. Helpful for bounds checks.
49    pub framebuffer_size: u64,
50
51    /// Visible width in **pixels**.
52    pub framebuffer_width: u64,
53
54    /// Visible height in **pixels**.
55    pub framebuffer_height: u64,
56
57    /// Pixels per scanline (a.k.a. stride). May be >= width due to padding.
58    pub framebuffer_stride: u64,
59
60    /// Pixel format tag (Rgb/Bgr/Bitmask/BltOnly). If `BltOnly`, you cannot draw directly.
61    pub framebuffer_format: BootPixelFormat,
62
63    /// Pixel bit masks (only meaningful when `framebuffer_format == Bitmask`).
64    pub framebuffer_masks: BootPixelMasks,
65}
66
67/// Pixel format tag compatible with UEFI GOP.
68/// We avoid Rust enums with payloads across the ABI boundary.
69#[repr(u32)]
70#[derive(Copy, Clone)]
71pub enum BootPixelFormat {
72    /// UEFI `PixelFormat::Rgb` — 8:8:8 (or bitmask-equivalent), stored as R,G,B in low-to-high bytes.
73    Rgb = 0,
74    /// UEFI `PixelFormat::Bgr` — 8:8:8 (or bitmask-equivalent), stored as B,G,R in low-to-high bytes.
75    Bgr = 1,
76    /// UEFI `PixelFormat::Bitmask(mask)` — see the masks in `BootPixelMasks`.
77    Bitmask = 2,
78    /// UEFI `PixelFormat::BltOnly` — **no linear framebuffer available** (you can’t draw).
79    BltOnly = 3,
80}
81
82/// Bit masks for `BootPixelFormat::Bitmask`.
83/// For `Rgb`/`Bgr`, these are set to zero.
84#[repr(C)]
85#[derive(Copy, Clone)]
86pub struct BootPixelMasks {
87    /// Mask of the red channel within a pixel (e.g., 0x00ff0000).
88    pub red_mask: u32,
89    /// Mask of the green channel within a pixel (e.g., 0x0000ff00).
90    pub green_mask: u32,
91    /// Mask of the blue channel within a pixel (e.g., 0x000000ff).
92    pub blue_mask: u32,
93    /// Mask of the alpha channel within a pixel (often 0x00000000 if opaque).
94    pub alpha_mask: u32,
95}