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 @@...@@ -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
1pub const InputKey = @import("protocols/simple_text_input_ex_protocol.zig").InputKey;5pub const InputKey = @import("protocols/simple_text_input_ex_protocol.zig").InputKey;
2pub const KeyData = @import("protocols/simple_text_input_ex_protocol.zig").KeyData;6pub const KeyData = @import("protocols/simple_text_input_ex_protocol.zig").KeyData;
3pub const KeyState = @import("protocols/simple_text_input_ex_protocol.zig").KeyState;7pub 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;...@@ -3,6 +3,7 @@ const Event = uefi.Event;
3const Guid = uefi.Guid;3const Guid = uefi.Guid;
4const Handle = uefi.Handle;4const Handle = uefi.Handle;
5const TableHeader = uefi.tables.TableHeader;5const TableHeader = uefi.tables.TableHeader;
6const DevicePathProtocol = uefi.protocols.DevicePathProtocol;
67
7/// Boot services are services provided by the system's firmware until the operating system takes8/// Boot services are services provided by the system's firmware until the operating system takes
8/// over control over the hardware by calling exitBootServices.9/// over control over the hardware by calling exitBootServices.
...@@ -17,47 +18,73 @@ const TableHeader = uefi.tables.TableHeader;...@@ -17,47 +18,73 @@ const TableHeader = uefi.tables.TableHeader;
17/// As the boot_services table may grow with new UEFI versions, it is important to check hdr.header_size.18/// As the boot_services table may grow with new UEFI versions, it is important to check hdr.header_size.
18pub const BootServices = extern struct {19pub const BootServices = extern struct {
19 hdr: TableHeader,20 hdr: TableHeader,
21
20 raiseTpl: usize, // TODO22 raiseTpl: usize, // TODO
21 restoreTpl: usize, // TODO23 restoreTpl: usize, // TODO
22 allocatePages: usize, // TODO24 allocatePages: usize, // TODO
23 freePages: usize, // TODO25 freePages: usize, // TODO
26
24 /// Returns the current memory map.27 /// Returns the current memory map.
25 getMemoryMap: extern fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) usize,28 getMemoryMap: extern fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) usize,
29
26 /// Allocates pool memory.30 /// Allocates pool memory.
27 allocatePool: extern fn (MemoryType, usize, *align(8) [*]u8) usize,31 allocatePool: extern fn (MemoryType, usize, *align(8) [*]u8) usize,
32
28 freePool: usize, // TODO33 freePool: usize, // TODO
34
29 /// Creates an event.35 /// Creates an event.
30 createEvent: extern fn (u32, usize, ?extern fn (Event, ?*const c_void) void, ?*const c_void, *Event) usize,36 createEvent: extern fn (u32, usize, ?extern fn (Event, ?*const c_void) void, ?*const c_void, *Event) usize,
37
31 /// Sets the type of timer and the trigger time for a timer event.38 /// Sets the type of timer and the trigger time for a timer event.
32 setTimer: extern fn (Event, TimerDelay, u64) usize,39 setTimer: extern fn (Event, TimerDelay, u64) usize,
40
33 /// Stops execution until an event is signaled.41 /// Stops execution until an event is signaled.
34 waitForEvent: extern fn (usize, [*]const Event, *usize) usize,42 waitForEvent: extern fn (usize, [*]const Event, *usize) usize,
43
35 /// Signals an event.44 /// Signals an event.
36 signalEvent: extern fn (Event) usize,45 signalEvent: extern fn (Event) usize,
46
37 /// Closes an event.47 /// Closes an event.
38 closeEvent: extern fn (Event) usize,48 closeEvent: extern fn (Event) usize,
49
39 checkEvent: usize, // TODO50 checkEvent: usize, // TODO
40 installProtocolInterface: usize, // TODO51 installProtocolInterface: usize, // TODO
41 reinstallProtocolInterface: usize, // TODO52 reinstallProtocolInterface: usize, // TODO
42 uninstallProtocolInterface: usize, // TODO53 uninstallProtocolInterface: usize, // TODO
43 handleProtocol: usize, // TODO54
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
44 reserved: *c_void,58 reserved: *c_void,
59
45 registerProtocolNotify: usize, // TODO60 registerProtocolNotify: usize, // TODO
46 locateHandle: usize, // TODO61 locateHandle: usize, // TODO
47 locateDevicePath: usize, // TODO62 locateDevicePath: usize, // TODO
48 installConfigurationTable: usize, // TODO63 installConfigurationTable: usize, // TODO
49 imageLoad: usize, // TODO64
50 imageStart: usize, // TODO65 /// 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
51 /// Terminates a loaded EFI image and returns control to boot services.71 /// Terminates a loaded EFI image and returns control to boot services.
52 exit: extern fn (Handle, usize, usize, ?*const c_void) usize,72 exit: extern fn (Handle, usize, usize, ?*const c_void) usize,
53 imageUnload: usize, // TODO73
74 /// Unloads an image.
75 unloadImage: extern fn (Handle) usize,
76
54 /// Terminates all boot services.77 /// Terminates all boot services.
55 exitBootServices: extern fn (Handle, usize) usize,78 exitBootServices: extern fn (Handle, usize) usize,
79
56 getNextMonotonicCount: usize, // TODO80 getNextMonotonicCount: usize, // TODO
81
57 /// Induces a fine-grained stall.82 /// Induces a fine-grained stall.
58 stall: extern fn (usize) usize,83 stall: extern fn (usize) usize,
84
59 /// Sets the system's watchdog timer.85 /// Sets the system's watchdog timer.
60 setWatchdogTimer: extern fn (usize, u64, usize, ?[*]const u16) usize,86 setWatchdogTimer: extern fn (usize, u64, usize, ?[*]const u16) usize,
87
61 connectController: usize, // TODO88 connectController: usize, // TODO
62 disconnectController: usize, // TODO89 disconnectController: usize, // TODO
63 openProtocol: usize, // TODO90 openProtocol: usize, // TODO
...@@ -65,8 +92,10 @@ pub const BootServices = extern struct {...@@ -65,8 +92,10 @@ pub const BootServices = extern struct {
65 openProtocolInformation: usize, // TODO92 openProtocolInformation: usize, // TODO
66 protocolsPerHandle: usize, // TODO93 protocolsPerHandle: usize, // TODO
67 locateHandleBuffer: usize, // TODO94 locateHandleBuffer: usize, // TODO
95
68 /// Returns the first protocol instance that matches the given protocol.96 /// Returns the first protocol instance that matches the given protocol.
69 locateProtocol: extern fn (*align(8) const Guid, ?*const c_void, *?*c_void) usize,97 locateProtocol: extern fn (*align(8) const Guid, ?*const c_void, *?*c_void) usize,
98
70 installMultipleProtocolInterfaces: usize, // TODO99 installMultipleProtocolInterfaces: usize, // TODO
71 uninstallMultipleProtocolInterfaces: usize, // TODO100 uninstallMultipleProtocolInterfaces: usize, // TODO
72 calculateCrc32: usize, // TODO101 calculateCrc32: usize, // TODO
lib/std/os/uefi/tables/runtime_services.zig+8
...@@ -14,22 +14,30 @@ const TimeCapabilities = uefi.TimeCapabilities;...@@ -14,22 +14,30 @@ const TimeCapabilities = uefi.TimeCapabilities;
14/// Some functions may not be called while other functions are running.14/// Some functions may not be called while other functions are running.
15pub const RuntimeServices = extern struct {15pub const RuntimeServices = extern struct {
16 hdr: TableHeader,16 hdr: TableHeader,
17
17 /// Returns the current time and date information, and the time-keeping capabilities of the hardware platform.18 /// Returns the current time and date information, and the time-keeping capabilities of the hardware platform.
18 getTime: extern fn (*uefi.Time, ?*TimeCapabilities) usize,19 getTime: extern fn (*uefi.Time, ?*TimeCapabilities) usize,
20
19 setTime: usize, // TODO21 setTime: usize, // TODO
20 getWakeupTime: usize, // TODO22 getWakeupTime: usize, // TODO
21 setWakeupTime: usize, // TODO23 setWakeupTime: usize, // TODO
22 setVirtualAddressMap: usize, // TODO24 setVirtualAddressMap: usize, // TODO
23 convertPointer: usize, // TODO25 convertPointer: usize, // TODO
26
24 /// Returns the value of a variable.27 /// Returns the value of a variable.
25 getVariable: extern fn ([*]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize,28 getVariable: extern fn ([*]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize,
29
26 /// Enumerates the current variable names.30 /// Enumerates the current variable names.
27 getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize,31 getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize,
32
28 /// Sets the value of a variable.33 /// Sets the value of a variable.
29 setVariable: extern fn ([*]const u16, *align(8) const Guid, u32, usize, *c_void) usize,34 setVariable: extern fn ([*]const u16, *align(8) const Guid, u32, usize, *c_void) usize,
35
30 getNextHighMonotonicCount: usize, // TODO36 getNextHighMonotonicCount: usize, // TODO
37
31 /// Resets the entire platform.38 /// Resets the entire platform.
32 resetSystem: extern fn (ResetType, usize, usize, ?*const c_void) noreturn,39 resetSystem: extern fn (ResetType, usize, usize, ?*const c_void) noreturn,
40
33 updateCapsule: usize, // TODO41 updateCapsule: usize, // TODO
34 queryCapsuleCapabilities: usize, // TODO42 queryCapsuleCapabilities: usize, // TODO
35 queryVariableInfo: usize, // TODO43 queryVariableInfo: usize, // TODO