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 {
5050test {
5151 _ = darwin;
5252 _ = linux;
53 _ = uefi;
53 if (builtin.os.tag == .uefi) {
54 _ = uefi;
55 }
5456 _ = wasi;
5557 _ = windows;
5658 _ = posix_spawn;
lib/std/os/uefi.zig+6-1
......@@ -35,7 +35,7 @@ pub const Ipv6Address = extern struct {
3535 address: [16]u8,
3636};
3737
38/// GUIDs must be align(8)
38/// GUIDs are align(8) unless otherwise specified.
3939pub const Guid = extern struct {
4040 time_low: u32,
4141 time_mid: u16,
......@@ -150,3 +150,8 @@ test "GUID formatting" {
150150
151151 try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
152152}
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");
4343pub const hii = @import("protocols/hii.zig");
4444pub usingnamespace @import("protocols/hii_database_protocol.zig");
4545pub 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 {
3131 };
3232};
3333
34pub const AbsolutePointerModeAttributes = packed struct(u32) {
35 supports_alt_active: bool,
36 supports_pressure_as_z: bool,
37 _pad: u30 = 0,
38};
39
3440pub const AbsolutePointerMode = extern struct {
3541 absolute_min_x: u64,
3642 absolute_min_y: u64,
......@@ -38,20 +44,18 @@ pub const AbsolutePointerMode = extern struct {
3844 absolute_max_x: u64,
3945 absolute_max_y: u64,
4046 absolute_max_z: u64,
41 attributes: packed struct {
42 supports_alt_active: bool,
43 supports_pressure_as_z: bool,
44 _pad: u30 = 0,
45 },
47 attributes: AbsolutePointerModeAttributes,
48};
49
50pub const AbsolutePointerStateActiveButtons = packed struct(u32) {
51 touch_active: bool,
52 alt_active: bool,
53 _pad: u30 = 0,
4654};
4755
4856pub const AbsolutePointerState = extern struct {
4957 current_x: u64,
5058 current_y: u64,
5159 current_z: u64,
52 active_buttons: packed struct {
53 touch_active: bool,
54 alt_active: bool,
55 _pad: u30 = 0,
56 },
60 active_buttons: AbsolutePointerStateActiveButtons,
5761};
lib/std/os/uefi/protocols/device_path_protocol.zig+618-159
......@@ -4,10 +4,13 @@ const uefi = std.os.uefi;
44const Allocator = mem.Allocator;
55const 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 {
811 type: DevicePathType,
912 subtype: u8,
10 length: u16,
13 length: u16 align(1),
1114
1215 pub const guid align(8) = Guid{
1316 .time_low = 0x09576e91,
......@@ -38,7 +41,7 @@ pub const DevicePathProtocol = packed struct {
3841 }
3942
4043 /// 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 {
4245 var path_size = self.size();
4346
4447 // 2 * (path.len + 1) for the path and its null terminator, which are u16s
......@@ -56,7 +59,7 @@ pub const DevicePathProtocol = packed struct {
5659 new.length = @sizeOf(MediaDevicePath.FilePathDevicePath) + 2 * (@intCast(u16, path.len) + 1);
5760
5861 // 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
6164 for (path) |s, i|
6265 ptr[i] = s;
......@@ -108,6 +111,15 @@ pub const DevicePathProtocol = packed struct {
108111 }
109112};
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
111123pub const DevicePath = union(DevicePathType) {
112124 Hardware: HardwareDevicePath,
113125 Acpi: AcpiDevicePath,
......@@ -145,51 +157,115 @@ pub const HardwareDevicePath = union(Subtype) {
145157 _,
146158 };
147159
148 pub const PciDevicePath = packed struct {
160 pub const PciDevicePath = extern struct {
149161 type: DevicePathType,
150162 subtype: Subtype,
151 length: u16,
163 length: u16 align(1),
152164 function: u8,
153165 device: u8,
154166 };
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 {
157180 type: DevicePathType,
158181 subtype: Subtype,
159 length: u16,
182 length: u16 align(1),
160183 function_number: u8,
161184 };
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 {
164197 type: DevicePathType,
165198 subtype: Subtype,
166 length: u16,
167 memory_type: u32,
168 start_address: u64,
169 end_address: u64,
199 length: u16 align(1),
200 memory_type: u32 align(1),
201 start_address: u64 align(1),
202 end_address: u64 align(1),
170203 };
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 {
173218 type: DevicePathType,
174219 subtype: Subtype,
175 length: u16,
176 vendor_guid: Guid,
220 length: u16 align(1),
221 vendor_guid: Guid align(1),
177222 };
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 {
180235 type: DevicePathType,
181236 subtype: Subtype,
182 length: u16,
183 controller_number: u32,
237 length: u16 align(1),
238 controller_number: u32 align(1),
184239 };
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 {
187252 type: DevicePathType,
188253 subtype: Subtype,
189 length: u16,
254 length: u16 align(1),
190255 interface_type: u8,
191 base_address: usize,
256 base_address: u64 align(1),
192257 };
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 }
193269};
194270
195271pub const AcpiDevicePath = union(Subtype) {
......@@ -204,37 +280,71 @@ pub const AcpiDevicePath = union(Subtype) {
204280 _,
205281 };
206282
207 pub const BaseAcpiDevicePath = packed struct {
283 pub const BaseAcpiDevicePath = extern struct {
208284 type: DevicePathType,
209285 subtype: Subtype,
210 length: u16,
211 hid: u32,
212 uid: u32,
286 length: u16 align(1),
287 hid: u32 align(1),
288 uid: u32 align(1),
213289 };
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 {
216303 type: DevicePathType,
217304 subtype: Subtype,
218 length: u16,
219 hid: u32,
220 uid: u32,
221 cid: u32,
305 length: u16 align(1),
306 hid: u32 align(1),
307 uid: u32 align(1),
308 cid: u32 align(1),
222309 // variable length u16[*:0] strings
223310 // hid_str, uid_str, cid_str
224311 };
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 {
227326 type: DevicePathType,
228327 subtype: Subtype,
229 length: u16,
230 adr: u32,
328 length: u16 align(1),
329 adr: u32 align(1),
330
231331 // 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 {
233333 // self.length is a minimum of 8 with one adr which is size 4.
234334 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];
236336 }
237337 };
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 }
238348};
239349
240350pub const MessagingDevicePath = union(Subtype) {
......@@ -279,7 +389,7 @@ pub const MessagingDevicePath = union(Subtype) {
279389 _,
280390 };
281391
282 pub const AtapiDevicePath = packed struct {
392 pub const AtapiDevicePath = extern struct {
283393 const Role = enum(u8) {
284394 Master = 0,
285395 Slave = 1,
......@@ -292,111 +402,249 @@ pub const MessagingDevicePath = union(Subtype) {
292402
293403 type: DevicePathType,
294404 subtype: Subtype,
295 length: u16,
405 length: u16 align(1),
296406 primary_secondary: Rank,
297407 slave_master: Role,
298 logical_unit_number: u16,
408 logical_unit_number: u16 align(1),
299409 };
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 {
302424 type: DevicePathType,
303425 subtype: Subtype,
304 length: u16,
305 target_id: u16,
306 logical_unit_number: u16,
426 length: u16 align(1),
427 target_id: u16 align(1),
428 logical_unit_number: u16 align(1),
307429 };
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 {
310443 type: DevicePathType,
311444 subtype: Subtype,
312 length: u16,
313 reserved: u32,
314 world_wide_name: u64,
315 logical_unit_number: u64,
445 length: u16 align(1),
446 reserved: u32 align(1),
447 world_wide_name: u64 align(1),
448 logical_unit_number: u64 align(1),
316449 };
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 {
319464 type: DevicePathType,
320465 subtype: Subtype,
321 length: u16,
322 reserved: u32,
323 world_wide_name: [8]u8,
324 logical_unit_number: [8]u8,
466 length: u16 align(1),
467 reserved: u32 align(1),
468 world_wide_name: u64 align(1),
469 logical_unit_number: u64 align(1),
325470 };
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 {
328485 type: DevicePathType,
329486 subtype: Subtype,
330 length: u16,
331 reserved: u32,
332 guid: u64,
487 length: u16 align(1),
488 reserved: u32 align(1),
489 guid: u64 align(1),
333490 };
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 {
336504 type: DevicePathType,
337505 subtype: Subtype,
338 length: u16,
506 length: u16 align(1),
339507 parent_port_number: u8,
340508 interface_number: u8,
341509 };
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 {
344523 type: DevicePathType,
345524 subtype: Subtype,
346 length: u16,
347 hba_port_number: u16,
348 port_multiplier_port_number: u16,
349 logical_unit_number: u16,
525 length: u16 align(1),
526 hba_port_number: u16 align(1),
527 port_multiplier_port_number: u16 align(1),
528 logical_unit_number: u16 align(1),
350529 };
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 {
353544 type: DevicePathType,
354545 subtype: Subtype,
355 length: u16,
356 interface_number: u16,
357 device_vendor_id: u16,
358 device_product_id: u16,
546 length: u16 align(1),
547 interface_number: u16 align(1),
548 device_vendor_id: u16 align(1),
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 {
361552 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];
363554 }
364555 };
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 {
367570 type: DevicePathType,
368571 subtype: Subtype,
369 length: u16,
572 length: u16 align(1),
370573 lun: u8,
371574 };
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 {
374587 type: DevicePathType,
375588 subtype: Subtype,
376 length: u16,
377 vendor_id: u16,
378 product_id: u16,
589 length: u16 align(1),
590 vendor_id: u16 align(1),
591 product_id: u16 align(1),
379592 device_class: u8,
380593 device_subclass: u8,
381594 device_protocol: u8,
382595 };
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 {
385612 type: DevicePathType,
386613 subtype: Subtype,
387 length: u16,
388 tid: u32,
614 length: u16 align(1),
615 tid: u32 align(1),
389616 };
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 {
392629 type: DevicePathType,
393630 subtype: Subtype,
394 length: u16,
631 length: u16 align(1),
395632 mac_address: uefi.MacAddress,
396633 if_type: u8,
397634 };
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 {
400648 pub const IpType = enum(u8) {
401649 Dhcp = 0,
402650 Static = 1,
......@@ -404,18 +652,35 @@ pub const MessagingDevicePath = union(Subtype) {
404652
405653 type: DevicePathType,
406654 subtype: Subtype,
407 length: u16,
408 local_ip_address: uefi.Ipv4Address,
409 remote_ip_address: uefi.Ipv4Address,
410 local_port: u16,
411 remote_port: u16,
412 network_protocol: u16,
655 length: u16 align(1),
656 local_ip_address: uefi.Ipv4Address align(1),
657 remote_ip_address: uefi.Ipv4Address align(1),
658 local_port: u16 align(1),
659 remote_port: u16 align(1),
660 network_protocol: u16 align(1),
413661 static_ip_address: IpType,
414 gateway_ip_address: u32,
415 subnet_mask: u32,
662 gateway_ip_address: u32 align(1),
663 subnet_mask: u32 align(1),
416664 };
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 {
419684 pub const Origin = enum(u8) {
420685 Manual = 0,
421686 AssignedStateless = 1,
......@@ -424,26 +689,53 @@ pub const MessagingDevicePath = union(Subtype) {
424689
425690 type: DevicePathType,
426691 subtype: Subtype,
427 length: u16,
692 length: u16 align(1),
428693 local_ip_address: uefi.Ipv6Address,
429694 remote_ip_address: uefi.Ipv6Address,
430 local_port: u16,
431 remote_port: u16,
432 protocol: u16,
695 local_port: u16 align(1),
696 remote_port: u16 align(1),
697 protocol: u16 align(1),
433698 ip_address_origin: Origin,
434699 prefix_length: u8,
435700 gateway_ip_address: uefi.Ipv6Address,
436701 };
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 {
439721 type: DevicePathType,
440722 subtype: Subtype,
441 length: u16,
442 vlan_id: u16,
723 length: u16 align(1),
724 vlan_id: u16 align(1),
443725 };
444726
445 pub const InfiniBandDevicePath = packed struct {
446 pub const ResourceFlags = packed struct {
727 comptime {
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) {
447739 pub const ControllerType = enum(u1) {
448740 Ioc = 0,
449741 Service = 1,
......@@ -461,15 +753,29 @@ pub const MessagingDevicePath = union(Subtype) {
461753
462754 type: DevicePathType,
463755 subtype: Subtype,
464 length: u16,
465 resource_flags: ResourceFlags,
756 length: u16 align(1),
757 resource_flags: ResourceFlags align(1),
466758 port_gid: [16]u8,
467 service_id: u64,
468 target_port_id: u64,
469 device_id: u64,
759 service_id: u64 align(1),
760 target_port_id: u64 align(1),
761 device_id: u64 align(1),
470762 };
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 {
473779 pub const Parity = enum(u8) {
474780 Default = 0,
475781 None = 1,
......@@ -490,20 +796,44 @@ pub const MessagingDevicePath = union(Subtype) {
490796
491797 type: DevicePathType,
492798 subtype: Subtype,
493 length: u16,
494 reserved: u16,
495 baud_rate: u32,
799 length: u16 align(1),
800 reserved: u32 align(1),
801 baud_rate: u64 align(1),
496802 data_bits: u8,
497803 parity: Parity,
498804 stop_bits: StopBits,
499805 };
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 {
502822 type: DevicePathType,
503823 subtype: Subtype,
504 length: u16,
505 vendor_guid: Guid,
824 length: u16 align(1),
825 vendor_guid: Guid align(1),
506826 };
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 }
507837};
508838
509839pub const MediaDevicePath = union(Subtype) {
......@@ -530,7 +860,7 @@ pub const MediaDevicePath = union(Subtype) {
530860 _,
531861 };
532862
533 pub const HardDriveDevicePath = packed struct {
863 pub const HardDriveDevicePath = extern struct {
534864 pub const Format = enum(u8) {
535865 LegacyMbr = 0x01,
536866 GuidPartitionTable = 0x02,
......@@ -545,81 +875,181 @@ pub const MediaDevicePath = union(Subtype) {
545875
546876 type: DevicePathType,
547877 subtype: Subtype,
548 length: u16,
549 partition_number: u32,
550 partition_start: u64,
551 partition_size: u64,
878 length: u16 align(1),
879 partition_number: u32 align(1),
880 partition_start: u64 align(1),
881 partition_size: u64 align(1),
552882 partition_signature: [16]u8,
553883 partition_format: Format,
554884 signature_type: SignatureType,
555885 };
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 {
558903 type: DevicePathType,
559904 subtype: Subtype,
560 length: u16,
561 boot_entry: u32,
562 partition_start: u64,
563 partition_size: u64,
905 length: u16 align(1),
906 boot_entry: u32 align(1),
907 partition_start: u64 align(1),
908 partition_size: u64 align(1),
564909 };
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 {
567924 type: DevicePathType,
568925 subtype: Subtype,
569 length: u16,
570 guid: Guid,
571 // vendor-defined variable data
926 length: u16 align(1),
927 guid: Guid align(1),
572928 };
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 {
575941 type: DevicePathType,
576942 subtype: Subtype,
577 length: u16,
943 length: u16 align(1),
578944
579 pub fn getPath(self: *const FilePathDevicePath) [*:0]const u16 {
580 return @ptrCast([*:0]const u16, @alignCast(2, @ptrCast([*]const u8, self)) + @sizeOf(FilePathDevicePath));
945 pub fn getPath(self: *const FilePathDevicePath) [*:0]align(1) const u16 {
946 return @ptrCast([*:0]align(1) const u16, @ptrCast([*]const u8, self) + @sizeOf(FilePathDevicePath));
581947 }
582948 };
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 {
585960 type: DevicePathType,
586961 subtype: Subtype,
587 length: u16,
588 guid: Guid,
962 length: u16 align(1),
963 guid: Guid align(1),
589964 };
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 {
592977 type: DevicePathType,
593978 subtype: Subtype,
594 length: u16,
595 fv_filename: Guid,
979 length: u16 align(1),
980 fv_filename: Guid align(1),
596981 };
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 {
599994 type: DevicePathType,
600995 subtype: Subtype,
601 length: u16,
602 fv_name: Guid,
996 length: u16 align(1),
997 fv_name: Guid align(1),
603998 };
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 {
6061011 type: DevicePathType,
6071012 subtype: Subtype,
608 length: u16,
609 reserved: u32,
610 start: u64,
611 end: u64,
1013 length: u16 align(1),
1014 reserved: u32 align(1),
1015 start: u64 align(1),
1016 end: u64 align(1),
6121017 };
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 {
6151032 type: DevicePathType,
6161033 subtype: Subtype,
617 length: u16,
618 start: u64,
619 end: u64,
620 disk_type: Guid,
621 instance: u16,
1034 length: u16 align(1),
1035 start: u64 align(1),
1036 end: u64 align(1),
1037 disk_type: Guid align(1),
1038 instance: u16 align(1),
6221039 };
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 }
6231053};
6241054
6251055pub const BiosBootSpecificationDevicePath = union(Subtype) {
......@@ -630,17 +1060,28 @@ pub const BiosBootSpecificationDevicePath = union(Subtype) {
6301060 _,
6311061 };
6321062
633 pub const BBS101DevicePath = packed struct {
1063 pub const BBS101DevicePath = extern struct {
6341064 type: DevicePathType,
6351065 subtype: Subtype,
636 length: u16,
637 device_type: u16,
638 status_flag: u16,
1066 length: u16 align(1),
1067 device_type: u16 align(1),
1068 status_flag: u16 align(1),
6391069
6401070 pub fn getDescription(self: *const BBS101DevicePath) [*:0]const u8 {
6411071 return @ptrCast([*:0]const u8, self) + @sizeOf(BBS101DevicePath);
6421072 }
6431073 };
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 }
6441085};
6451086
6461087pub const EndDevicePath = union(Subtype) {
......@@ -653,15 +1094,33 @@ pub const EndDevicePath = union(Subtype) {
6531094 _,
6541095 };
6551096
656 pub const EndEntireDevicePath = packed struct {
1097 pub const EndEntireDevicePath = extern struct {
6571098 type: DevicePathType,
6581099 subtype: Subtype,
659 length: u16,
1100 length: u16 align(1),
6601101 };
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 {
6631113 type: DevicePathType,
6641114 subtype: Subtype,
665 length: u16,
1115 length: u16 align(1),
6661116 };
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 }
6671126};
lib/std/os/uefi/protocols/edid_override_protocol.zig+4-6
......@@ -6,19 +6,17 @@ const Status = uefi.Status;
66
77/// Override EDID information
88pub 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
1111 /// Returns policy information and potentially a replacement EDID for the specified video output device.
1212 pub fn getEdid(
1313 self: *const EdidOverrideProtocol,
1414 handle: Handle,
15 /// The align(4) here should really be part of the EdidOverrideProtocolAttributes type.
16 /// TODO remove this workaround when packed(u32) structs are implemented.
17 attributes: *align(4) EdidOverrideProtocolAttributes,
15 attributes: *EdidOverrideProtocolAttributes,
1816 edid_size: *usize,
1917 edid: *?[*]u8,
2018 ) 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);
2220 }
2321
2422 pub const guid align(8) = Guid{
......@@ -31,7 +29,7 @@ pub const EdidOverrideProtocol = extern struct {
3129 };
3230};
3331
34pub const EdidOverrideProtocolAttributes = packed struct {
32pub const EdidOverrideProtocolAttributes = packed struct(u32) {
3533 dont_override: bool,
3634 enable_hot_plug: bool,
3735 _pad: u30 = 0,
lib/std/os/uefi/protocols/hii.zig+15-11
......@@ -4,7 +4,7 @@ const Guid = uefi.Guid;
44pub const HIIHandle = *opaque {};
55
66/// The header found at the start of each package.
7pub const HIIPackageHeader = packed struct {
7pub const HIIPackageHeader = packed struct(u32) {
88 length: u24,
99 type: u8,
1010
......@@ -43,23 +43,27 @@ pub const HIISimplifiedFontPackage = extern struct {
4343 }
4444};
4545
46pub const NarrowGlyphAttributes = packed struct(u8) {
47 non_spacing: bool,
48 wide: bool,
49 _pad: u6 = 0,
50};
51
4652pub const NarrowGlyph = extern struct {
4753 unicode_weight: u16,
48 attributes: packed struct {
49 non_spacing: bool,
50 wide: bool,
51 _pad: u6 = 0,
52 },
54 attributes: NarrowGlyphAttributes,
5355 glyph_col_1: [19]u8,
5456};
5557
58pub const WideGlyphAttributes = packed struct(u8) {
59 non_spacing: bool,
60 wide: bool,
61 _pad: u6 = 0,
62};
63
5664pub const WideGlyph = extern struct {
5765 unicode_weight: u16,
58 attributes: packed struct {
59 non_spacing: bool,
60 wide: bool,
61 _pad: u6,
62 },
66 attributes: WideGlyphAttributes,
6367 glyph_col_1: [19]u8,
6468 glyph_col_2: [19]u8,
6569 _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 {
121121 media_present: bool,
122122};
123123
124pub const SimpleNetworkReceiveFilter = packed struct {
124pub const SimpleNetworkReceiveFilter = packed struct(u32) {
125125 receive_unicast: bool,
126126 receive_multicast: bool,
127127 receive_broadcast: bool,
......@@ -165,7 +165,7 @@ pub const NetworkStatistics = extern struct {
165165 tx_retry_frames: u64,
166166};
167167
168pub const SimpleNetworkInterruptStatus = packed struct {
168pub const SimpleNetworkInterruptStatus = packed struct(u32) {
169169 receive_interrupt: bool,
170170 transmit_interrupt: bool,
171171 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 {
5353 key_state: KeyState = undefined,
5454};
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
5680pub const KeyState = extern struct {
57 key_shift_state: packed struct {
58 right_shift_pressed: bool,
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 },
81 key_shift_state: KeyShiftState,
82 key_toggle_state: KeyToggleState,
7983};
8084
8185pub const InputKey = extern struct {
lib/std/os/uefi/tables.zig+4
......@@ -3,3 +3,7 @@ pub usingnamespace @import("tables/runtime_services.zig");
33pub usingnamespace @import("tables/configuration_table.zig");
44pub usingnamespace @import("tables/system_table.zig");
55pub 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) {
219219 _,
220220};
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
222241pub const MemoryDescriptor = extern struct {
223242 type: MemoryType,
224243 padding: u32,
225244 physical_start: u64,
226245 virtual_start: u64,
227246 number_of_pages: usize,
228 attribute: packed struct {
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 },
247 attribute: MemoryDescriptorAttribute,
249248};
250249
251250pub const LocateSearchType = enum(u32) {
......@@ -254,14 +253,14 @@ pub const LocateSearchType = enum(u32) {
254253 ByProtocol,
255254};
256255
257pub const OpenProtocolAttributes = packed struct {
256pub const OpenProtocolAttributes = packed struct(u32) {
258257 by_handle_protocol: bool = false,
259258 get_protocol: bool = false,
260259 test_protocol: bool = false,
261260 by_child_controller: bool = false,
262261 by_driver: bool = false,
263262 exclusive: bool = false,
264 _pad: u26 = 0,
263 reserved: u26 = 0,
265264};
266265
267266pub const ProtocolInformationEntry = extern struct {
lib/std/os/uefi/tables/runtime_services.zig+1-1
......@@ -78,7 +78,7 @@ pub const CapsuleHeader = extern struct {
7878
7979pub const UefiCapsuleBlockDescriptor = extern struct {
8080 length: u64,
81 address: union {
81 address: extern union {
8282 dataBlock: EfiPhysicalAddress,
8383 continuationPointer: EfiPhysicalAddress,
8484 },