use lazy_static::lazy_static;
pub const BOOT_GDT_OFFSET: u64 = 0x500;
pub const BOOT_IDT_OFFSET: u64 = 0x520;
pub const BOOT_GDT_ADDRESS: u64 = 0x500;
pub const BOOT_GDT_MAX: usize = 4;
pub const BOOT_IDT_ADDRESS: u64 = 0x520;
pub const ZERO_PAGE_START: u64 = 0x7000;
pub const BOOT_STACK_POINTER: u64 = 0x8ff0;
pub const PML4_START: u64 = 0x9000;
pub const PDPTE_START: u64 = 0xa000;
pub const PDE_START: u64 = 0xb000;
pub const CMDLINE_START: u64 = 0x20000;
pub const CMDLINE_MAX_SIZE: usize = 0x10000;
pub const DB_BOOT_PARAM_START: u64 = 0x30000;
pub const DB_BOOT_PARAM_MAX_SIZE: u32 = 0x10000;
pub const HIMEM_START: u64 = 0x0010_0000;
pub const IRQ_BASE: u32 = 5;
pub const IRQ_MAX: u32 = 15;
pub const KVM_TSS_ADDRESS: u64 = 0xfffb_d000;
pub const EBDA_START: u64 = 0x9fc00;
pub const MMIO_LOW_START: u64 = 3u64 << 30;
pub const MMIO_LOW_END: u64 = (4u64 << 30) - 1;
pub const GUEST_MEM_START: u64 = 0u64;
pub const GUEST_MEM_LOW_SIZE: u64 = MMIO_LOW_START - GUEST_MEM_START;
const CPUINFO_READ_RETRY: u64 = 5;
lazy_static! {
pub static ref GUEST_PHYS_END: u64 = {
for _ in 0..CPUINFO_READ_RETRY {
if let Ok(buf) = std::fs::read("/proc/cpuinfo") {
let content = String::from_utf8_lossy(&buf);
for line in content.lines() {
if line.starts_with("address sizes : ") {
if let Some(end) = line.find(" bits physical") {
if let Ok(size) = line[16..end].parse::<u64>() {
if (36..=64).contains(&size) {
return (1u64 << size) - 1;
}
}
}
}
}
}
}
panic!("Exceed max retry times. Cannot get physical address size from /proc/cpuinfo");
};
pub static ref GUEST_MEM_END: u64 = *GUEST_PHYS_END >> 1;
}