src/x86/boot.bend checks
raw source on the hub · import 0x8cced805dd17b3296cb7aabd2fa292bb/src/x86/boot.bend as Boot
4 imports
import Base import ../lib/u64.bend as U import ../lib/bytes.bend as B import ./layout.bend as X
Types
type BzInfo source · line 29 · raw
Data
BzInfo@setup_sects:U32 -> @version:U32 -> @pref:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> @init_size:U32 -> @initrd_max:U32 -> @cmdline_size:U32 -> @hdr_end:U32 -> BzInfo
type BzLayout source · line 93 · raw
Data
Where everything goes: the file is loaded whole at kernel - setup_len, so the protected-mode kernel lands at its preferred address; the initrd ends at a 4 KiB boundary at or below the lowest of low RAM's end, the kernel's initrd_addr_max + 1 and 1 GiB (the identity map), clear of the kernel's init_size.
BzLayout@load:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> @kernel:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> @initrd:U32 -> @initrd_len:U32 -> BzLayout
type E820 source · line 128 · raw
Data
The memory map (e820 entries: base, size, type 1 RAM or 2 reserved) for RAM of size bytes: low RAM below the legacy hole, the hole (the EBDA, VGA, the BIOS area with the ACPI tables), the rest of low RAM from 1 MiB, and RAM past 3 GiB at 4 GiB.
E820@base:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> @size:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> @kind:U32 -> E820
Definitions
def Bz.u8 source · line 32 · raw
@bs:List<&2, U32> -> @off:Nat -> U32
def Bz.u16 source · line 35 · raw
@bs:List<&2, U32> -> @off:Nat -> U32
def Bz.u32 source · line 38 · raw
@bs:List<&2, U32> -> @off:Nat -> U32
def Bz.head_len source · line 42 · raw
U32
The header bytes a parse needs (the file's first 1024).
def Bz.boot_flag source · line 46 · raw
U32
0xAA55, "HdrS" (0x5372_6448), version 2.12 (0x020C: the 64-bit entry).
def Bz.magic source · line 49 · raw
U32
def Bz.min_version source · line 52 · raw
U32
def Bz.sects source · line 55 · raw
@+n:U32 -> U32
def Bz.when source · line 58 · raw
@-A:Data -> @ok:Bool -> @x:A -> Maybe<&2, A>
def Bz.parse.go source · line 65 · raw
@+bs:List<&2, U32> -> Maybe<&2, BzInfo>
def Bz.parse source · line 74 · raw
@+bs:List<&2, U32> -> Maybe<&2, BzInfo>
A bzImage whose kernel has a 64-bit entry (protocol 2.12 or later with XLF_KERNEL_64), from the file's first 1024 bytes; None for anything else.
def Bz.setup_len source · line 78 · raw
@info:BzInfo -> U32
The file's bytes before the protected-mode kernel: (setup_sects + 1) * 512.
def Bz.pref source · line 83 · raw
@info:BzInfo -> 0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64
def Bz.min source · line 96 · raw
@+a:U32 -> @+b:U32 -> U32
def Bz.gib1 source · line 99 · raw
U32
def Bz.initrd_top source · line 104 · raw
@+low_end:U32 -> @+max:U32 -> U32
The initrd's top: min(low RAM's end, initrd_addr_max + 1, 1 GiB), 4 KiB aligned down.
def Bz.layout source · line 110 · raw
@info:BzInfo -> @+size:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> @+flen:U32 -> @+ilen:U32 -> Maybe<&2, BzLayout>
The placement for a file of flen bytes and an initrd of ilen bytes in RAM of size bytes; None when it does not fit.
def Bz.e820 source · line 131 · raw
@+size:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> List<&2, E820>
def Bz.e820_bytes source · line 139 · raw
@es:List<&2, E820> -> List<&2, U32>
def Bz.put source · line 147 · raw
@+bs:List<&2, U32> -> @+off:Nat -> @+put:List<&2, U32> -> List<&2, U32>
bs with the bytes at off replaced by put (bs is long enough).
def Bz.zero_page source · line 153 · raw
@info:BzInfo -> @+head:List<&2, U32> -> @+size:0x8cced805dd17b3296cb7aabd2fa292bb/src/lib/u64.U64 -> @+lay:BzLayout -> @+rsdp:U32 -> List<&2, U32>
The zero page (4096 bytes): the file's setup header (bytes 497 up to its end), type_of_loader 0xFF (undefined), the command line, the initrd, the RSDP's address and the memory map.
def Bz.arm_default source · line 169 · raw
String
The command line an x86_64 guest gets: its own, or console=ttyS0 (COM1) where it was left at the VMM's default, which names arm64's PL011 (src/vmm/opts.bend).
def Bz.cmdline_for source · line 172 · raw
@+s:String -> String
def Bz.cmdline source · line 177 · raw
@info:BzInfo -> @s:String -> List<&2, U32>
The command line as the kernel reads it: NUL-terminated, cut to the header's cmdline_size (a protocol 2.06+ field: every 64-bit kernel has it).
def Boot.gdt source · line 186 · raw
List<&2, U32>
The GDT at X86.gdt(): null, null, the 64-bit code segment (selector 16, __BOOT_CS: 0x00AF_9B00_0000_FFFF), the data segment (selector 24, __BOOT_DS: 0x00CF_9300_0000_FFFF), and a 64-bit TSS (selector 32, 0x0000_8B00_0000_0067) for the task register VMX insists on.
def Boot.entry source · line 191 · raw
@+addr:U32 -> List<&2, U32>
Page tables: PML4[0] -> the PDPT, PDPT[0] -> the PD, and the PD maps the first GiB in 2 MiB pages (present, writable, large: 0x83).
def Boot.pml4 source · line 194 · raw
List<&2, U32>
def Boot.pdpt source · line 197 · raw
List<&2, U32>
def Boot.pd.go source · line 200 · raw
@n:Nat -> @+i:U32 -> List<&2, U32>
def Boot.pd source · line 207 · raw
List<&2, U32>
def Boot.u64 source · line 218 · raw
@+x:U32 -> List<&2, U32>
The boot vCPU's registers, as the words Hvf.x86_boot takes (64-bit values as hi, lo): rip, rsi, rsp, rflags, cr0, cr3, cr4, efer, the GDT's base and limit, the IDT's base and limit, then the segments cs, ds, es, fs, gs, ss, tr, ldt, each as base (hi, lo), limit, selector, type, present, dpl, db, s, l, g, avl, unusable. cr0 = PG | ET | PE (0x8000_0011), cr4 = PAE (0x20), efer = LME | LMA (0x500), cr3 = the PML4, rflags = 2 (the reserved bit), RSI = the zero page, RIP = the kernel + 512 (startup_64).
def Boot.seg source · line 221 · raw
@+sel:U32 -> @+ty:U32 -> @+s:U32 -> @+l:U32 -> @+db:U32 -> @+limit:U32 -> @+g:U32 -> @+unusable:U32 -> List<&2, U32>
def Boot.code source · line 224 · raw
List<&2, U32>
def Boot.data source · line 227 · raw
List<&2, U32>
def Boot.regs source · line 230 · raw
@+kernel:U32 -> List<&2, U32>
def Boot.cpuid_rules source · line 245 · raw
List<&2, U32>
CPUID: rules the host applies to every leaf KVM supports (Hvf.x86_setup), five words each: leaf, register (0 eax, 1 ebx, 2 ecx, 3 edx), bits to clear, bits to set, and the shift at which the vCPU's index (its APIC ID) goes in (32: none). The index of a subleaf does not matter. leaf 1 ECX bit 31: a hypervisor runs this CPU leaf 1 EBX bits 31..24: the initial APIC ID leaf 11 (0xB) and 31 (0x1F) EDX: the x2APIC ID
def Boot.reset_stub source · line 254 · raw
List<&2, U32>
The reset vector's code (at X86.reset_vector(), F000:FFF0 in real mode): where a PC's firmware starts on a reset, and where Linux's restart jumps back to (machine_real_restart, after it goes back to real mode). Here no firmware runs, so the code asks for a reset through the FADT's reset register: mov dx, 1538 (0x602); mov al, 1; out dx, al; hlt; jmp back to the hlt.