pub fn configure_system(
    guest_mem: &GuestMemoryMmap,
    cmdline_addr: GuestAddress,
    cmdline_size: usize,
    initrd: &Option<InitrdConfig>,
    num_cpus: u8,
) -> super::Result<()> {
    const KERNEL_BOOT_FLAG_MAGIC: u16 = 0xaa55;
    const KERNEL_HDR_MAGIC: u32 = 0x5372_6448;
    const KERNEL_LOADER_OTHER: u8 = 0xff;
    const KERNEL_MIN_ALIGNMENT_BYTES: u32 = 0x0100_0000; // Must be non-zero.
    let first_addr_past_32bits = GuestAddress(FIRST_ADDR_PAST_32BITS);
    let end_32bit_gap_start = GuestAddress(MMIO_MEM_START);

    let himem_start = GuestAddress(layout::HIMEM_START);

    // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
    mptable::setup_mptable(guest_mem, num_cpus).map_err(Error::MpTableSetup)?;

    let mut params = boot_params::default();

    params.hdr.type_of_loader = KERNEL_LOADER_OTHER;
    params.hdr.boot_flag = KERNEL_BOOT_FLAG_MAGIC;
    params.hdr.header = KERNEL_HDR_MAGIC;
    params.hdr.cmd_line_ptr = cmdline_addr.raw_value() as u32;
    params.hdr.cmdline_size = cmdline_size as u32;
    params.hdr.kernel_alignment = KERNEL_MIN_ALIGNMENT_BYTES;
    if let Some(initrd_config) = initrd {
        params.hdr.ramdisk_image = initrd_config.address.raw_value() as u32;
        params.hdr.ramdisk_size = initrd_config.size as u32;
    }

    add_e820_entry(&mut params, 0, EBDA_START, E820_RAM)?;

    let last_addr = guest_mem.last_addr();
    if last_addr < end_32bit_gap_start {
        add_e820_entry(
            &mut params,
            himem_start.raw_value() as u64,
            // it's safe to use unchecked_offset_from because
            // mem_end > himem_start
            last_addr.unchecked_offset_from(himem_start) as u64 + 1,
            E820_RAM,
        )?;
    } else {
        add_e820_entry(
            &mut params,
            himem_start.raw_value(),
            // it's safe to use unchecked_offset_from because
            // end_32bit_gap_start > himem_start
            end_32bit_gap_start.unchecked_offset_from(himem_start),
            E820_RAM,
        )?;

        if last_addr > first_addr_past_32bits {
            add_e820_entry(
                &mut params,
                first_addr_past_32bits.raw_value(),
                // it's safe to use unchecked_offset_from because
                // mem_end > first_addr_past_32bits
                last_addr.unchecked_offset_from(first_addr_past_32bits) + 1,
                E820_RAM,
            )?;
        }
    }

    LinuxBootConfigurator::write_bootparams(
        &BootParams::new(&params, GuestAddress(layout::ZERO_PAGE_START)),
        guest_mem,
    )
    .map_err(|_| Error::ZeroPageSetup)
}
/// Configures the system and should be called once per vm before starting vcpu threads.
///
/// # Arguments
///
/// * `guest_mem` - The memory to be used by the guest.
/// * `cmdline_addr` - Address in `guest_mem` where the kernel command line was loaded.
/// * `cmdline_size` - Size of the kernel command line in bytes including the null terminator.
/// * `initrd` - Information about where the ramdisk image was loaded in the `guest_mem`.
/// * `num_cpus` - Number of virtual CPUs the guest will have.
Configures the system and should be called once per vm before starting vcpu threads.
Configures the system and should be called once per vm before starting vcpu threads .
pub fn configure_system(
    guest_mem: &GuestMemoryMmap,
    cmdline_addr: GuestAddress,
    cmdline_size: usize,
    initrd: &Option<InitrdConfig>,
    num_cpus: u8,
) -> super::Result<()> {
    const KERNEL_BOOT_FLAG_MAGIC: u16 = 0xaa55;
    const KERNEL_HDR_MAGIC: u32 = 0x5372_6448;
    const KERNEL_LOADER_OTHER: u8 = 0xff;
    const KERNEL_MIN_ALIGNMENT_BYTES: u32 = 0x0100_0000; // Must be non-zero.
    let first_addr_past_32bits = GuestAddress(FIRST_ADDR_PAST_32BITS);
    let end_32bit_gap_start = GuestAddress(MMIO_MEM_START);
    let himem_start = GuestAddress(layout::HIMEM_START);
    // Note that this puts the mptable at the last 1k of Linux's 640k base RAM
    mptable::setup_mptable(guest_mem, num_cpus).map_err(Error::MpTableSetup)?;
    let mut params = boot_params::default();
    params.hdr.type_of_loader = KERNEL_LOADER_OTHER;
    params.hdr.boot_flag = KERNEL_BOOT_FLAG_MAGIC;
    params.hdr.header = KERNEL_HDR_MAGIC;
    params.hdr.cmd_line_ptr = cmdline_addr.raw_value() as u32;
    params.hdr.cmdline_size = cmdline_size as u32;
    params.hdr.kernel_alignment = KERNEL_MIN_ALIGNMENT_BYTES;
    if let Some(initrd_config) = initrd {
        params.hdr.ramdisk_image = initrd_config.address.raw_value() as u32;
        params.hdr.ramdisk_size = initrd_config.size as u32;
    }
    add_e820_entry(&mut params, 0, EBDA_START, E820_RAM)?;
    let last_addr = guest_mem.last_addr();
    if last_addr < end_32bit_gap_start {
        add_e820_entry(
            &mut params,
            himem_start.raw_value() as u64,
            // it's safe to use unchecked_offset_from because
            // mem_end > himem_start
            last_addr.unchecked_offset_from(himem_start) as u64 + 1,
            E820_RAM,
        )?;
    } else {
        add_e820_entry(
            &mut params,
            himem_start.raw_value(),
            // it's safe to use unchecked_offset_from because
            // end_32bit_gap_start > himem_start
            end_32bit_gap_start.unchecked_offset_from(himem_start),
            E820_RAM,
        )?;
        if last_addr > first_addr_past_32bits {
            add_e820_entry(
                &mut params,
                first_addr_past_32bits.raw_value(),
                // it's safe to use unchecked_offset_from because
                // mem_end > first_addr_past_32bits
                last_addr.unchecked_offset_from(first_addr_past_32bits) + 1,
                E820_RAM,
            )?;
        }
    }
    LinuxBootConfigurator::write_bootparams(
        &BootParams::new(&params, GuestAddress(layout::ZERO_PAGE_START)),
        guest_mem,
    )
    .map_err(|_| Error::ZeroPageSetup)
}
pub fn configure_system ( guest_mem : & GuestMemoryMmap , cmdline_addr : GuestAddress , cmdline_size : usize , initrd : & Option < InitrdConfig > , num_cpus : u8 , ) -> super :: Result < ( ) > { const KERNEL_BOOT_FLAG_MAGIC : u16 = 0xaa55 ; const KERNEL_HDR_MAGIC : u32 = 0x5372_6448 ; const KERNEL_LOADER_OTHER : u8 = 0xff ; const KERNEL_MIN_ALIGNMENT_BYTES : u32 = 0x0100_0000 ; // Must be non-zero. let first_addr_past_32bits = GuestAddress ( FIRST_ADDR_PAST_32BITS ) ; let end_32bit_gap_start = GuestAddress ( MMIO_MEM_START ) ; let himem_start = GuestAddress ( layout :: HIMEM_START ) ; // Note that this puts the mptable at the last 1k of Linux's 640k base RAM mptable :: setup_mptable ( guest_mem , num_cpus ) . map_err ( Error :: MpTableSetup ) ? ; let mut params = boot_params :: default ( ) ; params . hdr . type_of_loader = KERNEL_LOADER_OTHER ; params . hdr . boot_flag = KERNEL_BOOT_FLAG_MAGIC ; params . hdr . header = KERNEL_HDR_MAGIC ; params . hdr . cmd_line_ptr = cmdline_addr . raw_value ( ) as u32 ; params . hdr . cmdline_size = cmdline_size as u32 ; params . hdr . kernel_alignment = KERNEL_MIN_ALIGNMENT_BYTES ; if let Some ( initrd_config ) = initrd { params . hdr . ramdisk_image = initrd_config . address . raw_value ( ) as u32 ; params . hdr . ramdisk_size = initrd_config . size as u32 ; } add_e820_entry ( & mut params , 0 , EBDA_START , E820_RAM ) ? ; let last_addr = guest_mem . last_addr ( ) ; if last_addr < end_32bit_gap_start { add_e820_entry ( & mut params , himem_start . raw_value ( ) as u64 , // it's safe to use unchecked_offset_from because // mem_end > himem_start last_addr . unchecked_offset_from ( himem_start ) as u64 + 1 , E820_RAM , ) ? ; } else { add_e820_entry ( & mut params , himem_start . raw_value ( ) , // it's safe to use unchecked_offset_from because // end_32bit_gap_start > himem_start end_32bit_gap_start . unchecked_offset_from ( himem_start ) , E820_RAM , ) ? ; if last_addr > first_addr_past_32bits { add_e820_entry ( & mut params , first_addr_past_32bits . raw_value ( ) , // it's safe to use unchecked_offset_from because // mem_end > first_addr_past_32bits last_addr . unchecked_offset_from ( first_addr_past_32bits ) + 1 , E820_RAM , ) ? ; } } LinuxBootConfigurator :: write_bootparams ( & BootParams :: new ( & params , GuestAddress ( layout :: ZERO_PAGE_START ) ) , guest_mem , ) . map_err ( | _ | Error :: ZeroPageSetup ) }
Configures the system and should be called once per vm before starting vcpu threads.
Configures the system and should be called once per vm before starting vcpu threads .
guest_mem
&GuestMemoryMmap
cmdline_addr
GuestAddress
cmdline_size
usize
initrd
&Option<InitrdConfig>
num_cpus
u8
guest_mem
&GuestMemoryMmap
cmdline_addr
GuestAddress
cmdline_size
usize
initrd
&Option<InitrdConfig>
num_cpus
u8