mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
change uefi packed structs to new integer backed syntax (#13173)
* std.os.uefi: integer backed structs, add tests to catch regressions device_path_protocol now uses extern structs with align(1) fields because the transition to integer backed packed struct broke alignment added comptime asserts that device_path_protocol structs do not violate alignment and size specifications
This commit is contained in:
parent
1696434063
commit
40e84a27d6
12 changed files with 720 additions and 236 deletions
|
|
@ -50,7 +50,9 @@ comptime {
|
||||||
test {
|
test {
|
||||||
_ = darwin;
|
_ = darwin;
|
||||||
_ = linux;
|
_ = linux;
|
||||||
_ = uefi;
|
if (builtin.os.tag == .uefi) {
|
||||||
|
_ = uefi;
|
||||||
|
}
|
||||||
_ = wasi;
|
_ = wasi;
|
||||||
_ = windows;
|
_ = windows;
|
||||||
_ = posix_spawn;
|
_ = posix_spawn;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ pub const Ipv6Address = extern struct {
|
||||||
address: [16]u8,
|
address: [16]u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// GUIDs must be align(8)
|
/// GUIDs are align(8) unless otherwise specified.
|
||||||
pub const Guid = extern struct {
|
pub const Guid = extern struct {
|
||||||
time_low: u32,
|
time_low: u32,
|
||||||
time_mid: u16,
|
time_mid: u16,
|
||||||
|
|
@ -150,3 +150,8 @@ test "GUID formatting" {
|
||||||
|
|
||||||
try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
|
try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
_ = tables;
|
||||||
|
_ = protocols;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,3 +43,8 @@ pub usingnamespace @import("protocols/udp6_protocol.zig");
|
||||||
pub const hii = @import("protocols/hii.zig");
|
pub const hii = @import("protocols/hii.zig");
|
||||||
pub usingnamespace @import("protocols/hii_database_protocol.zig");
|
pub usingnamespace @import("protocols/hii_database_protocol.zig");
|
||||||
pub usingnamespace @import("protocols/hii_popup_protocol.zig");
|
pub usingnamespace @import("protocols/hii_popup_protocol.zig");
|
||||||
|
|
||||||
|
test {
|
||||||
|
@setEvalBranchQuota(2000);
|
||||||
|
@import("std").testing.refAllDeclsRecursive(@This());
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,12 @@ pub const AbsolutePointerProtocol = extern struct {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const AbsolutePointerModeAttributes = packed struct(u32) {
|
||||||
|
supports_alt_active: bool,
|
||||||
|
supports_pressure_as_z: bool,
|
||||||
|
_pad: u30 = 0,
|
||||||
|
};
|
||||||
|
|
||||||
pub const AbsolutePointerMode = extern struct {
|
pub const AbsolutePointerMode = extern struct {
|
||||||
absolute_min_x: u64,
|
absolute_min_x: u64,
|
||||||
absolute_min_y: u64,
|
absolute_min_y: u64,
|
||||||
|
|
@ -38,20 +44,18 @@ pub const AbsolutePointerMode = extern struct {
|
||||||
absolute_max_x: u64,
|
absolute_max_x: u64,
|
||||||
absolute_max_y: u64,
|
absolute_max_y: u64,
|
||||||
absolute_max_z: u64,
|
absolute_max_z: u64,
|
||||||
attributes: packed struct {
|
attributes: AbsolutePointerModeAttributes,
|
||||||
supports_alt_active: bool,
|
};
|
||||||
supports_pressure_as_z: bool,
|
|
||||||
_pad: u30 = 0,
|
pub const AbsolutePointerStateActiveButtons = packed struct(u32) {
|
||||||
},
|
touch_active: bool,
|
||||||
|
alt_active: bool,
|
||||||
|
_pad: u30 = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const AbsolutePointerState = extern struct {
|
pub const AbsolutePointerState = extern struct {
|
||||||
current_x: u64,
|
current_x: u64,
|
||||||
current_y: u64,
|
current_y: u64,
|
||||||
current_z: u64,
|
current_z: u64,
|
||||||
active_buttons: packed struct {
|
active_buttons: AbsolutePointerStateActiveButtons,
|
||||||
touch_active: bool,
|
|
||||||
alt_active: bool,
|
|
||||||
_pad: u30 = 0,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -6,19 +6,17 @@ const Status = uefi.Status;
|
||||||
|
|
||||||
/// Override EDID information
|
/// Override EDID information
|
||||||
pub const EdidOverrideProtocol = extern struct {
|
pub const EdidOverrideProtocol = extern struct {
|
||||||
_get_edid: std.meta.FnPtr(fn (*const EdidOverrideProtocol, Handle, *u32, *usize, *?[*]u8) callconv(.C) Status),
|
_get_edid: std.meta.FnPtr(fn (*const EdidOverrideProtocol, Handle, *EdidOverrideProtocolAttributes, *usize, *?[*]u8) callconv(.C) Status),
|
||||||
|
|
||||||
/// Returns policy information and potentially a replacement EDID for the specified video output device.
|
/// Returns policy information and potentially a replacement EDID for the specified video output device.
|
||||||
pub fn getEdid(
|
pub fn getEdid(
|
||||||
self: *const EdidOverrideProtocol,
|
self: *const EdidOverrideProtocol,
|
||||||
handle: Handle,
|
handle: Handle,
|
||||||
/// The align(4) here should really be part of the EdidOverrideProtocolAttributes type.
|
attributes: *EdidOverrideProtocolAttributes,
|
||||||
/// TODO remove this workaround when packed(u32) structs are implemented.
|
|
||||||
attributes: *align(4) EdidOverrideProtocolAttributes,
|
|
||||||
edid_size: *usize,
|
edid_size: *usize,
|
||||||
edid: *?[*]u8,
|
edid: *?[*]u8,
|
||||||
) Status {
|
) Status {
|
||||||
return self._get_edid(self, handle, @ptrCast(*u32, attributes), edid_size, edid);
|
return self._get_edid(self, handle, attributes, edid_size, edid);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const guid align(8) = Guid{
|
pub const guid align(8) = Guid{
|
||||||
|
|
@ -31,7 +29,7 @@ pub const EdidOverrideProtocol = extern struct {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const EdidOverrideProtocolAttributes = packed struct {
|
pub const EdidOverrideProtocolAttributes = packed struct(u32) {
|
||||||
dont_override: bool,
|
dont_override: bool,
|
||||||
enable_hot_plug: bool,
|
enable_hot_plug: bool,
|
||||||
_pad: u30 = 0,
|
_pad: u30 = 0,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ const Guid = uefi.Guid;
|
||||||
pub const HIIHandle = *opaque {};
|
pub const HIIHandle = *opaque {};
|
||||||
|
|
||||||
/// The header found at the start of each package.
|
/// The header found at the start of each package.
|
||||||
pub const HIIPackageHeader = packed struct {
|
pub const HIIPackageHeader = packed struct(u32) {
|
||||||
length: u24,
|
length: u24,
|
||||||
type: u8,
|
type: u8,
|
||||||
|
|
||||||
|
|
@ -43,23 +43,27 @@ pub const HIISimplifiedFontPackage = extern struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const NarrowGlyphAttributes = packed struct(u8) {
|
||||||
|
non_spacing: bool,
|
||||||
|
wide: bool,
|
||||||
|
_pad: u6 = 0,
|
||||||
|
};
|
||||||
|
|
||||||
pub const NarrowGlyph = extern struct {
|
pub const NarrowGlyph = extern struct {
|
||||||
unicode_weight: u16,
|
unicode_weight: u16,
|
||||||
attributes: packed struct {
|
attributes: NarrowGlyphAttributes,
|
||||||
non_spacing: bool,
|
|
||||||
wide: bool,
|
|
||||||
_pad: u6 = 0,
|
|
||||||
},
|
|
||||||
glyph_col_1: [19]u8,
|
glyph_col_1: [19]u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const WideGlyphAttributes = packed struct(u8) {
|
||||||
|
non_spacing: bool,
|
||||||
|
wide: bool,
|
||||||
|
_pad: u6 = 0,
|
||||||
|
};
|
||||||
|
|
||||||
pub const WideGlyph = extern struct {
|
pub const WideGlyph = extern struct {
|
||||||
unicode_weight: u16,
|
unicode_weight: u16,
|
||||||
attributes: packed struct {
|
attributes: WideGlyphAttributes,
|
||||||
non_spacing: bool,
|
|
||||||
wide: bool,
|
|
||||||
_pad: u6,
|
|
||||||
},
|
|
||||||
glyph_col_1: [19]u8,
|
glyph_col_1: [19]u8,
|
||||||
glyph_col_2: [19]u8,
|
glyph_col_2: [19]u8,
|
||||||
_pad: [3]u8 = [_]u8{0} ** 3,
|
_pad: [3]u8 = [_]u8{0} ** 3,
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ pub const SimpleNetworkMode = extern struct {
|
||||||
media_present: bool,
|
media_present: bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const SimpleNetworkReceiveFilter = packed struct {
|
pub const SimpleNetworkReceiveFilter = packed struct(u32) {
|
||||||
receive_unicast: bool,
|
receive_unicast: bool,
|
||||||
receive_multicast: bool,
|
receive_multicast: bool,
|
||||||
receive_broadcast: bool,
|
receive_broadcast: bool,
|
||||||
|
|
@ -165,7 +165,7 @@ pub const NetworkStatistics = extern struct {
|
||||||
tx_retry_frames: u64,
|
tx_retry_frames: u64,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const SimpleNetworkInterruptStatus = packed struct {
|
pub const SimpleNetworkInterruptStatus = packed struct(u32) {
|
||||||
receive_interrupt: bool,
|
receive_interrupt: bool,
|
||||||
transmit_interrupt: bool,
|
transmit_interrupt: bool,
|
||||||
command_interrupt: bool,
|
command_interrupt: bool,
|
||||||
|
|
|
||||||
|
|
@ -53,29 +53,33 @@ pub const KeyData = extern struct {
|
||||||
key_state: KeyState = undefined,
|
key_state: KeyState = undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const KeyShiftState = packed struct(u32) {
|
||||||
|
right_shift_pressed: bool,
|
||||||
|
left_shift_pressed: bool,
|
||||||
|
right_control_pressed: bool,
|
||||||
|
left_control_pressed: bool,
|
||||||
|
right_alt_pressed: bool,
|
||||||
|
left_alt_pressed: bool,
|
||||||
|
right_logo_pressed: bool,
|
||||||
|
left_logo_pressed: bool,
|
||||||
|
menu_key_pressed: bool,
|
||||||
|
sys_req_pressed: bool,
|
||||||
|
_pad: u21 = 0,
|
||||||
|
shift_state_valid: bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const KeyToggleState = packed struct(u8) {
|
||||||
|
scroll_lock_active: bool,
|
||||||
|
num_lock_active: bool,
|
||||||
|
caps_lock_active: bool,
|
||||||
|
_pad: u3 = 0,
|
||||||
|
key_state_exposed: bool,
|
||||||
|
toggle_state_valid: bool,
|
||||||
|
};
|
||||||
|
|
||||||
pub const KeyState = extern struct {
|
pub const KeyState = extern struct {
|
||||||
key_shift_state: packed struct {
|
key_shift_state: KeyShiftState,
|
||||||
right_shift_pressed: bool,
|
key_toggle_state: KeyToggleState,
|
||||||
left_shift_pressed: bool,
|
|
||||||
right_control_pressed: bool,
|
|
||||||
left_control_pressed: bool,
|
|
||||||
right_alt_pressed: bool,
|
|
||||||
left_alt_pressed: bool,
|
|
||||||
right_logo_pressed: bool,
|
|
||||||
left_logo_pressed: bool,
|
|
||||||
menu_key_pressed: bool,
|
|
||||||
sys_req_pressed: bool,
|
|
||||||
_pad: u21 = 0,
|
|
||||||
shift_state_valid: bool,
|
|
||||||
},
|
|
||||||
key_toggle_state: packed struct {
|
|
||||||
scroll_lock_active: bool,
|
|
||||||
num_lock_active: bool,
|
|
||||||
caps_lock_active: bool,
|
|
||||||
_pad: u3 = 0,
|
|
||||||
key_state_exposed: bool,
|
|
||||||
toggle_state_valid: bool,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const InputKey = extern struct {
|
pub const InputKey = extern struct {
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,7 @@ pub usingnamespace @import("tables/runtime_services.zig");
|
||||||
pub usingnamespace @import("tables/configuration_table.zig");
|
pub usingnamespace @import("tables/configuration_table.zig");
|
||||||
pub usingnamespace @import("tables/system_table.zig");
|
pub usingnamespace @import("tables/system_table.zig");
|
||||||
pub usingnamespace @import("tables/table_header.zig");
|
pub usingnamespace @import("tables/table_header.zig");
|
||||||
|
|
||||||
|
test {
|
||||||
|
@import("std").testing.refAllDeclsRecursive(@This());
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -219,33 +219,32 @@ pub const MemoryType = enum(u32) {
|
||||||
_,
|
_,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const MemoryDescriptorAttribute = packed struct(u64) {
|
||||||
|
uc: bool,
|
||||||
|
wc: bool,
|
||||||
|
wt: bool,
|
||||||
|
wb: bool,
|
||||||
|
uce: bool,
|
||||||
|
_pad1: u7 = 0,
|
||||||
|
wp: bool,
|
||||||
|
rp: bool,
|
||||||
|
xp: bool,
|
||||||
|
nv: bool,
|
||||||
|
more_reliable: bool,
|
||||||
|
ro: bool,
|
||||||
|
sp: bool,
|
||||||
|
cpu_crypto: bool,
|
||||||
|
_pad2: u43 = 0,
|
||||||
|
memory_runtime: bool,
|
||||||
|
};
|
||||||
|
|
||||||
pub const MemoryDescriptor = extern struct {
|
pub const MemoryDescriptor = extern struct {
|
||||||
type: MemoryType,
|
type: MemoryType,
|
||||||
padding: u32,
|
padding: u32,
|
||||||
physical_start: u64,
|
physical_start: u64,
|
||||||
virtual_start: u64,
|
virtual_start: u64,
|
||||||
number_of_pages: usize,
|
number_of_pages: usize,
|
||||||
attribute: packed struct {
|
attribute: MemoryDescriptorAttribute,
|
||||||
uc: bool,
|
|
||||||
wc: bool,
|
|
||||||
wt: bool,
|
|
||||||
wb: bool,
|
|
||||||
uce: bool,
|
|
||||||
_pad1: u3,
|
|
||||||
_pad2: u4,
|
|
||||||
wp: bool,
|
|
||||||
rp: bool,
|
|
||||||
xp: bool,
|
|
||||||
nv: bool,
|
|
||||||
more_reliable: bool,
|
|
||||||
ro: bool,
|
|
||||||
sp: bool,
|
|
||||||
cpu_crypto: bool,
|
|
||||||
_pad3: u4,
|
|
||||||
_pad4: u32,
|
|
||||||
_pad5: u7,
|
|
||||||
memory_runtime: bool,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const LocateSearchType = enum(u32) {
|
pub const LocateSearchType = enum(u32) {
|
||||||
|
|
@ -254,14 +253,14 @@ pub const LocateSearchType = enum(u32) {
|
||||||
ByProtocol,
|
ByProtocol,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const OpenProtocolAttributes = packed struct {
|
pub const OpenProtocolAttributes = packed struct(u32) {
|
||||||
by_handle_protocol: bool = false,
|
by_handle_protocol: bool = false,
|
||||||
get_protocol: bool = false,
|
get_protocol: bool = false,
|
||||||
test_protocol: bool = false,
|
test_protocol: bool = false,
|
||||||
by_child_controller: bool = false,
|
by_child_controller: bool = false,
|
||||||
by_driver: bool = false,
|
by_driver: bool = false,
|
||||||
exclusive: bool = false,
|
exclusive: bool = false,
|
||||||
_pad: u26 = 0,
|
reserved: u26 = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ProtocolInformationEntry = extern struct {
|
pub const ProtocolInformationEntry = extern struct {
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ pub const CapsuleHeader = extern struct {
|
||||||
|
|
||||||
pub const UefiCapsuleBlockDescriptor = extern struct {
|
pub const UefiCapsuleBlockDescriptor = extern struct {
|
||||||
length: u64,
|
length: u64,
|
||||||
address: union {
|
address: extern union {
|
||||||
dataBlock: EfiPhysicalAddress,
|
dataBlock: EfiPhysicalAddress,
|
||||||
continuationPointer: EfiPhysicalAddress,
|
continuationPointer: EfiPhysicalAddress,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue