Commit 20ce0b9952

Nick Erdmann <n@nirf.de>
2019-08-05 18:26:13
std/os/uefi: replace integer bit fields with packed structs
1 parent b979fc1
std/os/uefi/protocols/absolute_pointer_protocol.zig
@@ -34,17 +34,24 @@ pub const AbsolutePointerMode = extern struct {
     absolute_max_x: u64,
     absolute_max_y: u64,
     absolute_max_z: u64,
-    attributes: u32,
-
-    pub const supports_alt_active: u32 = 1;
-    pub const supports_pressure_as_z: u32 = 2;
+    attributes: packed struct {
+        _pad1: u6,
+        supports_pressure_as_z: bool,
+        supports_alt_active: bool,
+        _pad2: u24,
+    },
 };
 
 pub const AbsolutePointerState = extern struct {
     current_x: u64,
     current_y: u64,
     current_z: u64,
-    active_buttons: u32,
+    active_buttons: packed struct {
+        _pad1: u6,
+        alt_active: bool,
+        touch_active: bool,
+        _pad2: u24,
+    },
 
     pub fn init() AbsolutePointerState {
         return AbsolutePointerState{
@@ -54,7 +61,4 @@ pub const AbsolutePointerState = extern struct {
             .active_buttons = undefined,
         };
     }
-
-    pub const touch_active: u32 = 1;
-    pub const alt_active: u32 = 2;
 };
std/os/uefi/protocols/edid_override_protocol.zig
@@ -6,7 +6,8 @@ const Handle = uefi.Handle;
 pub const EdidOverrideProtocol = extern struct {
     _get_edid: extern fn (*const EdidOverrideProtocol, *const Handle, *u32, *usize, *?[*]u8) usize,
 
-    pub fn getEdid(self: *const EdidOverrideProtocol, handle: *const Handle, attributes: *u32, edid_size: *usize, edid: *?[*]u8) usize {
+    /// attributes must be align(4)
+    pub fn getEdid(self: *const EdidOverrideProtocol, handle: *const Handle, attributes: *EdidOverrideProtocolAttributes, edid_size: *usize, edid: *?[*]u8) usize {
         return self._get_edid(self, handle, attributes, edid_size, edid);
     }
 
@@ -18,6 +19,11 @@ pub const EdidOverrideProtocol = extern struct {
         .clock_seq_low = 0x22,
         .node = [_]u8{ 0xf4, 0x58, 0xfe, 0x04, 0x0b, 0xd5 },
     };
-    pub const dont_override: u32 = 1;
-    pub const enable_hot_plug: u32 = 2;
+};
+
+pub const EdidOverrideProtocolAttributes = packed struct {
+    _pad1: u6,
+    enable_hot_plug: bool,
+    dont_override: bool,
+    _pad2: u24,
 };
std/os/uefi/protocols/simple_text_input_ex_protocol.zig
@@ -54,25 +54,30 @@ pub const KeyData = extern struct {
 };
 
 pub const KeyState = extern struct {
-    key_shift_state: u32,
-    key_toggle_state: u8,
-
-    pub const shift_state_valid: u32 = 0x80000000;
-    pub const right_shift_pressed: u32 = 0x00000001;
-    pub const left_shift_pressed: u32 = 0x00000002;
-    pub const right_control_pressed: u32 = 0x00000004;
-    pub const left_control_pressed: u32 = 0x00000008;
-    pub const right_alt_pressed: u32 = 0x00000010;
-    pub const left_alt_pressed: u32 = 0x00000020;
-    pub const right_logo_pressed: u32 = 0x00000040;
-    pub const left_logo_pressed: u32 = 0x00000080;
-    pub const menu_key_pressed: u32 = 0x00000100;
-    pub const sys_req_pressed: u32 = 0x00000200;
-    pub const toggle_state_valid: u8 = 0x80;
-    pub const key_state_exposed: u8 = 0x40;
-    pub const scroll_lock_active: u8 = 0x01;
-    pub const num_lock_active: u8 = 0x02;
-    pub const caps_lock_active: u8 = 0x04;
+    key_shift_state: packed struct {
+        left_logo_pressed: bool,
+        right_logo_pressed: bool,
+        left_alt_pressed: bool,
+        right_alt_pressed: bool,
+        left_control_pressed: bool,
+        right_control_pressed: bool,
+        left_shift_pressed: bool,
+        right_shift_pressed: bool,
+        _pad1: u6,
+        sys_req_pressed: bool,
+        menu_key_pressed: bool,
+        _pad2: u15,
+        shift_state_valid: bool,
+    },
+    key_toggle_state: packed struct {
+        toggle_state_valid: bool,
+        _pad1: u2,
+        key_state_exposed: bool,
+        caps_lock_active: bool,
+        _pad2: u1,
+        num_lock_active: bool,
+        scroll_lock_active: bool,
+    },
 };
 
 pub const InputKey = extern struct {
std/os/uefi/protocols.zig
@@ -27,5 +27,6 @@ pub const EdidDiscoveredProtocol = @import("protocols/edid_discovered_protocol.z
 pub const EdidActiveProtocol = @import("protocols/edid_active_protocol.zig").EdidActiveProtocol;
 
 pub const EdidOverrideProtocol = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocol;
+pub const EdidOverrideProtocolAttributes = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocolAttributes;
 
 pub const RNGProtocol = @import("protocols/rng_protocol.zig").RNGProtocol;
std/os/uefi.zig
@@ -26,14 +26,16 @@ pub const Time = extern struct {
     hour: u8,
     minute: u8,
     second: u8,
-    pad1: u8,
+    _pad1: u8,
     nanosecond: u32,
     timezone: i16,
-    daylight: u8,
-    pad2: u8,
+    daylight: packed struct {
+        _pad1: u6,
+        in_daylight: bool,
+        adjust_daylight: bool,
+    },
+    _pad2: u8,
 
-    pub const adjust_daylight: u8 = 1;
-    pub const in_daylight: u8 = 2;
     pub const unspecified_timezone: i16 = 0x7ff;
 };
 pub const TimeCapabilities = extern struct {