authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-11 21:44:50-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-03-11 21:44:50-04:00
log3ded862cdf4cec619aea95b595103b72dd23c401
treeb2ca039f85c4d255c3e42b0168ca44d2b33721b1
parent895f67cc6dfe3ade4b635c4c2168843b022edee7
parent58941927c426f61a6680348e4380f9f4eed3e8a8
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4713 from Heppokoyuki/uefi-file-protocols

UEFI library improvements

4 files changed, 115 insertions(+), 2 deletions(-)

lib/std/os/uefi/protocols.zig+4
......@@ -2,6 +2,10 @@ pub const LoadedImageProtocol = @import("protocols/loaded_image_protocol.zig").L
22
33pub const DevicePathProtocol = @import("protocols/device_path_protocol.zig").DevicePathProtocol;
44
5pub const SimpleFileSystemProtocol = @import("protocols/simple_file_system_protocol.zig").SimpleFileSystemProtocol;
6pub const FileProtocol = @import("protocols/file_protocol.zig").FileProtocol;
7pub const FileInfo = @import("protocols/file_protocol.zig").FileInfo;
8
59pub const InputKey = @import("protocols/simple_text_input_ex_protocol.zig").InputKey;
610pub const KeyData = @import("protocols/simple_text_input_ex_protocol.zig").KeyData;
711pub const KeyState = @import("protocols/simple_text_input_ex_protocol.zig").KeyState;
lib/std/os/uefi/protocols/file_protocol.zig created+87
......@@ -0,0 +1,87 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3const Time = uefi.Time;
4
5const FileProtocol = extern struct {
6 revision: u64,
7 _open: extern fn (*const FileProtocol, **const FileProtocol, *u16, u64, u64) usize,
8 _close: extern fn (*const FileProtocol) usize,
9 _delete: extern fn (*const FileProtocol) usize,
10 _read: extern fn (*const FileProtocol, *usize, *c_void) usize,
11 _write: extern fn (*const FileProtocol, *usize, *c_void) usize,
12 _get_info: extern fn (*const FileProtocol, *Guid, *usize, *c_void) usize,
13 _set_info: extern fn (*const FileProtocol, *Guid, usize, *c_void) usize,
14 _flush: extern fn (*const FileProtocol) usize,
15
16 pub fn open(self: *const FileProtocol, new_handle: **const FileProtocol, file_name: *u16, open_mode: u64, attributes: u64) usize {
17 return self._open(self, new_handle, file_name, open_mode, attributes);
18 }
19
20 pub fn close(self: *const FileProtocol) usize {
21 return self._close(self);
22 }
23
24 pub fn delete(self: *const FileProtocol) usize {
25 return self._delete(self);
26 }
27
28 pub fn read(self: *const FileProtocol, buffer_size: *usize, buffer: *c_void) usize {
29 return self._read(self, buffer_size, buffer);
30 }
31
32 pub fn write(self: *const FileProtocol, buffer_size: *usize, buffer: *c_void) usize {
33 return self._write(self, buffer_size, buffer);
34 }
35
36 pub fn get_info(self: *const FileProtocol, information_type: *Guid, buffer_size: *usize, buffer: *c_void) usize {
37 return self._get_info(self, information_type, buffer_size, buffer);
38 }
39
40 pub fn set_info(self: *const FileProtocol, information_type: *Guid, buffer_size: usize, buffer: *c_void) usize {
41 return self._set_info(self, information_type, buffer_size, buffer);
42 }
43
44 pub fn flush(self: *const FileProtocol) usize {
45 return self._flush(self);
46 }
47
48 pub const guid align(8) = Guid{
49 .time_low = 0x09576e92,
50 .time_mid = 0x6d3f,
51 .time_high_and_version = 0x11d2,
52 .clock_seq_high_and_reserved = 0x8e,
53 .clock_seq_low = 0x39,
54 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
55 };
56
57 pub const efi_file_mode_read: u64 = 0x0000000000000001;
58 pub const efi_file_mode_write: u64 = 0x0000000000000002;
59 pub const efi_file_mode_create: u64 = 0x8000000000000000;
60
61 pub const efi_file_read_only: u64 = 0x0000000000000001;
62 pub const efi_file_hidden: u64 = 0x0000000000000002;
63 pub const efi_file_system: u64 = 0x0000000000000004;
64 pub const efi_file_reserved: u64 = 0x0000000000000008;
65 pub const efi_file_directory: u64 = 0x0000000000000010;
66 pub const efi_file_archive: u64 = 0x0000000000000020;
67 pub const efi_file_valid_attr: u64 = 0x0000000000000037;
68};
69
70const FileInfo = extern struct {
71 size: u64,
72 file_size: u64,
73 physical_size: u64,
74 create_time: Time,
75 last_access_time: Time,
76 modification_time: Time,
77 attribute: u64,
78 file_name: [100:0]u16,
79
80 pub const efi_file_read_only: u64 = 0x0000000000000001;
81 pub const efi_file_hidden: u64 = 0x0000000000000002;
82 pub const efi_file_system: u64 = 0x0000000000000004;
83 pub const efi_file_reserved: u64 = 0x0000000000000008;
84 pub const efi_file_directory: u64 = 0x0000000000000010;
85 pub const efi_file_archive: u64 = 0x0000000000000020;
86 pub const efi_file_valid_attr: u64 = 0x0000000000000037;
87};
lib/std/os/uefi/protocols/simple_file_system_protocol.zig created+21
......@@ -0,0 +1,21 @@
1const uefi = @import("std").os.uefi;
2const Guid = uefi.Guid;
3const FileProtocol = uefi.protocols.FileProtocol;
4
5const SimpleFileSystemProtocol = extern struct {
6 revision: u64,
7 _open_volume: extern fn (*const SimpleFileSystemProtocol, **const FileProtocol) usize,
8
9 pub fn openVolume(self: *const SimpleFileSystemProtocol, root: **const FileProtocol) usize {
10 return self._open_volume(self, root);
11 }
12
13 pub const guid align(8) = Guid{
14 .time_low = 0x0964e5b22,
15 .time_mid = 0x6459,
16 .time_high_and_version = 0x11d2,
17 .clock_seq_high_and_reserved = 0x8e,
18 .clock_seq_low = 0x39,
19 .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
20 };
21};
lib/std/os/uefi/protocols/simple_text_input_protocol.zig+3-2
......@@ -1,11 +1,12 @@
11const uefi = @import("std").os.uefi;
22const Event = uefi.Event;
33const Guid = uefi.Guid;
4const InputKey = uefi.protocols.InputKey;
45
56/// Character input devices, e.g. Keyboard
67pub const SimpleTextInputProtocol = extern struct {
78 _reset: extern fn (*const SimpleTextInputProtocol, bool) usize,
8 _read_key_stroke: extern fn (*const SimpleTextInputProtocol, *uefi.protocols.InputKey) usize,
9 _read_key_stroke: extern fn (*const SimpleTextInputProtocol, *InputKey) usize,
910 wait_for_key: Event,
1011
1112 /// Resets the input device hardware.
......@@ -14,7 +15,7 @@ pub const SimpleTextInputProtocol = extern struct {
1415 }
1516
1617 /// Reads the next keystroke from the input device.
17 pub fn readKeyStroke(self: *const SimpleTextInputProtocol, input_key: *uefi.protocols.InputKey) usize {
18 pub fn readKeyStroke(self: *const SimpleTextInputProtocol, input_key: *InputKey) usize {
1819 return self._read_key_stroke(self, input_key);
1920 }
2021