Commit f4767186dd

Nick Erdmann <n@nirf.de>
2019-10-28 23:12:28
std/os/uefi: loading images
1 parent 6fdeaac
lib/std/os/uefi/protocols/device_path_protocol.zig
@@ -0,0 +1,17 @@
+const uefi = @import("std").os.uefi;
+const Guid = uefi.Guid;
+
+pub const DevicePathProtocol = extern struct {
+    type: u8,
+    subtype: u8,
+    length: u16,
+
+    pub const guid align(8) = Guid{
+        .time_low = 0x09576e91,
+        .time_mid = 0x6d3f,
+        .time_high_and_version = 0x11d2,
+        .clock_seq_high_and_reserved = 0x8e,
+        .clock_seq_low = 0x39,
+        .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
+    };
+};
lib/std/os/uefi/protocols/loaded_image_protocol.zig
@@ -0,0 +1,36 @@
+const uefi = @import("std").os.uefi;
+const Guid = uefi.Guid;
+const Handle = uefi.Handle;
+const SystemTable = uefi.tables.SystemTable;
+const MemoryType = uefi.tables.MemoryType;
+const DevicePathProtocol = uefi.protocols.DevicePathProtocol;
+
+pub const LoadedImageProtocol = extern struct {
+    revision: u32,
+    parent_handle: Handle,
+    system_table: *SystemTable,
+    device_handle: ?Handle,
+    file_path: *DevicePathProtocol,
+    reserved: *c_void,
+    load_options_size: u32,
+    load_options: *c_void,
+    image_base: [*]u8,
+    image_size: u64,
+    image_code_type: MemoryType,
+    image_data_type: MemoryType,
+    _unload: extern fn (*const LoadedImageProtocol, Handle) usize,
+
+    /// Unloads an image from memory.
+    pub fn unload(self: *const LoadedImageProtocol, handle: Handle) usize {
+        return self._unload(self, handle);
+    }
+
+    pub const guid align(8) = Guid{
+        .time_low = 0x5b1b31a1,
+        .time_mid = 0x9562,
+        .time_high_and_version = 0x11d2,
+        .clock_seq_high_and_reserved = 0x8e,
+        .clock_seq_low = 0x3f,
+        .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
+    };
+};
lib/std/os/uefi/tables/boot_services.zig
@@ -3,6 +3,7 @@ const Event = uefi.Event;
 const Guid = uefi.Guid;
 const Handle = uefi.Handle;
 const TableHeader = uefi.tables.TableHeader;
+const DevicePathProtocol = uefi.protocols.DevicePathProtocol;
 
 /// Boot services are services provided by the system's firmware until the operating system takes
 /// over control over the hardware by calling exitBootServices.
@@ -17,47 +18,73 @@ const TableHeader = uefi.tables.TableHeader;
 /// As the boot_services table may grow with new UEFI versions, it is important to check hdr.header_size.
 pub const BootServices = extern struct {
     hdr: TableHeader,
+
     raiseTpl: usize, // TODO
     restoreTpl: usize, // TODO
     allocatePages: usize, // TODO
     freePages: usize, // TODO
+
     /// Returns the current memory map.
     getMemoryMap: extern fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) usize,
+
     /// Allocates pool memory.
     allocatePool: extern fn (MemoryType, usize, *align(8) [*]u8) usize,
+
     freePool: usize, // TODO
+
     /// Creates an event.
     createEvent: extern fn (u32, usize, ?extern fn (Event, ?*const c_void) void, ?*const c_void, *Event) usize,
+
     /// Sets the type of timer and the trigger time for a timer event.
     setTimer: extern fn (Event, TimerDelay, u64) usize,
+
     /// Stops execution until an event is signaled.
     waitForEvent: extern fn (usize, [*]const Event, *usize) usize,
+
     /// Signals an event.
     signalEvent: extern fn (Event) usize,
+
     /// Closes an event.
     closeEvent: extern fn (Event) usize,
+
     checkEvent: usize, // TODO
     installProtocolInterface: usize, // TODO
     reinstallProtocolInterface: usize, // TODO
     uninstallProtocolInterface: usize, // TODO
-    handleProtocol: usize, // TODO
+
+    /// Queries a handle to determine if it supports a specified protocol.
+    handleProtocol: extern fn (Handle, *align(8) const Guid, *?*c_void) usize,
+
     reserved: *c_void,
+
     registerProtocolNotify: usize, // TODO
     locateHandle: usize, // TODO
     locateDevicePath: usize, // TODO
     installConfigurationTable: usize, // TODO
-    imageLoad: usize, // TODO
-    imageStart: usize, // TODO
+
+    /// Loads an EFI image into memory.
+    loadImage: extern fn (bool, Handle, ?*const DevicePathProtocol, ?[*]const u8, usize, *?Handle) usize,
+
+    /// Transfers control to a loaded image's entry point.
+    startImage: extern fn (Handle, ?*usize, ?*[*]u16) usize,
+
     /// Terminates a loaded EFI image and returns control to boot services.
     exit: extern fn (Handle, usize, usize, ?*const c_void) usize,
-    imageUnload: usize, // TODO
+
+    /// Unloads an image.
+    unloadImage: extern fn (Handle) usize,
+
     /// Terminates all boot services.
     exitBootServices: extern fn (Handle, usize) usize,
+
     getNextMonotonicCount: usize, // TODO
+
     /// Induces a fine-grained stall.
     stall: extern fn (usize) usize,
+
     /// Sets the system's watchdog timer.
     setWatchdogTimer: extern fn (usize, u64, usize, ?[*]const u16) usize,
+
     connectController: usize, // TODO
     disconnectController: usize, // TODO
     openProtocol: usize, // TODO
@@ -65,8 +92,10 @@ pub const BootServices = extern struct {
     openProtocolInformation: usize, // TODO
     protocolsPerHandle: usize, // TODO
     locateHandleBuffer: usize, // TODO
+
     /// Returns the first protocol instance that matches the given protocol.
     locateProtocol: extern fn (*align(8) const Guid, ?*const c_void, *?*c_void) usize,
+
     installMultipleProtocolInterfaces: usize, // TODO
     uninstallMultipleProtocolInterfaces: usize, // TODO
     calculateCrc32: usize, // TODO
lib/std/os/uefi/tables/runtime_services.zig
@@ -14,22 +14,30 @@ const TimeCapabilities = uefi.TimeCapabilities;
 /// Some functions may not be called while other functions are running.
 pub const RuntimeServices = extern struct {
     hdr: TableHeader,
+
     /// Returns the current time and date information, and the time-keeping capabilities of the hardware platform.
     getTime: extern fn (*uefi.Time, ?*TimeCapabilities) usize,
+
     setTime: usize, // TODO
     getWakeupTime: usize, // TODO
     setWakeupTime: usize, // TODO
     setVirtualAddressMap: usize, // TODO
     convertPointer: usize, // TODO
+
     /// Returns the value of a variable.
     getVariable: extern fn ([*]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize,
+
     /// Enumerates the current variable names.
     getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize,
+
     /// Sets the value of a variable.
     setVariable: extern fn ([*]const u16, *align(8) const Guid, u32, usize, *c_void) usize,
+
     getNextHighMonotonicCount: usize, // TODO
+
     /// Resets the entire platform.
     resetSystem: extern fn (ResetType, usize, usize, ?*const c_void) noreturn,
+
     updateCapsule: usize, // TODO
     queryCapsuleCapabilities: usize, // TODO
     queryVariableInfo: usize, // TODO
lib/std/os/uefi/protocols.zig
@@ -1,3 +1,7 @@
+pub const LoadedImageProtocol = @import("protocols/loaded_image_protocol.zig").LoadedImageProtocol;
+
+pub const DevicePathProtocol = @import("protocols/device_path_protocol.zig").DevicePathProtocol;
+
 pub const InputKey = @import("protocols/simple_text_input_ex_protocol.zig").InputKey;
 pub const KeyData = @import("protocols/simple_text_input_ex_protocol.zig").KeyData;
 pub const KeyState = @import("protocols/simple_text_input_ex_protocol.zig").KeyState;