| author | |
| committer | |
| log | c15e464320ebb8c64ae19005e44ba5cb711f83c6 |
| tree | 774caf931a1c0b89698a5ef37dbb1912247182ee |
| parent | eb7d36ae0d240b8ef5421703e613d164cf691d8d |
| parent | 5e874a89b991fcabe8177c551c220894593c1632 |
| signature |
23 files changed, 1028 insertions(+), 16 deletions(-)
src/codegen.cpp+8-6| ... | ... | @@ -516,7 +516,9 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { |
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | 518 | if (g->have_stack_probing && !fn->def_scope->safety_off) { |
| 519 | addLLVMFnAttrStr(llvm_fn, "probe-stack", "__zig_probe_stack"); | |
| 519 | addLLVMFnAttrStr(fn->llvm_value, "probe-stack", "__zig_probe_stack"); | |
| 520 | } else { | |
| 521 | addLLVMFnAttrStr(fn->llvm_value, "no-stack-arg-probe", ""); | |
| 520 | 522 | } |
| 521 | 523 | } else { |
| 522 | 524 | maybe_import_dll(g, llvm_fn, linkage); |
| ... | ... | @@ -9081,10 +9083,6 @@ static bool want_startup_code(CodeGen *g) { |
| 9081 | 9083 | if (g->is_test_build) |
| 9082 | 9084 | return false; |
| 9083 | 9085 | |
| 9084 | // start code does not handle UEFI target | |
| 9085 | if (g->zig_target->os == OsUefi) | |
| 9086 | return false; | |
| 9087 | ||
| 9088 | 9086 | // WASM freestanding can still have an entry point but other freestanding targets do not. |
| 9089 | 9087 | if (g->zig_target->os == OsFreestanding && !target_is_wasm(g->zig_target)) |
| 9090 | 9088 | return false; |
| ... | ... | @@ -9094,8 +9092,12 @@ static bool want_startup_code(CodeGen *g) { |
| 9094 | 9092 | return false; |
| 9095 | 9093 | |
| 9096 | 9094 | // If there is a pub main in the root source file, that means we need start code. |
| 9097 | if (g->have_pub_main) | |
| 9095 | if (g->have_pub_main) { | |
| 9098 | 9096 | return true; |
| 9097 | } else { | |
| 9098 | if (g->zig_target->os == OsUefi) | |
| 9099 | return false; | |
| 9100 | } | |
| 9099 | 9101 | |
| 9100 | 9102 | if (g->out_type == OutTypeExe) { |
| 9101 | 9103 | // For build-exe, we might add start code even though there is no pub main, so that the |
src/target.cpp+3-3| ... | ... | @@ -1110,7 +1110,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | bool target_allows_addr_zero(const ZigTarget *target) { |
| 1113 | return target->os == OsFreestanding; | |
| 1113 | return target->os == OsFreestanding || target->os == OsUefi; | |
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | const char *target_o_file_ext(const ZigTarget *target) { |
| ... | ... | @@ -1535,12 +1535,12 @@ bool target_supports_fpic(const ZigTarget *target) { |
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | 1537 | bool target_supports_stack_probing(const ZigTarget *target) { |
| 1538 | return target->os != OsWindows && (target->arch == ZigLLVM_x86 || target->arch == ZigLLVM_x86_64); | |
| 1538 | return target->os != OsWindows && target->os != OsUefi && (target->arch == ZigLLVM_x86 || target->arch == ZigLLVM_x86_64); | |
| 1539 | 1539 | } |
| 1540 | 1540 | |
| 1541 | 1541 | bool target_requires_pic(const ZigTarget *target, bool linking_libc) { |
| 1542 | 1542 | // This function returns whether non-pic code is completely invalid on the given target. |
| 1543 | return target->os == OsWindows || target_os_requires_libc(target->os) || | |
| 1543 | return target->os == OsWindows || target->os == OsUefi || target_os_requires_libc(target->os) || | |
| 1544 | 1544 | (linking_libc && target_is_glibc(target)); |
| 1545 | 1545 | } |
| 1546 | 1546 |
std/build.zig+9-2| ... | ... | @@ -1175,6 +1175,13 @@ pub const Target = union(enum) { |
| 1175 | 1175 | }; |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | pub fn isUefi(self: Target) bool { | |
| 1179 | return switch (self.getOs()) { | |
| 1180 | .uefi => true, | |
| 1181 | else => false, | |
| 1182 | }; | |
| 1183 | } | |
| 1184 | ||
| 1178 | 1185 | pub fn isWasm(self: Target) bool { |
| 1179 | 1186 | return switch (self.getArch()) { |
| 1180 | 1187 | .wasm32, .wasm64 => true, |
| ... | ... | @@ -1490,7 +1497,7 @@ pub const LibExeObjStep = struct { |
| 1490 | 1497 | } |
| 1491 | 1498 | |
| 1492 | 1499 | pub fn producesPdbFile(self: *LibExeObjStep) bool { |
| 1493 | if (!self.target.isWindows()) return false; | |
| 1500 | if (!self.target.isWindows() and !self.target.isUefi()) return false; | |
| 1494 | 1501 | if (self.strip) return false; |
| 1495 | 1502 | return self.isDynamicLibrary() or self.kind == .Exe; |
| 1496 | 1503 | } |
| ... | ... | @@ -1587,7 +1594,7 @@ pub const LibExeObjStep = struct { |
| 1587 | 1594 | /// Unless setOutputDir was called, this function must be called only in |
| 1588 | 1595 | /// the make step, from a step that has declared a dependency on this one. |
| 1589 | 1596 | pub fn getOutputPdbPath(self: *LibExeObjStep) []const u8 { |
| 1590 | assert(self.target.isWindows()); | |
| 1597 | assert(self.target.isWindows() or self.target.isUefi()); | |
| 1591 | 1598 | return fs.path.join( |
| 1592 | 1599 | self.builder.allocator, |
| 1593 | 1600 | [_][]const u8{ self.output_dir.?, self.out_pdb_filename }, |
std/os.zig+10-2| ... | ... | @@ -172,8 +172,7 @@ pub fn abort() noreturn { |
| 172 | 172 | system.abort(); |
| 173 | 173 | } |
| 174 | 174 | if (builtin.os == .uefi) { |
| 175 | // TODO there must be a better thing to do here than loop forever | |
| 176 | while (true) {} | |
| 175 | exit(0); // TODO choose appropriate exit code | |
| 177 | 176 | } |
| 178 | 177 | |
| 179 | 178 | raise(SIGABRT) catch {}; |
| ... | ... | @@ -245,6 +244,15 @@ pub fn exit(status: u8) noreturn { |
| 245 | 244 | if (linux.is_the_target and !builtin.single_threaded) { |
| 246 | 245 | linux.exit_group(status); |
| 247 | 246 | } |
| 247 | if (uefi.is_the_target) { | |
| 248 | // exit() is only avaliable if exitBootServices() has not been called yet. | |
| 249 | // This call to exit should not fail, so we don't care about its return value. | |
| 250 | if (uefi.system_table.boot_services) |bs| { | |
| 251 | _ = bs.exit(uefi.handle, status, 0, null); | |
| 252 | } | |
| 253 | // If we can't exit, reboot the system instead. | |
| 254 | uefi.system_table.runtime_services.resetSystem(uefi.tables.ResetType.ResetCold, status, 0, null); | |
| 255 | } | |
| 248 | 256 | system.exit(status); |
| 249 | 257 | } |
| 250 | 258 |
std/os/uefi.zig+42-3| ... | ... | @@ -1,6 +1,45 @@ |
| 1 | // TODO this is where the extern declarations go. For example, see | |
| 2 | // inc/efilib.h in gnu-efi-code | |
| 1 | pub const protocols = @import("uefi/protocols.zig"); | |
| 2 | pub const status = @import("uefi/status.zig"); | |
| 3 | pub const tables = @import("uefi/tables.zig"); | |
| 3 | 4 | |
| 4 | 5 | const builtin = @import("builtin"); |
| 5 | ||
| 6 | 6 | pub const is_the_target = builtin.os == .uefi; |
| 7 | ||
| 8 | pub var handle: Handle = undefined; | |
| 9 | pub var system_table: *tables.SystemTable = undefined; | |
| 10 | ||
| 11 | pub const Event = *@OpaqueType(); | |
| 12 | // GUIDs must be align(8) | |
| 13 | pub const Guid = extern struct { | |
| 14 | time_low: u32, | |
| 15 | time_mid: u16, | |
| 16 | time_high_and_version: u16, | |
| 17 | clock_seq_high_and_reserved: u8, | |
| 18 | clock_seq_low: u8, | |
| 19 | node: [6]u8, | |
| 20 | }; | |
| 21 | pub const Handle = *@OpaqueType(); | |
| 22 | pub const Time = extern struct { | |
| 23 | year: u16, | |
| 24 | month: u8, | |
| 25 | day: u8, | |
| 26 | hour: u8, | |
| 27 | minute: u8, | |
| 28 | second: u8, | |
| 29 | _pad1: u8, | |
| 30 | nanosecond: u32, | |
| 31 | timezone: i16, | |
| 32 | daylight: packed struct { | |
| 33 | _pad1: u6, | |
| 34 | in_daylight: bool, | |
| 35 | adjust_daylight: bool, | |
| 36 | }, | |
| 37 | _pad2: u8, | |
| 38 | ||
| 39 | pub const unspecified_timezone: i16 = 0x7ff; | |
| 40 | }; | |
| 41 | pub const TimeCapabilities = extern struct { | |
| 42 | resolution: u32, | |
| 43 | accuracy: u32, | |
| 44 | sets_to_zero: bool, | |
| 45 | }; |
std/os/uefi/protocols.zig created+32| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | pub const InputKey = @import("protocols/simple_text_input_ex_protocol.zig").InputKey; | |
| 2 | pub const KeyData = @import("protocols/simple_text_input_ex_protocol.zig").KeyData; | |
| 3 | pub const KeyState = @import("protocols/simple_text_input_ex_protocol.zig").KeyState; | |
| 4 | pub const SimpleTextInputExProtocol = @import("protocols/simple_text_input_ex_protocol.zig").SimpleTextInputExProtocol; | |
| 5 | ||
| 6 | pub const SimpleTextOutputMode = @import("protocols/simple_text_output_protocol.zig").SimpleTextOutputMode; | |
| 7 | pub const SimpleTextOutputProtocol = @import("protocols/simple_text_output_protocol.zig").SimpleTextOutputProtocol; | |
| 8 | ||
| 9 | pub const SimplePointerMode = @import("protocols/simple_pointer_protocol.zig").SimplePointerMode; | |
| 10 | pub const SimplePointerProtocol = @import("protocols/simple_pointer_protocol.zig").SimplePointerProtocol; | |
| 11 | pub const SimplePointerState = @import("protocols/simple_pointer_protocol.zig").SimplePointerState; | |
| 12 | ||
| 13 | pub const AbsolutePointerMode = @import("protocols/absolute_pointer_protocol.zig").AbsolutePointerMode; | |
| 14 | pub const AbsolutePointerProtocol = @import("protocols/absolute_pointer_protocol.zig").AbsolutePointerProtocol; | |
| 15 | pub const AbsolutePointerState = @import("protocols/absolute_pointer_protocol.zig").AbsolutePointerState; | |
| 16 | ||
| 17 | pub const GraphicsOutputBltPixel = @import("protocols/graphics_output_protocol.zig").GraphicsOutputBltPixel; | |
| 18 | pub const GraphicsOutputBltOperation = @import("protocols/graphics_output_protocol.zig").GraphicsOutputBltOperation; | |
| 19 | pub const GraphicsOutputModeInformation = @import("protocols/graphics_output_protocol.zig").GraphicsOutputModeInformation; | |
| 20 | pub const GraphicsOutputProtocol = @import("protocols/graphics_output_protocol.zig").GraphicsOutputProtocol; | |
| 21 | pub const GraphicsOutputProtocolMode = @import("protocols/graphics_output_protocol.zig").GraphicsOutputProtocolMode; | |
| 22 | pub const GraphicsPixelFormat = @import("protocols/graphics_output_protocol.zig").GraphicsPixelFormat; | |
| 23 | pub const PixelBitmask = @import("protocols/graphics_output_protocol.zig").PixelBitmask; | |
| 24 | ||
| 25 | pub const EdidDiscoveredProtocol = @import("protocols/edid_discovered_protocol.zig").EdidDiscoveredProtocol; | |
| 26 | ||
| 27 | pub const EdidActiveProtocol = @import("protocols/edid_active_protocol.zig").EdidActiveProtocol; | |
| 28 | ||
| 29 | pub const EdidOverrideProtocol = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocol; | |
| 30 | pub const EdidOverrideProtocolAttributes = @import("protocols/edid_override_protocol.zig").EdidOverrideProtocolAttributes; | |
| 31 | ||
| 32 | pub const RNGProtocol = @import("protocols/rng_protocol.zig").RNGProtocol; |
std/os/uefi/protocols/absolute_pointer_protocol.zig created+53| ... | ... | @@ -0,0 +1,53 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Event = uefi.Event; | |
| 3 | const Guid = uefi.Guid; | |
| 4 | ||
| 5 | /// UEFI Specification, Version 2.8, 12.7 | |
| 6 | pub const AbsolutePointerProtocol = extern struct { | |
| 7 | _reset: extern fn (*const AbsolutePointerProtocol, bool) usize, | |
| 8 | _get_state: extern fn (*const AbsolutePointerProtocol, *AbsolutePointerState) usize, | |
| 9 | wait_for_input: Event, | |
| 10 | mode: *AbsolutePointerMode, | |
| 11 | ||
| 12 | pub fn reset(self: *const AbsolutePointerProtocol, verify: bool) usize { | |
| 13 | return self._reset(self, verify); | |
| 14 | } | |
| 15 | ||
| 16 | pub fn getState(self: *const AbsolutePointerProtocol, state: *AbsolutePointerState) usize { | |
| 17 | return self._get_state(self, state); | |
| 18 | } | |
| 19 | ||
| 20 | pub const guid align(8) = Guid{ | |
| 21 | .time_low = 0x8d59d32b, | |
| 22 | .time_mid = 0xc655, | |
| 23 | .time_high_and_version = 0x4ae9, | |
| 24 | .clock_seq_high_and_reserved = 0x9b, | |
| 25 | .clock_seq_low = 0x15, | |
| 26 | .node = [_]u8{ 0xf2, 0x59, 0x04, 0x99, 0x2a, 0x43 }, | |
| 27 | }; | |
| 28 | }; | |
| 29 | ||
| 30 | pub const AbsolutePointerMode = extern struct { | |
| 31 | absolute_min_x: u64, | |
| 32 | absolute_min_y: u64, | |
| 33 | absolute_min_z: u64, | |
| 34 | absolute_max_x: u64, | |
| 35 | absolute_max_y: u64, | |
| 36 | absolute_max_z: u64, | |
| 37 | attributes: packed struct { | |
| 38 | supports_alt_active: bool, | |
| 39 | supports_pressure_as_z: bool, | |
| 40 | _pad1: u30, | |
| 41 | }, | |
| 42 | }; | |
| 43 | ||
| 44 | pub const AbsolutePointerState = extern struct { | |
| 45 | current_x: u64 = undefined, | |
| 46 | current_y: u64 = undefined, | |
| 47 | current_z: u64 = undefined, | |
| 48 | active_buttons: packed struct { | |
| 49 | touch_active: bool, | |
| 50 | alt_active: bool, | |
| 51 | _pad1: u30, | |
| 52 | } = undefined, | |
| 53 | }; |
std/os/uefi/protocols/edid_active_protocol.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Guid = uefi.Guid; | |
| 3 | ||
| 4 | /// UEFI Specification, Version 2.8, 12.9 | |
| 5 | pub const EdidActiveProtocol = extern struct { | |
| 6 | size_of_edid: u32, | |
| 7 | edid: ?[*]u8, | |
| 8 | ||
| 9 | pub const guid align(8) = Guid{ | |
| 10 | .time_low = 0xbd8c1056, | |
| 11 | .time_mid = 0x9f36, | |
| 12 | .time_high_and_version = 0x44ec, | |
| 13 | .clock_seq_high_and_reserved = 0x92, | |
| 14 | .clock_seq_low = 0xa8, | |
| 15 | .node = [_]u8{ 0xa6, 0x33, 0x7f, 0x81, 0x79, 0x86 }, | |
| 16 | }; | |
| 17 | }; |
std/os/uefi/protocols/edid_discovered_protocol.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Guid = uefi.Guid; | |
| 3 | ||
| 4 | /// UEFI Specification, Version 2.8, 12.9 | |
| 5 | pub const EdidDiscoveredProtocol = extern struct { | |
| 6 | size_of_edid: u32, | |
| 7 | edid: ?[*]u8, | |
| 8 | ||
| 9 | pub const guid align(8) = Guid{ | |
| 10 | .time_low = 0x1c0c34f6, | |
| 11 | .time_mid = 0xd380, | |
| 12 | .time_high_and_version = 0x41fa, | |
| 13 | .clock_seq_high_and_reserved = 0xa0, | |
| 14 | .clock_seq_low = 0x49, | |
| 15 | .node = [_]u8{ 0x8a, 0xd0, 0x6c, 0x1a, 0x66, 0xaa }, | |
| 16 | }; | |
| 17 | }; |
std/os/uefi/protocols/edid_override_protocol.zig created+28| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Guid = uefi.Guid; | |
| 3 | const Handle = uefi.Handle; | |
| 4 | ||
| 5 | /// UEFI Specification, Version 2.8, 12.9 | |
| 6 | pub const EdidOverrideProtocol = extern struct { | |
| 7 | _get_edid: extern fn (*const EdidOverrideProtocol, Handle, *u32, *usize, *?[*]u8) usize, | |
| 8 | ||
| 9 | /// attributes must be align(4) | |
| 10 | pub fn getEdid(self: *const EdidOverrideProtocol, handle: Handle, attributes: *EdidOverrideProtocolAttributes, edid_size: *usize, edid: *?[*]u8) usize { | |
| 11 | return self._get_edid(self, handle, attributes, edid_size, edid); | |
| 12 | } | |
| 13 | ||
| 14 | pub const guid align(8) = Guid{ | |
| 15 | .time_low = 0x48ecb431, | |
| 16 | .time_mid = 0xfb72, | |
| 17 | .time_high_and_version = 0x45c0, | |
| 18 | .clock_seq_high_and_reserved = 0xa9, | |
| 19 | .clock_seq_low = 0x22, | |
| 20 | .node = [_]u8{ 0xf4, 0x58, 0xfe, 0x04, 0x0b, 0xd5 }, | |
| 21 | }; | |
| 22 | }; | |
| 23 | ||
| 24 | pub const EdidOverrideProtocolAttributes = packed struct { | |
| 25 | dont_override: bool, | |
| 26 | enable_hot_plug: bool, | |
| 27 | _pad1: u30, | |
| 28 | }; |
std/os/uefi/protocols/graphics_output_protocol.zig created+79| ... | ... | @@ -0,0 +1,79 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Guid = uefi.Guid; | |
| 3 | ||
| 4 | /// UEFI Specification, Version 2.8, 12.9 | |
| 5 | pub const GraphicsOutputProtocol = extern struct { | |
| 6 | _query_mode: extern fn (*const GraphicsOutputProtocol, u32, *usize, **GraphicsOutputModeInformation) usize, | |
| 7 | _set_mode: extern fn (*const GraphicsOutputProtocol, u32) usize, | |
| 8 | _blt: extern fn (*const GraphicsOutputProtocol, ?[*]GraphicsOutputBltPixel, GraphicsOutputBltOperation, usize, usize, usize, usize, usize, usize, usize) usize, | |
| 9 | mode: *GraphicsOutputProtocolMode, | |
| 10 | ||
| 11 | pub fn queryMode(self: *const GraphicsOutputProtocol, mode: u32, size_of_info: *usize, info: **GraphicsOutputModeInformation) usize { | |
| 12 | return self._query_mode(self, mode, size_of_info, info); | |
| 13 | } | |
| 14 | ||
| 15 | pub fn setMode(self: *const GraphicsOutputProtocol, mode: u32) usize { | |
| 16 | return self._set_mode(self, mode); | |
| 17 | } | |
| 18 | ||
| 19 | pub fn blt(self: *const GraphicsOutputProtocol, blt_buffer: ?[*]GraphicsOutputBltPixel, blt_operation: GraphicsOutputBltOperation, source_x: usize, source_y: usize, destination_x: usize, destination_y: usize, width: usize, height: usize, delta: usize) usize { | |
| 20 | return self._blt(self, blt_buffer, blt_operation, source_x, source_y, destination_x, destination_y, width, height, delta); | |
| 21 | } | |
| 22 | ||
| 23 | pub const guid align(8) = Guid{ | |
| 24 | .time_low = 0x9042a9de, | |
| 25 | .time_mid = 0x23dc, | |
| 26 | .time_high_and_version = 0x4a38, | |
| 27 | .clock_seq_high_and_reserved = 0x96, | |
| 28 | .clock_seq_low = 0xfb, | |
| 29 | .node = [_]u8{ 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a }, | |
| 30 | }; | |
| 31 | }; | |
| 32 | ||
| 33 | pub const GraphicsOutputProtocolMode = extern struct { | |
| 34 | max_mode: u32, | |
| 35 | mode: u32, | |
| 36 | info: *GraphicsOutputModeInformation, | |
| 37 | size_of_info: usize, | |
| 38 | frame_buffer_base: u64, | |
| 39 | frame_buffer_size: usize, | |
| 40 | }; | |
| 41 | ||
| 42 | pub const GraphicsOutputModeInformation = extern struct { | |
| 43 | version: u32 = undefined, | |
| 44 | horizontal_resolution: u32 = undefined, | |
| 45 | vertical_resolution: u32 = undefined, | |
| 46 | pixel_format: GraphicsPixelFormat = undefined, | |
| 47 | pixel_information: PixelBitmask = undefined, | |
| 48 | pixels_per_scan_line: u32 = undefined, | |
| 49 | }; | |
| 50 | ||
| 51 | pub const GraphicsPixelFormat = extern enum(u32) { | |
| 52 | PixelRedGreenBlueReserved8BitPerColor, | |
| 53 | PixelBlueGreenRedReserved8BitPerColor, | |
| 54 | PixelBitMask, | |
| 55 | PixelBltOnly, | |
| 56 | PixelFormatMax, | |
| 57 | }; | |
| 58 | ||
| 59 | pub const PixelBitmask = extern struct { | |
| 60 | red_mask: u32, | |
| 61 | green_mask: u32, | |
| 62 | blue_mask: u32, | |
| 63 | reserved_mask: u32, | |
| 64 | }; | |
| 65 | ||
| 66 | pub const GraphicsOutputBltPixel = extern struct { | |
| 67 | blue: u8, | |
| 68 | green: u8, | |
| 69 | red: u8, | |
| 70 | reserved: u8 = undefined, | |
| 71 | }; | |
| 72 | ||
| 73 | pub const GraphicsOutputBltOperation = extern enum(u32) { | |
| 74 | BltVideoFill, | |
| 75 | BltVideoToBltBuffer, | |
| 76 | BltBufferToVideo, | |
| 77 | BltVideoToVideo, | |
| 78 | GraphicsOutputBltOperationMax, | |
| 79 | }; |
std/os/uefi/protocols/rng_protocol.zig created+73| ... | ... | @@ -0,0 +1,73 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Guid = uefi.Guid; | |
| 3 | ||
| 4 | /// UEFI Specification, Version 2.8, 37.5 | |
| 5 | pub const RNGProtocol = extern struct { | |
| 6 | _get_info: extern fn (*const RNGProtocol, *usize, [*]align(8) Guid) usize, | |
| 7 | _get_rng: extern fn (*const RNGProtocol, ?*align(8) const Guid, usize, [*]u8) usize, | |
| 8 | ||
| 9 | pub fn getInfo(self: *const RNGProtocol, list_size: *usize, list: [*]align(8) Guid) usize { | |
| 10 | return self._get_info(self, list_size, list); | |
| 11 | } | |
| 12 | ||
| 13 | pub fn getRNG(self: *const RNGProtocol, algo: ?*const Guid, value_length: usize, value: [*]u8) usize { | |
| 14 | return self._get_rng(self, algo, value_length, value); | |
| 15 | } | |
| 16 | ||
| 17 | pub const guid align(8) = Guid{ | |
| 18 | .time_low = 0x3152bca5, | |
| 19 | .time_mid = 0xeade, | |
| 20 | .time_high_and_version = 0x433d, | |
| 21 | .clock_seq_high_and_reserved = 0x86, | |
| 22 | .clock_seq_low = 0x2e, | |
| 23 | .node = [_]u8{ 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 }, | |
| 24 | }; | |
| 25 | pub const algorithm_sp800_90_hash_256 align(8) = Guid{ | |
| 26 | .time_low = 0xa7af67cb, | |
| 27 | .time_mid = 0x603b, | |
| 28 | .time_high_and_version = 0x4d42, | |
| 29 | .clock_seq_high_and_reserved = 0xba, | |
| 30 | .clock_seq_low = 0x21, | |
| 31 | .node = [_]u8{ 0x70, 0xbf, 0xb6, 0x29, 0x3f, 0x96 }, | |
| 32 | }; | |
| 33 | pub const algorithm_sp800_90_hmac_256 align(8) = Guid{ | |
| 34 | .time_low = 0xc5149b43, | |
| 35 | .time_mid = 0xae85, | |
| 36 | .time_high_and_version = 0x4f53, | |
| 37 | .clock_seq_high_and_reserved = 0x99, | |
| 38 | .clock_seq_low = 0x82, | |
| 39 | .node = [_]u8{ 0xb9, 0x43, 0x35, 0xd3, 0xa9, 0xe7 }, | |
| 40 | }; | |
| 41 | pub const algorithm_sp800_90_ctr_256 align(8) = Guid{ | |
| 42 | .time_low = 0x44f0de6e, | |
| 43 | .time_mid = 0x4d8c, | |
| 44 | .time_high_and_version = 0x4045, | |
| 45 | .clock_seq_high_and_reserved = 0xa8, | |
| 46 | .clock_seq_low = 0xc7, | |
| 47 | .node = [_]u8{ 0x4d, 0xd1, 0x68, 0x85, 0x6b, 0x9e }, | |
| 48 | }; | |
| 49 | pub const algorithm_x9_31_3des align(8) = Guid{ | |
| 50 | .time_low = 0x63c4785a, | |
| 51 | .time_mid = 0xca34, | |
| 52 | .time_high_and_version = 0x4012, | |
| 53 | .clock_seq_high_and_reserved = 0xa3, | |
| 54 | .clock_seq_low = 0xc8, | |
| 55 | .node = [_]u8{ 0x0b, 0x6a, 0x32, 0x4f, 0x55, 0x46 }, | |
| 56 | }; | |
| 57 | pub const algorithm_x9_31_aes align(8) = Guid{ | |
| 58 | .time_low = 0xacd03321, | |
| 59 | .time_mid = 0x777e, | |
| 60 | .time_high_and_version = 0x4d3d, | |
| 61 | .clock_seq_high_and_reserved = 0xb1, | |
| 62 | .clock_seq_low = 0xc8, | |
| 63 | .node = [_]u8{ 0x20, 0xcf, 0xd8, 0x88, 0x20, 0xc9 }, | |
| 64 | }; | |
| 65 | pub const algorithm_raw align(8) = Guid{ | |
| 66 | .time_low = 0xe43176d7, | |
| 67 | .time_mid = 0xb6e8, | |
| 68 | .time_high_and_version = 0x4827, | |
| 69 | .clock_seq_high_and_reserved = 0xb7, | |
| 70 | .clock_seq_low = 0x84, | |
| 71 | .node = [_]u8{ 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61 }, | |
| 72 | }; | |
| 73 | }; |
std/os/uefi/protocols/simple_pointer_protocol.zig created+44| ... | ... | @@ -0,0 +1,44 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Event = uefi.Event; | |
| 3 | const Guid = uefi.Guid; | |
| 4 | ||
| 5 | /// UEFI Specification, Version 2.8, 12.5 | |
| 6 | pub const SimplePointerProtocol = struct { | |
| 7 | _reset: extern fn (*const SimplePointerProtocol, bool) usize, | |
| 8 | _get_state: extern fn (*const SimplePointerProtocol, *SimplePointerState) usize, | |
| 9 | wait_for_input: Event, | |
| 10 | mode: *SimplePointerMode, | |
| 11 | ||
| 12 | pub fn reset(self: *const SimplePointerProtocol, verify: bool) usize { | |
| 13 | return self._reset(self, verify); | |
| 14 | } | |
| 15 | ||
| 16 | pub fn getState(self: *const SimplePointerProtocol, state: *SimplePointerState) usize { | |
| 17 | return self._get_state(self, state); | |
| 18 | } | |
| 19 | ||
| 20 | pub const guid align(8) = Guid{ | |
| 21 | .time_low = 0x31878c87, | |
| 22 | .time_mid = 0x0b75, | |
| 23 | .time_high_and_version = 0x11d5, | |
| 24 | .clock_seq_high_and_reserved = 0x9a, | |
| 25 | .clock_seq_low = 0x4f, | |
| 26 | .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, | |
| 27 | }; | |
| 28 | }; | |
| 29 | ||
| 30 | pub const SimplePointerMode = struct { | |
| 31 | resolution_x: u64, | |
| 32 | resolution_y: u64, | |
| 33 | resolution_z: u64, | |
| 34 | left_button: bool, | |
| 35 | right_button: bool, | |
| 36 | }; | |
| 37 | ||
| 38 | pub const SimplePointerState = struct { | |
| 39 | relative_movement_x: i32 = undefined, | |
| 40 | relative_movement_y: i32 = undefined, | |
| 41 | relative_movement_z: i32 = undefined, | |
| 42 | left_button: bool = undefined, | |
| 43 | right_button: bool = undefined, | |
| 44 | }; |
std/os/uefi/protocols/simple_text_input_ex_protocol.zig created+77| ... | ... | @@ -0,0 +1,77 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Event = uefi.Event; | |
| 3 | const Guid = uefi.Guid; | |
| 4 | ||
| 5 | /// UEFI Specification, Version 2.8, 12.3 | |
| 6 | pub const SimpleTextInputExProtocol = extern struct { | |
| 7 | _reset: extern fn (*const SimpleTextInputExProtocol, bool) usize, | |
| 8 | _read_key_stroke_ex: extern fn (*const SimpleTextInputExProtocol, *KeyData) usize, | |
| 9 | wait_for_key_ex: Event, | |
| 10 | _set_state: extern fn (*const SimpleTextInputExProtocol, *const u8) usize, | |
| 11 | _register_key_notify: extern fn (*const SimpleTextInputExProtocol, *const KeyData, extern fn (*const KeyData) usize, **c_void) usize, | |
| 12 | _unregister_key_notify: extern fn (*const SimpleTextInputExProtocol, *const c_void) usize, | |
| 13 | ||
| 14 | pub fn reset(self: *const SimpleTextInputExProtocol, verify: bool) usize { | |
| 15 | return self._reset(self, verify); | |
| 16 | } | |
| 17 | ||
| 18 | pub fn readKeyStrokeEx(self: *const SimpleTextInputExProtocol, key_data: *KeyData) usize { | |
| 19 | return self._read_key_stroke_ex(self, key_data); | |
| 20 | } | |
| 21 | ||
| 22 | pub fn setState(self: *const SimpleTextInputExProtocol, state: *const u8) usize { | |
| 23 | return self._set_state(self, state); | |
| 24 | } | |
| 25 | ||
| 26 | pub fn registerKeyNotify(self: *const SimpleTextInputExProtocol, key_data: *const KeyData, notify: extern fn (*const KeyData) usize, handle: **c_void) usize { | |
| 27 | return self._register_key_notify(self, key_data, notify, handle); | |
| 28 | } | |
| 29 | ||
| 30 | pub fn unregisterKeyNotify(self: *const SimpleTextInputExProtocol, handle: *const c_void) usize { | |
| 31 | return self._unregister_key_notify(self, handle); | |
| 32 | } | |
| 33 | ||
| 34 | pub const guid align(8) = Guid{ | |
| 35 | .time_low = 0xdd9e7534, | |
| 36 | .time_mid = 0x7762, | |
| 37 | .time_high_and_version = 0x4698, | |
| 38 | .clock_seq_high_and_reserved = 0x8c, | |
| 39 | .clock_seq_low = 0x14, | |
| 40 | .node = [_]u8{ 0xf5, 0x85, 0x17, 0xa6, 0x25, 0xaa }, | |
| 41 | }; | |
| 42 | }; | |
| 43 | ||
| 44 | pub const KeyData = extern struct { | |
| 45 | key: InputKey = undefined, | |
| 46 | key_state: KeyState = undefined, | |
| 47 | }; | |
| 48 | ||
| 49 | pub const KeyState = extern struct { | |
| 50 | key_shift_state: packed struct { | |
| 51 | right_shift_pressed: bool, | |
| 52 | left_shift_pressed: bool, | |
| 53 | right_control_pressed: bool, | |
| 54 | left_control_pressed: bool, | |
| 55 | right_alt_pressed: bool, | |
| 56 | left_alt_pressed: bool, | |
| 57 | right_logo_pressed: bool, | |
| 58 | left_logo_pressed: bool, | |
| 59 | menu_key_pressed: bool, | |
| 60 | sys_req_pressed: bool, | |
| 61 | _pad1: u21, | |
| 62 | shift_state_valid: bool, | |
| 63 | }, | |
| 64 | key_toggle_state: packed struct { | |
| 65 | scroll_lock_active: bool, | |
| 66 | num_lock_active: bool, | |
| 67 | caps_lock_active: bool, | |
| 68 | _pad1: u3, | |
| 69 | key_state_exposed: bool, | |
| 70 | toggle_state_valid: bool, | |
| 71 | }, | |
| 72 | }; | |
| 73 | ||
| 74 | pub const InputKey = extern struct { | |
| 75 | scan_code: u16, | |
| 76 | unicode_char: u16, | |
| 77 | }; |
std/os/uefi/protocols/simple_text_output_protocol.zig created+143| ... | ... | @@ -0,0 +1,143 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Guid = uefi.Guid; | |
| 3 | ||
| 4 | /// UEFI Specification, Version 2.8, 12.4 | |
| 5 | pub const SimpleTextOutputProtocol = extern struct { | |
| 6 | _reset: extern fn (*const SimpleTextOutputProtocol, bool) usize, | |
| 7 | _output_string: extern fn (*const SimpleTextOutputProtocol, [*]const u16) usize, | |
| 8 | _test_string: extern fn (*const SimpleTextOutputProtocol, [*]const u16) usize, | |
| 9 | _query_mode: extern fn (*const SimpleTextOutputProtocol, usize, *usize, *usize) usize, | |
| 10 | _set_mode: extern fn (*const SimpleTextOutputProtocol, usize) usize, | |
| 11 | _set_attribute: extern fn (*const SimpleTextOutputProtocol, usize) usize, | |
| 12 | _clear_screen: extern fn (*const SimpleTextOutputProtocol) usize, | |
| 13 | _set_cursor_position: extern fn (*const SimpleTextOutputProtocol, usize, usize) usize, | |
| 14 | _enable_cursor: extern fn (*const SimpleTextOutputProtocol, bool) usize, | |
| 15 | mode: *SimpleTextOutputMode, | |
| 16 | ||
| 17 | pub fn reset(self: *const SimpleTextOutputProtocol, verify: bool) usize { | |
| 18 | return self._reset(self, verify); | |
| 19 | } | |
| 20 | ||
| 21 | pub fn outputString(self: *const SimpleTextOutputProtocol, msg: [*]const u16) usize { | |
| 22 | return self._output_string(self, msg); | |
| 23 | } | |
| 24 | ||
| 25 | pub fn testString(self: *const SimpleTextOutputProtocol, msg: [*]const u16) usize { | |
| 26 | return self._test_string(self, msg); | |
| 27 | } | |
| 28 | ||
| 29 | pub fn queryMode(self: *const SimpleTextOutputProtocol, mode_number: usize, columns: *usize, rows: *usize) usize { | |
| 30 | return self._query_mode(self, mode_number, columns, rows); | |
| 31 | } | |
| 32 | ||
| 33 | pub fn setMode(self: *const SimpleTextOutputProtocol, mode_number: usize) usize { | |
| 34 | return self._set_mode(self, mode_number); | |
| 35 | } | |
| 36 | ||
| 37 | pub fn setAttribute(self: *const SimpleTextOutputProtocol, attribute: usize) usize { | |
| 38 | return self._set_attribute(self, attribute); | |
| 39 | } | |
| 40 | ||
| 41 | pub fn clearScreen(self: *const SimpleTextOutputProtocol) usize { | |
| 42 | return self._clear_screen(self); | |
| 43 | } | |
| 44 | ||
| 45 | pub fn setCursorPosition(self: *const SimpleTextOutputProtocol, column: usize, row: usize) usize { | |
| 46 | return self._set_cursor_position(self, column, row); | |
| 47 | } | |
| 48 | ||
| 49 | pub fn enableCursor(self: *const SimpleTextOutputProtocol, visible: bool) usize { | |
| 50 | return self._enable_cursor(self, visible); | |
| 51 | } | |
| 52 | ||
| 53 | pub const guid align(8) = Guid{ | |
| 54 | .time_low = 0x387477c2, | |
| 55 | .time_mid = 0x69c7, | |
| 56 | .time_high_and_version = 0x11d2, | |
| 57 | .clock_seq_high_and_reserved = 0x8e, | |
| 58 | .clock_seq_low = 0x39, | |
| 59 | .node = [_]u8{ 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b }, | |
| 60 | }; | |
| 61 | pub const boxdraw_horizontal: u16 = 0x2500; | |
| 62 | pub const boxdraw_vertical: u16 = 0x2502; | |
| 63 | pub const boxdraw_down_right: u16 = 0x250c; | |
| 64 | pub const boxdraw_down_left: u16 = 0x2510; | |
| 65 | pub const boxdraw_up_right: u16 = 0x2514; | |
| 66 | pub const boxdraw_up_left: u16 = 0x2518; | |
| 67 | pub const boxdraw_vertical_right: u16 = 0x251c; | |
| 68 | pub const boxdraw_vertical_left: u16 = 0x2524; | |
| 69 | pub const boxdraw_down_horizontal: u16 = 0x252c; | |
| 70 | pub const boxdraw_up_horizontal: u16 = 0x2534; | |
| 71 | pub const boxdraw_vertical_horizontal: u16 = 0x253c; | |
| 72 | pub const boxdraw_double_horizontal: u16 = 0x2550; | |
| 73 | pub const boxdraw_double_vertical: u16 = 0x2551; | |
| 74 | pub const boxdraw_down_right_double: u16 = 0x2552; | |
| 75 | pub const boxdraw_down_double_right: u16 = 0x2553; | |
| 76 | pub const boxdraw_double_down_right: u16 = 0x2554; | |
| 77 | pub const boxdraw_down_left_double: u16 = 0x2555; | |
| 78 | pub const boxdraw_down_double_left: u16 = 0x2556; | |
| 79 | pub const boxdraw_double_down_left: u16 = 0x2557; | |
| 80 | pub const boxdraw_up_right_double: u16 = 0x2558; | |
| 81 | pub const boxdraw_up_double_right: u16 = 0x2559; | |
| 82 | pub const boxdraw_double_up_right: u16 = 0x255a; | |
| 83 | pub const boxdraw_up_left_double: u16 = 0x255b; | |
| 84 | pub const boxdraw_up_double_left: u16 = 0x255c; | |
| 85 | pub const boxdraw_double_up_left: u16 = 0x255d; | |
| 86 | pub const boxdraw_vertical_right_double: u16 = 0x255e; | |
| 87 | pub const boxdraw_vertical_double_right: u16 = 0x255f; | |
| 88 | pub const boxdraw_double_vertical_right: u16 = 0x2560; | |
| 89 | pub const boxdraw_vertical_left_double: u16 = 0x2561; | |
| 90 | pub const boxdraw_vertical_double_left: u16 = 0x2562; | |
| 91 | pub const boxdraw_double_vertical_left: u16 = 0x2563; | |
| 92 | pub const boxdraw_down_horizontal_double: u16 = 0x2564; | |
| 93 | pub const boxdraw_down_double_horizontal: u16 = 0x2565; | |
| 94 | pub const boxdraw_double_down_horizontal: u16 = 0x2566; | |
| 95 | pub const boxdraw_up_horizontal_double: u16 = 0x2567; | |
| 96 | pub const boxdraw_up_double_horizontal: u16 = 0x2568; | |
| 97 | pub const boxdraw_double_up_horizontal: u16 = 0x2569; | |
| 98 | pub const boxdraw_vertical_horizontal_double: u16 = 0x256a; | |
| 99 | pub const boxdraw_vertical_double_horizontal: u16 = 0x256b; | |
| 100 | pub const boxdraw_double_vertical_horizontal: u16 = 0x256c; | |
| 101 | pub const blockelement_full_block: u16 = 0x2588; | |
| 102 | pub const blockelement_light_shade: u16 = 0x2591; | |
| 103 | pub const geometricshape_up_triangle: u16 = 0x25b2; | |
| 104 | pub const geometricshape_right_triangle: u16 = 0x25ba; | |
| 105 | pub const geometricshape_down_triangle: u16 = 0x25bc; | |
| 106 | pub const geometricshape_left_triangle: u16 = 0x25c4; | |
| 107 | pub const arrow_up: u16 = 0x2591; | |
| 108 | pub const arrow_down: u16 = 0x2593; | |
| 109 | pub const black: u8 = 0x00; | |
| 110 | pub const blue: u8 = 0x01; | |
| 111 | pub const green: u8 = 0x02; | |
| 112 | pub const cyan: u8 = 0x03; | |
| 113 | pub const red: u8 = 0x04; | |
| 114 | pub const magenta: u8 = 0x05; | |
| 115 | pub const brown: u8 = 0x06; | |
| 116 | pub const lightgray: u8 = 0x07; | |
| 117 | pub const bright: u8 = 0x08; | |
| 118 | pub const darkgray: u8 = 0x08; | |
| 119 | pub const lightblue: u8 = 0x09; | |
| 120 | pub const lightgreen: u8 = 0x0a; | |
| 121 | pub const lightcyan: u8 = 0x0b; | |
| 122 | pub const lightred: u8 = 0x0c; | |
| 123 | pub const lightmagenta: u8 = 0x0d; | |
| 124 | pub const yellow: u8 = 0x0e; | |
| 125 | pub const white: u8 = 0x0f; | |
| 126 | pub const background_black: u8 = 0x00; | |
| 127 | pub const background_blue: u8 = 0x10; | |
| 128 | pub const background_green: u8 = 0x20; | |
| 129 | pub const background_cyan: u8 = 0x30; | |
| 130 | pub const background_red: u8 = 0x40; | |
| 131 | pub const background_magenta: u8 = 0x50; | |
| 132 | pub const background_brown: u8 = 0x60; | |
| 133 | pub const background_lightgray: u8 = 0x70; | |
| 134 | }; | |
| 135 | ||
| 136 | pub const SimpleTextOutputMode = extern struct { | |
| 137 | max_mode: u32, // specified as signed | |
| 138 | mode: u32, // specified as signed | |
| 139 | attribute: i32, | |
| 140 | cursor_column: i32, | |
| 141 | cursor_row: i32, | |
| 142 | cursor_visible: bool, | |
| 143 | }; |
std/os/uefi/status.zig created+46| ... | ... | @@ -0,0 +1,46 @@ |
| 1 | const high_bit = 1 << @typeInfo(usize).Int.bits - 1; | |
| 2 | ||
| 3 | /// UEFI Specification, Version 2.8, Appendix D | |
| 4 | pub const success: usize = 0; | |
| 5 | ||
| 6 | pub const load_error: usize = high_bit | 1; | |
| 7 | pub const invalid_parameter: usize = high_bit | 2; | |
| 8 | pub const unsupported: usize = high_bit | 3; | |
| 9 | pub const bad_buffer_size: usize = high_bit | 4; | |
| 10 | pub const buffer_too_small: usize = high_bit | 5; | |
| 11 | pub const not_ready: usize = high_bit | 6; | |
| 12 | pub const device_error: usize = high_bit | 7; | |
| 13 | pub const write_protected: usize = high_bit | 8; | |
| 14 | pub const out_of_resources: usize = high_bit | 9; | |
| 15 | pub const volume_corrupted: usize = high_bit | 10; | |
| 16 | pub const volume_full: usize = high_bit | 11; | |
| 17 | pub const no_media: usize = high_bit | 12; | |
| 18 | pub const media_changed: usize = high_bit | 13; | |
| 19 | pub const not_found: usize = high_bit | 14; | |
| 20 | pub const access_denied: usize = high_bit | 15; | |
| 21 | pub const no_response: usize = high_bit | 16; | |
| 22 | pub const no_mapping: usize = high_bit | 17; | |
| 23 | pub const timeout: usize = high_bit | 18; | |
| 24 | pub const not_started: usize = high_bit | 19; | |
| 25 | pub const already_started: usize = high_bit | 20; | |
| 26 | pub const aborted: usize = high_bit | 21; | |
| 27 | pub const icmp_error: usize = high_bit | 22; | |
| 28 | pub const tftp_error: usize = high_bit | 23; | |
| 29 | pub const protocol_error: usize = high_bit | 24; | |
| 30 | pub const incompatible_version: usize = high_bit | 25; | |
| 31 | pub const security_violation: usize = high_bit | 26; | |
| 32 | pub const crc_error: usize = high_bit | 27; | |
| 33 | pub const end_of_media: usize = high_bit | 28; | |
| 34 | pub const end_of_file: usize = high_bit | 31; | |
| 35 | pub const invalid_language: usize = high_bit | 32; | |
| 36 | pub const compromised_data: usize = high_bit | 33; | |
| 37 | pub const ip_address_conflict: usize = high_bit | 34; | |
| 38 | pub const http_error: usize = high_bit | 35; | |
| 39 | ||
| 40 | pub const warn_unknown_glyph: usize = 1; | |
| 41 | pub const warn_delete_failure: usize = 2; | |
| 42 | pub const warn_write_failure: usize = 3; | |
| 43 | pub const warn_buffer_too_small: usize = 4; | |
| 44 | pub const warn_stale_data: usize = 5; | |
| 45 | pub const warn_file_system: usize = 6; | |
| 46 | pub const warn_reset_required: usize = 7; |
std/os/uefi/tables.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | pub const BootServices = @import("tables/boot_services.zig").BootServices; | |
| 2 | pub const ConfigurationTable = @import("tables/configuration_table.zig").ConfigurationTable; | |
| 3 | pub const global_variable align(8) = @import("tables/runtime_services.zig").global_variable; | |
| 4 | pub const MemoryDescriptor = @import("tables/boot_services.zig").MemoryDescriptor; | |
| 5 | pub const ResetType = @import("tables/runtime_services.zig").ResetType; | |
| 6 | pub const RuntimeServices = @import("tables/runtime_services.zig").RuntimeServices; | |
| 7 | pub const SystemTable = @import("tables/system_table.zig").SystemTable; | |
| 8 | pub const TableHeader = @import("tables/table_header.zig").TableHeader; | |
| 9 | pub const TimerDelay = @import("tables/boot_services.zig").TimerDelay; |
std/os/uefi/tables/boot_services.zig created+125| ... | ... | @@ -0,0 +1,125 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Event = uefi.Event; | |
| 3 | const Guid = uefi.Guid; | |
| 4 | const Handle = uefi.Handle; | |
| 5 | const TableHeader = uefi.tables.TableHeader; | |
| 6 | ||
| 7 | /// UEFI Specification, Version 2.8, 4.4 | |
| 8 | /// | |
| 9 | /// As the boot_services table may grow with new UEFI versions, it is important to check hdr.header_size. | |
| 10 | /// | |
| 11 | /// Boot Services must not be used after exitBootServices has been called. The only exception is | |
| 12 | /// getMemoryMap, which may be used after the first unsuccessful call to exitBootServices. | |
| 13 | /// After successfully calling exitBootServices, system_table.console_in_handle, system_table.con_in, | |
| 14 | /// system_table.console_out_handle, system_table.con_out, system_table.standard_error_handle, | |
| 15 | /// system_table.std_err, and system_table.boot_services should be set to null. After setting these | |
| 16 | /// attributes to null, system_table.hdr.crc32 must be recomputed. See UEFI Specification, Version 2.8, 7.4. | |
| 17 | pub const BootServices = extern struct { | |
| 18 | hdr: TableHeader, | |
| 19 | raiseTpl: usize, // TODO | |
| 20 | restoreTpl: usize, // TODO | |
| 21 | allocatePages: usize, // TODO | |
| 22 | freePages: usize, // TODO | |
| 23 | getMemoryMap: extern fn (*usize, [*]MemoryDescriptor, *usize, *usize, *u32) usize, | |
| 24 | allocatePool: usize, // TODO | |
| 25 | freePool: usize, // TODO | |
| 26 | createEvent: extern fn (u32, usize, ?extern fn (Event, ?*const c_void) void, ?*const c_void, *Event) usize, | |
| 27 | setTimer: extern fn (Event, TimerDelay, u64) usize, | |
| 28 | waitForEvent: extern fn (usize, [*]const Event, *usize) usize, | |
| 29 | signalEvent: extern fn (Event) usize, | |
| 30 | closeEvent: extern fn (Event) usize, | |
| 31 | checkEvent: usize, // TODO | |
| 32 | installProtocolInterface: usize, // TODO | |
| 33 | reinstallProtocolInterface: usize, // TODO | |
| 34 | uninstallProtocolInterface: usize, // TODO | |
| 35 | handleProtocol: usize, // TODO | |
| 36 | reserved: *c_void, | |
| 37 | registerProtocolNotify: usize, // TODO | |
| 38 | locateHandle: usize, // TODO | |
| 39 | locateDevicePath: usize, // TODO | |
| 40 | installConfigurationTable: usize, // TODO | |
| 41 | imageLoad: usize, // TODO | |
| 42 | imageStart: usize, // TODO | |
| 43 | exit: extern fn (Handle, usize, usize, ?*const c_void) usize, | |
| 44 | imageUnload: usize, // TODO | |
| 45 | exitBootServices: usize, // TODO | |
| 46 | getNextMonotonicCount: usize, // TODO | |
| 47 | stall: extern fn (usize) usize, | |
| 48 | setWatchdogTimer: extern fn (usize, u64, usize, ?[*]const u16) usize, | |
| 49 | connectController: usize, // TODO | |
| 50 | disconnectController: usize, // TODO | |
| 51 | openProtocol: usize, // TODO | |
| 52 | closeProtocol: usize, // TODO | |
| 53 | openProtocolInformation: usize, // TODO | |
| 54 | protocolsPerHandle: usize, // TODO | |
| 55 | locateHandleBuffer: usize, // TODO | |
| 56 | locateProtocol: extern fn (*align(8) const Guid, ?*const c_void, *?*c_void) usize, | |
| 57 | installMultipleProtocolInterfaces: usize, // TODO | |
| 58 | uninstallMultipleProtocolInterfaces: usize, // TODO | |
| 59 | calculateCrc32: usize, // TODO | |
| 60 | copyMem: usize, // TODO | |
| 61 | setMem: usize, // TODO | |
| 62 | createEventEx: usize, // TODO | |
| 63 | ||
| 64 | pub const signature: u64 = 0x56524553544f4f42; | |
| 65 | ||
| 66 | pub const event_timer: u32 = 0x80000000; | |
| 67 | pub const event_runtime: u32 = 0x40000000; | |
| 68 | pub const event_notify_wait: u32 = 0x00000100; | |
| 69 | pub const event_notify_signal: u32 = 0x00000200; | |
| 70 | pub const event_signal_exit_boot_services: u32 = 0x00000201; | |
| 71 | pub const event_signal_virtual_address_change: u32 = 0x00000202; | |
| 72 | ||
| 73 | pub const tpl_application: usize = 4; | |
| 74 | pub const tpl_callback: usize = 8; | |
| 75 | pub const tpl_notify: usize = 16; | |
| 76 | pub const tpl_high_level: usize = 31; | |
| 77 | }; | |
| 78 | ||
| 79 | pub const TimerDelay = extern enum(u32) { | |
| 80 | TimerCancel, | |
| 81 | TimerPeriodic, | |
| 82 | TimerRelative, | |
| 83 | }; | |
| 84 | ||
| 85 | pub const MemoryDescriptor = extern struct { | |
| 86 | type: extern enum(u32) { | |
| 87 | ReservedMemoryType, | |
| 88 | LoaderCode, | |
| 89 | LoaderData, | |
| 90 | BootServicesCode, | |
| 91 | BootServicesData, | |
| 92 | RuntimeServicesCode, | |
| 93 | RuntimeServicesData, | |
| 94 | ConventionalMemory, | |
| 95 | UnusableMemory, | |
| 96 | ACPIReclaimMemory, | |
| 97 | ACPIMemoryNVS, | |
| 98 | MemoryMappedIO, | |
| 99 | MemoryMappedIOPortSpace, | |
| 100 | PalCode, | |
| 101 | PersistentMemory, | |
| 102 | MaxMemoryType, | |
| 103 | }, | |
| 104 | physical_start: u64, | |
| 105 | virtual_start: u64, | |
| 106 | number_of_pages: usize, | |
| 107 | attribute: packed struct { | |
| 108 | uc: bool, | |
| 109 | wc: bool, | |
| 110 | wt: bool, | |
| 111 | wb: bool, | |
| 112 | uce: bool, | |
| 113 | _pad1: u7, | |
| 114 | wp: bool, | |
| 115 | rp: bool, | |
| 116 | xp: bool, | |
| 117 | nv: bool, | |
| 118 | more_reliable: bool, | |
| 119 | ro: bool, | |
| 120 | sp: bool, | |
| 121 | cpu_crypto: bool, | |
| 122 | _pad2: u43, | |
| 123 | memory_runtime: bool, | |
| 124 | }, | |
| 125 | }; |
std/os/uefi/tables/configuration_table.zig created+82| ... | ... | @@ -0,0 +1,82 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Guid = uefi.Guid; | |
| 3 | ||
| 4 | /// UEFI Specification, Version 2.8, 4.6 | |
| 5 | /// Because GUIDs must be align(8), structs of this type also must be align(8) | |
| 6 | pub const ConfigurationTable = extern struct { | |
| 7 | vendor_guid: Guid, | |
| 8 | vendor_table: *c_void, | |
| 9 | ||
| 10 | pub const acpi_20_table_guid align(8) = Guid{ | |
| 11 | .time_low = 0x8868e871, | |
| 12 | .time_mid = 0xe4f1, | |
| 13 | .time_high_and_version = 0x11d3, | |
| 14 | .clock_seq_high_and_reserved = 0xbc, | |
| 15 | .clock_seq_low = 0x22, | |
| 16 | .node = [_]u8{ 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81 }, | |
| 17 | }; | |
| 18 | pub const acpi_10_table_guid align(8) = Guid{ | |
| 19 | .time_low = 0xeb9d2d30, | |
| 20 | .time_mid = 0x2d88, | |
| 21 | .time_high_and_version = 0x11d3, | |
| 22 | .clock_seq_high_and_reserved = 0x9a, | |
| 23 | .clock_seq_low = 0x16, | |
| 24 | .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, | |
| 25 | }; | |
| 26 | pub const sal_system_table_guid align(8) = Guid{ | |
| 27 | .time_low = 0xeb9d2d32, | |
| 28 | .time_mid = 0x2d88, | |
| 29 | .time_high_and_version = 0x113d, | |
| 30 | .clock_seq_high_and_reserved = 0x9a, | |
| 31 | .clock_seq_low = 0x16, | |
| 32 | .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, | |
| 33 | }; | |
| 34 | pub const smbios_table_guid align(8) = Guid{ | |
| 35 | .time_low = 0xeb9d2d31, | |
| 36 | .time_mid = 0x2d88, | |
| 37 | .time_high_and_version = 0x11d3, | |
| 38 | .clock_seq_high_and_reserved = 0x9a, | |
| 39 | .clock_seq_low = 0x16, | |
| 40 | .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, | |
| 41 | }; | |
| 42 | pub const smbios3_table_guid align(8) = Guid{ | |
| 43 | .time_low = 0xf2fd1544, | |
| 44 | .time_mid = 0x9794, | |
| 45 | .time_high_and_version = 0x4a2c, | |
| 46 | .clock_seq_high_and_reserved = 0x99, | |
| 47 | .clock_seq_low = 0x2e, | |
| 48 | .node = [_]u8{ 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 }, | |
| 49 | }; | |
| 50 | pub const mps_table_guid align(8) = Guid{ | |
| 51 | .time_low = 0xeb9d2d2f, | |
| 52 | .time_mid = 0x2d88, | |
| 53 | .time_high_and_version = 0x11d3, | |
| 54 | .clock_seq_high_and_reserved = 0x9a, | |
| 55 | .clock_seq_low = 0x16, | |
| 56 | .node = [_]u8{ 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d }, | |
| 57 | }; | |
| 58 | pub const json_config_data_table_guid align(8) = Guid{ | |
| 59 | .time_low = 0x87367f87, | |
| 60 | .time_mid = 0x1119, | |
| 61 | .time_high_and_version = 0x41ce, | |
| 62 | .clock_seq_high_and_reserved = 0xaa, | |
| 63 | .clock_seq_low = 0xec, | |
| 64 | .node = [_]u8{ 0x8b, 0xe0, 0x11, 0x1f, 0x55, 0x8a }, | |
| 65 | }; | |
| 66 | pub const json_capsule_data_table_guid align(8) = Guid{ | |
| 67 | .time_low = 0x35e7a725, | |
| 68 | .time_mid = 0x8dd2, | |
| 69 | .time_high_and_version = 0x4cac, | |
| 70 | .clock_seq_high_and_reserved = 0x80, | |
| 71 | .clock_seq_low = 0x11, | |
| 72 | .node = [_]u8{ 0x33, 0xcd, 0xa8, 0x10, 0x90, 0x56 }, | |
| 73 | }; | |
| 74 | pub const json_capsule_result_table_guid align(8) = Guid{ | |
| 75 | .time_low = 0xdbc461c3, | |
| 76 | .time_mid = 0xb3de, | |
| 77 | .time_high_and_version = 0x422a, | |
| 78 | .clock_seq_high_and_reserved = 0xb9, | |
| 79 | .clock_seq_low = 0xb4, | |
| 80 | .node = [_]u8{ 0x98, 0x86, 0xfd, 0x49, 0xa1, 0xe5 }, | |
| 81 | }; | |
| 82 | }; |
std/os/uefi/tables/runtime_services.zig created+51| ... | ... | @@ -0,0 +1,51 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const Guid = uefi.Guid; | |
| 3 | const TableHeader = uefi.tables.TableHeader; | |
| 4 | const Time = uefi.Time; | |
| 5 | const TimeCapabilities = uefi.TimeCapabilities; | |
| 6 | ||
| 7 | /// UEFI Specification, Version 2.8, 4.5 | |
| 8 | /// | |
| 9 | /// As the runtime_services table may grow with new UEFI versions, it is important to check hdr.header_size. | |
| 10 | /// | |
| 11 | /// Some functions may not be supported. Check the RuntimeServicesSupported variable using getVariable. | |
| 12 | /// getVariable is one of the functions that may not be supported. See UEFI Specification, Version 2.8, 8.1. | |
| 13 | /// | |
| 14 | /// Some functions may not be called while other functions are running. See UEFI Specification, Version 2.8, 8.1. | |
| 15 | pub const RuntimeServices = extern struct { | |
| 16 | hdr: TableHeader, | |
| 17 | getTime: extern fn (*uefi.Time, ?*TimeCapabilities) usize, | |
| 18 | setTime: usize, // TODO | |
| 19 | getWakeupTime: usize, // TODO | |
| 20 | setWakeupTime: usize, // TODO | |
| 21 | setVirtualAddressMap: usize, // TODO | |
| 22 | convertPointer: usize, // TODO | |
| 23 | getVariable: extern fn ([*]const u16, *align(8) const Guid, ?*u32, *usize, ?*c_void) usize, | |
| 24 | getNextVariableName: extern fn (*usize, [*]u16, *align(8) Guid) usize, | |
| 25 | setVariable: extern fn ([*]const u16, *align(8) const Guid, u32, usize, *c_void) usize, | |
| 26 | getNextHighMonotonicCount: usize, // TODO | |
| 27 | resetSystem: extern fn (ResetType, usize, usize, ?*const c_void) noreturn, | |
| 28 | updateCapsule: usize, // TODO | |
| 29 | queryCapsuleCapabilities: usize, // TODO | |
| 30 | queryVariableInfo: usize, // TODO | |
| 31 | ||
| 32 | pub const signature: u64 = 0x56524553544e5552; | |
| 33 | }; | |
| 34 | ||
| 35 | /// UEFI Specification, Version 2.8, 8.5.1 | |
| 36 | pub const ResetType = extern enum(u32) { | |
| 37 | ResetCold, | |
| 38 | ResetWarm, | |
| 39 | ResetShutdown, | |
| 40 | ResetPlatformSpecific, | |
| 41 | }; | |
| 42 | ||
| 43 | /// UEFI Specification, Version 2.8, 3.3 | |
| 44 | pub const global_variable align(8) = Guid{ | |
| 45 | .time_low = 0x8be4df61, | |
| 46 | .time_mid = 0x93ca, | |
| 47 | .time_high_and_version = 0x11d2, | |
| 48 | .clock_seq_high_and_reserved = 0xaa, | |
| 49 | .clock_seq_low = 0x0d, | |
| 50 | .node = [_]u8{ 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c }, | |
| 51 | }; |
std/os/uefi/tables/system_table.zig created+46| ... | ... | @@ -0,0 +1,46 @@ |
| 1 | const uefi = @import("std").os.uefi; | |
| 2 | const BootServices = uefi.tables.BootServices; | |
| 3 | const ConfigurationTable = uefi.tables.ConfigurationTable; | |
| 4 | const Handle = uefi.Handle; | |
| 5 | const RuntimeServices = uefi.tables.RuntimeServices; | |
| 6 | const SimpleTextInputExProtocol = uefi.protocols.SimpleTextInputExProtocol; | |
| 7 | const SimpleTextOutputProtocol = uefi.protocols.SimpleTextOutputProtocol; | |
| 8 | const TableHeader = uefi.tables.TableHeader; | |
| 9 | ||
| 10 | /// UEFI Specification, Version 2.8, 4.3 | |
| 11 | /// | |
| 12 | /// As the system_table may grow with new UEFI versions, it is important to check hdr.header_size. | |
| 13 | /// | |
| 14 | /// After successfully calling boot_services.exitBootServices, console_in_handle, | |
| 15 | /// con_in, console_out_handle, con_out, standard_error_handle, std_err, and | |
| 16 | /// boot_services should be set to null. After setting these attributes to null, | |
| 17 | /// hdr.crc32 must be recomputed. See UEFI Specification, Version 2.8, 7.4. | |
| 18 | pub const SystemTable = extern struct { | |
| 19 | hdr: TableHeader, | |
| 20 | firmware_vendor: *u16, | |
| 21 | firmware_revision: u32, | |
| 22 | console_in_handle: ?Handle, | |
| 23 | con_in: ?*SimpleTextInputExProtocol, | |
| 24 | console_out_handle: ?Handle, | |
| 25 | con_out: ?*SimpleTextOutputProtocol, | |
| 26 | standard_error_handle: ?Handle, | |
| 27 | std_err: ?*SimpleTextOutputProtocol, | |
| 28 | runtime_services: *RuntimeServices, | |
| 29 | boot_services: ?*BootServices, | |
| 30 | number_of_table_entries: usize, | |
| 31 | configuration_table: *ConfigurationTable, | |
| 32 | ||
| 33 | pub const signature: u64 = 0x5453595320494249; | |
| 34 | pub const revision_1_02: u32 = (1 << 16) | 2; | |
| 35 | pub const revision_1_10: u32 = (1 << 16) | 10; | |
| 36 | pub const revision_2_00: u32 = (2 << 16); | |
| 37 | pub const revision_2_10: u32 = (2 << 16) | 10; | |
| 38 | pub const revision_2_20: u32 = (2 << 16) | 20; | |
| 39 | pub const revision_2_30: u32 = (2 << 16) | 30; | |
| 40 | pub const revision_2_31: u32 = (2 << 16) | 31; | |
| 41 | pub const revision_2_40: u32 = (2 << 16) | 40; | |
| 42 | pub const revision_2_50: u32 = (2 << 16) | 50; | |
| 43 | pub const revision_2_60: u32 = (2 << 16) | 60; | |
| 44 | pub const revision_2_70: u32 = (2 << 16) | 70; | |
| 45 | pub const revision_2_80: u32 = (2 << 16) | 80; | |
| 46 | }; |
std/os/uefi/tables/table_header.zig created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | /// UEFI Specification, Version 2.8, 4.2 | |
| 2 | pub const TableHeader = extern struct { | |
| 3 | signature: u64, | |
| 4 | revision: u32, | |
| 5 | header_size: u32, | |
| 6 | crc32: u32, | |
| 7 | reserved: u32, | |
| 8 | }; |
std/special/start.zig+26| ... | ... | @@ -4,6 +4,7 @@ const root = @import("root"); |
| 4 | 4 | const std = @import("std"); |
| 5 | 5 | const builtin = @import("builtin"); |
| 6 | 6 | const assert = std.debug.assert; |
| 7 | const uefi = std.os.uefi; | |
| 7 | 8 | |
| 8 | 9 | var starting_stack_ptr: [*]usize = undefined; |
| 9 | 10 | |
| ... | ... | @@ -19,6 +20,8 @@ comptime { |
| 19 | 20 | @export("WinMainCRTStartup", WinMainCRTStartup, .Strong); |
| 20 | 21 | } else if (is_wasm and builtin.os == .freestanding) { |
| 21 | 22 | @export("_start", wasm_freestanding_start, .Strong); |
| 23 | } else if (builtin.os == .uefi) { | |
| 24 | @export("EfiMain", EfiMain, .Strong); | |
| 22 | 25 | } else { |
| 23 | 26 | @export("_start", _start, .Strong); |
| 24 | 27 | } |
| ... | ... | @@ -28,6 +31,29 @@ extern fn wasm_freestanding_start() void { |
| 28 | 31 | _ = callMain(); |
| 29 | 32 | } |
| 30 | 33 | |
| 34 | extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) usize { | |
| 35 | const bad_efi_main_ret = "expected return type of main to be 'void', 'noreturn', or 'usize'"; | |
| 36 | uefi.handle = handle; | |
| 37 | uefi.system_table = system_table; | |
| 38 | ||
| 39 | switch (@typeInfo(@typeOf(root.main).ReturnType)) { | |
| 40 | .NoReturn => { | |
| 41 | root.main(); | |
| 42 | }, | |
| 43 | .Void => { | |
| 44 | root.main(); | |
| 45 | return 0; | |
| 46 | }, | |
| 47 | .Int => |info| { | |
| 48 | if (info.bits != @typeInfo(usize).Int.bits) { | |
| 49 | @compileError(bad_efi_main_ret); | |
| 50 | } | |
| 51 | return root.main(); | |
| 52 | }, | |
| 53 | else => @compileError(bad_efi_main_ret), | |
| 54 | } | |
| 55 | } | |
| 56 | ||
| 31 | 57 | nakedcc fn _start() noreturn { |
| 32 | 58 | if (builtin.os == builtin.Os.wasi) { |
| 33 | 59 | std.os.wasi.proc_exit(callMain()); |