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: [u8; 4], // Align hhdm_offset to 8-byte boundary
39    pub hhdm_offset: u64,
40    /// Pointer to the kernel command line string (null-terminated C string).
41    pub cmdline_ptr: u64,
42    /// Length of the kernel command line string (including null terminator).
43    pub cmdline_len: u64,
44}
45
46/// Memory region descriptor for the bootloader memory map.
47#[derive(Debug, Clone, Copy, FromBytes, IntoBytes)]
48#[repr(C)]
49pub struct MemoryRegion {
50    pub base: u64,
51    pub size: u64,
52    pub kind: MemoryKind,
53}
54
55/// Memory region type identifier.
56///
57/// Used by the bootloader to communicate the memory map to the kernel.
58#[derive(Clone, Copy, Debug, PartialEq, Eq, FromBytes, IntoBytes)]
59#[repr(transparent)]
60pub struct MemoryKind(pub u64);
61
62#[allow(non_upper_case_globals)]
63impl MemoryKind {
64    pub const Null: Self = Self(0);
65    pub const Free: Self = Self(1);
66    pub const Reclaim: Self = Self(2);
67    pub const Reserved: Self = Self(3);
68}
69
70// ABI size assertions for bootloader structures
71static_assertions::assert_eq_size!(KernelArgs, [u8; 160]);
72static_assertions::const_assert_eq!(core::mem::align_of::<KernelArgs>(), 8);
73static_assertions::assert_eq_size!(MemoryRegion, [u8; 24]);
74static_assertions::const_assert_eq!(core::mem::align_of::<MemoryRegion>(), 8);
75static_assertions::assert_eq_size!(MemoryKind, [u8; 8]);