#[cfg(feature = "loader")]
mod loader;
#[cfg(feature = "kernel")]
mod kernel;
use core::fmt;
use core::num::{NonZeroU32, NonZeroU64};
use core::ops::Range;
use time::OffsetDateTime;
#[cfg(target_arch = "x86_64")]
pub type SerialPortBase = core::num::NonZeroU16;
#[cfg(target_arch = "aarch64")]
pub type SerialPortBase = core::num::NonZeroU64;
#[cfg(target_arch = "riscv64")]
pub type SerialPortBase = core::num::NonZeroU64;
pub type DeviceTreeAddress = core::num::NonZeroU64;
#[derive(Debug)]
pub struct BootInfo {
pub hardware_info: HardwareInfo,
pub load_info: LoadInfo,
pub platform_info: PlatformInfo,
}
#[derive(Debug)]
pub struct HardwareInfo {
pub phys_addr_range: Range<u64>,
pub serial_port_base: Option<SerialPortBase>,
pub device_tree: Option<DeviceTreeAddress>,
}
#[derive(Debug)]
pub struct LoadInfo {
pub kernel_image_addr_range: Range<u64>,
pub tls_info: Option<TlsInfo>,
}
#[derive(Debug)]
pub enum PlatformInfo {
#[cfg(target_arch = "x86_64")]
Multiboot {
command_line: Option<&'static str>,
multiboot_info_addr: core::num::NonZeroU64,
},
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
LinuxBoot,
Uhyve {
has_pci: bool,
num_cpus: NonZeroU64,
cpu_freq: Option<NonZeroU32>,
boot_time: OffsetDateTime,
},
LinuxBootParams {
command_line: Option<&'static str>,
boot_params_addr: core::num::NonZeroU64,
},
Fdt,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct TlsInfo {
pub start: u64,
pub filesz: u64,
pub memsz: u64,
pub align: u64,
}
impl fmt::Debug for TlsInfo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TlsInfo")
.field("start", &format_args!("{:#x}", self.start))
.field("filesz", &format_args!("{:#x}", self.filesz))
.field("memsz", &format_args!("{:#x}", self.memsz))
.field("align", &format_args!("{:#x}", self.align))
.finish()
}
}
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct RawBootInfo {
hardware_info: RawHardwareInfo,
load_info: RawLoadInfo,
platform_info: RawPlatformInfo,
}
#[derive(Clone, Copy, Debug)]
#[repr(C)]
struct RawHardwareInfo {
phys_addr_start: u64,
phys_addr_end: u64,
serial_port_base: Option<SerialPortBase>,
device_tree: Option<DeviceTreeAddress>,
}
#[derive(Clone, Copy, Debug)]
#[repr(C)]
struct RawLoadInfo {
kernel_image_addr_start: u64,
kernel_image_addr_end: u64,
tls_info: TlsInfo,
}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(target_arch = "x86_64", repr(C, align(8)))]
#[cfg_attr(not(target_arch = "x86_64"), repr(transparent))]
struct Align8<T>(pub T);
impl<T> From<T> for Align8<T> {
fn from(value: T) -> Self {
Self(value)
}
}
#[cfg_attr(not(all(feature = "loader", feature = "kernel")), expect(dead_code))]
#[derive(Clone, Copy, Debug)]
#[repr(C)]
enum RawPlatformInfo {
#[cfg(target_arch = "x86_64")]
Multiboot {
command_line_data: *const u8,
command_line_len: u64,
multiboot_info_addr: core::num::NonZeroU64,
},
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
LinuxBoot,
Uhyve {
has_pci: bool,
num_cpus: NonZeroU64,
cpu_freq: Option<NonZeroU32>,
boot_time: Align8<[u8; 16]>,
},
LinuxBootParams {
command_line_data: *const u8,
command_line_len: u64,
boot_params_addr: core::num::NonZeroU64,
},
Fdt,
}