//! Built-in x86 boot image used when BIOS boot is enabled and the VM config omits `bios_path`.
//!
//! Axvisor starts x86 guests in 16-bit real mode. This tiny axvm-bios image
//! switches the guest to 32-bit protected mode, sets the multiboot magic in
//! `eax`, loads the multiboot info pointer into `ebx`, and jumps to the guest
//! kernel entry at `0x20_0000`.

/// Default GPA where the built-in axvm-bios image is loaded.
pub const DEFAULT_BIOS_LOAD_GPA: usize = 0x8000;

/// Offset of the 4-byte immediate operand in `mov ebx, imm32`.
///
/// Axvisor patches this immediate with the generated multiboot info GPA before
/// the guest starts.
pub const AXVM_BIOS_EBX_IMM_OFFSET: usize = 0x3c;
/// Opcode used to verify that `AXVM_BIOS_EBX_IMM_OFFSET` points into `mov ebx, imm32`.
pub const MOV_EBX_IMM32_OPCODE: u8 = 0xbb;

/// Raw axvm-bios fallback image.
///
/// This byte sequence is intentionally identical to the external
/// `axvm-bios.bin` used by x86 NimbOS/ArceOS guests, so existing guest boot
/// assumptions remain unchanged when `enable_bios = true` and `bios_path` is omitted.
///
/// Reproducibility:
/// - Source archive:
///   <https://github.com/arceos-hypervisor/axvisor-guest/releases/download/v0.0.25/qemu_x86_64_nimbos.tar.gz>
/// - Archive SHA-256:
///   `766aee71072bed3a76fc29781cddd43d243228bd62144115b597f659d9ca8793`
/// - Extract `./axvm-bios.bin`; its SHA-256 must be:
///   `323e108956d8ab67b4b57259272c78df725053f7d7f0bd08ebe1f9eaaabfd4d4`
pub const DEFAULT_BIOS_IMAGE: &[u8] = &[
    0xfa, 0xfc, 0x31, 0xc0, 0x8e, 0xd8, 0x8e, 0xc0, 0x8e, 0xd0, 0x0f, 0x01, 0x16, 0x68, 0x80, 0x0f,
    0x20, 0xc0, 0x66, 0x83, 0xc8, 0x01, 0x0f, 0x22, 0xc0, 0xea, 0x1e, 0x80, 0x08, 0x00, 0x66, 0xb8,
    0x10, 0x00, 0x8e, 0xd8, 0x8e, 0xc0, 0x8e, 0xd0, 0x8e, 0xe0, 0x8e, 0xe8, 0xbc, 0x00, 0x70, 0x00,
    0x00, 0xb9, 0x00, 0x00, 0x20, 0x00, 0xb8, 0x02, 0xb0, 0xad, 0x2b, 0xbb, 0x00, 0x00, 0x00, 0x00,
    0xff, 0xe1, 0x2e, 0x8d, 0xb4, 0x26, 0x00, 0x00, 0x00, 0x00, 0x8d, 0xb6, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x9b, 0xcf, 0x00,
    0xff, 0xff, 0x00, 0x00, 0x00, 0x93, 0xcf, 0x00, 0x17, 0x00, 0x50, 0x80, 0x00, 0x00,
];
