feature. See also
. The project being documented here (as the example) is the Zig library itself.
File
Code
const std = @import("../std.zig");
const assert = std.debug.assert;
pub const protocol = @import("uefi/protocol.zig");
pub const DevicePath = @import("uefi/device_path.zig").DevicePath;
pub const hii = @import("uefi/hii.zig");
pub const Status = @import("uefi/status.zig").Status;
pub const Error = UnexpectedError || Status.Error;
pub const tables = @import("uefi/tables.zig");
pub var efi_pool_memory_type: tables.MemoryType = .loader_data;
pub const pool_allocator = @import("uefi/pool_allocator.zig").pool_allocator;
pub const raw_pool_allocator = @import("uefi/pool_allocator.zig").raw_pool_allocator;
pub var handle: Handle = undefined;
pub var system_table: *tables.SystemTable = undefined;
pub const Page = [4096]u8;
pub const Event = *opaque {};
pub const EventRegistration = *const opaque {};
pub const EventType = packed struct(u32) {
lo_context: u8 = 0,
wait: bool = false,
signal: bool = false,
hi_context: u20 = 0,
runtime: bool = false,
timer: bool = false,
pub const signal_exit_boot_services: EventType = .{
.signal = true,
.lo_context = 1,
};
pub const signal_virtual_address_change: EventType = .{
.runtime = true,
.hi_context = 0x20000,
.signal = true,
.lo_context = 2,
};
};
pub const cc: std.builtin.CallingConvention = switch (@import("builtin").target.cpu.arch) {
.x86_64 => .{ .x86_64_win = .{} },
else => .c,
};
pub const MacAddress = extern struct {
address: [32]u8,
};
pub const Ipv4Address = extern struct {
address: [4]u8,
};
pub const Ipv6Address = extern struct {
address: [16]u8,
};
pub const IpAddress = extern union {
v4: Ipv4Address,
v6: Ipv6Address,
};
pub const Guid = extern struct {
comptime {
std.debug.assert(std.mem.Alignment.of(Guid) == .@"8");
}
time_low: u32 align(8),
time_mid: u16,
time_high_and_version: u16,
clock_seq_high_and_reserved: u8,
clock_seq_low: u8,
node: [6]u8,
pub fn format(self: Guid, writer: *std.Io.Writer) std.Io.Writer.Error!void {
return writer.print("{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x}", .{
self.time_low,
self.time_mid,
self.time_high_and_version,
self.clock_seq_high_and_reserved,
self.clock_seq_low,
self.node,
});
}
pub fn eql(a: Guid, b: Guid) bool {
return a.time_low == b.time_low and
a.time_mid == b.time_mid and
a.time_high_and_version == b.time_high_and_version and
a.clock_seq_high_and_reserved == b.clock_seq_high_and_reserved and
a.clock_seq_low == b.clock_seq_low and
std.mem.eql(u8, &a.node, &b.node);
}
};
pub const Handle = *opaque {};
pub const Time = extern struct {
year: u16,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
_pad1: u8,
nanosecond: u32,
timezone: i16,
daylight: packed struct(u8) {
in_daylight: bool,
adjust_daylight: bool,
_: u6,
},
_pad2: u8,
comptime {
std.debug.assert(@sizeOf(Time) == 16);
}
pub const unspecified_timezone: i16 = 0x7ff;
fn daysInYear(year: u16, max_month: u4) u9 {
var days: u9 = 0;
var month: u4 = 0;
while (month < max_month) : (month += 1) {
days += std.time.epoch.getDaysInMonth(year, @fromBackingInt(@intCast(month + 1)));
}
return days;
}
pub fn toEpoch(self: std.os.uefi.Time) u64 {
var year: u16 = 0;
var days: u32 = 0;
while (year < (self.year - 1971)) : (year += 1) {
days += daysInYear(year + 1970, 12);
}
days += daysInYear(self.year, @as(u4, @intCast(self.month)) - 1) + self.day;
const hours: u64 = self.hour + (days * 24);
const minutes: u64 = self.minute + (hours * 60);
const seconds: u64 = self.second + (minutes * std.time.s_per_min);
return self.nanosecond + (seconds * std.time.ns_per_s);
}
};
pub const TimeCapabilities = extern struct {
resolution: u32,
accuracy: u32,
sets_to_zero: bool,
};
pub const FileHandle = *opaque {};
test "GUID formatting" {
const bytes: [16]u8 = .{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };
const guid: Guid = @bitCast(bytes);
const str = try std.fmt.allocPrint(std.testing.allocator, "{f}", .{guid});
defer std.testing.allocator.free(str);
try std.testing.expectEqualStrings(str, "32cb3c89-8080-427c-ba13-5049873bc287");
}
test {
_ = tables;
_ = protocol;
}
pub const UnexpectedError = error{Unexpected};
pub fn unexpectedStatus(status: Status) UnexpectedError {
_ = status;
return error.Unexpected;
}