diff --git a/lib/std/os/uefi/protocols.zig b/lib/std/os/uefi/protocols.zig index 58f342ac2..500a246e2 100644 --- a/lib/std/os/uefi/protocols.zig +++ b/lib/std/os/uefi/protocols.zig @@ -2,6 +2,10 @@ pub const LoadedImageProtocol = @import("protocols/loaded_image_protocol.zig").L pub const DevicePathProtocol = @import("protocols/device_path_protocol.zig").DevicePathProtocol; +pub const SimpleFileSystemProtocol = @import("protocols/simple_file_system_protocol.zig").SimpleFileSystemProtocol; +pub const FileProtocol = @import("protocols/file_protocol.zig").FileProtocol; +pub const FileInfo = @import("protocols/file_protocol.zig").FileInfo; + 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; diff --git a/lib/std/os/uefi/protocols/file_protocol.zig b/lib/std/os/uefi/protocols/file_protocol.zig new file mode 100644 index 000000000..cc6785caf --- /dev/null +++ b/lib/std/os/uefi/protocols/file_protocol.zig @@ -0,0 +1,87 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; +const Time = uefi.Time; + +const FileProtocol = extern struct { + revision: u64, + _open: extern fn (*const FileProtocol, **const FileProtocol, *u16, u64, u64) usize, + _close: extern fn (*const FileProtocol) usize, + _delete: extern fn (*const FileProtocol) usize, + _read: extern fn (*const FileProtocol, *usize, *c_void) usize, + _write: extern fn (*const FileProtocol, *usize, *c_void) usize, + _get_info: extern fn (*const FileProtocol, *Guid, *usize, *c_void) usize, + _set_info: extern fn (*const FileProtocol, *Guid, usize, *c_void) usize, + _flush: extern fn (*const FileProtocol) usize, + + pub fn open(self: *const FileProtocol, new_handle: **const FileProtocol, file_name: *u16, open_mode: u64, attributes: u64) usize { + return self._open(self, new_handle, file_name, open_mode, attributes); + } + + pub fn close(self: *const FileProtocol) usize { + return self._close(self); + } + + pub fn delete(self: *const FileProtocol) usize { + return self._delete(self); + } + + pub fn read(self: *const FileProtocol, buffer_size: *usize, buffer: *c_void) usize { + return self._read(self, buffer_size, buffer); + } + + pub fn write(self: *const FileProtocol, buffer_size: *usize, buffer: *c_void) usize { + return self._write(self, buffer_size, buffer); + } + + pub fn get_info(self: *const FileProtocol, information_type: *Guid, buffer_size: *usize, buffer: *c_void) usize { + return self._get_info(self, information_type, buffer_size, buffer); + } + + pub fn set_info(self: *const FileProtocol, information_type: *Guid, buffer_size: usize, buffer: *c_void) usize { + return self._set_info(self, information_type, buffer_size, buffer); + } + + pub fn flush(self: *const FileProtocol) usize { + return self._flush(self); + } + + pub const guid align(8) = Guid{ + .time_low = 0x09576e92, + .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 }, + }; + + pub const efi_file_mode_read: u64 = 0x0000000000000001; + pub const efi_file_mode_write: u64 = 0x0000000000000002; + pub const efi_file_mode_create: u64 = 0x8000000000000000; + + pub const efi_file_read_only: u64 = 0x0000000000000001; + pub const efi_file_hidden: u64 = 0x0000000000000002; + pub const efi_file_system: u64 = 0x0000000000000004; + pub const efi_file_reserved: u64 = 0x0000000000000008; + pub const efi_file_directory: u64 = 0x0000000000000010; + pub const efi_file_archive: u64 = 0x0000000000000020; + pub const efi_file_valid_attr: u64 = 0x0000000000000037; +}; + +const FileInfo = extern struct { + size: u64, + file_size: u64, + physical_size: u64, + create_time: Time, + last_access_time: Time, + modification_time: Time, + attribute: u64, + file_name: [100:0]u16, + + pub const efi_file_read_only: u64 = 0x0000000000000001; + pub const efi_file_hidden: u64 = 0x0000000000000002; + pub const efi_file_system: u64 = 0x0000000000000004; + pub const efi_file_reserved: u64 = 0x0000000000000008; + pub const efi_file_directory: u64 = 0x0000000000000010; + pub const efi_file_archive: u64 = 0x0000000000000020; + pub const efi_file_valid_attr: u64 = 0x0000000000000037; +}; diff --git a/lib/std/os/uefi/protocols/simple_file_system_protocol.zig b/lib/std/os/uefi/protocols/simple_file_system_protocol.zig new file mode 100644 index 000000000..41bfaa18a --- /dev/null +++ b/lib/std/os/uefi/protocols/simple_file_system_protocol.zig @@ -0,0 +1,21 @@ +const uefi = @import("std").os.uefi; +const Guid = uefi.Guid; +const FileProtocol = uefi.protocols.FileProtocol; + +const SimpleFileSystemProtocol = extern struct { + revision: u64, + _open_volume: extern fn (*const SimpleFileSystemProtocol, **const FileProtocol) usize, + + pub fn openVolume(self: *const SimpleFileSystemProtocol, root: **const FileProtocol) usize { + return self._open_volume(self, root); + } + + pub const guid align(8) = Guid{ + .time_low = 0x0964e5b22, + .time_mid = 0x6459, + .time_high_and_version = 0x11d2, + .clock_seq_high_and_reserved = 0x8e, + .clock_seq_low = 0x39, + .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b }, + }; +}; diff --git a/lib/std/os/uefi/protocols/simple_text_input_protocol.zig b/lib/std/os/uefi/protocols/simple_text_input_protocol.zig index b56ff728e..a6d5f837a 100644 --- a/lib/std/os/uefi/protocols/simple_text_input_protocol.zig +++ b/lib/std/os/uefi/protocols/simple_text_input_protocol.zig @@ -1,11 +1,12 @@ const uefi = @import("std").os.uefi; const Event = uefi.Event; const Guid = uefi.Guid; +const InputKey = uefi.protocols.InputKey; /// Character input devices, e.g. Keyboard pub const SimpleTextInputProtocol = extern struct { _reset: extern fn (*const SimpleTextInputProtocol, bool) usize, - _read_key_stroke: extern fn (*const SimpleTextInputProtocol, *uefi.protocols.InputKey) usize, + _read_key_stroke: extern fn (*const SimpleTextInputProtocol, *InputKey) usize, wait_for_key: Event, /// Resets the input device hardware. @@ -14,7 +15,7 @@ pub const SimpleTextInputProtocol = extern struct { } /// Reads the next keystroke from the input device. - pub fn readKeyStroke(self: *const SimpleTextInputProtocol, input_key: *uefi.protocols.InputKey) usize { + pub fn readKeyStroke(self: *const SimpleTextInputProtocol, input_key: *InputKey) usize { return self._read_key_stroke(self, input_key); }