authorgravatar for n@nirf.deNick Erdmann <n@nirf.de> 2019-10-28 23:12:28+01:00
committergravatar for n@nirf.deNick Erdmann <n@nirf.de> 2019-11-07 02:53:53+01:00
logf4767186dd34118a27c205fe481b42c33e7ba0d3
tree190cb224846f06894b05da1620487b43172145e2
parent6fdeaac338f3a4a1f3455653ce29bf6ce4bbe335
signaturelock-open Commit is signed but in an unrecognized format.

std/os/uefi: loading images


5 files changed, 98 insertions(+), 4 deletions(-)

lib/std/os/uefi/protocols.zig+4
......@@ -1,3 +1,7 @@
1pub const LoadedImageProtocol = @import("protocols/loaded_image_protocol.zig").LoadedImageProtocol;
2
3pub const DevicePathProtocol = @import("protocols/device_path_protocol.zig").DevicePathProtocol;
4
15pub const InputKey = @import("protocols/simple_text_input_ex_protocol.zig").InputKey;
26pub const KeyData = @import("protocols/simple_text_input_ex_protocol.zig").KeyData;
37pub const KeyState = @import("protocols/simple_text_input_ex_protocol.zig").KeyState;
lib/std/os/uefi/protocols/device_path_protocol.zig created+17
......@@ -0,0 +1,17 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3
4pub const DevicePathProtocol = extern struct {
5 type: u8,
6 subtype: u8,
7 length: u16,
8
9 pub const guid align(8) = Guid{
10 .time_low = 0x09576e91,
11 .time_mid = 0x6d3f,
12 .time_high_and_version = 0x11d2,
13 .clock_seq_high_and_reserved = 0x8e,
14 .clock_seq_low = 0x39,
15 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
16 };
17};
lib/std/os/uefi/protocols/loaded_image_protocol.zig created+36
......@@ -0,0 +1,36 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3const Handle = uefi.Handle;
4const SystemTable = uefi.tables.SystemTable;
5const MemoryType = uefi.tables.MemoryType;
6const DevicePathProtocol = uefi.protocols.DevicePathProtocol;
7
8pub const LoadedImageProtocol = extern struct {
9 revision: u32,
10 parent_handle: Handle,
11 system_table: *SystemTable,
12 device_handle: ?Handle,
13 file_path: *DevicePathProtocol,
14 reserved: *c_void,
15 load_options_size: u32,
16 load_options: *c_void,
17 image_base: [*]u8,
18 image_size: u64,
19 image_code_type: MemoryType,
20 image_data_type: MemoryType,
21 _unload: extern fn (*const LoadedImageProtocol, Handle) usize,
22
23 /// Unloads an image from memory.
24 pub fn unload(self: *const LoadedImageProtocol, handle: Handle) usize {
25 return self._unload(self, handle);
26 }
27
28 pub const guid align(8) = Guid{
29 .time_low = 0x5b1b31a1,
30 .time_mid = 0x9562,
31 .time_high_and_version = 0x11d2,
32 .clock_seq_high_and_reserved = 0x8e,
33 .clock_seq_low = 0x3f,
34 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
35 };
36};
lib/std/os/uefi/tables/boot_services.zig+33-4
......@@ -3,6 +3,7 @@ const Event = uefi.Event;
33const Guid = uefi.Guid;
44const Handle = uefi.Handle;
55const TableHeader = uefi.tables.TableHeader;
6const DevicePathProtocol = uefi.protocols.DevicePathProtocol;
67
78/// Boot services are services provided by the system's firmware until the operating system takes
89/// over control over the hardware by calling exitBootServices.
......@@ -17,47 +18,73 @@ const TableHeader = uefi.tables.TableHeader;
1718/// As the boot_services table may grow with new UEFI versions, it is important to check hdr.header_size.
1819pub const BootServices = extern struct {
1920 hdr: TableHeader,
21
2022 raiseTpl: usize, // TODO
2123 restoreTpl: usize, // TODO
2224 allocatePages: usize, // TODO
2325 freePages: usize, // TODO
26
2427 /// Returns the current memory map.
2528 getMemoryMap: extern fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) usize,
29
2630 /// Allocates pool memory.
2731 allocatePool: extern fn (MemoryType, usize, *align(8) [*]u8) usize,
32
2833 freePool: usize, // TODO
34
2935 /// Creates an event.
3036 createEvent: extern fn (u32, usize, ?extern fn (Event, ?*const c_void) void, ?*const c_void, *Event) usize,
37
3138 /// Sets the type of timer and the trigger time for a timer event.
3239 setTimer: extern fn (Event, TimerDelay, u64) usize,
40
3341 /// Stops execution until an event is signaled.
3442 waitForEvent: extern fn (usize, [*]const Event, *usize) usize,
43
3544 /// Signals an event.
3645 signalEvent: extern fn (Event) usize,
46
3747 /// Closes an event.
3848 closeEvent: extern fn (Event) usize,
49
3950 checkEvent: usize, // TODO
4051 installProtocolInterface: usize, // TODO
4152 reinstallProtocolInterface: usize, // TODO
4253 uninstallProtocolInterface: usize, // TODO
43 handleProtocol: usize, // TODO
54
55 /// Queries a handle to determine if it supports a specified protocol.
56 handleProtocol: extern fn (Handle, *align(8) const Guid, *?*c_void) usize,
57
4458 reserved: *c_void,
59
4560 registerProtocolNotify: usize, // TODO
4661 locateHandle: usize, // TODO
4762 locateDevicePath: usize, // TODO
4863 installConfigurationTable: usize, // TODO
49 imageLoad: usize, // TODO
50 imageStart: usize, // TODO
64
65 /// Loads an EFI image into memory.
66 loadImage: extern fn (bool, Handle, ?*const DevicePathProtocol, ?[*]const u8, usize, *?Handle) usize,
67
68 /// Transfers control to a loaded image's entry point.
69 startImage: extern fn (Handle, ?*usize, ?*[*]u16) usize,
70
5171 /// Terminates a loaded EFI image and returns control to boot services.
5272 exit: extern fn (Handle, usize, usize, ?*const c_void) usize,
53 imageUnload: usize, // TODO
73
74 /// Unloads an image.
75 unloadImage: extern fn (Handle) usize,
76
5477 /// Terminates all boot services.
5578 exitBootServices: extern fn (Handle, usize) usize,
79
5680 getNextMonotonicCount: usize, // TODO
81
5782 /// Induces a fine-grained stall.
5883 stall: extern fn (usize) usize,
84
5985 /// Sets the system's watchdog timer.
6086 setWatchdogTimer: extern fn (usize, u64, usize, ?[*]const u16) usize,
87
6188 connectController: usize, // TODO
6289 disconnectController: usize, // TODO
6390 openProtocol: usize, // TODO
......@@ -65,8 +92,10 @@ pub const BootServices = extern struct {
6592 openProtocolInformation: usize, // TODO
6693 protocolsPerHandle: usize, // TODO
6794 locateHandleBuffer: usize, // TODO
95
6896 /// Returns the first protocol instance that matches the given protocol.
6997 locateProtocol: extern fn (*align(8) const Guid, ?*const c_void, *?*c_void) usize,
98
7099 installMultipleProtocolInterfaces: usize, // TODO
71100 uninstallMultipleProtocolInterfaces: usize, // TODO
72101 calculateCrc32: usize, // TODO
lib/std/os/uefi/tables/runtime_services.zig+8
......@@ -14,22 +14,30 @@ const TimeCapabilities = uefi.TimeCapabilities;
1414/// Some functions may not be called while other functions are running.
1515pub const RuntimeServices = extern struct {
1616 hdr: TableHeader,
17
1718 /// Returns the current time and date information, and the time-keeping capabilities of the hardware platform.
1819 getTime: extern fn (*uefi.Time, ?*TimeCapabilities) usize,
20
1921 setTime: usize, // TODO
2022 getWakeupTime: usize, // TODO
2123 setWakeupTime: usize, // TODO
2224 setVirtualAddressMap: usize, // TODO
2325 convertPointer: usize, // TODO
26
2427 /// Returns the value of a variable.
2528 getVariable: extern fn ([*]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize,
29
2630 /// Enumerates the current variable names.
2731 getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize,
32
2833 /// Sets the value of a variable.
2934 setVariable: extern fn ([*]const u16, *align(8) const Guid, u32, usize, *c_void) usize,
35
3036 getNextHighMonotonicCount: usize, // TODO
37
3138 /// Resets the entire platform.
3239 resetSystem: extern fn (ResetType, usize, usize, ?*const c_void) noreturn,
40
3341 updateCapsule: usize, // TODO
3442 queryCapsuleCapabilities: usize, // TODO
3543 queryVariableInfo: usize, // TODO