2024-01-10 10:08:39 -08:00
|
|
|
use std::{env, process};
|
2024-01-10 08:57:44 -08:00
|
|
|
use xencall::domctl::DomainControl;
|
2024-01-10 16:07:57 -08:00
|
|
|
use xencall::memory::MemoryControl;
|
2024-01-10 08:57:44 -08:00
|
|
|
use xencall::sys::CreateDomain;
|
|
|
|
use xencall::XenCall;
|
2024-01-10 16:07:57 -08:00
|
|
|
use xenclient::boot::{BootImageLoader, BootSetup};
|
2024-01-10 08:57:44 -08:00
|
|
|
use xenclient::elfloader::ElfImageLoader;
|
2024-01-09 22:39:32 -08:00
|
|
|
use xenclient::XenClientError;
|
|
|
|
|
|
|
|
fn main() -> Result<(), XenClientError> {
|
2024-01-10 10:08:39 -08:00
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
if args.len() != 2 {
|
|
|
|
println!("usage: boot <kernel-image>");
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
let kernel_image_path = args.get(1).expect("argument not specified");
|
2024-01-10 08:57:44 -08:00
|
|
|
let call = XenCall::open()?;
|
|
|
|
let domctl = DomainControl::new(&call);
|
2024-01-10 10:08:39 -08:00
|
|
|
let domid = domctl.create_domain(CreateDomain::default())?;
|
|
|
|
let domain = domctl.get_domain_info(domid)?;
|
|
|
|
println!("domain created: {:?}", domain);
|
2024-01-10 16:07:57 -08:00
|
|
|
let image_loader = ElfImageLoader::load_file_kernel(kernel_image_path.as_str())?;
|
|
|
|
let image_info = image_loader.parse()?;
|
|
|
|
println!("loaded kernel image into memory: {:?}", image_info);
|
|
|
|
let memctl = MemoryControl::new(&call);
|
2024-01-10 19:18:48 -08:00
|
|
|
let mut boot = BootSetup::new(&call, &domctl, &memctl, domid);
|
|
|
|
boot.initialize(image_info, 512 * 1024)?;
|
2024-01-10 10:08:39 -08:00
|
|
|
domctl.destroy_domain(domid)?;
|
|
|
|
println!("domain destroyed: {}", domid);
|
2024-01-09 22:39:32 -08:00
|
|
|
Ok(())
|
|
|
|
}
|