Skip to main content

strat9_abi/
boot.rs

1use zerocopy::{FromBytes, IntoBytes};
2
3pub const STRAT9_BOOT_ABI_VERSION: u32 = 1;
4pub const STRAT9_BOOT_MAGIC: u32 = 0x5354_3942; // "ST9B"
5
6/// Bootloader-to-kernel handoff structure.
7///
8/// Passed by the bootloader to the kernel at entry point.
9/// Layout is `#[repr(C)]` for natural alignment across all fields.
10#[derive(Debug, FromBytes, IntoBytes)]
11#[repr(C)]
12pub struct KernelArgs {
13    pub magic: u32,
14    pub abi_version: u32,
15    pub kernel_base: u64,
16    pub kernel_size: u64,
17    pub stack_base: u64,
18    pub stack_size: u64,
19    pub env_base: u64,
20    pub env_size: u64,
21    pub acpi_rsdp_base: u64,
22    pub acpi_rsdp_size: u64,
23    pub memory_map_base: u64,
24    pub memory_map_size: u64,
25    pub initfs_base: u64,
26    pub initfs_size: u64,
27    pub framebuffer_addr: u64,
28    pub framebuffer_width: u32,
29    pub framebuffer_height: u32,
30    pub framebuffer_stride: u32,
31    pub framebuffer_bpp: u16,
32    pub framebuffer_red_mask_size: u8,
33    pub framebuffer_red_mask_shift: u8,
34    pub framebuffer_green_mask_size: u8,
35    pub framebuffer_green_mask_shift: u8,
36    pub framebuffer_blue_mask_size: u8,
37    pub framebuffer_blue_mask_shift: u8,
38    pub _padding1: u32,
39    pub hhdm_offset: u64,
40}
41
42/// Memory region descriptor for the bootloader memory map.
43#[derive(Debug, Clone, Copy, FromBytes, IntoBytes)]
44#[repr(C)]
45pub struct MemoryRegion {
46    pub base: u64,
47    pub size: u64,
48    pub kind: MemoryKind,
49}
50
51/// Memory region type identifier.
52///
53/// Used by the bootloader to communicate the memory map to the kernel.
54#[derive(Clone, Copy, Debug, PartialEq, Eq, FromBytes, IntoBytes)]
55#[repr(transparent)]
56pub struct MemoryKind(pub u64);
57
58#[allow(non_upper_case_globals)]
59impl MemoryKind {
60    pub const Null: Self = Self(0);
61    pub const Free: Self = Self(1);
62    pub const Reclaim: Self = Self(2);
63    pub const Reserved: Self = Self(3);
64}
65
66// ABI size assertions for bootloader structures
67static_assertions::assert_eq_size!(KernelArgs, [u8; 144]);
68static_assertions::const_assert_eq!(core::mem::align_of::<KernelArgs>(), 8);
69static_assertions::assert_eq_size!(MemoryRegion, [u8; 24]);
70static_assertions::const_assert_eq!(core::mem::align_of::<MemoryRegion>(), 8);
71static_assertions::assert_eq_size!(MemoryKind, [u8; 8]);