efi +linux +x86_64

This module provides convenience wrappers around EFI functionality for bootloaders in boot/ to take advantage of.

Index

Types

type BOOT_SERVICES;
type CONFIGURATION_TABLE;
type FILE_ATTRIBUTES;
type FILE_INFO;
type FILE_MODE;
type FILE_PROTOCOL;
type GUID;
type HANDLE;
type LOADED_IMAGE_PROTOCOL;
type MEMORY_DESCRIPTOR;
type MEMORY_TYPE;
type RUNTIME_SERVICES;
type SIMPLE_FILE_SYSTEM_PROTOCOL;
type SIMPLE_TEXT_INPUT_PROTOCOL;
type SIMPLE_TEXT_OUTPUT_PROTOCOL;
type STATUS;
type SYSTEM_TABLE;
type TABLE_HEADER;
type wstr;

// Undocumented types:
type TIME;
type mmap_iter;

Errors

type error;

Globals

let DTB_TABLE_GUID: GUID;
let EFI_FILE_INFO_ID: GUID;
let LOADED_IMAGE_PROTOCOL_GUID: GUID;
let SIMPLE_FILE_SYSTEM_PROTOCOL_GUID: GUID;
let image: HANDLE;
let systab: *SYSTEM_TABLE;

Functions

fn close(*FILE_PROTOCOL) (void | error);
fn efi_call(STATUS) (void | error);
fn exit_boot_services() void;
fn file_info(*FILE_PROTOCOL) (*FILE_INFO | error);
fn filename(*FILE_INFO) str;
fn from_wstr([]u16) str;
fn guid_eq(*const GUID, *const GUID) bool;
fn init(HANDLE, *SYSTEM_TABLE) (void | error);
fn iter_mmap() (mmap_iter | error);
fn memory_type_str(MEMORY_TYPE) const str;
fn mmap_next(*mmap_iter) (*MEMORY_DESCRIPTOR | void);
fn open(str, FILE_MODE, FILE_ATTRIBUTES...) (*FILE_PROTOCOL | error);
fn open_relative(*FILE_PROTOCOL, str, FILE_MODE, FILE_ATTRIBUTES...) (*FILE_PROTOCOL | error);
fn opendir(str, FILE_MODE, FILE_ATTRIBUTES...) (*FILE_PROTOCOL | error);
fn read(*FILE_PROTOCOL, []u8) (size | error);
fn readdir(*FILE_PROTOCOL) (*FILE_INFO | void | error);
fn seek(*FILE_PROTOCOL, u64) (void | error);
fn to_wstr(str) wstr;
fn writecons(str) void;

Types

type BOOT_SERVICES[link]

type BOOT_SERVICES = struct {
	Hdr: TABLE_HEADER,
	RaiseTpl: *void,
	RestoreTpl: *void,
	AllocatePages: *void,
	FreePages: *void,
	GetMemoryMap: *fn(MemoryMapSize: *size, MemoryMap: nullable *void, MapKey: *u64, DescriptorSize: *size, DescriptorVersion: *u32) STATUS,
	AllocatePool: *void,
	FreePool: *void,
	CreateEvent: *void,
	SetTimer: *void,
	WaitForEvent: *void,
	SignalEvent: *void,
	CloseEvent: *void,
	CheckEvent: *void,
	InstallProtocolInterface: *void,
	ReinstallProtocolInterface: *void,
	UninstallProtocolInterface: *void,
	HandleProtocol: *fn(Handle: HANDLE, Protocol: *GUID, Interface: **void) STATUS,
	Reserved: *void,
	RegisterProtocolNotify: *void,
	LocateHandle: *void,
	LocateDevicePath: *void,
	InstallConfigurationTable: *void,
	LoadImage: *void,
	StartImage: *void,
	Exit: *void,
	UnloadImage: *void,
	ExitBootServices: *fn(ImageHandle: HANDLE, MapKey: u64) STATUS,
	GetNextMonotonicCount: *void,
	Stall: *void,
	SetWatchdogTimer: *void,
	ConnectController: *void,
	DisconnectController: *void,
	OpenProtocol: *void,
	CloseProtocol: *void,
	OpenProtocolInformation: *void,
	ProtocolsPerHandle: *void,
	LocateHandleBuffer: *void,
	LocateProtocol: *void,
	InstallMultipleProtocolInterfaces: *void,
	UninstallMultipleProtocolInterfaces: *void,
	CalculateCrc32: *void,
	CopyMem: *void,
	SetMem: *void,
	CreateEventEx: *void,
};

Boot-time EFI services.

type CONFIGURATION_TABLE[link]

type CONFIGURATION_TABLE = struct {
	VendorGuid: GUID,
	VendorTable: *void,
};

Entry in system_table.configuration_table.

type FILE_ATTRIBUTES[link]

type FILE_ATTRIBUTES = enum u64 {
	NONE = 0,
	READ_ONLY = 1,
	HIDDEN = 2,
	SYSTEM = 4,
	RESERVED = 8,
	DIRECTORY = 16,
	ARCHIVE = 32,
	VALID_ATTR = 55,

};

File attributes.

type FILE_INFO[link]

type FILE_INFO = struct {
	Size: u64,
	FileSize: u64,
	PhysicalSize: u64,
	CreateTime: TIME,
	LastAccessTime: TIME,
	ModificationTime: TIME,
	Attribute: u64,
	Filename: [*]u16,
};

EFI_FILE_INFO struct.

type FILE_MODE[link]

type FILE_MODE = enum u64 {
	READ = 1,
	WRITE = 2,
	CREATE = 9223372036854775808,

};

File modes.

type FILE_PROTOCOL[link]

type FILE_PROTOCOL = struct {
	Revision: u64,
	Open: *fn(This: *FILE_PROTOCOL, NewHandle: **FILE_PROTOCOL, FileName: wstr, OpenMode: FILE_MODE, Attributes: FILE_ATTRIBUTES) STATUS,
	Close: *fn(This: *FILE_PROTOCOL) STATUS,
	Delete: *void,
	Read: *fn(This: *FILE_PROTOCOL, BufferSize: nullable *size, Buffer: *void) STATUS,
	Write: *void,
	GetPosition: *fn(This: *FILE_PROTOCOL, Position: *u64) STATUS,
	SetPosition: *fn(This: *FILE_PROTOCOL, Position: u64) STATUS,
	GetInfo: *fn(This: *FILE_PROTOCOL, InformationType: *GUID, BufferSize: *size, Buffer: *void) STATUS,
	SetInfo: *void,
	Flush: *void,
};

File based access to supported file systems.

type GUID[link]

type GUID = (u32, u16, u16,
[8]u8);

Unique object identifier.

type HANDLE[link]

type HANDLE = *void;

Collection of related interfaces (opaque).

type LOADED_IMAGE_PROTOCOL[link]

type LOADED_IMAGE_PROTOCOL = struct {
	Revision: u32,
	ParentHandle: HANDLE,
	SystemTable: *SYSTEM_TABLE,
	// Source location
DeviceHandle: HANDLE, FilePath: *void, Reserved: *void, // Load options
LoadOptionsSize: u32, LoadOptions: *void, // Location where image was loaded
ImageBase: *void, ImageSize: size, ImageCodeType: MEMORY_TYPE, ImageDataType: MEMORY_TYPE, Unload: *void, };

Information about currently loaded image.

type MEMORY_DESCRIPTOR[link]

type MEMORY_DESCRIPTOR = struct {
	DescriptorType: MEMORY_TYPE,
	PhysicalStart: uintptr,
	VirtualStart: uintptr,
	NumberOfPages: u64,
	Attribute: u64,
};

A region in the memory map.

type MEMORY_TYPE[link]

type MEMORY_TYPE = enum u32 {
	RESERVED,
	LOADER_CODE,
	LOADER_DATA,
	BOOT_SERVICES_CODE,
	BOOT_SERVICES_DATA,
	RUNTIME_SERVICES_CODE,
	RUNTIME_SERVICES_DATA,
	CONVENTIONAL,
	UNUSABLE,
	ACPI_RECLAIM,
	ACPI_NVS,
	MEMORY_MAPPED_IO,
	MEMORY_MAPPED_IO_PORT_SPACE,
	PAL_CODE,
	PERSISTENT_MEMORY,

};

Type of a memory region.

type RUNTIME_SERVICES[link]

type RUNTIME_SERVICES = void;

Pointers to various runtime services (omitted).

type SIMPLE_FILE_SYSTEM_PROTOCOL[link]

type SIMPLE_FILE_SYSTEM_PROTOCOL = struct {
	Revision: u64,
	OpenVolume: *fn(This: *SIMPLE_FILE_SYSTEM_PROTOCOL, Root: **FILE_PROTOCOL) STATUS,
};

Minimal interface for file-type access to a device.

type SIMPLE_TEXT_INPUT_PROTOCOL[link]

type SIMPLE_TEXT_INPUT_PROTOCOL = struct {
	Reset: *void,
	ReadKeyStroke: *void,
	WaitForKey: *void,
};

Protocol used to control text input devices.

type SIMPLE_TEXT_OUTPUT_PROTOCOL[link]

type SIMPLE_TEXT_OUTPUT_PROTOCOL = struct {
	Reset: *void,
	OutputString: *fn(this: *SIMPLE_TEXT_OUTPUT_PROTOCOL, string: wstr) STATUS,
	TestString: *void,
	QueryMode: *void,
	SetMode: *void,
	SetAttribute: *void,
	ClearScreen: *void,
	SetCursorPosition: *void,
	EnableCursor: *void,
	Mode: *void,
};

Protocol used to control text output devices.

type STATUS[link]

type STATUS = enum u64 {
	SUCCESS = 0,
	LOAD_ERROR = 1 | 9223372036854775808,
	BUFFER_TOO_SMALL = 5 | 9223372036854775808,
	NOT_FOUND = 14 | 9223372036854775808,

};

EFI status code.

type SYSTEM_TABLE[link]

type SYSTEM_TABLE = struct {
	hdr: TABLE_HEADER,
	FirmwareVendor: wstr,
	FirmwareRevision: u32,
	ConInHandle: HANDLE,
	ConIn: *SIMPLE_TEXT_INPUT_PROTOCOL,
	ConOutHandle: HANDLE,
	ConOut: *SIMPLE_TEXT_OUTPUT_PROTOCOL,
	StdErrHandle: HANDLE,
	StdErr: *SIMPLE_TEXT_OUTPUT_PROTOCOL,
	RuntimeServices: *RUNTIME_SERVICES,
	BootServices: *BOOT_SERVICES,
	NumberOfTableEntries: size,
	ConfigurationTable: *[*]CONFIGURATION_TABLE,
};

Core EFI services.

type TABLE_HEADER[link]

type TABLE_HEADER = struct {
	Signature: u64,
	Revision: u32,
	HeaderSize: u32,
	CRC32: u32,
	Reserved: u32,
};

Identification data for all standard EFI tables.

type wstr[link]

type wstr = *[*]u16;

A "wide" NUL-terminated string composed of 16-bit characters.

type TIME[link]

Show undocumented member
type TIME = struct {
	Year: u16,
	Month: u8,
	Day: u8,
	Hour: u8,
	Minute: u8,
	Second: u8,
	Pad1: u8,
	Nanosecond: u32,
	TimeZone: i16,
	Daylight: u8,
	Pad2: u8,
};

type mmap_iter[link]

Show undocumented member
type mmap_iter = struct {
	i: size,
	n: size,
	dsize: size,
};

Errors

type error[link]

type error = !STATUS;

An EFI-related error.

Globals

let DTB_TABLE_GUID[link]

const DTB_TABLE_GUID: GUID;

GUID of the device tree blob in CONFIGURATION_TABLE.

let EFI_FILE_INFO_ID[link]

const EFI_FILE_INFO_ID: GUID;

GUID of the EFI_FILE_INFO identifier.

let LOADED_IMAGE_PROTOCOL_GUID[link]

const LOADED_IMAGE_PROTOCOL_GUID: GUID;

GUID of the LOADED_IMAGE_PROTOCOL.

let SIMPLE_FILE_SYSTEM_PROTOCOL_GUID[link]

const SIMPLE_FILE_SYSTEM_PROTOCOL_GUID: GUID;

GUID of the SIMPLE_FILE_SYSTEM_PROTOCOL.

let image[link]

let image: HANDLE;

Global EFI loaded image handle.

let systab[link]

let systab: *SYSTEM_TABLE;

Global EFI system table.

Functions

fn close[link]

fn close(file: *FILE_PROTOCOL) (void | error);

Closes an EFI FILE_PROTOCOL handle.

fn efi_call[link]

fn efi_call(status: STATUS) (void | error);

Performs an EFI call and wraps the status code in a Hare error.

fn exit_boot_services[link]

fn exit_boot_services() void;

Instructs the EFI boot services to exit.

fn file_info[link]

fn file_info(file: *FILE_PROTOCOL) (*FILE_INFO | error);

Returns information about a file object. The return value is statically allocated and will be overwritten on subsequent calls.

fn filename[link]

fn filename(info: *FILE_INFO) str;

Utility function which returns the file name from a FILE_INFO as a UTF-8 Hare string. Same constraints as from_wstr.

fn from_wstr[link]

fn from_wstr(s: []u16) str;

Converts a wstr to a Hare string. Only supports ASCII characters.

fn guid_eq[link]

fn guid_eq(a: *const GUID, b: *const GUID) bool;

Returns whether two guids are equal.

fn init[link]

fn init(init_image: HANDLE, init_systab: *SYSTEM_TABLE) (void | error);

Initializes Helios EFI services.

fn iter_mmap[link]

fn iter_mmap() (mmap_iter | error);

Iterates over the EFI memory map.

fn memory_type_str[link]

fn memory_type_str(mtype: MEMORY_TYPE) const str;

Returns the name of a MEMORY_TYPE member as a string.

fn mmap_next[link]

fn mmap_next(iter: *mmap_iter) (*MEMORY_DESCRIPTOR | void);

Returns the next item from the EFI memory map.

fn open[link]

fn open(
	path: str,
	mode: FILE_MODE,
	attrs: FILE_ATTRIBUTES...
) (*FILE_PROTOCOL | error);

Opens a file from the EFI boot device.

fn open_relative[link]

fn open_relative(
	root: *FILE_PROTOCOL,
	path: str,
	mode: FILE_MODE,
	attrs: FILE_ATTRIBUTES...
) (*FILE_PROTOCOL | error);

Opens a file relative to another file.

fn opendir[link]

fn opendir(
	path: str,
	mode: FILE_MODE,
	attrs: FILE_ATTRIBUTES...
) (*FILE_PROTOCOL | error);

Opens a directory from the EFI boot device.

fn read[link]

fn read(file: *FILE_PROTOCOL, buf: []u8) (size | error);

Reads from a file from EFI.

fn readdir[link]

fn readdir(dir: *FILE_PROTOCOL) (*FILE_INFO | void | error);

Reads the next entry from an EFI FILE_PROTOCOL handle of an open directory. The return value is statically allocated and will be overwritten on the next call.

fn seek[link]

fn seek(file: *FILE_PROTOCOL, pos: u64) (void | error);

Seeks to a given offset in a file handle.

fn to_wstr[link]

fn to_wstr(s: str) wstr;

Converts an ASCII Hare string to wstr. The return value is overwritten on the next call.

fn writecons[link]

fn writecons(msg: str) void;

Writes a string to the EFI console.