mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-25 02:13:24 +00:00
Refactor the crate linux-boot-params
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
327e991477
commit
501894652f
@ -1,6 +1,4 @@
|
||||
#![feature(offset_of)]
|
||||
|
||||
//! The Linux Boot Protocol boot_params definition.
|
||||
//! The definition of Linux Boot Protocol boot_params struct.
|
||||
//!
|
||||
//! The bootloader will deliver the address of the `BootParams` struct
|
||||
//! as the argument of the kernel entrypoint. So we must define a Linux
|
||||
@ -8,8 +6,104 @@
|
||||
//! currently not needed by Asterinas.
|
||||
//!
|
||||
|
||||
#![feature(offset_of)]
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
|
||||
/// Magic stored in the boot protocol header.
|
||||
pub const LINUX_BOOT_HEADER_MAGIC: u32 = 0x53726448;
|
||||
|
||||
/// Linux 32/64-bit Boot Protocol parameter struct.
|
||||
///
|
||||
/// Originally defined in the linux source tree:
|
||||
/// `linux/arch/x86/include/uapi/asm/bootparam.h`
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[repr(C, packed)]
|
||||
pub struct BootParams {
|
||||
pub screen_info: ScreenInfo, /* 0x000 */
|
||||
pub apm_bios_info: ApmBiosInfo, /* 0x040 */
|
||||
pub _pad2: [u8; 4], /* 0x054 */
|
||||
pub tboot_addr: u64, /* 0x058 */
|
||||
pub ist_info: IstInfo, /* 0x060 */
|
||||
pub acpi_rsdp_addr: u64, /* 0x070 */
|
||||
pub _pad3: [u8; 8], /* 0x078 */
|
||||
pub hd0_info: [u8; 16], /* obsolete! 0x080 */
|
||||
pub hd1_info: [u8; 16], /* obsolete! 0x090 */
|
||||
pub sys_desc_table: SysDescTable, /* obsolete! 0x0a0 */
|
||||
pub olpc_ofw_header: OlpcOfwHeader, /* 0x0b0 */
|
||||
pub ext_ramdisk_image: u32, /* 0x0c0 */
|
||||
pub ext_ramdisk_size: u32, /* 0x0c4 */
|
||||
pub ext_cmd_line_ptr: u32, /* 0x0c8 */
|
||||
pub _pad4: [u8; 112], /* 0x0cc */
|
||||
pub cc_blob_address: u32, /* 0x13c */
|
||||
pub edid_info: EdidInfo, /* 0x140 */
|
||||
pub efi_info: EfiInfo, /* 0x1c0 */
|
||||
pub alt_mem_k: u32, /* 0x1e0 */
|
||||
pub scratch: u32, /* Scratch field! 0x1e4 */
|
||||
pub e820_entries: u8, /* 0x1e8 */
|
||||
pub eddbuf_entries: u8, /* 0x1e9 */
|
||||
pub edd_mbr_sig_buf_entries: u8, /* 0x1ea */
|
||||
pub kbd_status: u8, /* 0x1eb */
|
||||
pub secure_boot: u8, /* 0x1ec */
|
||||
pub _pad5: [u8; 2], /* 0x1ed */
|
||||
pub sentinel: u8, /* 0x1ef */
|
||||
pub _pad6: [u8; 1], /* 0x1f0 */
|
||||
pub hdr: SetupHeader, /* setup header 0x1f1 */
|
||||
pub _pad7: [u8; 0x290 - 0x1f1 - core::mem::size_of::<SetupHeader>()],
|
||||
pub edd_mbr_sig_buffer: [u32; EDD_MBR_SIG_MAX], /* 0x290 */
|
||||
pub e820_table: [BootE820Entry; E820_MAX_ENTRIES_ZEROPAGE], /* 0x2d0 */
|
||||
pub _pad8: [u8; 48], /* 0xcd0 */
|
||||
pub eddbuf: [EddInfo; EDDMAXNR], /* 0xd00 */
|
||||
pub _pad9: [u8; 276], /* 0xeec */
|
||||
}
|
||||
|
||||
/// Linux Boot Protocol header.
|
||||
///
|
||||
/// Originally defined in the linux source tree:
|
||||
/// `linux/arch/x86/include/uapi/asm/bootparam.h`
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[repr(C, packed)]
|
||||
pub struct SetupHeader {
|
||||
pub setup_sects: u8,
|
||||
pub root_flags: u16,
|
||||
pub syssize: u32,
|
||||
pub ram_size: u16,
|
||||
pub vid_mode: u16,
|
||||
pub root_dev: u16,
|
||||
pub boot_flag: u16,
|
||||
pub jump: u16,
|
||||
pub header: u32,
|
||||
pub version: u16,
|
||||
pub realmode_swtch: u32,
|
||||
pub start_sys_seg: u16,
|
||||
pub kernel_version: u16,
|
||||
pub type_of_loader: u8,
|
||||
pub loadflags: u8,
|
||||
pub setup_move_size: u16,
|
||||
pub code32_start: u32,
|
||||
pub ramdisk_image: u32,
|
||||
pub ramdisk_size: u32,
|
||||
pub bootsect_kludge: u32,
|
||||
pub heap_end_ptr: u16,
|
||||
pub ext_loader_ver: u8,
|
||||
pub ext_loader_type: u8,
|
||||
pub cmd_line_ptr: u32,
|
||||
pub initrd_addr_max: u32,
|
||||
pub kernel_alignment: u32,
|
||||
pub relocatable_kernel: u8,
|
||||
pub min_alignment: u8,
|
||||
pub xloadflags: u16,
|
||||
pub cmdline_size: u32,
|
||||
pub hardware_subarch: u32,
|
||||
pub hardware_subarch_data: u64,
|
||||
pub payload_offset: u32,
|
||||
pub payload_length: u32,
|
||||
pub setup_data: u64,
|
||||
pub pref_address: u64,
|
||||
pub init_size: u32,
|
||||
pub handover_offset: u32,
|
||||
pub kernel_info_offset: u32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[repr(C, packed)]
|
||||
pub struct ScreenInfo {
|
||||
@ -111,57 +205,6 @@ pub struct EfiInfo {
|
||||
pub efi_memmap_hi: u32,
|
||||
}
|
||||
|
||||
/// Magic stored in SetupHeader.header.
|
||||
pub const LINUX_BOOT_HEADER_MAGIC: u32 = 0x53726448;
|
||||
|
||||
/// Linux Boot Protocol Header.
|
||||
///
|
||||
/// Originally defined in the linux source tree:
|
||||
/// `linux/arch/x86/include/uapi/asm/bootparam.h`
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[repr(C, packed)]
|
||||
pub struct SetupHeader {
|
||||
pub setup_sects: u8,
|
||||
pub root_flags: u16,
|
||||
pub syssize: u32,
|
||||
pub ram_size: u16,
|
||||
pub vid_mode: u16,
|
||||
pub root_dev: u16,
|
||||
pub boot_flag: u16,
|
||||
pub jump: u16,
|
||||
pub header: u32,
|
||||
pub version: u16,
|
||||
pub realmode_swtch: u32,
|
||||
pub start_sys_seg: u16,
|
||||
pub kernel_version: u16,
|
||||
pub type_of_loader: u8,
|
||||
pub loadflags: u8,
|
||||
pub setup_move_size: u16,
|
||||
pub code32_start: u32,
|
||||
pub ramdisk_image: u32,
|
||||
pub ramdisk_size: u32,
|
||||
pub bootsect_kludge: u32,
|
||||
pub heap_end_ptr: u16,
|
||||
pub ext_loader_ver: u8,
|
||||
pub ext_loader_type: u8,
|
||||
pub cmd_line_ptr: u32,
|
||||
pub initrd_addr_max: u32,
|
||||
pub kernel_alignment: u32,
|
||||
pub relocatable_kernel: u8,
|
||||
pub min_alignment: u8,
|
||||
pub xloadflags: u16,
|
||||
pub cmdline_size: u32,
|
||||
pub hardware_subarch: u32,
|
||||
pub hardware_subarch_data: u64,
|
||||
pub payload_offset: u32,
|
||||
pub payload_length: u32,
|
||||
pub setup_data: u64,
|
||||
pub pref_address: u64,
|
||||
pub init_size: u32,
|
||||
pub handover_offset: u32,
|
||||
pub kernel_info_offset: u32,
|
||||
}
|
||||
|
||||
/// The E820 types known to the kernel.
|
||||
///
|
||||
/// Originally defined in the linux source tree:
|
||||
@ -175,32 +218,8 @@ pub enum E820Type {
|
||||
Nvs = 4,
|
||||
Unusable = 5,
|
||||
Pmem = 7,
|
||||
/*
|
||||
* This is a non-standardized way to represent ADR or
|
||||
* NVDIMM regions that persist over a reboot.
|
||||
*
|
||||
* The kernel will ignore their special capabilities
|
||||
* unless the CONFIG_X86_PMEM_LEGACY=y option is set.
|
||||
*
|
||||
* ( Note that older platforms also used 6 for the same
|
||||
* type of memory, but newer versions switched to 12 as
|
||||
* 6 was assigned differently. Some time they will learn... )
|
||||
*/
|
||||
Pram = 12,
|
||||
/*
|
||||
* Special-purpose memory is indicated to the system via the
|
||||
* EFI_MEMORY_SP attribute. Define an e820 translation of this
|
||||
* memory type for the purpose of reserving this range and
|
||||
* marking it with the IORES_DESC_SOFT_RESERVED designation.
|
||||
*/
|
||||
SoftReserved = 0xefffffff,
|
||||
/*
|
||||
* Reserved RAM used by the kernel itself if
|
||||
* CONFIG_INTEL_TXT=y is enabled, memory of this type
|
||||
* will be included in the S3 integrity calculation
|
||||
* and so should not include any memory that the BIOS
|
||||
* might alter over the S3 transition:
|
||||
*/
|
||||
ReservedKern = 128,
|
||||
}
|
||||
|
||||
@ -239,61 +258,6 @@ pub struct EddInfo {
|
||||
const EDD_MBR_SIG_MAX: usize = 16;
|
||||
const EDDMAXNR: usize = 6;
|
||||
|
||||
/// Linux 32/64-bit Boot Protocol parameter struct.
|
||||
///
|
||||
/// Originally defined in the linux source tree:
|
||||
/// `linux/arch/x86/include/uapi/asm/bootparam.h`
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[repr(C, packed)]
|
||||
pub struct BootParams {
|
||||
pub screen_info: ScreenInfo, /* 0x000 */
|
||||
pub apm_bios_info: ApmBiosInfo, /* 0x040 */
|
||||
pub _pad2: [u8; 4], /* 0x054 */
|
||||
pub tboot_addr: u64, /* 0x058 */
|
||||
pub ist_info: IstInfo, /* 0x060 */
|
||||
pub acpi_rsdp_addr: u64, /* 0x070 */
|
||||
pub _pad3: [u8; 8], /* 0x078 */
|
||||
pub hd0_info: [u8; 16], /* obsolete! 0x080 */
|
||||
pub hd1_info: [u8; 16], /* obsolete! 0x090 */
|
||||
pub sys_desc_table: SysDescTable, /* obsolete! 0x0a0 */
|
||||
pub olpc_ofw_header: OlpcOfwHeader, /* 0x0b0 */
|
||||
pub ext_ramdisk_image: u32, /* 0x0c0 */
|
||||
pub ext_ramdisk_size: u32, /* 0x0c4 */
|
||||
pub ext_cmd_line_ptr: u32, /* 0x0c8 */
|
||||
pub _pad4: [u8; 112], /* 0x0cc */
|
||||
pub cc_blob_address: u32, /* 0x13c */
|
||||
pub edid_info: EdidInfo, /* 0x140 */
|
||||
pub efi_info: EfiInfo, /* 0x1c0 */
|
||||
pub alt_mem_k: u32, /* 0x1e0 */
|
||||
pub scratch: u32, /* Scratch field! 0x1e4 */
|
||||
pub e820_entries: u8, /* 0x1e8 */
|
||||
pub eddbuf_entries: u8, /* 0x1e9 */
|
||||
pub edd_mbr_sig_buf_entries: u8, /* 0x1ea */
|
||||
pub kbd_status: u8, /* 0x1eb */
|
||||
pub secure_boot: u8, /* 0x1ec */
|
||||
pub _pad5: [u8; 2], /* 0x1ed */
|
||||
/*
|
||||
* The sentinel is set to a nonzero value (0xff) in header.S.
|
||||
*
|
||||
* A bootloader is supposed to only take setup_header and put
|
||||
* it into a clean boot_params buffer. If it turns out that
|
||||
* it is clumsy or too generous with the buffer, it most
|
||||
* probably will pick up the sentinel variable too. The fact
|
||||
* that this variable then is still 0xff will let kernel
|
||||
* know that some variables in boot_params are invalid and
|
||||
* kernel should zero out certain portions of boot_params.
|
||||
*/
|
||||
pub sentinel: u8, /* 0x1ef */
|
||||
pub _pad6: [u8; 1], /* 0x1f0 */
|
||||
pub hdr: SetupHeader, /* setup header 0x1f1 */
|
||||
pub _pad7: [u8; 0x290 - 0x1f1 - core::mem::size_of::<SetupHeader>()],
|
||||
pub edd_mbr_sig_buffer: [u32; EDD_MBR_SIG_MAX], /* 0x290 */
|
||||
pub e820_table: [BootE820Entry; E820_MAX_ENTRIES_ZEROPAGE], /* 0x2d0 */
|
||||
pub _pad8: [u8; 48], /* 0xcd0 */
|
||||
pub eddbuf: [EddInfo; EDDMAXNR], /* 0xd00 */
|
||||
pub _pad9: [u8; 276], /* 0xeec */
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Reference in New Issue
Block a user