Firmware services for a UEFI application built with the native backend: console output, key input, memory, delays and shutdown.
import uefi
uefi is for programs that run as a UEFI application: no operating system, no C library, started by the firmware. Build one with salam build app.salam --backend=native --target=x86_64-unknown-uefi --output=BOOTX64.EFI and put the file at EFI/BOOT/BOOTX64.EFI on a FAT disk. The result is a PE32+ image with subsystem 10 (EFI application), no import table and a .reloc section, so the firmware can load it at any address. aarch64-unknown-uefi builds the same way, but the firmware looks for EFI/BOOT/BOOTAA64.EFI, so name the output BOOTAA64.EFI.
The program's main function is called with the image handle and the system table stored for the package, and println writes to the firmware console. A newline becomes a carriage return and a line feed, and UTF-8 text is converted to UTF-16 for the firmware. main returning 0 reports success to the firmware; any other value reports an aborted status. The standard memory functions allocate from the firmware pool.
A first application
Println and Print write through the same console as println and print. Shutdown powers the machine off, which is how a test run under QEMU ends. On a normal computer the same program runs as an ordinary program, so you can test it before you boot it.
import uefi
funcmain:
println"Hello from Salam"
uefi.Println("through the firmware console")
buf := uefi.Allocate(64asu64)
uefi.Free(buf)
uefi.Shutdown()
end
Output
Hello from Salam
through the firmware console
Status codes
Firmware services report a status as a 64-bit number: 0 is success and a number with the top bit set is an error. IsError tells them apart and StatusName gives the text for the common ones.
Waits for a key and returns its Unicode character, or 65536 plus the scan code for a key without a character such as an arrow, or -1 on a failure and on a normal computer.
The example for this item is shown with the ones above: uefi-Console.salam
Leaves the application and returns control to the firmware with success for 0 and an aborted status for any other code. On a normal computer it exits the process.