commit a1a3e46e0aa9add9997fe8d56f167830e007ab7f (tree)
parent 23a82b5ffdc0973e6d62b0171268781f8cbcb70d
Author: Andrew Kelley <andrew@ziglang.org>
Date: Fri, 27 Sep 2019 10:41:26 -0400
Merge pull request #3323 from nrdmn/uefi
some minor UEFI improvements
Diffstat:
6 files changed, 184 insertions(+), 20 deletions(-)
diff --git a/lib/std/os/uefi/protocols.zig b/lib/std/os/uefi/protocols.zig
@@ -29,4 +29,11 @@ pub const EdidActiveProtocol = @import("protocols/edid_active_protocol.zig").Edi
pub const EdidOverrideProtocol = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocol;
pub const EdidOverrideProtocolAttributes = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocolAttributes;
+pub const hii = @import("protocols/hii.zig");
+pub const HIIDatabaseProtocol = @import("protocols/hii_database_protocol.zig").HIIDatabaseProtocol;
+pub const HIIPopupProtocol = @import("protocols/hii_popup_protocol.zig").HIIPopupProtocol;
+pub const HIIPopupStyle = @import("protocols/hii_popup_protocol.zig").HIIPopupStyle;
+pub const HIIPopupType = @import("protocols/hii_popup_protocol.zig").HIIPopupType;
+pub const HIIPopupSelection = @import("protocols/hii_popup_protocol.zig").HIIPopupSelection;
+
pub const RNGProtocol = @import("protocols/rng_protocol.zig").RNGProtocol;
diff --git a/lib/std/os/uefi/protocols/hii.zig b/lib/std/os/uefi/protocols/hii.zig
@@ -0,0 +1,71 @@
+const uefi = @import("std").os.uefi;
+const Guid = uefi.Guid;
+
+pub const HIIHandle = *@OpaqueType();
+
+pub const HIIPackageHeader = packed struct {
+ length: u24,
+ type: u8,
+
+ pub const type_all: u8 = 0x0;
+ pub const type_guid: u8 = 0x1;
+ pub const forms: u8 = 0x2;
+ pub const strings: u8 = 0x4;
+ pub const fonts: u8 = 0x5;
+ pub const images: u8 = 0x6;
+ pub const simple_fonsts: u8 = 0x7;
+ pub const device_path: u8 = 0x8;
+ pub const keyboard_layout: u8 = 0x9;
+ pub const animations: u8 = 0xa;
+ pub const end: u8 = 0xdf;
+ pub const type_system_begin: u8 = 0xe0;
+ pub const type_system_end: u8 = 0xff;
+};
+
+pub const HIIPackageList = extern struct {
+ package_list_guid: Guid,
+ package_list_length: u32,
+
+ // TODO implement iterator
+};
+
+pub const HIISimplifiedFontPackage = extern struct {
+ header: HIIPackageHeader,
+ number_of_narrow_glyphs: u16,
+ number_of_wide_glyphs: u16,
+
+ pub fn getNarrowGlyphs(self: *HIISimplifiedFontPackage) []NarrowGlyph {
+ return @ptrCast([*]NarrowGlyph, @ptrCast([*]u8, self) + @sizeOf(HIISimplifiedFontPackage))[0..self.number_of_narrow_glyphs];
+ }
+};
+
+pub const NarrowGlyph = extern struct {
+ unicode_weight: u16,
+ attributes: packed struct {
+ non_spacing: bool,
+ wide: bool,
+ _pad: u6,
+ },
+ glyph_col_1: [19]u8,
+};
+
+pub const WideGlyph = extern struct {
+ unicode_weight: u16,
+ attributes: packed struct {
+ non_spacing: bool,
+ wide: bool,
+ _pad: u6,
+ },
+ glyph_col_1: [19]u8,
+ glyph_col_2: [19]u8,
+ _pad: [3]u8,
+};
+
+pub const HIIStringPackage = extern struct {
+ header: HIIPackageHeader,
+ hdr_size: u32,
+ string_info_offset: u32,
+ language_window: [16]u16,
+ language_name: u16,
+ language: [3]u8,
+};
diff --git a/lib/std/os/uefi/protocols/hii_database_protocol.zig b/lib/std/os/uefi/protocols/hii_database_protocol.zig
@@ -0,0 +1,42 @@
+const uefi = @import("std").os.uefi;
+const Guid = uefi.Guid;
+const hii = uefi.protocols.hii;
+
+pub const HIIDatabaseProtocol = extern struct {
+ _new_package_list: usize, // TODO
+ _remove_package_list: extern fn (*const HIIDatabaseProtocol, hii.HIIHandle) usize,
+ _update_package_list: extern fn (*const HIIDatabaseProtocol, hii.HIIHandle, *const hii.HIIPackageList) usize,
+ _list_package_lists: extern fn (*const HIIDatabaseProtocol, u8, ?*const Guid, *usize, [*]hii.HIIHandle) usize,
+ _export_package_lists: extern fn (*const HIIDatabaseProtocol, ?hii.HIIHandle, *usize, *hii.HIIPackageList) usize,
+ _register_package_notify: usize, // TODO
+ _unregister_package_notify: usize, // TODO
+ _find_keyboard_layouts: usize, // TODO
+ _get_keyboard_layout: usize, // TODO
+ _set_keyboard_layout: usize, // TODO
+ _get_package_list_handle: usize, // TODO
+
+ pub fn removePackageList(self: *const HIIDatabaseProtocol, handle: hii.HIIHandle) usize {
+ return self._remove_package_list(self, handle);
+ }
+
+ pub fn updatePackageList(self: *const HIIDatabaseProtocol, handle: hii.HIIHandle, buffer: *const hii.HIIPackageList) usize {
+ return self._update_package_list(self, handle, buffer);
+ }
+
+ pub fn listPackageLists(self: *const HIIDatabaseProtocol, package_type: u8, package_guid: ?*const Guid, buffer_length: *usize, handles: [*]hii.HIIHandle) usize {
+ return self._list_package_lists(self, package_type, package_guid, buffer_length, handles);
+ }
+
+ pub fn exportPackageLists(self: *const HIIDatabaseProtocol, handle: ?hii.HIIHandle, buffer_size: *usize, buffer: *hii.HIIPackageList) usize {
+ return self._export_package_lists(self, handle, buffer_size, buffer);
+ }
+
+ pub const guid align(8) = Guid{
+ .time_low = 0xef9fc172,
+ .time_mid = 0xa1b2,
+ .time_high_and_version = 0x4693,
+ .clock_seq_high_and_reserved = 0xb3,
+ .clock_seq_low = 0x27,
+ .node = [_]u8{ 0x6d, 0x32, 0xfc, 0x41, 0x60, 0x42 },
+ };
+};
diff --git a/lib/std/os/uefi/protocols/hii_popup_protocol.zig b/lib/std/os/uefi/protocols/hii_popup_protocol.zig
@@ -0,0 +1,41 @@
+const uefi = @import("std").os.uefi;
+const Guid = uefi.Guid;
+const hii = uefi.protocols.hii;
+
+pub const HIIPopupProtocol = extern struct {
+ revision: u64,
+ _create_popup: extern fn (*const HIIPopupProtocol, HIIPopupStyle, HIIPopupType, hii.HIIHandle, u16, ?*HIIPopupSelection) usize,
+
+ pub fn createPopup(self: *const HIIPopupProtocol, style: HIIPopupStyle, popup_type: HIIPopupType, handle: hii.HIIHandle, msg: u16, user_selection: ?*HIIPopupSelection) usize {
+ return self._create_popup(self, style, popup_type, handle, msg, user_selection);
+ }
+
+ pub const guid align(8) = Guid{
+ .time_low = 0x4311edc0,
+ .time_mid = 0x6054,
+ .time_high_and_version = 0x46d4,
+ .clock_seq_high_and_reserved = 0x9e,
+ .clock_seq_low = 0x40,
+ .node = [_]u8{ 0x89, 0x3e, 0xa9, 0x52, 0xfc, 0xcc },
+ };
+};
+
+pub const HIIPopupStyle = extern enum(u32) {
+ Info,
+ Warning,
+ Error,
+};
+
+pub const HIIPopupType = extern enum(u32) {
+ Ok,
+ Cancel,
+ YesNo,
+ YesNoCancel,
+};
+
+pub const HIIPopupSelection = extern enum(u32) {
+ Ok,
+ Cancel,
+ Yes,
+ No,
+};
diff --git a/lib/std/os/uefi/tables.zig b/lib/std/os/uefi/tables.zig
@@ -2,6 +2,7 @@ pub const BootServices = @import("tables/boot_services.zig").BootServices;
pub const ConfigurationTable = @import("tables/configuration_table.zig").ConfigurationTable;
pub const global_variable align(8) = @import("tables/runtime_services.zig").global_variable;
pub const MemoryDescriptor = @import("tables/boot_services.zig").MemoryDescriptor;
+pub const MemoryType = @import("tables/boot_services.zig").MemoryType;
pub const ResetType = @import("tables/runtime_services.zig").ResetType;
pub const RuntimeServices = @import("tables/runtime_services.zig").RuntimeServices;
pub const SystemTable = @import("tables/system_table.zig").SystemTable;
diff --git a/lib/std/os/uefi/tables/boot_services.zig b/lib/std/os/uefi/tables/boot_services.zig
@@ -21,7 +21,7 @@ pub const BootServices = extern struct {
allocatePages: usize, // TODO
freePages: usize, // TODO
getMemoryMap: extern fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) usize,
- allocatePool: usize, // TODO
+ allocatePool: extern fn (MemoryType, usize, *align(8) [*]u8) usize,
freePool: usize, // TODO
createEvent: extern fn (u32, usize, ?extern fn (Event, ?*const c_void) void, ?*const c_void, *Event) usize,
setTimer: extern fn (Event, TimerDelay, u64) usize,
@@ -42,7 +42,7 @@ pub const BootServices = extern struct {
imageStart: usize, // TODO
exit: extern fn (Handle, usize, usize, ?*const c_void) usize,
imageUnload: usize, // TODO
- exitBootServices: usize, // TODO
+ exitBootServices: extern fn (Handle, usize) usize,
getNextMonotonicCount: usize, // TODO
stall: extern fn (usize) usize,
setWatchdogTimer: extern fn (usize, u64, usize, ?[*]const u16) usize,
@@ -82,25 +82,27 @@ pub const TimerDelay = extern enum(u32) {
TimerRelative,
};
+pub const MemoryType = extern enum(u32) {
+ ReservedMemoryType,
+ LoaderCode,
+ LoaderData,
+ BootServicesCode,
+ BootServicesData,
+ RuntimeServicesCode,
+ RuntimeServicesData,
+ ConventionalMemory,
+ UnusableMemory,
+ ACPIReclaimMemory,
+ ACPIMemoryNVS,
+ MemoryMappedIO,
+ MemoryMappedIOPortSpace,
+ PalCode,
+ PersistentMemory,
+ MaxMemoryType,
+};
+
pub const MemoryDescriptor = extern struct {
- type: extern enum(u32) {
- ReservedMemoryType,
- LoaderCode,
- LoaderData,
- BootServicesCode,
- BootServicesData,
- RuntimeServicesCode,
- RuntimeServicesData,
- ConventionalMemory,
- UnusableMemory,
- ACPIReclaimMemory,
- ACPIMemoryNVS,
- MemoryMappedIO,
- MemoryMappedIOPortSpace,
- PalCode,
- PersistentMemory,
- MaxMemoryType,
- },
+ type: MemoryType,
physical_start: u64,
virtual_start: u64,
number_of_pages: usize,