authorgravatar for truemedian@gmail.comNameless <truemedian@gmail.com> 2022-10-30 19:08:32+00:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-10-30 15:08:32-04:00
log40e84a27d68e34b26a9e132b59169b14b6ef99c5
tree7489f217dcd2e874121d2048e98002a68cad1ba9
parent1696434063dd6b09af93fbab04727f91397e2e00
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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

12 files changed, 720 insertions(+), 236 deletions(-)

lib/std/os.zig+3-1
...@@ -50,7 +50,9 @@ comptime {...@@ -50,7 +50,9 @@ comptime {
50test {50test {
51 _ = darwin;51 _ = darwin;
52 _ = linux;52 _ = linux;
53 _ = uefi;53 if (builtin.os.tag == .uefi) {
54 _ = uefi;
55 }
54 _ = wasi;56 _ = wasi;
55 _ = windows;57 _ = windows;
56 _ = posix_spawn;58 _ = posix_spawn;
lib/std/os/uefi.zig+6-1
...@@ -35,7 +35,7 @@ pub const Ipv6Address = extern struct {...@@ -35,7 +35,7 @@ pub const Ipv6Address = extern struct {
35 address: [16]u8,35 address: [16]u8,
36};36};
3737
38/// GUIDs must be align(8)38/// GUIDs are align(8) unless otherwise specified.
39pub const Guid = extern struct {39pub const Guid = extern struct {
40 time_low: u32,40 time_low: u32,
41 time_mid: u16,41 time_mid: u16,
...@@ -150,3 +150,8 @@ test "GUID formatting" {...@@ -150,3 +150,8 @@ test "GUID formatting" {
150150
151 try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));151 try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
152}152}
153
154test {
155 _ = tables;
156 _ = protocols;
157}
lib/std/os/uefi/protocols.zig+5
...@@ -43,3 +43,8 @@ pub usingnamespace @import("protocols/udp6_protocol.zig");...@@ -43,3 +43,8 @@ pub usingnamespace @import("protocols/udp6_protocol.zig");
43pub const hii = @import("protocols/hii.zig");43pub const hii = @import("protocols/hii.zig");
44pub usingnamespace @import("protocols/hii_database_protocol.zig");44pub usingnamespace @import("protocols/hii_database_protocol.zig");
45pub usingnamespace @import("protocols/hii_popup_protocol.zig");45pub usingnamespace @import("protocols/hii_popup_protocol.zig");
46
47test {
48 @setEvalBranchQuota(2000);
49 @import("std").testing.refAllDeclsRecursive(@This());
50}
lib/std/os/uefi/protocols/absolute_pointer_protocol.zig+14-10
...@@ -31,6 +31,12 @@ pub const AbsolutePointerProtocol = extern struct {...@@ -31,6 +31,12 @@ pub const AbsolutePointerProtocol = extern struct {
31 };31 };
32};32};
3333
34pub const AbsolutePointerModeAttributes = packed struct(u32) {
35 supports_alt_active: bool,
36 supports_pressure_as_z: bool,
37 _pad: u30 = 0,
38};
39
34pub const AbsolutePointerMode = extern struct {40pub const AbsolutePointerMode = extern struct {
35 absolute_min_x: u64,41 absolute_min_x: u64,
36 absolute_min_y: u64,42 absolute_min_y: u64,
...@@ -38,20 +44,18 @@ pub const AbsolutePointerMode = extern struct {...@@ -38,20 +44,18 @@ pub const AbsolutePointerMode = extern struct {
38 absolute_max_x: u64,44 absolute_max_x: u64,
39 absolute_max_y: u64,45 absolute_max_y: u64,
40 absolute_max_z: u64,46 absolute_max_z: u64,
41 attributes: packed struct {47 attributes: AbsolutePointerModeAttributes,
42 supports_alt_active: bool,48};
43 supports_pressure_as_z: bool,49
44 _pad: u30 = 0,50pub const AbsolutePointerStateActiveButtons = packed struct(u32) {
45 },51 touch_active: bool,
52 alt_active: bool,
53 _pad: u30 = 0,
46};54};
4755
48pub const AbsolutePointerState = extern struct {56pub const AbsolutePointerState = extern struct {
49 current_x: u64,57 current_x: u64,
50 current_y: u64,58 current_y: u64,
51 current_z: u64,59 current_z: u64,
52 active_buttons: packed struct {60 active_buttons: AbsolutePointerStateActiveButtons,
53 touch_active: bool,
54 alt_active: bool,
55 _pad: u30 = 0,
56 },
57};61};
lib/std/os/uefi/protocols/device_path_protocol.zig+618-159
...@@ -4,10 +4,13 @@ const uefi = std.os.uefi;...@@ -4,10 +4,13 @@ const uefi = std.os.uefi;
4const Allocator = mem.Allocator;4const Allocator = mem.Allocator;
5const Guid = uefi.Guid;5const Guid = uefi.Guid;
66
7pub const DevicePathProtocol = packed struct {7// All Device Path Nodes are byte-packed and may appear on any byte boundary.
8// All code references to device path nodes must assume all fields are unaligned.
9
10pub const DevicePathProtocol = extern struct {
8 type: DevicePathType,11 type: DevicePathType,
9 subtype: u8,12 subtype: u8,
10 length: u16,13 length: u16 align(1),
1114
12 pub const guid align(8) = Guid{15 pub const guid align(8) = Guid{
13 .time_low = 0x09576e91,16 .time_low = 0x09576e91,
...@@ -38,7 +41,7 @@ pub const DevicePathProtocol = packed struct {...@@ -38,7 +41,7 @@ pub const DevicePathProtocol = packed struct {
38 }41 }
3942
40 /// Creates a file device path from the existing device path and a file path.43 /// Creates a file device path from the existing device path and a file path.
41 pub fn create_file_device_path(self: *DevicePathProtocol, allocator: Allocator, path: [:0]const u16) !*DevicePathProtocol {44 pub fn create_file_device_path(self: *DevicePathProtocol, allocator: Allocator, path: [:0]align(1) const u16) !*DevicePathProtocol {
42 var path_size = self.size();45 var path_size = self.size();
4346
44 // 2 * (path.len + 1) for the path and its null terminator, which are u16s47 // 2 * (path.len + 1) for the path and its null terminator, which are u16s
...@@ -56,7 +59,7 @@ pub const DevicePathProtocol = packed struct {...@@ -56,7 +59,7 @@ pub const DevicePathProtocol = packed struct {
56 new.length = @sizeOf(MediaDevicePath.FilePathDevicePath) + 2 * (@intCast(u16, path.len) + 1);59 new.length = @sizeOf(MediaDevicePath.FilePathDevicePath) + 2 * (@intCast(u16, path.len) + 1);
5760
58 // The same as new.getPath(), but not const as we're filling it in.61 // The same as new.getPath(), but not const as we're filling it in.
59 var ptr = @ptrCast([*:0]u16, @alignCast(2, @ptrCast([*]u8, new)) + @sizeOf(MediaDevicePath.FilePathDevicePath));62 var ptr = @ptrCast([*:0]align(1) u16, @ptrCast([*]u8, new) + @sizeOf(MediaDevicePath.FilePathDevicePath));
6063
61 for (path) |s, i|64 for (path) |s, i|
62 ptr[i] = s;65 ptr[i] = s;
...@@ -108,6 +111,15 @@ pub const DevicePathProtocol = packed struct {...@@ -108,6 +111,15 @@ pub const DevicePathProtocol = packed struct {
108 }111 }
109};112};
110113
114comptime {
115 std.debug.assert(4 == @sizeOf(DevicePathProtocol));
116 std.debug.assert(1 == @alignOf(DevicePathProtocol));
117
118 std.debug.assert(0 == @offsetOf(DevicePathProtocol, "type"));
119 std.debug.assert(1 == @offsetOf(DevicePathProtocol, "subtype"));
120 std.debug.assert(2 == @offsetOf(DevicePathProtocol, "length"));
121}
122
111pub const DevicePath = union(DevicePathType) {123pub const DevicePath = union(DevicePathType) {
112 Hardware: HardwareDevicePath,124 Hardware: HardwareDevicePath,
113 Acpi: AcpiDevicePath,125 Acpi: AcpiDevicePath,
...@@ -145,51 +157,115 @@ pub const HardwareDevicePath = union(Subtype) {...@@ -145,51 +157,115 @@ pub const HardwareDevicePath = union(Subtype) {
145 _,157 _,
146 };158 };
147159
148 pub const PciDevicePath = packed struct {160 pub const PciDevicePath = extern struct {
149 type: DevicePathType,161 type: DevicePathType,
150 subtype: Subtype,162 subtype: Subtype,
151 length: u16,163 length: u16 align(1),
152 function: u8,164 function: u8,
153 device: u8,165 device: u8,
154 };166 };
155167
156 pub const PcCardDevicePath = packed struct {168 comptime {
169 std.debug.assert(6 == @sizeOf(PciDevicePath));
170 std.debug.assert(1 == @alignOf(PciDevicePath));
171
172 std.debug.assert(0 == @offsetOf(PciDevicePath, "type"));
173 std.debug.assert(1 == @offsetOf(PciDevicePath, "subtype"));
174 std.debug.assert(2 == @offsetOf(PciDevicePath, "length"));
175 std.debug.assert(4 == @offsetOf(PciDevicePath, "function"));
176 std.debug.assert(5 == @offsetOf(PciDevicePath, "device"));
177 }
178
179 pub const PcCardDevicePath = extern struct {
157 type: DevicePathType,180 type: DevicePathType,
158 subtype: Subtype,181 subtype: Subtype,
159 length: u16,182 length: u16 align(1),
160 function_number: u8,183 function_number: u8,
161 };184 };
162185
163 pub const MemoryMappedDevicePath = packed struct {186 comptime {
187 std.debug.assert(5 == @sizeOf(PcCardDevicePath));
188 std.debug.assert(1 == @alignOf(PcCardDevicePath));
189
190 std.debug.assert(0 == @offsetOf(PcCardDevicePath, "type"));
191 std.debug.assert(1 == @offsetOf(PcCardDevicePath, "subtype"));
192 std.debug.assert(2 == @offsetOf(PcCardDevicePath, "length"));
193 std.debug.assert(4 == @offsetOf(PcCardDevicePath, "function_number"));
194 }
195
196 pub const MemoryMappedDevicePath = extern struct {
164 type: DevicePathType,197 type: DevicePathType,
165 subtype: Subtype,198 subtype: Subtype,
166 length: u16,199 length: u16 align(1),
167 memory_type: u32,200 memory_type: u32 align(1),
168 start_address: u64,201 start_address: u64 align(1),
169 end_address: u64,202 end_address: u64 align(1),
170 };203 };
171204
172 pub const VendorDevicePath = packed struct {205 comptime {
206 std.debug.assert(24 == @sizeOf(MemoryMappedDevicePath));
207 std.debug.assert(1 == @alignOf(MemoryMappedDevicePath));
208
209 std.debug.assert(0 == @offsetOf(MemoryMappedDevicePath, "type"));
210 std.debug.assert(1 == @offsetOf(MemoryMappedDevicePath, "subtype"));
211 std.debug.assert(2 == @offsetOf(MemoryMappedDevicePath, "length"));
212 std.debug.assert(4 == @offsetOf(MemoryMappedDevicePath, "memory_type"));
213 std.debug.assert(8 == @offsetOf(MemoryMappedDevicePath, "start_address"));
214 std.debug.assert(16 == @offsetOf(MemoryMappedDevicePath, "end_address"));
215 }
216
217 pub const VendorDevicePath = extern struct {
173 type: DevicePathType,218 type: DevicePathType,
174 subtype: Subtype,219 subtype: Subtype,
175 length: u16,220 length: u16 align(1),
176 vendor_guid: Guid,221 vendor_guid: Guid align(1),
177 };222 };
178223
179 pub const ControllerDevicePath = packed struct {224 comptime {
225 std.debug.assert(20 == @sizeOf(VendorDevicePath));
226 std.debug.assert(1 == @alignOf(VendorDevicePath));
227
228 std.debug.assert(0 == @offsetOf(VendorDevicePath, "type"));
229 std.debug.assert(1 == @offsetOf(VendorDevicePath, "subtype"));
230 std.debug.assert(2 == @offsetOf(VendorDevicePath, "length"));
231 std.debug.assert(4 == @offsetOf(VendorDevicePath, "vendor_guid"));
232 }
233
234 pub const ControllerDevicePath = extern struct {
180 type: DevicePathType,235 type: DevicePathType,
181 subtype: Subtype,236 subtype: Subtype,
182 length: u16,237 length: u16 align(1),
183 controller_number: u32,238 controller_number: u32 align(1),
184 };239 };
185240
186 pub const BmcDevicePath = packed struct {241 comptime {
242 std.debug.assert(8 == @sizeOf(ControllerDevicePath));
243 std.debug.assert(1 == @alignOf(ControllerDevicePath));
244
245 std.debug.assert(0 == @offsetOf(ControllerDevicePath, "type"));
246 std.debug.assert(1 == @offsetOf(ControllerDevicePath, "subtype"));
247 std.debug.assert(2 == @offsetOf(ControllerDevicePath, "length"));
248 std.debug.assert(4 == @offsetOf(ControllerDevicePath, "controller_number"));
249 }
250
251 pub const BmcDevicePath = extern struct {
187 type: DevicePathType,252 type: DevicePathType,
188 subtype: Subtype,253 subtype: Subtype,
189 length: u16,254 length: u16 align(1),
190 interface_type: u8,255 interface_type: u8,
191 base_address: usize,256 base_address: u64 align(1),
192 };257 };
258
259 comptime {
260 std.debug.assert(13 == @sizeOf(BmcDevicePath));
261 std.debug.assert(1 == @alignOf(BmcDevicePath));
262
263 std.debug.assert(0 == @offsetOf(BmcDevicePath, "type"));
264 std.debug.assert(1 == @offsetOf(BmcDevicePath, "subtype"));
265 std.debug.assert(2 == @offsetOf(BmcDevicePath, "length"));
266 std.debug.assert(4 == @offsetOf(BmcDevicePath, "interface_type"));
267 std.debug.assert(5 == @offsetOf(BmcDevicePath, "base_address"));
268 }
193};269};
194270
195pub const AcpiDevicePath = union(Subtype) {271pub const AcpiDevicePath = union(Subtype) {
...@@ -204,37 +280,71 @@ pub const AcpiDevicePath = union(Subtype) {...@@ -204,37 +280,71 @@ pub const AcpiDevicePath = union(Subtype) {
204 _,280 _,
205 };281 };
206282
207 pub const BaseAcpiDevicePath = packed struct {283 pub const BaseAcpiDevicePath = extern struct {
208 type: DevicePathType,284 type: DevicePathType,
209 subtype: Subtype,285 subtype: Subtype,
210 length: u16,286 length: u16 align(1),
211 hid: u32,287 hid: u32 align(1),
212 uid: u32,288 uid: u32 align(1),
213 };289 };
214290
215 pub const ExpandedAcpiDevicePath = packed struct {291 comptime {
292 std.debug.assert(12 == @sizeOf(BaseAcpiDevicePath));
293 std.debug.assert(1 == @alignOf(BaseAcpiDevicePath));
294
295 std.debug.assert(0 == @offsetOf(BaseAcpiDevicePath, "type"));
296 std.debug.assert(1 == @offsetOf(BaseAcpiDevicePath, "subtype"));
297 std.debug.assert(2 == @offsetOf(BaseAcpiDevicePath, "length"));
298 std.debug.assert(4 == @offsetOf(BaseAcpiDevicePath, "hid"));
299 std.debug.assert(8 == @offsetOf(BaseAcpiDevicePath, "uid"));
300 }
301
302 pub const ExpandedAcpiDevicePath = extern struct {
216 type: DevicePathType,303 type: DevicePathType,
217 subtype: Subtype,304 subtype: Subtype,
218 length: u16,305 length: u16 align(1),
219 hid: u32,306 hid: u32 align(1),
220 uid: u32,307 uid: u32 align(1),
221 cid: u32,308 cid: u32 align(1),
222 // variable length u16[*:0] strings309 // variable length u16[*:0] strings
223 // hid_str, uid_str, cid_str310 // hid_str, uid_str, cid_str
224 };311 };
225312
226 pub const AdrDevicePath = packed struct {313 comptime {
314 std.debug.assert(16 == @sizeOf(ExpandedAcpiDevicePath));
315 std.debug.assert(1 == @alignOf(ExpandedAcpiDevicePath));
316
317 std.debug.assert(0 == @offsetOf(ExpandedAcpiDevicePath, "type"));
318 std.debug.assert(1 == @offsetOf(ExpandedAcpiDevicePath, "subtype"));
319 std.debug.assert(2 == @offsetOf(ExpandedAcpiDevicePath, "length"));
320 std.debug.assert(4 == @offsetOf(ExpandedAcpiDevicePath, "hid"));
321 std.debug.assert(8 == @offsetOf(ExpandedAcpiDevicePath, "uid"));
322 std.debug.assert(12 == @offsetOf(ExpandedAcpiDevicePath, "cid"));
323 }
324
325 pub const AdrDevicePath = extern struct {
227 type: DevicePathType,326 type: DevicePathType,
228 subtype: Subtype,327 subtype: Subtype,
229 length: u16,328 length: u16 align(1),
230 adr: u32,329 adr: u32 align(1),
330
231 // multiple adr entries can optionally follow331 // multiple adr entries can optionally follow
232 pub fn adrs(self: *const AdrDevicePath) []const u32 {332 pub fn adrs(self: *const AdrDevicePath) []align(1) const u32 {
233 // self.length is a minimum of 8 with one adr which is size 4.333 // self.length is a minimum of 8 with one adr which is size 4.
234 var entries = (self.length - 4) / @sizeOf(u32);334 var entries = (self.length - 4) / @sizeOf(u32);
235 return @ptrCast([*]const u32, &self.adr)[0..entries];335 return @ptrCast([*]align(1) const u32, &self.adr)[0..entries];
236 }336 }
237 };337 };
338
339 comptime {
340 std.debug.assert(8 == @sizeOf(AdrDevicePath));
341 std.debug.assert(1 == @alignOf(AdrDevicePath));
342
343 std.debug.assert(0 == @offsetOf(AdrDevicePath, "type"));
344 std.debug.assert(1 == @offsetOf(AdrDevicePath, "subtype"));
345 std.debug.assert(2 == @offsetOf(AdrDevicePath, "length"));
346 std.debug.assert(4 == @offsetOf(AdrDevicePath, "adr"));
347 }
238};348};
239349
240pub const MessagingDevicePath = union(Subtype) {350pub const MessagingDevicePath = union(Subtype) {
...@@ -279,7 +389,7 @@ pub const MessagingDevicePath = union(Subtype) {...@@ -279,7 +389,7 @@ pub const MessagingDevicePath = union(Subtype) {
279 _,389 _,
280 };390 };
281391
282 pub const AtapiDevicePath = packed struct {392 pub const AtapiDevicePath = extern struct {
283 const Role = enum(u8) {393 const Role = enum(u8) {
284 Master = 0,394 Master = 0,
285 Slave = 1,395 Slave = 1,
...@@ -292,111 +402,249 @@ pub const MessagingDevicePath = union(Subtype) {...@@ -292,111 +402,249 @@ pub const MessagingDevicePath = union(Subtype) {
292402
293 type: DevicePathType,403 type: DevicePathType,
294 subtype: Subtype,404 subtype: Subtype,
295 length: u16,405 length: u16 align(1),
296 primary_secondary: Rank,406 primary_secondary: Rank,
297 slave_master: Role,407 slave_master: Role,
298 logical_unit_number: u16,408 logical_unit_number: u16 align(1),
299 };409 };
300410
301 pub const ScsiDevicePath = packed struct {411 comptime {
412 std.debug.assert(8 == @sizeOf(AtapiDevicePath));
413 std.debug.assert(1 == @alignOf(AtapiDevicePath));
414
415 std.debug.assert(0 == @offsetOf(AtapiDevicePath, "type"));
416 std.debug.assert(1 == @offsetOf(AtapiDevicePath, "subtype"));
417 std.debug.assert(2 == @offsetOf(AtapiDevicePath, "length"));
418 std.debug.assert(4 == @offsetOf(AtapiDevicePath, "primary_secondary"));
419 std.debug.assert(5 == @offsetOf(AtapiDevicePath, "slave_master"));
420 std.debug.assert(6 == @offsetOf(AtapiDevicePath, "logical_unit_number"));
421 }
422
423 pub const ScsiDevicePath = extern struct {
302 type: DevicePathType,424 type: DevicePathType,
303 subtype: Subtype,425 subtype: Subtype,
304 length: u16,426 length: u16 align(1),
305 target_id: u16,427 target_id: u16 align(1),
306 logical_unit_number: u16,428 logical_unit_number: u16 align(1),
307 };429 };
308430
309 pub const FibreChannelDevicePath = packed struct {431 comptime {
432 std.debug.assert(8 == @sizeOf(ScsiDevicePath));
433 std.debug.assert(1 == @alignOf(ScsiDevicePath));
434
435 std.debug.assert(0 == @offsetOf(ScsiDevicePath, "type"));
436 std.debug.assert(1 == @offsetOf(ScsiDevicePath, "subtype"));
437 std.debug.assert(2 == @offsetOf(ScsiDevicePath, "length"));
438 std.debug.assert(4 == @offsetOf(ScsiDevicePath, "target_id"));
439 std.debug.assert(6 == @offsetOf(ScsiDevicePath, "logical_unit_number"));
440 }
441
442 pub const FibreChannelDevicePath = extern struct {
310 type: DevicePathType,443 type: DevicePathType,
311 subtype: Subtype,444 subtype: Subtype,
312 length: u16,445 length: u16 align(1),
313 reserved: u32,446 reserved: u32 align(1),
314 world_wide_name: u64,447 world_wide_name: u64 align(1),
315 logical_unit_number: u64,448 logical_unit_number: u64 align(1),
316 };449 };
317450
318 pub const FibreChannelExDevicePath = packed struct {451 comptime {
452 std.debug.assert(24 == @sizeOf(FibreChannelDevicePath));
453 std.debug.assert(1 == @alignOf(FibreChannelDevicePath));
454
455 std.debug.assert(0 == @offsetOf(FibreChannelDevicePath, "type"));
456 std.debug.assert(1 == @offsetOf(FibreChannelDevicePath, "subtype"));
457 std.debug.assert(2 == @offsetOf(FibreChannelDevicePath, "length"));
458 std.debug.assert(4 == @offsetOf(FibreChannelDevicePath, "reserved"));
459 std.debug.assert(8 == @offsetOf(FibreChannelDevicePath, "world_wide_name"));
460 std.debug.assert(16 == @offsetOf(FibreChannelDevicePath, "logical_unit_number"));
461 }
462
463 pub const FibreChannelExDevicePath = extern struct {
319 type: DevicePathType,464 type: DevicePathType,
320 subtype: Subtype,465 subtype: Subtype,
321 length: u16,466 length: u16 align(1),
322 reserved: u32,467 reserved: u32 align(1),
323 world_wide_name: [8]u8,468 world_wide_name: u64 align(1),
324 logical_unit_number: [8]u8,469 logical_unit_number: u64 align(1),
325 };470 };
326471
327 pub const F1394DevicePath = packed struct {472 comptime {
473 std.debug.assert(24 == @sizeOf(FibreChannelExDevicePath));
474 std.debug.assert(1 == @alignOf(FibreChannelExDevicePath));
475
476 std.debug.assert(0 == @offsetOf(FibreChannelExDevicePath, "type"));
477 std.debug.assert(1 == @offsetOf(FibreChannelExDevicePath, "subtype"));
478 std.debug.assert(2 == @offsetOf(FibreChannelExDevicePath, "length"));
479 std.debug.assert(4 == @offsetOf(FibreChannelExDevicePath, "reserved"));
480 std.debug.assert(8 == @offsetOf(FibreChannelExDevicePath, "world_wide_name"));
481 std.debug.assert(16 == @offsetOf(FibreChannelExDevicePath, "logical_unit_number"));
482 }
483
484 pub const F1394DevicePath = extern struct {
328 type: DevicePathType,485 type: DevicePathType,
329 subtype: Subtype,486 subtype: Subtype,
330 length: u16,487 length: u16 align(1),
331 reserved: u32,488 reserved: u32 align(1),
332 guid: u64,489 guid: u64 align(1),
333 };490 };
334491
335 pub const UsbDevicePath = packed struct {492 comptime {
493 std.debug.assert(16 == @sizeOf(F1394DevicePath));
494 std.debug.assert(1 == @alignOf(F1394DevicePath));
495
496 std.debug.assert(0 == @offsetOf(F1394DevicePath, "type"));
497 std.debug.assert(1 == @offsetOf(F1394DevicePath, "subtype"));
498 std.debug.assert(2 == @offsetOf(F1394DevicePath, "length"));
499 std.debug.assert(4 == @offsetOf(F1394DevicePath, "reserved"));
500 std.debug.assert(8 == @offsetOf(F1394DevicePath, "guid"));
501 }
502
503 pub const UsbDevicePath = extern struct {
336 type: DevicePathType,504 type: DevicePathType,
337 subtype: Subtype,505 subtype: Subtype,
338 length: u16,506 length: u16 align(1),
339 parent_port_number: u8,507 parent_port_number: u8,
340 interface_number: u8,508 interface_number: u8,
341 };509 };
342510
343 pub const SataDevicePath = packed struct {511 comptime {
512 std.debug.assert(6 == @sizeOf(UsbDevicePath));
513 std.debug.assert(1 == @alignOf(UsbDevicePath));
514
515 std.debug.assert(0 == @offsetOf(UsbDevicePath, "type"));
516 std.debug.assert(1 == @offsetOf(UsbDevicePath, "subtype"));
517 std.debug.assert(2 == @offsetOf(UsbDevicePath, "length"));
518 std.debug.assert(4 == @offsetOf(UsbDevicePath, "parent_port_number"));
519 std.debug.assert(5 == @offsetOf(UsbDevicePath, "interface_number"));
520 }
521
522 pub const SataDevicePath = extern struct {
344 type: DevicePathType,523 type: DevicePathType,
345 subtype: Subtype,524 subtype: Subtype,
346 length: u16,525 length: u16 align(1),
347 hba_port_number: u16,526 hba_port_number: u16 align(1),
348 port_multiplier_port_number: u16,527 port_multiplier_port_number: u16 align(1),
349 logical_unit_number: u16,528 logical_unit_number: u16 align(1),
350 };529 };
351530
352 pub const UsbWwidDevicePath = packed struct {531 comptime {
532 std.debug.assert(10 == @sizeOf(SataDevicePath));
533 std.debug.assert(1 == @alignOf(SataDevicePath));
534
535 std.debug.assert(0 == @offsetOf(SataDevicePath, "type"));
536 std.debug.assert(1 == @offsetOf(SataDevicePath, "subtype"));
537 std.debug.assert(2 == @offsetOf(SataDevicePath, "length"));
538 std.debug.assert(4 == @offsetOf(SataDevicePath, "hba_port_number"));
539 std.debug.assert(6 == @offsetOf(SataDevicePath, "port_multiplier_port_number"));
540 std.debug.assert(8 == @offsetOf(SataDevicePath, "logical_unit_number"));
541 }
542
543 pub const UsbWwidDevicePath = extern struct {
353 type: DevicePathType,544 type: DevicePathType,
354 subtype: Subtype,545 subtype: Subtype,
355 length: u16,546 length: u16 align(1),
356 interface_number: u16,547 interface_number: u16 align(1),
357 device_vendor_id: u16,548 device_vendor_id: u16 align(1),
358 device_product_id: u16,549 device_product_id: u16 align(1),
359550
360 pub fn serial_number(self: *const UsbWwidDevicePath) []const u16 {551 pub fn serial_number(self: *const UsbWwidDevicePath) []align(1) const u16 {
361 var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);552 var serial_len = (self.length - @sizeOf(UsbWwidDevicePath)) / @sizeOf(u16);
362 return @ptrCast([*]u16, @ptrCast([*]u8, self) + @sizeOf(UsbWwidDevicePath))[0..serial_len];553 return @ptrCast([*]align(1) const u16, @ptrCast([*]const u8, self) + @sizeOf(UsbWwidDevicePath))[0..serial_len];
363 }554 }
364 };555 };
365556
366 pub const DeviceLogicalUnitDevicePath = packed struct {557 comptime {
558 std.debug.assert(10 == @sizeOf(UsbWwidDevicePath));
559 std.debug.assert(1 == @alignOf(UsbWwidDevicePath));
560
561 std.debug.assert(0 == @offsetOf(UsbWwidDevicePath, "type"));
562 std.debug.assert(1 == @offsetOf(UsbWwidDevicePath, "subtype"));
563 std.debug.assert(2 == @offsetOf(UsbWwidDevicePath, "length"));
564 std.debug.assert(4 == @offsetOf(UsbWwidDevicePath, "interface_number"));
565 std.debug.assert(6 == @offsetOf(UsbWwidDevicePath, "device_vendor_id"));
566 std.debug.assert(8 == @offsetOf(UsbWwidDevicePath, "device_product_id"));
567 }
568
569 pub const DeviceLogicalUnitDevicePath = extern struct {
367 type: DevicePathType,570 type: DevicePathType,
368 subtype: Subtype,571 subtype: Subtype,
369 length: u16,572 length: u16 align(1),
370 lun: u8,573 lun: u8,
371 };574 };
372575
373 pub const UsbClassDevicePath = packed struct {576 comptime {
577 std.debug.assert(5 == @sizeOf(DeviceLogicalUnitDevicePath));
578 std.debug.assert(1 == @alignOf(DeviceLogicalUnitDevicePath));
579
580 std.debug.assert(0 == @offsetOf(DeviceLogicalUnitDevicePath, "type"));
581 std.debug.assert(1 == @offsetOf(DeviceLogicalUnitDevicePath, "subtype"));
582 std.debug.assert(2 == @offsetOf(DeviceLogicalUnitDevicePath, "length"));
583 std.debug.assert(4 == @offsetOf(DeviceLogicalUnitDevicePath, "lun"));
584 }
585
586 pub const UsbClassDevicePath = extern struct {
374 type: DevicePathType,587 type: DevicePathType,
375 subtype: Subtype,588 subtype: Subtype,
376 length: u16,589 length: u16 align(1),
377 vendor_id: u16,590 vendor_id: u16 align(1),
378 product_id: u16,591 product_id: u16 align(1),
379 device_class: u8,592 device_class: u8,
380 device_subclass: u8,593 device_subclass: u8,
381 device_protocol: u8,594 device_protocol: u8,
382 };595 };
383596
384 pub const I2oDevicePath = packed struct {597 comptime {
598 std.debug.assert(11 == @sizeOf(UsbClassDevicePath));
599 std.debug.assert(1 == @alignOf(UsbClassDevicePath));
600
601 std.debug.assert(0 == @offsetOf(UsbClassDevicePath, "type"));
602 std.debug.assert(1 == @offsetOf(UsbClassDevicePath, "subtype"));
603 std.debug.assert(2 == @offsetOf(UsbClassDevicePath, "length"));
604 std.debug.assert(4 == @offsetOf(UsbClassDevicePath, "vendor_id"));
605 std.debug.assert(6 == @offsetOf(UsbClassDevicePath, "product_id"));
606 std.debug.assert(8 == @offsetOf(UsbClassDevicePath, "device_class"));
607 std.debug.assert(9 == @offsetOf(UsbClassDevicePath, "device_subclass"));
608 std.debug.assert(10 == @offsetOf(UsbClassDevicePath, "device_protocol"));
609 }
610
611 pub const I2oDevicePath = extern struct {
385 type: DevicePathType,612 type: DevicePathType,
386 subtype: Subtype,613 subtype: Subtype,
387 length: u16,614 length: u16 align(1),
388 tid: u32,615 tid: u32 align(1),
389 };616 };
390617
391 pub const MacAddressDevicePath = packed struct {618 comptime {
619 std.debug.assert(8 == @sizeOf(I2oDevicePath));
620 std.debug.assert(1 == @alignOf(I2oDevicePath));
621
622 std.debug.assert(0 == @offsetOf(I2oDevicePath, "type"));
623 std.debug.assert(1 == @offsetOf(I2oDevicePath, "subtype"));
624 std.debug.assert(2 == @offsetOf(I2oDevicePath, "length"));
625 std.debug.assert(4 == @offsetOf(I2oDevicePath, "tid"));
626 }
627
628 pub const MacAddressDevicePath = extern struct {
392 type: DevicePathType,629 type: DevicePathType,
393 subtype: Subtype,630 subtype: Subtype,
394 length: u16,631 length: u16 align(1),
395 mac_address: uefi.MacAddress,632 mac_address: uefi.MacAddress,
396 if_type: u8,633 if_type: u8,
397 };634 };
398635
399 pub const Ipv4DevicePath = packed struct {636 comptime {
637 std.debug.assert(37 == @sizeOf(MacAddressDevicePath));
638 std.debug.assert(1 == @alignOf(MacAddressDevicePath));
639
640 std.debug.assert(0 == @offsetOf(MacAddressDevicePath, "type"));
641 std.debug.assert(1 == @offsetOf(MacAddressDevicePath, "subtype"));
642 std.debug.assert(2 == @offsetOf(MacAddressDevicePath, "length"));
643 std.debug.assert(4 == @offsetOf(MacAddressDevicePath, "mac_address"));
644 std.debug.assert(36 == @offsetOf(MacAddressDevicePath, "if_type"));
645 }
646
647 pub const Ipv4DevicePath = extern struct {
400 pub const IpType = enum(u8) {648 pub const IpType = enum(u8) {
401 Dhcp = 0,649 Dhcp = 0,
402 Static = 1,650 Static = 1,
...@@ -404,18 +652,35 @@ pub const MessagingDevicePath = union(Subtype) {...@@ -404,18 +652,35 @@ pub const MessagingDevicePath = union(Subtype) {
404652
405 type: DevicePathType,653 type: DevicePathType,
406 subtype: Subtype,654 subtype: Subtype,
407 length: u16,655 length: u16 align(1),
408 local_ip_address: uefi.Ipv4Address,656 local_ip_address: uefi.Ipv4Address align(1),
409 remote_ip_address: uefi.Ipv4Address,657 remote_ip_address: uefi.Ipv4Address align(1),
410 local_port: u16,658 local_port: u16 align(1),
411 remote_port: u16,659 remote_port: u16 align(1),
412 network_protocol: u16,660 network_protocol: u16 align(1),
413 static_ip_address: IpType,661 static_ip_address: IpType,
414 gateway_ip_address: u32,662 gateway_ip_address: u32 align(1),
415 subnet_mask: u32,663 subnet_mask: u32 align(1),
416 };664 };
417665
418 pub const Ipv6DevicePath = packed struct {666 comptime {
667 std.debug.assert(27 == @sizeOf(Ipv4DevicePath));
668 std.debug.assert(1 == @alignOf(Ipv4DevicePath));
669
670 std.debug.assert(0 == @offsetOf(Ipv4DevicePath, "type"));
671 std.debug.assert(1 == @offsetOf(Ipv4DevicePath, "subtype"));
672 std.debug.assert(2 == @offsetOf(Ipv4DevicePath, "length"));
673 std.debug.assert(4 == @offsetOf(Ipv4DevicePath, "local_ip_address"));
674 std.debug.assert(8 == @offsetOf(Ipv4DevicePath, "remote_ip_address"));
675 std.debug.assert(12 == @offsetOf(Ipv4DevicePath, "local_port"));
676 std.debug.assert(14 == @offsetOf(Ipv4DevicePath, "remote_port"));
677 std.debug.assert(16 == @offsetOf(Ipv4DevicePath, "network_protocol"));
678 std.debug.assert(18 == @offsetOf(Ipv4DevicePath, "static_ip_address"));
679 std.debug.assert(19 == @offsetOf(Ipv4DevicePath, "gateway_ip_address"));
680 std.debug.assert(23 == @offsetOf(Ipv4DevicePath, "subnet_mask"));
681 }
682
683 pub const Ipv6DevicePath = extern struct {
419 pub const Origin = enum(u8) {684 pub const Origin = enum(u8) {
420 Manual = 0,685 Manual = 0,
421 AssignedStateless = 1,686 AssignedStateless = 1,
...@@ -424,26 +689,53 @@ pub const MessagingDevicePath = union(Subtype) {...@@ -424,26 +689,53 @@ pub const MessagingDevicePath = union(Subtype) {
424689
425 type: DevicePathType,690 type: DevicePathType,
426 subtype: Subtype,691 subtype: Subtype,
427 length: u16,692 length: u16 align(1),
428 local_ip_address: uefi.Ipv6Address,693 local_ip_address: uefi.Ipv6Address,
429 remote_ip_address: uefi.Ipv6Address,694 remote_ip_address: uefi.Ipv6Address,
430 local_port: u16,695 local_port: u16 align(1),
431 remote_port: u16,696 remote_port: u16 align(1),
432 protocol: u16,697 protocol: u16 align(1),
433 ip_address_origin: Origin,698 ip_address_origin: Origin,
434 prefix_length: u8,699 prefix_length: u8,
435 gateway_ip_address: uefi.Ipv6Address,700 gateway_ip_address: uefi.Ipv6Address,
436 };701 };
437702
438 pub const VlanDevicePath = packed struct {703 comptime {
704 std.debug.assert(60 == @sizeOf(Ipv6DevicePath));
705 std.debug.assert(1 == @alignOf(Ipv6DevicePath));
706
707 std.debug.assert(0 == @offsetOf(Ipv6DevicePath, "type"));
708 std.debug.assert(1 == @offsetOf(Ipv6DevicePath, "subtype"));
709 std.debug.assert(2 == @offsetOf(Ipv6DevicePath, "length"));
710 std.debug.assert(4 == @offsetOf(Ipv6DevicePath, "local_ip_address"));
711 std.debug.assert(20 == @offsetOf(Ipv6DevicePath, "remote_ip_address"));
712 std.debug.assert(36 == @offsetOf(Ipv6DevicePath, "local_port"));
713 std.debug.assert(38 == @offsetOf(Ipv6DevicePath, "remote_port"));
714 std.debug.assert(40 == @offsetOf(Ipv6DevicePath, "protocol"));
715 std.debug.assert(42 == @offsetOf(Ipv6DevicePath, "ip_address_origin"));
716 std.debug.assert(43 == @offsetOf(Ipv6DevicePath, "prefix_length"));
717 std.debug.assert(44 == @offsetOf(Ipv6DevicePath, "gateway_ip_address"));
718 }
719
720 pub const VlanDevicePath = extern struct {
439 type: DevicePathType,721 type: DevicePathType,
440 subtype: Subtype,722 subtype: Subtype,
441 length: u16,723 length: u16 align(1),
442 vlan_id: u16,724 vlan_id: u16 align(1),
443 };725 };
444726
445 pub const InfiniBandDevicePath = packed struct {727 comptime {
446 pub const ResourceFlags = packed struct {728 std.debug.assert(6 == @sizeOf(VlanDevicePath));
729 std.debug.assert(1 == @alignOf(VlanDevicePath));
730
731 std.debug.assert(0 == @offsetOf(VlanDevicePath, "type"));
732 std.debug.assert(1 == @offsetOf(VlanDevicePath, "subtype"));
733 std.debug.assert(2 == @offsetOf(VlanDevicePath, "length"));
734 std.debug.assert(4 == @offsetOf(VlanDevicePath, "vlan_id"));
735 }
736
737 pub const InfiniBandDevicePath = extern struct {
738 pub const ResourceFlags = packed struct(u32) {
447 pub const ControllerType = enum(u1) {739 pub const ControllerType = enum(u1) {
448 Ioc = 0,740 Ioc = 0,
449 Service = 1,741 Service = 1,
...@@ -461,15 +753,29 @@ pub const MessagingDevicePath = union(Subtype) {...@@ -461,15 +753,29 @@ pub const MessagingDevicePath = union(Subtype) {
461753
462 type: DevicePathType,754 type: DevicePathType,
463 subtype: Subtype,755 subtype: Subtype,
464 length: u16,756 length: u16 align(1),
465 resource_flags: ResourceFlags,757 resource_flags: ResourceFlags align(1),
466 port_gid: [16]u8,758 port_gid: [16]u8,
467 service_id: u64,759 service_id: u64 align(1),
468 target_port_id: u64,760 target_port_id: u64 align(1),
469 device_id: u64,761 device_id: u64 align(1),
470 };762 };
471763
472 pub const UartDevicePath = packed struct {764 comptime {
765 std.debug.assert(48 == @sizeOf(InfiniBandDevicePath));
766 std.debug.assert(1 == @alignOf(InfiniBandDevicePath));
767
768 std.debug.assert(0 == @offsetOf(InfiniBandDevicePath, "type"));
769 std.debug.assert(1 == @offsetOf(InfiniBandDevicePath, "subtype"));
770 std.debug.assert(2 == @offsetOf(InfiniBandDevicePath, "length"));
771 std.debug.assert(4 == @offsetOf(InfiniBandDevicePath, "resource_flags"));
772 std.debug.assert(8 == @offsetOf(InfiniBandDevicePath, "port_gid"));
773 std.debug.assert(24 == @offsetOf(InfiniBandDevicePath, "service_id"));
774 std.debug.assert(32 == @offsetOf(InfiniBandDevicePath, "target_port_id"));
775 std.debug.assert(40 == @offsetOf(InfiniBandDevicePath, "device_id"));
776 }
777
778 pub const UartDevicePath = extern struct {
473 pub const Parity = enum(u8) {779 pub const Parity = enum(u8) {
474 Default = 0,780 Default = 0,
475 None = 1,781 None = 1,
...@@ -490,20 +796,44 @@ pub const MessagingDevicePath = union(Subtype) {...@@ -490,20 +796,44 @@ pub const MessagingDevicePath = union(Subtype) {
490796
491 type: DevicePathType,797 type: DevicePathType,
492 subtype: Subtype,798 subtype: Subtype,
493 length: u16,799 length: u16 align(1),
494 reserved: u16,800 reserved: u32 align(1),
495 baud_rate: u32,801 baud_rate: u64 align(1),
496 data_bits: u8,802 data_bits: u8,
497 parity: Parity,803 parity: Parity,
498 stop_bits: StopBits,804 stop_bits: StopBits,
499 };805 };
500806
501 pub const VendorDefinedDevicePath = packed struct {807 comptime {
808 std.debug.assert(19 == @sizeOf(UartDevicePath));
809 std.debug.assert(1 == @alignOf(UartDevicePath));
810
811 std.debug.assert(0 == @offsetOf(UartDevicePath, "type"));
812 std.debug.assert(1 == @offsetOf(UartDevicePath, "subtype"));
813 std.debug.assert(2 == @offsetOf(UartDevicePath, "length"));
814 std.debug.assert(4 == @offsetOf(UartDevicePath, "reserved"));
815 std.debug.assert(8 == @offsetOf(UartDevicePath, "baud_rate"));
816 std.debug.assert(16 == @offsetOf(UartDevicePath, "data_bits"));
817 std.debug.assert(17 == @offsetOf(UartDevicePath, "parity"));
818 std.debug.assert(18 == @offsetOf(UartDevicePath, "stop_bits"));
819 }
820
821 pub const VendorDefinedDevicePath = extern struct {
502 type: DevicePathType,822 type: DevicePathType,
503 subtype: Subtype,823 subtype: Subtype,
504 length: u16,824 length: u16 align(1),
505 vendor_guid: Guid,825 vendor_guid: Guid align(1),
506 };826 };
827
828 comptime {
829 std.debug.assert(20 == @sizeOf(VendorDefinedDevicePath));
830 std.debug.assert(1 == @alignOf(VendorDefinedDevicePath));
831
832 std.debug.assert(0 == @offsetOf(VendorDefinedDevicePath, "type"));
833 std.debug.assert(1 == @offsetOf(VendorDefinedDevicePath, "subtype"));
834 std.debug.assert(2 == @offsetOf(VendorDefinedDevicePath, "length"));
835 std.debug.assert(4 == @offsetOf(VendorDefinedDevicePath, "vendor_guid"));
836 }
507};837};
508838
509pub const MediaDevicePath = union(Subtype) {839pub const MediaDevicePath = union(Subtype) {
...@@ -530,7 +860,7 @@ pub const MediaDevicePath = union(Subtype) {...@@ -530,7 +860,7 @@ pub const MediaDevicePath = union(Subtype) {
530 _,860 _,
531 };861 };
532862
533 pub const HardDriveDevicePath = packed struct {863 pub const HardDriveDevicePath = extern struct {
534 pub const Format = enum(u8) {864 pub const Format = enum(u8) {
535 LegacyMbr = 0x01,865 LegacyMbr = 0x01,
536 GuidPartitionTable = 0x02,866 GuidPartitionTable = 0x02,
...@@ -545,81 +875,181 @@ pub const MediaDevicePath = union(Subtype) {...@@ -545,81 +875,181 @@ pub const MediaDevicePath = union(Subtype) {
545875
546 type: DevicePathType,876 type: DevicePathType,
547 subtype: Subtype,877 subtype: Subtype,
548 length: u16,878 length: u16 align(1),
549 partition_number: u32,879 partition_number: u32 align(1),
550 partition_start: u64,880 partition_start: u64 align(1),
551 partition_size: u64,881 partition_size: u64 align(1),
552 partition_signature: [16]u8,882 partition_signature: [16]u8,
553 partition_format: Format,883 partition_format: Format,
554 signature_type: SignatureType,884 signature_type: SignatureType,
555 };885 };
556886
557 pub const CdromDevicePath = packed struct {887 comptime {
888 std.debug.assert(42 == @sizeOf(HardDriveDevicePath));
889 std.debug.assert(1 == @alignOf(HardDriveDevicePath));
890
891 std.debug.assert(0 == @offsetOf(HardDriveDevicePath, "type"));
892 std.debug.assert(1 == @offsetOf(HardDriveDevicePath, "subtype"));
893 std.debug.assert(2 == @offsetOf(HardDriveDevicePath, "length"));
894 std.debug.assert(4 == @offsetOf(HardDriveDevicePath, "partition_number"));
895 std.debug.assert(8 == @offsetOf(HardDriveDevicePath, "partition_start"));
896 std.debug.assert(16 == @offsetOf(HardDriveDevicePath, "partition_size"));
897 std.debug.assert(24 == @offsetOf(HardDriveDevicePath, "partition_signature"));
898 std.debug.assert(40 == @offsetOf(HardDriveDevicePath, "partition_format"));
899 std.debug.assert(41 == @offsetOf(HardDriveDevicePath, "signature_type"));
900 }
901
902 pub const CdromDevicePath = extern struct {
558 type: DevicePathType,903 type: DevicePathType,
559 subtype: Subtype,904 subtype: Subtype,
560 length: u16,905 length: u16 align(1),
561 boot_entry: u32,906 boot_entry: u32 align(1),
562 partition_start: u64,907 partition_start: u64 align(1),
563 partition_size: u64,908 partition_size: u64 align(1),
564 };909 };
565910
566 pub const VendorDevicePath = packed struct {911 comptime {
912 std.debug.assert(24 == @sizeOf(CdromDevicePath));
913 std.debug.assert(1 == @alignOf(CdromDevicePath));
914
915 std.debug.assert(0 == @offsetOf(CdromDevicePath, "type"));
916 std.debug.assert(1 == @offsetOf(CdromDevicePath, "subtype"));
917 std.debug.assert(2 == @offsetOf(CdromDevicePath, "length"));
918 std.debug.assert(4 == @offsetOf(CdromDevicePath, "boot_entry"));
919 std.debug.assert(8 == @offsetOf(CdromDevicePath, "partition_start"));
920 std.debug.assert(16 == @offsetOf(CdromDevicePath, "partition_size"));
921 }
922
923 pub const VendorDevicePath = extern struct {
567 type: DevicePathType,924 type: DevicePathType,
568 subtype: Subtype,925 subtype: Subtype,
569 length: u16,926 length: u16 align(1),
570 guid: Guid,927 guid: Guid align(1),
571 // vendor-defined variable data
572 };928 };
573929
574 pub const FilePathDevicePath = packed struct {930 comptime {
931 std.debug.assert(20 == @sizeOf(VendorDevicePath));
932 std.debug.assert(1 == @alignOf(VendorDevicePath));
933
934 std.debug.assert(0 == @offsetOf(VendorDevicePath, "type"));
935 std.debug.assert(1 == @offsetOf(VendorDevicePath, "subtype"));
936 std.debug.assert(2 == @offsetOf(VendorDevicePath, "length"));
937 std.debug.assert(4 == @offsetOf(VendorDevicePath, "guid"));
938 }
939
940 pub const FilePathDevicePath = extern struct {
575 type: DevicePathType,941 type: DevicePathType,
576 subtype: Subtype,942 subtype: Subtype,
577 length: u16,943 length: u16 align(1),
578944
579 pub fn getPath(self: *const FilePathDevicePath) [*:0]const u16 {945 pub fn getPath(self: *const FilePathDevicePath) [*:0]align(1) const u16 {
580 return @ptrCast([*:0]const u16, @alignCast(2, @ptrCast([*]const u8, self)) + @sizeOf(FilePathDevicePath));946 return @ptrCast([*:0]align(1) const u16, @ptrCast([*]const u8, self) + @sizeOf(FilePathDevicePath));
581 }947 }
582 };948 };
583949
584 pub const MediaProtocolDevicePath = packed struct {950 comptime {
951 std.debug.assert(4 == @sizeOf(FilePathDevicePath));
952 std.debug.assert(1 == @alignOf(FilePathDevicePath));
953
954 std.debug.assert(0 == @offsetOf(FilePathDevicePath, "type"));
955 std.debug.assert(1 == @offsetOf(FilePathDevicePath, "subtype"));
956 std.debug.assert(2 == @offsetOf(FilePathDevicePath, "length"));
957 }
958
959 pub const MediaProtocolDevicePath = extern struct {
585 type: DevicePathType,960 type: DevicePathType,
586 subtype: Subtype,961 subtype: Subtype,
587 length: u16,962 length: u16 align(1),
588 guid: Guid,963 guid: Guid align(1),
589 };964 };
590965
591 pub const PiwgFirmwareFileDevicePath = packed struct {966 comptime {
967 std.debug.assert(20 == @sizeOf(MediaProtocolDevicePath));
968 std.debug.assert(1 == @alignOf(MediaProtocolDevicePath));
969
970 std.debug.assert(0 == @offsetOf(MediaProtocolDevicePath, "type"));
971 std.debug.assert(1 == @offsetOf(MediaProtocolDevicePath, "subtype"));
972 std.debug.assert(2 == @offsetOf(MediaProtocolDevicePath, "length"));
973 std.debug.assert(4 == @offsetOf(MediaProtocolDevicePath, "guid"));
974 }
975
976 pub const PiwgFirmwareFileDevicePath = extern struct {
592 type: DevicePathType,977 type: DevicePathType,
593 subtype: Subtype,978 subtype: Subtype,
594 length: u16,979 length: u16 align(1),
595 fv_filename: Guid,980 fv_filename: Guid align(1),
596 };981 };
597982
598 pub const PiwgFirmwareVolumeDevicePath = packed struct {983 comptime {
984 std.debug.assert(20 == @sizeOf(PiwgFirmwareFileDevicePath));
985 std.debug.assert(1 == @alignOf(PiwgFirmwareFileDevicePath));
986
987 std.debug.assert(0 == @offsetOf(PiwgFirmwareFileDevicePath, "type"));
988 std.debug.assert(1 == @offsetOf(PiwgFirmwareFileDevicePath, "subtype"));
989 std.debug.assert(2 == @offsetOf(PiwgFirmwareFileDevicePath, "length"));
990 std.debug.assert(4 == @offsetOf(PiwgFirmwareFileDevicePath, "fv_filename"));
991 }
992
993 pub const PiwgFirmwareVolumeDevicePath = extern struct {
599 type: DevicePathType,994 type: DevicePathType,
600 subtype: Subtype,995 subtype: Subtype,
601 length: u16,996 length: u16 align(1),
602 fv_name: Guid,997 fv_name: Guid align(1),
603 };998 };
604999
605 pub const RelativeOffsetRangeDevicePath = packed struct {1000 comptime {
1001 std.debug.assert(20 == @sizeOf(PiwgFirmwareVolumeDevicePath));
1002 std.debug.assert(1 == @alignOf(PiwgFirmwareVolumeDevicePath));
1003
1004 std.debug.assert(0 == @offsetOf(PiwgFirmwareVolumeDevicePath, "type"));
1005 std.debug.assert(1 == @offsetOf(PiwgFirmwareVolumeDevicePath, "subtype"));
1006 std.debug.assert(2 == @offsetOf(PiwgFirmwareVolumeDevicePath, "length"));
1007 std.debug.assert(4 == @offsetOf(PiwgFirmwareVolumeDevicePath, "fv_name"));
1008 }
1009
1010 pub const RelativeOffsetRangeDevicePath = extern struct {
606 type: DevicePathType,1011 type: DevicePathType,
607 subtype: Subtype,1012 subtype: Subtype,
608 length: u16,1013 length: u16 align(1),
609 reserved: u32,1014 reserved: u32 align(1),
610 start: u64,1015 start: u64 align(1),
611 end: u64,1016 end: u64 align(1),
612 };1017 };
6131018
614 pub const RamDiskDevicePath = packed struct {1019 comptime {
1020 std.debug.assert(24 == @sizeOf(RelativeOffsetRangeDevicePath));
1021 std.debug.assert(1 == @alignOf(RelativeOffsetRangeDevicePath));
1022
1023 std.debug.assert(0 == @offsetOf(RelativeOffsetRangeDevicePath, "type"));
1024 std.debug.assert(1 == @offsetOf(RelativeOffsetRangeDevicePath, "subtype"));
1025 std.debug.assert(2 == @offsetOf(RelativeOffsetRangeDevicePath, "length"));
1026 std.debug.assert(4 == @offsetOf(RelativeOffsetRangeDevicePath, "reserved"));
1027 std.debug.assert(8 == @offsetOf(RelativeOffsetRangeDevicePath, "start"));
1028 std.debug.assert(16 == @offsetOf(RelativeOffsetRangeDevicePath, "end"));
1029 }
1030
1031 pub const RamDiskDevicePath = extern struct {
615 type: DevicePathType,1032 type: DevicePathType,
616 subtype: Subtype,1033 subtype: Subtype,
617 length: u16,1034 length: u16 align(1),
618 start: u64,1035 start: u64 align(1),
619 end: u64,1036 end: u64 align(1),
620 disk_type: Guid,1037 disk_type: Guid align(1),
621 instance: u16,1038 instance: u16 align(1),
622 };1039 };
1040
1041 comptime {
1042 std.debug.assert(38 == @sizeOf(RamDiskDevicePath));
1043 std.debug.assert(1 == @alignOf(RamDiskDevicePath));
1044
1045 std.debug.assert(0 == @offsetOf(RamDiskDevicePath, "type"));
1046 std.debug.assert(1 == @offsetOf(RamDiskDevicePath, "subtype"));
1047 std.debug.assert(2 == @offsetOf(RamDiskDevicePath, "length"));
1048 std.debug.assert(4 == @offsetOf(RamDiskDevicePath, "start"));
1049 std.debug.assert(12 == @offsetOf(RamDiskDevicePath, "end"));
1050 std.debug.assert(20 == @offsetOf(RamDiskDevicePath, "disk_type"));
1051 std.debug.assert(36 == @offsetOf(RamDiskDevicePath, "instance"));
1052 }
623};1053};
6241054
625pub const BiosBootSpecificationDevicePath = union(Subtype) {1055pub const BiosBootSpecificationDevicePath = union(Subtype) {
...@@ -630,17 +1060,28 @@ pub const BiosBootSpecificationDevicePath = union(Subtype) {...@@ -630,17 +1060,28 @@ pub const BiosBootSpecificationDevicePath = union(Subtype) {
630 _,1060 _,
631 };1061 };
6321062
633 pub const BBS101DevicePath = packed struct {1063 pub const BBS101DevicePath = extern struct {
634 type: DevicePathType,1064 type: DevicePathType,
635 subtype: Subtype,1065 subtype: Subtype,
636 length: u16,1066 length: u16 align(1),
637 device_type: u16,1067 device_type: u16 align(1),
638 status_flag: u16,1068 status_flag: u16 align(1),
6391069
640 pub fn getDescription(self: *const BBS101DevicePath) [*:0]const u8 {1070 pub fn getDescription(self: *const BBS101DevicePath) [*:0]const u8 {
641 return @ptrCast([*:0]const u8, self) + @sizeOf(BBS101DevicePath);1071 return @ptrCast([*:0]const u8, self) + @sizeOf(BBS101DevicePath);
642 }1072 }
643 };1073 };
1074
1075 comptime {
1076 std.debug.assert(8 == @sizeOf(BBS101DevicePath));
1077 std.debug.assert(1 == @alignOf(BBS101DevicePath));
1078
1079 std.debug.assert(0 == @offsetOf(BBS101DevicePath, "type"));
1080 std.debug.assert(1 == @offsetOf(BBS101DevicePath, "subtype"));
1081 std.debug.assert(2 == @offsetOf(BBS101DevicePath, "length"));
1082 std.debug.assert(4 == @offsetOf(BBS101DevicePath, "device_type"));
1083 std.debug.assert(6 == @offsetOf(BBS101DevicePath, "status_flag"));
1084 }
644};1085};
6451086
646pub const EndDevicePath = union(Subtype) {1087pub const EndDevicePath = union(Subtype) {
...@@ -653,15 +1094,33 @@ pub const EndDevicePath = union(Subtype) {...@@ -653,15 +1094,33 @@ pub const EndDevicePath = union(Subtype) {
653 _,1094 _,
654 };1095 };
6551096
656 pub const EndEntireDevicePath = packed struct {1097 pub const EndEntireDevicePath = extern struct {
657 type: DevicePathType,1098 type: DevicePathType,
658 subtype: Subtype,1099 subtype: Subtype,
659 length: u16,1100 length: u16 align(1),
660 };1101 };
6611102
662 pub const EndThisInstanceDevicePath = packed struct {1103 comptime {
1104 std.debug.assert(4 == @sizeOf(EndEntireDevicePath));
1105 std.debug.assert(1 == @alignOf(EndEntireDevicePath));
1106
1107 std.debug.assert(0 == @offsetOf(EndEntireDevicePath, "type"));
1108 std.debug.assert(1 == @offsetOf(EndEntireDevicePath, "subtype"));
1109 std.debug.assert(2 == @offsetOf(EndEntireDevicePath, "length"));
1110 }
1111
1112 pub const EndThisInstanceDevicePath = extern struct {
663 type: DevicePathType,1113 type: DevicePathType,
664 subtype: Subtype,1114 subtype: Subtype,
665 length: u16,1115 length: u16 align(1),
666 };1116 };
1117
1118 comptime {
1119 std.debug.assert(4 == @sizeOf(EndEntireDevicePath));
1120 std.debug.assert(1 == @alignOf(EndEntireDevicePath));
1121
1122 std.debug.assert(0 == @offsetOf(EndEntireDevicePath, "type"));
1123 std.debug.assert(1 == @offsetOf(EndEntireDevicePath, "subtype"));
1124 std.debug.assert(2 == @offsetOf(EndEntireDevicePath, "length"));
1125 }
667};1126};
lib/std/os/uefi/protocols/edid_override_protocol.zig+4-6
...@@ -6,19 +6,17 @@ const Status = uefi.Status;...@@ -6,19 +6,17 @@ const Status = uefi.Status;
66
7/// Override EDID information7/// Override EDID information
8pub const EdidOverrideProtocol = extern struct {8pub const EdidOverrideProtocol = extern struct {
9 _get_edid: std.meta.FnPtr(fn (*const EdidOverrideProtocol, Handle, *u32, *usize, *?[*]u8) callconv(.C) Status),9 _get_edid: std.meta.FnPtr(fn (*const EdidOverrideProtocol, Handle, *EdidOverrideProtocolAttributes, *usize, *?[*]u8) callconv(.C) Status),
1010
11 /// Returns policy information and potentially a replacement EDID for the specified video output device.11 /// Returns policy information and potentially a replacement EDID for the specified video output device.
12 pub fn getEdid(12 pub fn getEdid(
13 self: *const EdidOverrideProtocol,13 self: *const EdidOverrideProtocol,
14 handle: Handle,14 handle: Handle,
15 /// The align(4) here should really be part of the EdidOverrideProtocolAttributes type.15 attributes: *EdidOverrideProtocolAttributes,
16 /// TODO remove this workaround when packed(u32) structs are implemented.
17 attributes: *align(4) EdidOverrideProtocolAttributes,
18 edid_size: *usize,16 edid_size: *usize,
19 edid: *?[*]u8,17 edid: *?[*]u8,
20 ) Status {18 ) Status {
21 return self._get_edid(self, handle, @ptrCast(*u32, attributes), edid_size, edid);19 return self._get_edid(self, handle, attributes, edid_size, edid);
22 }20 }
2321
24 pub const guid align(8) = Guid{22 pub const guid align(8) = Guid{
...@@ -31,7 +29,7 @@ pub const EdidOverrideProtocol = extern struct {...@@ -31,7 +29,7 @@ pub const EdidOverrideProtocol = extern struct {
31 };29 };
32};30};
3331
34pub const EdidOverrideProtocolAttributes = packed struct {32pub const EdidOverrideProtocolAttributes = packed struct(u32) {
35 dont_override: bool,33 dont_override: bool,
36 enable_hot_plug: bool,34 enable_hot_plug: bool,
37 _pad: u30 = 0,35 _pad: u30 = 0,
lib/std/os/uefi/protocols/hii.zig+15-11
...@@ -4,7 +4,7 @@ const Guid = uefi.Guid;...@@ -4,7 +4,7 @@ const Guid = uefi.Guid;
4pub const HIIHandle = *opaque {};4pub const HIIHandle = *opaque {};
55
6/// The header found at the start of each package.6/// The header found at the start of each package.
7pub const HIIPackageHeader = packed struct {7pub const HIIPackageHeader = packed struct(u32) {
8 length: u24,8 length: u24,
9 type: u8,9 type: u8,
1010
...@@ -43,23 +43,27 @@ pub const HIISimplifiedFontPackage = extern struct {...@@ -43,23 +43,27 @@ pub const HIISimplifiedFontPackage = extern struct {
43 }43 }
44};44};
4545
46pub const NarrowGlyphAttributes = packed struct(u8) {
47 non_spacing: bool,
48 wide: bool,
49 _pad: u6 = 0,
50};
51
46pub const NarrowGlyph = extern struct {52pub const NarrowGlyph = extern struct {
47 unicode_weight: u16,53 unicode_weight: u16,
48 attributes: packed struct {54 attributes: NarrowGlyphAttributes,
49 non_spacing: bool,
50 wide: bool,
51 _pad: u6 = 0,
52 },
53 glyph_col_1: [19]u8,55 glyph_col_1: [19]u8,
54};56};
5557
58pub const WideGlyphAttributes = packed struct(u8) {
59 non_spacing: bool,
60 wide: bool,
61 _pad: u6 = 0,
62};
63
56pub const WideGlyph = extern struct {64pub const WideGlyph = extern struct {
57 unicode_weight: u16,65 unicode_weight: u16,
58 attributes: packed struct {66 attributes: WideGlyphAttributes,
59 non_spacing: bool,
60 wide: bool,
61 _pad: u6,
62 },
63 glyph_col_1: [19]u8,67 glyph_col_1: [19]u8,
64 glyph_col_2: [19]u8,68 glyph_col_2: [19]u8,
65 _pad: [3]u8 = [_]u8{0} ** 3,69 _pad: [3]u8 = [_]u8{0} ** 3,
lib/std/os/uefi/protocols/simple_network_protocol.zig+2-2
...@@ -121,7 +121,7 @@ pub const SimpleNetworkMode = extern struct {...@@ -121,7 +121,7 @@ pub const SimpleNetworkMode = extern struct {
121 media_present: bool,121 media_present: bool,
122};122};
123123
124pub const SimpleNetworkReceiveFilter = packed struct {124pub const SimpleNetworkReceiveFilter = packed struct(u32) {
125 receive_unicast: bool,125 receive_unicast: bool,
126 receive_multicast: bool,126 receive_multicast: bool,
127 receive_broadcast: bool,127 receive_broadcast: bool,
...@@ -165,7 +165,7 @@ pub const NetworkStatistics = extern struct {...@@ -165,7 +165,7 @@ pub const NetworkStatistics = extern struct {
165 tx_retry_frames: u64,165 tx_retry_frames: u64,
166};166};
167167
168pub const SimpleNetworkInterruptStatus = packed struct {168pub const SimpleNetworkInterruptStatus = packed struct(u32) {
169 receive_interrupt: bool,169 receive_interrupt: bool,
170 transmit_interrupt: bool,170 transmit_interrupt: bool,
171 command_interrupt: bool,171 command_interrupt: bool,
lib/std/os/uefi/protocols/simple_text_input_ex_protocol.zig+26-22
...@@ -53,29 +53,33 @@ pub const KeyData = extern struct {...@@ -53,29 +53,33 @@ pub const KeyData = extern struct {
53 key_state: KeyState = undefined,53 key_state: KeyState = undefined,
54};54};
5555
56pub const KeyShiftState = packed struct(u32) {
57 right_shift_pressed: bool,
58 left_shift_pressed: bool,
59 right_control_pressed: bool,
60 left_control_pressed: bool,
61 right_alt_pressed: bool,
62 left_alt_pressed: bool,
63 right_logo_pressed: bool,
64 left_logo_pressed: bool,
65 menu_key_pressed: bool,
66 sys_req_pressed: bool,
67 _pad: u21 = 0,
68 shift_state_valid: bool,
69};
70
71pub const KeyToggleState = packed struct(u8) {
72 scroll_lock_active: bool,
73 num_lock_active: bool,
74 caps_lock_active: bool,
75 _pad: u3 = 0,
76 key_state_exposed: bool,
77 toggle_state_valid: bool,
78};
79
56pub const KeyState = extern struct {80pub const KeyState = extern struct {
57 key_shift_state: packed struct {81 key_shift_state: KeyShiftState,
58 right_shift_pressed: bool,82 key_toggle_state: KeyToggleState,
59 left_shift_pressed: bool,
60 right_control_pressed: bool,
61 left_control_pressed: bool,
62 right_alt_pressed: bool,
63 left_alt_pressed: bool,
64 right_logo_pressed: bool,
65 left_logo_pressed: bool,
66 menu_key_pressed: bool,
67 sys_req_pressed: bool,
68 _pad: u21 = 0,
69 shift_state_valid: bool,
70 },
71 key_toggle_state: packed struct {
72 scroll_lock_active: bool,
73 num_lock_active: bool,
74 caps_lock_active: bool,
75 _pad: u3 = 0,
76 key_state_exposed: bool,
77 toggle_state_valid: bool,
78 },
79};83};
8084
81pub const InputKey = extern struct {85pub const InputKey = extern struct {
lib/std/os/uefi/tables.zig+4
...@@ -3,3 +3,7 @@ pub usingnamespace @import("tables/runtime_services.zig");...@@ -3,3 +3,7 @@ pub usingnamespace @import("tables/runtime_services.zig");
3pub usingnamespace @import("tables/configuration_table.zig");3pub usingnamespace @import("tables/configuration_table.zig");
4pub usingnamespace @import("tables/system_table.zig");4pub usingnamespace @import("tables/system_table.zig");
5pub usingnamespace @import("tables/table_header.zig");5pub usingnamespace @import("tables/table_header.zig");
6
7test {
8 @import("std").testing.refAllDeclsRecursive(@This());
9}
lib/std/os/uefi/tables/boot_services.zig+22-23
...@@ -219,33 +219,32 @@ pub const MemoryType = enum(u32) {...@@ -219,33 +219,32 @@ pub const MemoryType = enum(u32) {
219 _,219 _,
220};220};
221221
222pub const MemoryDescriptorAttribute = packed struct(u64) {
223 uc: bool,
224 wc: bool,
225 wt: bool,
226 wb: bool,
227 uce: bool,
228 _pad1: u7 = 0,
229 wp: bool,
230 rp: bool,
231 xp: bool,
232 nv: bool,
233 more_reliable: bool,
234 ro: bool,
235 sp: bool,
236 cpu_crypto: bool,
237 _pad2: u43 = 0,
238 memory_runtime: bool,
239};
240
222pub const MemoryDescriptor = extern struct {241pub const MemoryDescriptor = extern struct {
223 type: MemoryType,242 type: MemoryType,
224 padding: u32,243 padding: u32,
225 physical_start: u64,244 physical_start: u64,
226 virtual_start: u64,245 virtual_start: u64,
227 number_of_pages: usize,246 number_of_pages: usize,
228 attribute: packed struct {247 attribute: MemoryDescriptorAttribute,
229 uc: bool,
230 wc: bool,
231 wt: bool,
232 wb: bool,
233 uce: bool,
234 _pad1: u3,
235 _pad2: u4,
236 wp: bool,
237 rp: bool,
238 xp: bool,
239 nv: bool,
240 more_reliable: bool,
241 ro: bool,
242 sp: bool,
243 cpu_crypto: bool,
244 _pad3: u4,
245 _pad4: u32,
246 _pad5: u7,
247 memory_runtime: bool,
248 },
249};248};
250249
251pub const LocateSearchType = enum(u32) {250pub const LocateSearchType = enum(u32) {
...@@ -254,14 +253,14 @@ pub const LocateSearchType = enum(u32) {...@@ -254,14 +253,14 @@ pub const LocateSearchType = enum(u32) {
254 ByProtocol,253 ByProtocol,
255};254};
256255
257pub const OpenProtocolAttributes = packed struct {256pub const OpenProtocolAttributes = packed struct(u32) {
258 by_handle_protocol: bool = false,257 by_handle_protocol: bool = false,
259 get_protocol: bool = false,258 get_protocol: bool = false,
260 test_protocol: bool = false,259 test_protocol: bool = false,
261 by_child_controller: bool = false,260 by_child_controller: bool = false,
262 by_driver: bool = false,261 by_driver: bool = false,
263 exclusive: bool = false,262 exclusive: bool = false,
264 _pad: u26 = 0,263 reserved: u26 = 0,
265};264};
266265
267pub const ProtocolInformationEntry = extern struct {266pub const ProtocolInformationEntry = extern struct {
lib/std/os/uefi/tables/runtime_services.zig+1-1
...@@ -78,7 +78,7 @@ pub const CapsuleHeader = extern struct {...@@ -78,7 +78,7 @@ pub const CapsuleHeader = extern struct {
7878
79pub const UefiCapsuleBlockDescriptor = extern struct {79pub const UefiCapsuleBlockDescriptor = extern struct {
80 length: u64,80 length: u64,
81 address: union {81 address: extern union {
82 dataBlock: EfiPhysicalAddress,82 dataBlock: EfiPhysicalAddress,
83 continuationPointer: EfiPhysicalAddress,83 continuationPointer: EfiPhysicalAddress,
84 },84 },