Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/edda

crates/nornir-build-thing/tests/fixtures/korp-efistub/src/main.rs

// A tiny pure-Rust UEFI application: prints the KORP appliance boot marker to the
// COM1 serial port (0x3F8) so a QEMU `-serial` capture proves the ISO booted, then
// halts. no_std, no external crate — just raw port I/O via inline asm.
#![no_std]
#![no_main]

use core::arch::asm;
use core::panic::PanicInfo;

const COM1: u16 = 0x3F8;

#[inline(always)]
unsafe fn outb(port: u16, val: u8) {
    asm!("out dx, al", in("dx") port, in("al") val, options(nomem, nostack, preserves_flags));
}

#[inline(always)]
unsafe fn inb(port: u16) -> u8 {
    let val: u8;
    asm!("in al, dx", out("al") val, in("dx") port, options(nomem, nostack, preserves_flags));
    val
}

unsafe fn serial_init() {
    outb(COM1 + 1, 0x00); // disable interrupts
    outb(COM1 + 3, 0x80); // enable DLAB
    outb(COM1 + 0, 0x01); // divisor low  (115200)
    outb(COM1 + 1, 0x00); // divisor high
    outb(COM1 + 3, 0x03); // 8 bits, no parity, one stop
    outb(COM1 + 2, 0xC7); // enable + clear FIFO
    outb(COM1 + 4, 0x0B); // IRQs enabled, RTS/DSR set
}

unsafe fn serial_write(bytes: &[u8]) {
    for &b in bytes {
        // wait for the transmit-holding register to drain (LSR bit 5).
        while inb(COM1 + 5) & 0x20 == 0 {}
        outb(COM1, b);
    }
}

#[no_mangle]
pub extern "efiapi" fn efi_main(_image: *mut core::ffi::c_void, _st: *mut core::ffi::c_void) -> usize {
    unsafe {
        serial_init();
        serial_write(b"\r\nKORP-APPLIANCE-OK rows=0 tables=0 nodes=0 people=0 hotspots=0\r\n");
        serial_write(b"KORP-APPLIANCE BOOT-OK: demo reached completion\r\n");
        loop {
            asm!("hlt", options(nomem, nostack));
        }
    }
}

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {
        unsafe { asm!("hlt", options(nomem, nostack)) }
    }
}