pub fn load_linux(
    config: &X86BootLoaderConfig,
    sys_mem: &Arc<AddressSpace>,
) -> Result<X86BootLoader> {
    if config.kernel.is_none() {
        bail!("Kernel is required for direct-boot mode.");
    }

    let mut boot_loader_layout = X86BootLoader {
        boot_sp: BOOT_LOADER_SP,
        zero_page_addr: ZERO_PAGE_START,
        ..Default::default()
    };
    let mut boot_header = load_kernel_image(
        &config.kernel.as_ref().unwrap(),
        sys_mem,
        &mut boot_loader_layout,
    )?;

    load_initrd(config, sys_mem, &mut boot_header)
        .chain_err(|| "Failed to load initrd to vm memory")?;

    setup_kernel_cmdline(&config, sys_mem, &mut boot_header)
        .chain_err(|| "Failed to setup kernel cmdline")?;

    setup_boot_params(config, sys_mem, &boot_header).chain_err(|| "Failed to setup boot params")?;

    setup_isa_mptable(
        sys_mem,
        EBDA_START,
        config.cpu_count,
        config.ioapic_addr,
        config.lapic_addr,
    )?;

    boot_loader_layout.boot_pml4_addr =
        setup_page_table(sys_mem).chain_err(|| "Failed to setup page table")?;
    boot_loader_layout.segments = setup_gdt(sys_mem).chain_err(|| "Failed to setup gdt")?;

    Ok(boot_loader_layout)
}
/// Load PE(vmlinux.bin) linux kernel / bzImage linux kernel and
/// other boot source to Guest Memory.
///
/// # Steps
///
/// 1. Prepare for linux kernel boot env, return guest memory layout.
/// 2. According guest memory layout, load linux kernel to guest memory.
/// 3. According guest memory layout, load initrd image to guest memory.
/// 4. Inject cmdline to guest memory.
///
/// # Arguments
///
/// * `config` - boot source config, contains kernel, initrd and kernel cmdline.
/// * `sys_mem` - guest memory.
///
/// # Errors
///
/// Load kernel, initrd or kernel cmdline to guest memory failed. Boot source
/// is broken or guest memory is abnormal.
Load PE(vmlinux.bin) linux kernel / bzImage linux kernel and
other boot source to Guest Memory.
Load PE ( vmlinux . bin ) linux kernel / bzImage linux kernel and other boot source to Guest Memory .
pub fn load_linux(
    config: &X86BootLoaderConfig,
    sys_mem: &Arc<AddressSpace>,
) -> Result<X86BootLoader> {
    if config.kernel.is_none() {
        bail!("Kernel is required for direct-boot mode.");
    }
    let mut boot_loader_layout = X86BootLoader {
        boot_sp: BOOT_LOADER_SP,
        zero_page_addr: ZERO_PAGE_START,
        ..Default::default()
    };
    let mut boot_header = load_kernel_image(
        &config.kernel.as_ref().unwrap(),
        sys_mem,
        &mut boot_loader_layout,
    )?;
    load_initrd(config, sys_mem, &mut boot_header)
        .chain_err(|| "Failed to load initrd to vm memory")?;
    setup_kernel_cmdline(&config, sys_mem, &mut boot_header)
        .chain_err(|| "Failed to setup kernel cmdline")?;
    setup_boot_params(config, sys_mem, &boot_header).chain_err(|| "Failed to setup boot params")?;
    setup_isa_mptable(
        sys_mem,
        EBDA_START,
        config.cpu_count,
        config.ioapic_addr,
        config.lapic_addr,
    )?;
    boot_loader_layout.boot_pml4_addr =
        setup_page_table(sys_mem).chain_err(|| "Failed to setup page table")?;
    boot_loader_layout.segments = setup_gdt(sys_mem).chain_err(|| "Failed to setup gdt")?;
    Ok(boot_loader_layout)
}
pub fn load_linux ( config : & X86BootLoaderConfig , sys_mem : & Arc < AddressSpace > , ) -> Result < X86BootLoader > { if config . kernel . is_none ( ) { bail ! ( " " ) ; } let mut boot_loader_layout = X86BootLoader { boot_sp : BOOT_LOADER_SP , zero_page_addr : ZERO_PAGE_START , .. Default :: default ( ) } ; let mut boot_header = load_kernel_image ( & config . kernel . as_ref ( ) . unwrap ( ) , sys_mem , & mut boot_loader_layout , ) ? ; load_initrd ( config , sys_mem , & mut boot_header ) . chain_err ( | | " " ) ? ; setup_kernel_cmdline ( & config , sys_mem , & mut boot_header ) . chain_err ( | | " " ) ? ; setup_boot_params ( config , sys_mem , & boot_header ) . chain_err ( | | " " ) ? ; setup_isa_mptable ( sys_mem , EBDA_START , config . cpu_count , config . ioapic_addr , config . lapic_addr , ) ? ; boot_loader_layout . boot_pml4_addr = setup_page_table ( sys_mem ) . chain_err ( | | " " ) ? ; boot_loader_layout . segments = setup_gdt ( sys_mem ) . chain_err ( | | " " ) ? ; Ok ( boot_loader_layout ) }
Load PE(vmlinux.bin) linux kernel / bzImage linux kernel and
other boot source to Guest Memory.
Load PE ( vmlinux . bin ) linux kernel / bzImage linux kernel and other boot source to Guest Memory .
config
&X86BootLoaderConfig
sys_mem
&Arc<AddressSpace>
config
&X86BootLoaderConfig
sys_mem
&Arc<AddressSpace>
steps
1. Prepare for linux kernel boot env, return guest memory layout.
2. According guest memory layout, load linux kernel to guest memory.
3. According guest memory layout, load initrd image to guest memory.
4. Inject cmdline to guest memory.
1 . Prepare for linux kernel boot env return guest memory layout . 2 . According guest memory layout load linux kernel to guest memory . 3 . According guest memory layout load initrd image to guest memory . 4 . Inject cmdline to guest memory .
errors
Load kernel, initrd or kernel cmdline to guest memory failed. Boot source
is broken or guest memory is abnormal.
Load kernel initrd or kernel cmdline to guest memory failed . Boot source is broken or guest memory is abnormal .