2021-02-21 10:17:59 +00:00
|
|
|
const std = @import("../std.zig");
|
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// A protocol is an interface identified by a GUID.
|
2023-08-25 02:44:27 +00:00
|
|
|
pub const protocol = @import("uefi/protocol.zig");
|
|
|
|
pub const DevicePath = @import("uefi/device_path.zig").DevicePath;
|
|
|
|
pub const hii = @import("uefi/hii.zig");
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// Status codes returned by EFI interfaces
|
2020-03-09 23:56:47 +00:00
|
|
|
pub const Status = @import("uefi/status.zig").Status;
|
2019-07-28 21:51:51 +00:00
|
|
|
pub const tables = @import("uefi/tables.zig");
|
2019-05-29 07:43:39 +00:00
|
|
|
|
2022-01-11 08:59:48 +00:00
|
|
|
/// The memory type to allocate when using the pool
|
2022-01-11 18:00:19 +00:00
|
|
|
/// Defaults to .LoaderData, the default data allocation type
|
2022-01-11 08:59:48 +00:00
|
|
|
/// used by UEFI applications to allocate pool memory.
|
|
|
|
pub var efi_pool_memory_type: tables.MemoryType = .LoaderData;
|
|
|
|
pub const pool_allocator = @import("uefi/pool_allocator.zig").pool_allocator;
|
|
|
|
pub const raw_pool_allocator = @import("uefi/pool_allocator.zig").raw_pool_allocator;
|
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// The EFI image's handle that is passed to its entry point.
|
2019-08-09 21:12:59 +00:00
|
|
|
pub var handle: Handle = undefined;
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// A pointer to the EFI System Table that is passed to the EFI image's entry point.
|
2019-07-28 21:51:51 +00:00
|
|
|
pub var system_table: *tables.SystemTable = undefined;
|
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// A handle to an event structure.
|
2020-09-25 20:29:03 +00:00
|
|
|
pub const Event = *opaque {};
|
2019-10-16 17:42:44 +00:00
|
|
|
|
2023-07-06 21:48:29 +00:00
|
|
|
/// The calling convention used for all external functions part of the UEFI API.
|
|
|
|
pub const cc = switch (@import("builtin").target.cpu.arch) {
|
|
|
|
.x86_64 => .Win64,
|
|
|
|
else => .C,
|
|
|
|
};
|
|
|
|
|
2022-01-14 12:02:34 +00:00
|
|
|
pub const MacAddress = extern struct {
|
|
|
|
address: [32]u8,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const Ipv4Address = extern struct {
|
|
|
|
address: [4]u8,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const Ipv6Address = extern struct {
|
|
|
|
address: [16]u8,
|
|
|
|
};
|
|
|
|
|
2022-10-30 19:08:32 +00:00
|
|
|
/// GUIDs are align(8) unless otherwise specified.
|
2019-07-28 21:51:51 +00:00
|
|
|
pub const Guid = extern struct {
|
|
|
|
time_low: u32,
|
|
|
|
time_mid: u16,
|
|
|
|
time_high_and_version: u16,
|
|
|
|
clock_seq_high_and_reserved: u8,
|
|
|
|
clock_seq_low: u8,
|
|
|
|
node: [6]u8,
|
2019-10-07 12:53:14 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// Format GUID into hexadecimal lowercase xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format
|
2019-10-07 12:53:14 +00:00
|
|
|
pub fn format(
|
|
|
|
self: @This(),
|
|
|
|
comptime f: []const u8,
|
2020-03-06 22:59:21 +00:00
|
|
|
options: std.fmt.FormatOptions,
|
2021-02-21 10:17:59 +00:00
|
|
|
writer: anytype,
|
|
|
|
) !void {
|
2021-06-20 01:10:22 +00:00
|
|
|
_ = options;
|
2019-10-07 12:53:14 +00:00
|
|
|
if (f.len == 0) {
|
2022-04-17 10:15:15 +00:00
|
|
|
const fmt = std.fmt.fmtSliceHexLower;
|
|
|
|
|
2022-08-21 14:24:04 +00:00
|
|
|
const time_low = @byteSwap(self.time_low);
|
|
|
|
const time_mid = @byteSwap(self.time_mid);
|
|
|
|
const time_high_and_version = @byteSwap(self.time_high_and_version);
|
2022-04-17 10:15:15 +00:00
|
|
|
|
|
|
|
return std.fmt.format(writer, "{:0>8}-{:0>4}-{:0>4}-{:0>2}{:0>2}-{:0>12}", .{
|
|
|
|
fmt(std.mem.asBytes(&time_low)),
|
|
|
|
fmt(std.mem.asBytes(&time_mid)),
|
|
|
|
fmt(std.mem.asBytes(&time_high_and_version)),
|
|
|
|
fmt(std.mem.asBytes(&self.clock_seq_high_and_reserved)),
|
|
|
|
fmt(std.mem.asBytes(&self.clock_seq_low)),
|
|
|
|
fmt(std.mem.asBytes(&self.node)),
|
2020-01-09 09:56:38 +00:00
|
|
|
});
|
2019-10-07 12:53:14 +00:00
|
|
|
} else {
|
2022-11-12 19:03:24 +00:00
|
|
|
std.fmt.invalidFmtError(f, self);
|
2019-10-07 12:53:14 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-21 10:17:59 +00:00
|
|
|
|
|
|
|
pub fn eql(a: std.os.uefi.Guid, b: std.os.uefi.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);
|
|
|
|
}
|
2019-07-28 21:51:51 +00:00
|
|
|
};
|
2019-10-16 17:42:44 +00:00
|
|
|
|
|
|
|
/// An EFI Handle represents a collection of related interfaces.
|
2020-09-25 20:29:03 +00:00
|
|
|
pub const Handle = *opaque {};
|
2019-10-16 17:42:44 +00:00
|
|
|
|
|
|
|
/// This structure represents time information.
|
2019-07-28 21:51:51 +00:00
|
|
|
pub const Time = extern struct {
|
2019-10-16 17:42:44 +00:00
|
|
|
/// 1900 - 9999
|
2019-07-28 21:51:51 +00:00
|
|
|
year: u16,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// 1 - 12
|
2019-07-28 21:51:51 +00:00
|
|
|
month: u8,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// 1 - 31
|
2019-07-28 21:51:51 +00:00
|
|
|
day: u8,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// 0 - 23
|
2019-07-28 21:51:51 +00:00
|
|
|
hour: u8,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// 0 - 59
|
2019-07-28 21:51:51 +00:00
|
|
|
minute: u8,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// 0 - 59
|
2019-07-28 21:51:51 +00:00
|
|
|
second: u8,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// 0 - 999999999
|
2019-07-28 21:51:51 +00:00
|
|
|
nanosecond: u32,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// The time's offset in minutes from UTC.
|
|
|
|
/// Allowed values are -1440 to 1440 or unspecified_timezone
|
2019-07-28 21:51:51 +00:00
|
|
|
timezone: i16,
|
2019-08-05 16:26:13 +00:00
|
|
|
daylight: packed struct {
|
|
|
|
_pad1: u6,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// If true, the time has been adjusted for daylight savings time.
|
2019-08-05 16:26:13 +00:00
|
|
|
in_daylight: bool,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// If true, the time is affected by daylight savings time.
|
2019-08-05 16:26:13 +00:00
|
|
|
adjust_daylight: bool,
|
|
|
|
},
|
2019-07-28 21:51:51 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// Time is to be interpreted as local time
|
2019-07-28 21:51:51 +00:00
|
|
|
pub const unspecified_timezone: i16 = 0x7ff;
|
2023-12-20 07:42:47 +00:00
|
|
|
|
|
|
|
fn daysInYear(year: u16, maxMonth: u4) u32 {
|
|
|
|
const leapYear: std.time.epoch.YearLeapKind = if (std.time.epoch.isLeapYear(year)) .leap else .not_leap;
|
|
|
|
var days: u32 = 0;
|
|
|
|
var month: u4 = 0;
|
|
|
|
while (month < maxMonth) : (month += 1) {
|
|
|
|
days += std.time.epoch.getDaysInMonth(leapYear, @enumFromInt(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 = self.hour + (days * 24);
|
|
|
|
const minutes = self.minute + (hours * 60);
|
2023-12-20 17:33:59 +00:00
|
|
|
const seconds = self.second + (minutes * std.time.s_per_min);
|
|
|
|
return self.nanosecond + (seconds * std.time.ns_per_s);
|
2023-12-20 07:42:47 +00:00
|
|
|
}
|
2019-07-28 21:51:51 +00:00
|
|
|
};
|
2019-10-16 17:42:44 +00:00
|
|
|
|
|
|
|
/// Capabilities of the clock device
|
2019-07-28 21:51:51 +00:00
|
|
|
pub const TimeCapabilities = extern struct {
|
2019-10-16 17:42:44 +00:00
|
|
|
/// Resolution in Hz
|
2019-07-28 21:51:51 +00:00
|
|
|
resolution: u32,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// Accuracy in an error rate of 1e-6 parts per million.
|
2019-07-28 21:51:51 +00:00
|
|
|
accuracy: u32,
|
2019-10-24 05:06:03 +00:00
|
|
|
|
2019-10-16 17:42:44 +00:00
|
|
|
/// If true, a time set operation clears the device's time below the resolution level.
|
2019-07-28 21:51:51 +00:00
|
|
|
sets_to_zero: bool,
|
|
|
|
};
|
2020-03-09 19:27:53 +00:00
|
|
|
|
|
|
|
/// File Handle as specified in the EFI Shell Spec
|
2020-09-25 20:29:03 +00:00
|
|
|
pub const FileHandle = *opaque {};
|
2022-04-17 10:15:15 +00:00
|
|
|
|
|
|
|
test "GUID formatting" {
|
2023-11-10 05:27:17 +00:00
|
|
|
const bytes = [_]u8{ 137, 60, 203, 50, 128, 128, 124, 66, 186, 19, 80, 73, 135, 59, 194, 135 };
|
|
|
|
const guid: Guid = @bitCast(bytes);
|
2022-04-17 10:15:15 +00:00
|
|
|
|
2023-11-10 05:27:17 +00:00
|
|
|
const str = try std.fmt.allocPrint(std.testing.allocator, "{}", .{guid});
|
2022-04-17 10:15:15 +00:00
|
|
|
defer std.testing.allocator.free(str);
|
|
|
|
|
|
|
|
try std.testing.expect(std.mem.eql(u8, str, "32cb3c89-8080-427c-ba13-5049873bc287"));
|
|
|
|
}
|
2022-10-30 19:08:32 +00:00
|
|
|
|
2023-08-25 02:44:27 +00:00
|
|
|
pub const FileInfo = extern struct {
|
|
|
|
size: u64,
|
|
|
|
file_size: u64,
|
|
|
|
physical_size: u64,
|
|
|
|
create_time: Time,
|
|
|
|
last_access_time: Time,
|
|
|
|
modification_time: Time,
|
|
|
|
attribute: u64,
|
|
|
|
|
|
|
|
pub fn getFileName(self: *const FileInfo) [*:0]const u16 {
|
|
|
|
return @ptrCast(@alignCast(@as([*]const u8, @ptrCast(self)) + @sizeOf(FileInfo)));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const efi_file_read_only: u64 = 0x0000000000000001;
|
|
|
|
pub const efi_file_hidden: u64 = 0x0000000000000002;
|
|
|
|
pub const efi_file_system: u64 = 0x0000000000000004;
|
|
|
|
pub const efi_file_reserved: u64 = 0x0000000000000008;
|
|
|
|
pub const efi_file_directory: u64 = 0x0000000000000010;
|
|
|
|
pub const efi_file_archive: u64 = 0x0000000000000020;
|
|
|
|
pub const efi_file_valid_attr: u64 = 0x0000000000000037;
|
|
|
|
|
|
|
|
pub const guid align(8) = Guid{
|
|
|
|
.time_low = 0x09576e92,
|
|
|
|
.time_mid = 0x6d3f,
|
|
|
|
.time_high_and_version = 0x11d2,
|
|
|
|
.clock_seq_high_and_reserved = 0x8e,
|
|
|
|
.clock_seq_low = 0x39,
|
|
|
|
.node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const FileSystemInfo = extern struct {
|
|
|
|
size: u64,
|
|
|
|
read_only: bool,
|
|
|
|
volume_size: u64,
|
|
|
|
free_space: u64,
|
|
|
|
block_size: u32,
|
|
|
|
_volume_label: u16,
|
|
|
|
|
|
|
|
pub fn getVolumeLabel(self: *const FileSystemInfo) [*:0]const u16 {
|
|
|
|
return @as([*:0]const u16, @ptrCast(&self._volume_label));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub const guid align(8) = Guid{
|
|
|
|
.time_low = 0x09576e93,
|
|
|
|
.time_mid = 0x6d3f,
|
|
|
|
.time_high_and_version = 0x11d2,
|
|
|
|
.clock_seq_high_and_reserved = 0x8e,
|
|
|
|
.clock_seq_low = 0x39,
|
|
|
|
.node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-10-30 19:08:32 +00:00
|
|
|
test {
|
|
|
|
_ = tables;
|
2023-08-25 02:44:27 +00:00
|
|
|
_ = protocol;
|
2022-10-30 19:08:32 +00:00
|
|
|
}
|