| author | |
| committer | |
| log | c4416b224d29692556d828c0902f6416f3f5b534 |
| tree | 3703daa3f28ddbf4b61db91a8bdf4664550260e4 |
| parent | 92a427437c420195a55df4baee1bd0738dc4ed70 |
| parent | 8223aca09bc93279a88d1439d6dfc437144ec578 |
| signature | Commit is signed but in an unrecognized format. |
35 files changed, 1224 insertions(+), 90 deletions(-)
src/analyze.cpp+24-8| ... | ... | @@ -2406,8 +2406,6 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 2406 | 2406 | ZigType *tag_int_type; |
| 2407 | 2407 | if (enum_type->data.enumeration.layout == ContainerLayoutExtern) { |
| 2408 | 2408 | tag_int_type = get_c_int_type(g, CIntTypeInt); |
| 2409 | } else if (enum_type->data.enumeration.layout == ContainerLayoutAuto && field_count == 1) { | |
| 2410 | tag_int_type = g->builtin_types.entry_num_lit_int; | |
| 2411 | 2409 | } else { |
| 2412 | 2410 | tag_int_type = get_smallest_unsigned_int_type(g, field_count - 1); |
| 2413 | 2411 | } |
| ... | ... | @@ -2420,7 +2418,8 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 2420 | 2418 | ZigType *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr); |
| 2421 | 2419 | if (type_is_invalid(wanted_tag_int_type)) { |
| 2422 | 2420 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 2423 | } else if (wanted_tag_int_type->id != ZigTypeIdInt) { | |
| 2421 | } else if (wanted_tag_int_type->id != ZigTypeIdInt && | |
| 2422 | wanted_tag_int_type->id != ZigTypeIdComptimeInt) { | |
| 2424 | 2423 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 2425 | 2424 | add_node_error(g, decl_node->data.container_decl.init_arg_expr, |
| 2426 | 2425 | buf_sprintf("expected integer, found '%s'", buf_ptr(&wanted_tag_int_type->name))); |
| ... | ... | @@ -2538,6 +2537,8 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 2538 | 2537 | enum_type->data.enumeration.resolve_loop_flag = false; |
| 2539 | 2538 | enum_type->data.enumeration.resolve_status = ResolveStatusSizeKnown; |
| 2540 | 2539 | |
| 2540 | occupied_tag_values.deinit(); | |
| 2541 | ||
| 2541 | 2542 | return ErrorNone; |
| 2542 | 2543 | } |
| 2543 | 2544 | |
| ... | ... | @@ -2804,14 +2805,12 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 2804 | 2805 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 2805 | 2806 | return ErrorSemanticAnalyzeFail; |
| 2806 | 2807 | } |
| 2807 | if (tag_int_type->id != ZigTypeIdInt) { | |
| 2808 | if (tag_int_type->id != ZigTypeIdInt && tag_int_type->id != ZigTypeIdComptimeInt) { | |
| 2808 | 2809 | add_node_error(g, enum_type_node, |
| 2809 | 2810 | buf_sprintf("expected integer tag type, found '%s'", buf_ptr(&tag_int_type->name))); |
| 2810 | 2811 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 2811 | 2812 | return ErrorSemanticAnalyzeFail; |
| 2812 | 2813 | } |
| 2813 | } else if (auto_layout && field_count == 1) { | |
| 2814 | tag_int_type = g->builtin_types.entry_num_lit_int; | |
| 2815 | 2814 | } else { |
| 2816 | 2815 | tag_int_type = get_smallest_unsigned_int_type(g, field_count - 1); |
| 2817 | 2816 | } |
| ... | ... | @@ -5878,6 +5877,11 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5878 | 5877 | fn->err_code_spill = &alloca_gen->base; |
| 5879 | 5878 | } |
| 5880 | 5879 | |
| 5880 | ZigType *largest_call_frame_type = nullptr; | |
| 5881 | // Later we'll change this to be largest_call_frame_type instead of void. | |
| 5882 | IrInstruction *all_calls_alloca = ir_create_alloca(g, &fn->fndef_scope->base, fn->body_node, | |
| 5883 | fn, g->builtin_types.entry_void, "@async_call_frame"); | |
| 5884 | ||
| 5881 | 5885 | for (size_t i = 0; i < fn->call_list.length; i += 1) { |
| 5882 | 5886 | IrInstructionCallGen *call = fn->call_list.at(i); |
| 5883 | 5887 | if (call->new_stack != nullptr) { |
| ... | ... | @@ -5921,9 +5925,21 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5921 | 5925 | |
| 5922 | 5926 | mark_suspension_point(call->base.scope); |
| 5923 | 5927 | |
| 5924 | call->frame_result_loc = ir_create_alloca(g, call->base.scope, call->base.source_node, fn, | |
| 5925 | callee_frame_type, ""); | |
| 5928 | if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) { | |
| 5929 | return err; | |
| 5930 | } | |
| 5931 | if (largest_call_frame_type == nullptr || | |
| 5932 | callee_frame_type->abi_size > largest_call_frame_type->abi_size) | |
| 5933 | { | |
| 5934 | largest_call_frame_type = callee_frame_type; | |
| 5935 | } | |
| 5936 | ||
| 5937 | call->frame_result_loc = all_calls_alloca; | |
| 5926 | 5938 | } |
| 5939 | if (largest_call_frame_type != nullptr) { | |
| 5940 | all_calls_alloca->value.type = get_pointer_to_type(g, largest_call_frame_type, false); | |
| 5941 | } | |
| 5942 | ||
| 5927 | 5943 | // Since this frame is async, an await might represent a suspend point, and |
| 5928 | 5944 | // therefore need to spill. It also needs to mark expr scopes as having to spill. |
| 5929 | 5945 | // For example: foo() + await z |
src/codegen.cpp+31-8| ... | ... | @@ -517,6 +517,8 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) { |
| 517 | 517 | } |
| 518 | 518 | if (g->have_stack_probing && !fn->def_scope->safety_off) { |
| 519 | 519 | addLLVMFnAttrStr(llvm_fn, "probe-stack", "__zig_probe_stack"); |
| 520 | } else if (g->zig_target->os == OsUefi) { | |
| 521 | addLLVMFnAttrStr(llvm_fn, "no-stack-arg-probe", ""); | |
| 520 | 522 | } |
| 521 | 523 | } else { |
| 522 | 524 | maybe_import_dll(g, llvm_fn, linkage); |
| ... | ... | @@ -3863,6 +3865,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr |
| 3863 | 3865 | ZigList<ZigType *> gen_param_types = {}; |
| 3864 | 3866 | LLVMValueRef result_loc = instruction->result_loc ? ir_llvm_value(g, instruction->result_loc) : nullptr; |
| 3865 | 3867 | LLVMValueRef zero = LLVMConstNull(usize_type_ref); |
| 3868 | LLVMValueRef frame_result_loc_uncasted = nullptr; | |
| 3866 | 3869 | LLVMValueRef frame_result_loc; |
| 3867 | 3870 | LLVMValueRef awaiter_init_val; |
| 3868 | 3871 | LLVMValueRef ret_ptr; |
| ... | ... | @@ -3871,7 +3874,10 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr |
| 3871 | 3874 | if (instruction->modifier == CallModifierAsync) { |
| 3872 | 3875 | frame_result_loc = result_loc; |
| 3873 | 3876 | } else { |
| 3874 | frame_result_loc = ir_llvm_value(g, instruction->frame_result_loc); | |
| 3877 | frame_result_loc_uncasted = ir_llvm_value(g, instruction->frame_result_loc); | |
| 3878 | src_assert(instruction->fn_entry != nullptr, instruction->base.source_node); | |
| 3879 | frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted, | |
| 3880 | LLVMPointerType(get_llvm_type(g, instruction->fn_entry->frame_type), 0), ""); | |
| 3875 | 3881 | } |
| 3876 | 3882 | } else { |
| 3877 | 3883 | if (instruction->new_stack->value.type->id == ZigTypeIdPointer && |
| ... | ... | @@ -4138,6 +4144,13 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr |
| 4138 | 4144 | } |
| 4139 | 4145 | } |
| 4140 | 4146 | |
| 4147 | if (frame_result_loc_uncasted != nullptr && instruction->fn_entry != nullptr) { | |
| 4148 | // Instead of a spill, we do the bitcast again. The uncasted LLVM IR instruction will | |
| 4149 | // be an Alloca from the entry block, so it does not need to be spilled. | |
| 4150 | frame_result_loc = LLVMBuildBitCast(g->builder, frame_result_loc_uncasted, | |
| 4151 | LLVMPointerType(get_llvm_type(g, instruction->fn_entry->frame_type), 0), ""); | |
| 4152 | } | |
| 4153 | ||
| 4141 | 4154 | LLVMValueRef result_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 2, ""); |
| 4142 | 4155 | return LLVMBuildLoad(g->builder, result_ptr, ""); |
| 4143 | 4156 | } |
| ... | ... | @@ -7173,6 +7186,9 @@ static void do_code_gen(CodeGen *g) { |
| 7173 | 7186 | |
| 7174 | 7187 | if (!is_async) { |
| 7175 | 7188 | // allocate async frames for noasync calls & awaits to async functions |
| 7189 | ZigType *largest_call_frame_type = nullptr; | |
| 7190 | IrInstruction *all_calls_alloca = ir_create_alloca(g, &fn_table_entry->fndef_scope->base, | |
| 7191 | fn_table_entry->body_node, fn_table_entry, g->builtin_types.entry_void, "@async_call_frame"); | |
| 7176 | 7192 | for (size_t i = 0; i < fn_table_entry->call_list.length; i += 1) { |
| 7177 | 7193 | IrInstructionCallGen *call = fn_table_entry->call_list.at(i); |
| 7178 | 7194 | if (call->fn_entry == nullptr) |
| ... | ... | @@ -7184,8 +7200,15 @@ static void do_code_gen(CodeGen *g) { |
| 7184 | 7200 | if (call->frame_result_loc != nullptr) |
| 7185 | 7201 | continue; |
| 7186 | 7202 | ZigType *callee_frame_type = get_fn_frame_type(g, call->fn_entry); |
| 7187 | call->frame_result_loc = ir_create_alloca(g, call->base.scope, call->base.source_node, | |
| 7188 | fn_table_entry, callee_frame_type, ""); | |
| 7203 | if (largest_call_frame_type == nullptr || | |
| 7204 | callee_frame_type->abi_size > largest_call_frame_type->abi_size) | |
| 7205 | { | |
| 7206 | largest_call_frame_type = callee_frame_type; | |
| 7207 | } | |
| 7208 | call->frame_result_loc = all_calls_alloca; | |
| 7209 | } | |
| 7210 | if (largest_call_frame_type != nullptr) { | |
| 7211 | all_calls_alloca->value.type = get_pointer_to_type(g, largest_call_frame_type, false); | |
| 7189 | 7212 | } |
| 7190 | 7213 | // allocate temporary stack data |
| 7191 | 7214 | for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) { |
| ... | ... | @@ -9074,10 +9097,6 @@ static bool want_startup_code(CodeGen *g) { |
| 9074 | 9097 | if (g->is_test_build) |
| 9075 | 9098 | return false; |
| 9076 | 9099 | |
| 9077 | // start code does not handle UEFI target | |
| 9078 | if (g->zig_target->os == OsUefi) | |
| 9079 | return false; | |
| 9080 | ||
| 9081 | 9100 | // WASM freestanding can still have an entry point but other freestanding targets do not. |
| 9082 | 9101 | if (g->zig_target->os == OsFreestanding && !target_is_wasm(g->zig_target)) |
| 9083 | 9102 | return false; |
| ... | ... | @@ -9087,8 +9106,12 @@ static bool want_startup_code(CodeGen *g) { |
| 9087 | 9106 | return false; |
| 9088 | 9107 | |
| 9089 | 9108 | // If there is a pub main in the root source file, that means we need start code. |
| 9090 | if (g->have_pub_main) | |
| 9109 | if (g->have_pub_main) { | |
| 9091 | 9110 | return true; |
| 9111 | } else { | |
| 9112 | if (g->zig_target->os == OsUefi) | |
| 9113 | return false; | |
| 9114 | } | |
| 9092 | 9115 | |
| 9093 | 9116 | if (g->out_type == OutTypeExe) { |
| 9094 | 9117 | // For build-exe, we might add start code even though there is no pub main, so that the |
src/link.cpp+5| ... | ... | @@ -1615,6 +1615,11 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1615 | 1615 | |
| 1616 | 1616 | lj->args.append("-error-limit=0"); |
| 1617 | 1617 | |
| 1618 | if (g->out_type == OutTypeExe) { | |
| 1619 | lj->args.append("-z"); | |
| 1620 | lj->args.append("stack-size=16777216"); // default to 16 MiB | |
| 1621 | } | |
| 1622 | ||
| 1618 | 1623 | if (g->linker_script) { |
| 1619 | 1624 | lj->args.append("-T"); |
| 1620 | 1625 | lj->args.append(g->linker_script); |
src/target.cpp+3-3| ... | ... | @@ -1129,7 +1129,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | bool target_allows_addr_zero(const ZigTarget *target) { |
| 1132 | return target->os == OsFreestanding; | |
| 1132 | return target->os == OsFreestanding || target->os == OsUefi; | |
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | const char *target_o_file_ext(const ZigTarget *target) { |
| ... | ... | @@ -1585,12 +1585,12 @@ bool target_supports_fpic(const ZigTarget *target) { |
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | 1587 | bool target_supports_stack_probing(const ZigTarget *target) { |
| 1588 | return target->os != OsWindows && (target->arch == ZigLLVM_x86 || target->arch == ZigLLVM_x86_64); | |
| 1588 | return target->os != OsWindows && target->os != OsUefi && (target->arch == ZigLLVM_x86 || target->arch == ZigLLVM_x86_64); | |
| 1589 | 1589 | } |
| 1590 | 1590 | |
| 1591 | 1591 | bool target_requires_pic(const ZigTarget *target, bool linking_libc) { |
| 1592 | 1592 | // This function returns whether non-pic code is completely invalid on the given target. |
| 1593 | return target->os == OsWindows || target_os_requires_libc(target->os) || | |
| 1593 | return target->os == OsWindows || target->os == OsUefi || target_os_requires_libc(target->os) || | |
| 1594 | 1594 | (linking_libc && target_is_glibc(target)); |
| 1595 | 1595 | } |
| 1596 | 1596 |
src/tokenizer.cpp+7-2| ... | ... | @@ -407,9 +407,14 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 407 | 407 | t.buf = buf; |
| 408 | 408 | |
| 409 | 409 | out->line_offsets = allocate<ZigList<size_t>>(1); |
| 410 | ||
| 411 | 410 | out->line_offsets->append(0); |
| 412 | for (t.pos = 0; t.pos < buf_len(t.buf); t.pos += 1) { | |
| 411 | ||
| 412 | // Skip the UTF-8 BOM if present | |
| 413 | if (buf_starts_with_mem(buf, "\xEF\xBB\xBF", 3)) { | |
| 414 | t.pos += 3; | |
| 415 | } | |
| 416 | ||
| 417 | for (; t.pos < buf_len(t.buf); t.pos += 1) { | |
| 413 | 418 | uint8_t c = buf_ptr(t.buf)[t.pos]; |
| 414 | 419 | switch (t.state) { |
| 415 | 420 | case TokenizeStateError: |
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/c/freebsd.zig+3| ... | ... | @@ -7,3 +7,6 @@ pub const _errno = __error; |
| 7 | 7 | pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; |
| 8 | 8 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
| 9 | 9 | pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize; |
| 10 | ||
| 11 | pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int; | |
| 12 | pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int; |
std/debug.zig+39-39| ... | ... | @@ -1478,10 +1478,11 @@ const LineNumberProgram = struct { |
| 1478 | 1478 | } |
| 1479 | 1479 | }; |
| 1480 | 1480 | |
| 1481 | // TODO the noasyncs here are workarounds | |
| 1481 | 1482 | fn readStringRaw(allocator: *mem.Allocator, in_stream: var) ![]u8 { |
| 1482 | 1483 | var buf = ArrayList(u8).init(allocator); |
| 1483 | 1484 | while (true) { |
| 1484 | const byte = try in_stream.readByte(); | |
| 1485 | const byte = try noasync in_stream.readByte(); | |
| 1485 | 1486 | if (byte == 0) break; |
| 1486 | 1487 | try buf.append(byte); |
| 1487 | 1488 | } |
| ... | ... | @@ -1494,10 +1495,11 @@ fn getString(di: *DwarfInfo, offset: u64) ![]u8 { |
| 1494 | 1495 | return di.readString(); |
| 1495 | 1496 | } |
| 1496 | 1497 | |
| 1498 | // TODO the noasyncs here are workarounds | |
| 1497 | 1499 | fn readAllocBytes(allocator: *mem.Allocator, in_stream: var, size: usize) ![]u8 { |
| 1498 | 1500 | const buf = try allocator.alloc(u8, size); |
| 1499 | 1501 | errdefer allocator.free(buf); |
| 1500 | if ((try in_stream.read(buf)) < size) return error.EndOfFile; | |
| 1502 | if ((try noasync in_stream.read(buf)) < size) return error.EndOfFile; | |
| 1501 | 1503 | return buf; |
| 1502 | 1504 | } |
| 1503 | 1505 | |
| ... | ... | @@ -1506,8 +1508,9 @@ fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: var, size: usize |
| 1506 | 1508 | return FormValue{ .Block = buf }; |
| 1507 | 1509 | } |
| 1508 | 1510 | |
| 1511 | // TODO the noasyncs here are workarounds | |
| 1509 | 1512 | fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, size: usize) !FormValue { |
| 1510 | const block_len = try in_stream.readVarInt(usize, builtin.Endian.Little, size); | |
| 1513 | const block_len = try noasync in_stream.readVarInt(usize, builtin.Endian.Little, size); | |
| 1511 | 1514 | return parseFormValueBlockLen(allocator, in_stream, block_len); |
| 1512 | 1515 | } |
| 1513 | 1516 | |
| ... | ... | @@ -1537,27 +1540,37 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: boo |
| 1537 | 1540 | }; |
| 1538 | 1541 | } |
| 1539 | 1542 | |
| 1543 | // TODO the noasyncs here are workarounds | |
| 1540 | 1544 | fn parseFormValueDwarfOffsetSize(in_stream: var, is_64: bool) !u64 { |
| 1541 | return if (is_64) try in_stream.readIntLittle(u64) else u64(try in_stream.readIntLittle(u32)); | |
| 1545 | return if (is_64) try noasync in_stream.readIntLittle(u64) else u64(try noasync in_stream.readIntLittle(u32)); | |
| 1542 | 1546 | } |
| 1543 | 1547 | |
| 1548 | // TODO the noasyncs here are workarounds | |
| 1544 | 1549 | fn parseFormValueTargetAddrSize(in_stream: var) !u64 { |
| 1545 | return if (@sizeOf(usize) == 4) u64(try in_stream.readIntLittle(u32)) else if (@sizeOf(usize) == 8) try in_stream.readIntLittle(u64) else unreachable; | |
| 1550 | if (@sizeOf(usize) == 4) { | |
| 1551 | return u64(try noasync in_stream.readIntLittle(u32)); | |
| 1552 | } else if (@sizeOf(usize) == 8) { | |
| 1553 | return noasync in_stream.readIntLittle(u64); | |
| 1554 | } else { | |
| 1555 | unreachable; | |
| 1556 | } | |
| 1546 | 1557 | } |
| 1547 | 1558 | |
| 1559 | // TODO the noasyncs here are workarounds | |
| 1548 | 1560 | fn parseFormValueRef(allocator: *mem.Allocator, in_stream: var, size: i32) !FormValue { |
| 1549 | 1561 | return FormValue{ |
| 1550 | 1562 | .Ref = switch (size) { |
| 1551 | 1 => try in_stream.readIntLittle(u8), | |
| 1552 | 2 => try in_stream.readIntLittle(u16), | |
| 1553 | 4 => try in_stream.readIntLittle(u32), | |
| 1554 | 8 => try in_stream.readIntLittle(u64), | |
| 1555 | -1 => try leb.readULEB128(u64, in_stream), | |
| 1563 | 1 => try noasync in_stream.readIntLittle(u8), | |
| 1564 | 2 => try noasync in_stream.readIntLittle(u16), | |
| 1565 | 4 => try noasync in_stream.readIntLittle(u32), | |
| 1566 | 8 => try noasync in_stream.readIntLittle(u64), | |
| 1567 | -1 => try noasync leb.readULEB128(u64, in_stream), | |
| 1556 | 1568 | else => unreachable, |
| 1557 | 1569 | }, |
| 1558 | 1570 | }; |
| 1559 | 1571 | } |
| 1560 | 1572 | |
| 1573 | // TODO the noasyncs here are workarounds | |
| 1561 | 1574 | fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64: bool) anyerror!FormValue { |
| 1562 | 1575 | return switch (form_id) { |
| 1563 | 1576 | DW.FORM_addr => FormValue{ .Address = try parseFormValueTargetAddrSize(in_stream) }, |
| ... | ... | @@ -1565,7 +1578,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 |
| 1565 | 1578 | DW.FORM_block2 => parseFormValueBlock(allocator, in_stream, 2), |
| 1566 | 1579 | DW.FORM_block4 => parseFormValueBlock(allocator, in_stream, 4), |
| 1567 | 1580 | DW.FORM_block => x: { |
| 1568 | const block_len = try leb.readULEB128(usize, in_stream); | |
| 1581 | const block_len = try noasync leb.readULEB128(usize, in_stream); | |
| 1569 | 1582 | return parseFormValueBlockLen(allocator, in_stream, block_len); |
| 1570 | 1583 | }, |
| 1571 | 1584 | DW.FORM_data1 => parseFormValueConstant(allocator, in_stream, false, 1), |
| ... | ... | @@ -1577,11 +1590,11 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 |
| 1577 | 1590 | return parseFormValueConstant(allocator, in_stream, signed, -1); |
| 1578 | 1591 | }, |
| 1579 | 1592 | DW.FORM_exprloc => { |
| 1580 | const size = try leb.readULEB128(usize, in_stream); | |
| 1593 | const size = try noasync leb.readULEB128(usize, in_stream); | |
| 1581 | 1594 | const buf = try readAllocBytes(allocator, in_stream, size); |
| 1582 | 1595 | return FormValue{ .ExprLoc = buf }; |
| 1583 | 1596 | }, |
| 1584 | DW.FORM_flag => FormValue{ .Flag = (try in_stream.readByte()) != 0 }, | |
| 1597 | DW.FORM_flag => FormValue{ .Flag = (try noasync in_stream.readByte()) != 0 }, | |
| 1585 | 1598 | DW.FORM_flag_present => FormValue{ .Flag = true }, |
| 1586 | 1599 | DW.FORM_sec_offset => FormValue{ .SecOffset = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, |
| 1587 | 1600 | |
| ... | ... | @@ -1592,12 +1605,12 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 |
| 1592 | 1605 | DW.FORM_ref_udata => parseFormValueRef(allocator, in_stream, -1), |
| 1593 | 1606 | |
| 1594 | 1607 | DW.FORM_ref_addr => FormValue{ .RefAddr = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, |
| 1595 | DW.FORM_ref_sig8 => FormValue{ .Ref = try in_stream.readIntLittle(u64) }, | |
| 1608 | DW.FORM_ref_sig8 => FormValue{ .Ref = try noasync in_stream.readIntLittle(u64) }, | |
| 1596 | 1609 | |
| 1597 | 1610 | DW.FORM_string => FormValue{ .String = try readStringRaw(allocator, in_stream) }, |
| 1598 | 1611 | DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, |
| 1599 | 1612 | DW.FORM_indirect => { |
| 1600 | const child_form_id = try leb.readULEB128(u64, in_stream); | |
| 1613 | const child_form_id = try noasync leb.readULEB128(u64, in_stream); | |
| 1601 | 1614 | const F = @typeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64)); |
| 1602 | 1615 | var frame = try allocator.create(F); |
| 1603 | 1616 | defer allocator.destroy(frame); |
| ... | ... | @@ -1655,7 +1668,7 @@ fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*con |
| 1655 | 1668 | return null; |
| 1656 | 1669 | } |
| 1657 | 1670 | |
| 1658 | fn parseDie1(di: *DwarfInfo, abbrev_table: *const AbbrevTable, is_64: bool) !?Die { | |
| 1671 | fn parseDie(di: *DwarfInfo, abbrev_table: *const AbbrevTable, is_64: bool) !?Die { | |
| 1659 | 1672 | const abbrev_code = try leb.readULEB128(u64, di.dwarf_in_stream); |
| 1660 | 1673 | if (abbrev_code == 0) return null; |
| 1661 | 1674 | const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo; |
| ... | ... | @@ -1675,25 +1688,6 @@ fn parseDie1(di: *DwarfInfo, abbrev_table: *const AbbrevTable, is_64: bool) !?Di |
| 1675 | 1688 | return result; |
| 1676 | 1689 | } |
| 1677 | 1690 | |
| 1678 | fn parseDie(di: *DwarfInfo, abbrev_table: *const AbbrevTable, is_64: bool) !Die { | |
| 1679 | const abbrev_code = try leb.readULEB128(u64, di.dwarf_in_stream); | |
| 1680 | const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo; | |
| 1681 | ||
| 1682 | var result = Die{ | |
| 1683 | .tag_id = table_entry.tag_id, | |
| 1684 | .has_children = table_entry.has_children, | |
| 1685 | .attrs = ArrayList(Die.Attr).init(di.allocator()), | |
| 1686 | }; | |
| 1687 | try result.attrs.resize(table_entry.attrs.len); | |
| 1688 | for (table_entry.attrs.toSliceConst()) |attr, i| { | |
| 1689 | result.attrs.items[i] = Die.Attr{ | |
| 1690 | .id = attr.attr_id, | |
| 1691 | .value = try parseFormValue(di.allocator(), di.dwarf_in_stream, attr.form_id, is_64), | |
| 1692 | }; | |
| 1693 | } | |
| 1694 | return result; | |
| 1695 | } | |
| 1696 | ||
| 1697 | 1691 | fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: usize) !LineInfo { |
| 1698 | 1692 | const ofile = symbol.ofile orelse return error.MissingDebugInfo; |
| 1699 | 1693 | const gop = try di.ofiles.getOrPut(ofile); |
| ... | ... | @@ -2103,7 +2097,7 @@ fn scanAllFunctions(di: *DwarfInfo) !void { |
| 2103 | 2097 | const next_unit_pos = this_unit_offset + next_offset; |
| 2104 | 2098 | |
| 2105 | 2099 | while ((try di.dwarf_seekable_stream.getPos()) < next_unit_pos) { |
| 2106 | const die_obj = (try parseDie1(di, abbrev_table, is_64)) orelse continue; | |
| 2100 | const die_obj = (try parseDie(di, abbrev_table, is_64)) orelse continue; | |
| 2107 | 2101 | const after_die_offset = try di.dwarf_seekable_stream.getPos(); |
| 2108 | 2102 | |
| 2109 | 2103 | switch (die_obj.tag_id) { |
| ... | ... | @@ -2121,13 +2115,13 @@ fn scanAllFunctions(di: *DwarfInfo) !void { |
| 2121 | 2115 | const ref_offset = try this_die_obj.getAttrRef(DW.AT_abstract_origin); |
| 2122 | 2116 | if (ref_offset > next_offset) return error.InvalidDebugInfo; |
| 2123 | 2117 | try di.dwarf_seekable_stream.seekTo(this_unit_offset + ref_offset); |
| 2124 | this_die_obj = (try parseDie1(di, abbrev_table, is_64)) orelse return error.InvalidDebugInfo; | |
| 2118 | this_die_obj = (try parseDie(di, abbrev_table, is_64)) orelse return error.InvalidDebugInfo; | |
| 2125 | 2119 | } else if (this_die_obj.getAttr(DW.AT_specification)) |ref| { |
| 2126 | 2120 | // Follow the DIE it points to and repeat |
| 2127 | 2121 | const ref_offset = try this_die_obj.getAttrRef(DW.AT_specification); |
| 2128 | 2122 | if (ref_offset > next_offset) return error.InvalidDebugInfo; |
| 2129 | 2123 | try di.dwarf_seekable_stream.seekTo(this_unit_offset + ref_offset); |
| 2130 | this_die_obj = (try parseDie1(di, abbrev_table, is_64)) orelse return error.InvalidDebugInfo; | |
| 2124 | this_die_obj = (try parseDie(di, abbrev_table, is_64)) orelse return error.InvalidDebugInfo; | |
| 2131 | 2125 | } else { |
| 2132 | 2126 | break :x null; |
| 2133 | 2127 | } |
| ... | ... | @@ -2203,7 +2197,7 @@ fn scanAllCompileUnits(di: *DwarfInfo) !void { |
| 2203 | 2197 | try di.dwarf_seekable_stream.seekTo(compile_unit_pos); |
| 2204 | 2198 | |
| 2205 | 2199 | const compile_unit_die = try di.allocator().create(Die); |
| 2206 | compile_unit_die.* = try parseDie(di, abbrev_table, is_64); | |
| 2200 | compile_unit_die.* = (try parseDie(di, abbrev_table, is_64)) orelse return error.InvalidDebugInfo; | |
| 2207 | 2201 | |
| 2208 | 2202 | if (compile_unit_die.tag_id != DW.TAG_compile_unit) return error.InvalidDebugInfo; |
| 2209 | 2203 | |
| ... | ... | @@ -2419,3 +2413,9 @@ stdcallcc fn handleSegfaultWindows(info: *windows.EXCEPTION_POINTERS) c_long { |
| 2419 | 2413 | else => return windows.EXCEPTION_CONTINUE_SEARCH, |
| 2420 | 2414 | } |
| 2421 | 2415 | } |
| 2416 | ||
| 2417 | pub fn dumpStackPointerAddr(prefix: []const u8) void { | |
| 2418 | const sp = asm ("" : [argc] "={rsp}" (-> usize)); | |
| 2419 | std.debug.warn("{} sp = 0x{x}\n", prefix, sp); | |
| 2420 | } | |
| 2421 |
std/io/in_stream.zig+4-4| ... | ... | @@ -6,7 +6,7 @@ const assert = std.debug.assert; |
| 6 | 6 | const mem = std.mem; |
| 7 | 7 | const Buffer = std.Buffer; |
| 8 | 8 | |
| 9 | pub const default_stack_size = 4 * 1024 * 1024; | |
| 9 | pub const default_stack_size = 1 * 1024 * 1024; | |
| 10 | 10 | pub const stack_size: usize = if (@hasDecl(root, "stack_size_std_io_InStream")) |
| 11 | 11 | root.stack_size_std_io_InStream |
| 12 | 12 | else |
| ... | ... | @@ -32,10 +32,10 @@ pub fn InStream(comptime ReadError: type) type { |
| 32 | 32 | /// End of stream is not an error condition. |
| 33 | 33 | pub fn read(self: *Self, buffer: []u8) Error!usize { |
| 34 | 34 | if (std.io.is_async) { |
| 35 | // Let's not be writing 0xaa in safe modes for upwards of 4 MiB for every stream read. | |
| 36 | @setRuntimeSafety(false); | |
| 35 | 37 | var stack_frame: [stack_size]u8 align(stack_align) = undefined; |
| 36 | // TODO https://github.com/ziglang/zig/issues/3068 | |
| 37 | var result: Error!usize = undefined; | |
| 38 | return await @asyncCall(&stack_frame, &result, self.readFn, self, buffer); | |
| 38 | return await @asyncCall(&stack_frame, {}, self.readFn, self, buffer); | |
| 39 | 39 | } else { |
| 40 | 40 | return self.readFn(self, buffer); |
| 41 | 41 | } |
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/bits/linux.zig+1-1| ... | ... | @@ -25,7 +25,7 @@ pub const STDOUT_FILENO = 1; |
| 25 | 25 | pub const STDERR_FILENO = 2; |
| 26 | 26 | |
| 27 | 27 | /// Special value used to indicate openat should use the current working directory |
| 28 | pub const AT_FDCWD = 100; | |
| 28 | pub const AT_FDCWD = -100; | |
| 29 | 29 | |
| 30 | 30 | /// Do not follow symbolic links |
| 31 | 31 | pub const AT_SYMLINK_NOFOLLOW = 0x100; |
std/os/linux/tls.zig+6-1| ... | ... | @@ -132,7 +132,7 @@ pub fn setThreadPointer(addr: usize) void { |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | pub fn initTLS() void { | |
| 135 | pub fn initTLS() ?*elf.Phdr { | |
| 136 | 136 | var tls_phdr: ?*elf.Phdr = null; |
| 137 | 137 | var img_base: usize = 0; |
| 138 | 138 | |
| ... | ... | @@ -159,10 +159,13 @@ pub fn initTLS() void { |
| 159 | 159 | // Search the TLS section |
| 160 | 160 | const phdrs = (@intToPtr([*]elf.Phdr, at_phdr))[0..at_phnum]; |
| 161 | 161 | |
| 162 | var gnu_stack: ?*elf.Phdr = null; | |
| 163 | ||
| 162 | 164 | for (phdrs) |*phdr| { |
| 163 | 165 | switch (phdr.p_type) { |
| 164 | 166 | elf.PT_PHDR => img_base = at_phdr - phdr.p_vaddr, |
| 165 | 167 | elf.PT_TLS => tls_phdr = phdr, |
| 168 | elf.PT_GNU_STACK => gnu_stack = phdr, | |
| 166 | 169 | else => continue, |
| 167 | 170 | } |
| 168 | 171 | } |
| ... | ... | @@ -224,6 +227,8 @@ pub fn initTLS() void { |
| 224 | 227 | .data_offset = data_offset, |
| 225 | 228 | }; |
| 226 | 229 | } |
| 230 | ||
| 231 | return gnu_stack; | |
| 227 | 232 | } |
| 228 | 233 | |
| 229 | 234 | pub fn copyTLS(addr: usize) usize { |
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+57-12| ... | ... | @@ -4,8 +4,9 @@ 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 | var argc_ptr: [*]usize = undefined; | |
| 9 | var starting_stack_ptr: [*]usize = undefined; | |
| 9 | 10 | |
| 10 | 11 | const is_wasm = switch (builtin.arch) { |
| 11 | 12 | .wasm32, .wasm64 => true, |
| ... | ... | @@ -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()); |
| ... | ... | @@ -35,17 +61,17 @@ nakedcc fn _start() noreturn { |
| 35 | 61 | |
| 36 | 62 | switch (builtin.arch) { |
| 37 | 63 | .x86_64 => { |
| 38 | argc_ptr = asm ("" | |
| 64 | starting_stack_ptr = asm ("" | |
| 39 | 65 | : [argc] "={rsp}" (-> [*]usize) |
| 40 | 66 | ); |
| 41 | 67 | }, |
| 42 | 68 | .i386 => { |
| 43 | argc_ptr = asm ("" | |
| 69 | starting_stack_ptr = asm ("" | |
| 44 | 70 | : [argc] "={esp}" (-> [*]usize) |
| 45 | 71 | ); |
| 46 | 72 | }, |
| 47 | 73 | .aarch64, .aarch64_be, .arm => { |
| 48 | argc_ptr = asm ("mov %[argc], sp" | |
| 74 | starting_stack_ptr = asm ("mov %[argc], sp" | |
| 49 | 75 | : [argc] "=r" (-> [*]usize) |
| 50 | 76 | ); |
| 51 | 77 | }, |
| ... | ... | @@ -77,8 +103,8 @@ fn posixCallMainAndExit() noreturn { |
| 77 | 103 | if (builtin.os == builtin.Os.freebsd) { |
| 78 | 104 | @setAlignStack(16); |
| 79 | 105 | } |
| 80 | const argc = argc_ptr[0]; | |
| 81 | const argv = @ptrCast([*][*]u8, argc_ptr + 1); | |
| 106 | const argc = starting_stack_ptr[0]; | |
| 107 | const argv = @ptrCast([*][*]u8, starting_stack_ptr + 1); | |
| 82 | 108 | |
| 83 | 109 | const envp_optional = @ptrCast([*]?[*]u8, argv + argc + 1); |
| 84 | 110 | var envp_count: usize = 0; |
| ... | ... | @@ -90,21 +116,40 @@ fn posixCallMainAndExit() noreturn { |
| 90 | 116 | const auxv = @ptrCast([*]std.elf.Auxv, envp.ptr + envp_count + 1); |
| 91 | 117 | std.os.linux.elf_aux_maybe = auxv; |
| 92 | 118 | // Initialize the TLS area |
| 93 | std.os.linux.tls.initTLS(); | |
| 119 | const gnu_stack_phdr = std.os.linux.tls.initTLS() orelse @panic("ELF missing stack size"); | |
| 94 | 120 | |
| 95 | 121 | if (std.os.linux.tls.tls_image) |tls_img| { |
| 96 | 122 | const tls_addr = std.os.linux.tls.allocateTLS(tls_img.alloc_size); |
| 97 | 123 | const tp = std.os.linux.tls.copyTLS(tls_addr); |
| 98 | 124 | std.os.linux.tls.setThreadPointer(tp); |
| 99 | 125 | } |
| 126 | ||
| 127 | // TODO This is disabled because what should we do when linking libc and this code | |
| 128 | // does not execute? And also it's causing a test failure in stack traces in release modes. | |
| 129 | ||
| 130 | //// Linux ignores the stack size from the ELF file, and instead always does 8 MiB. A further | |
| 131 | //// problem is that it uses PROT_GROWSDOWN which prevents stores to addresses too far down | |
| 132 | //// the stack and requires "probing". So here we allocate our own stack. | |
| 133 | //const wanted_stack_size = gnu_stack_phdr.p_memsz; | |
| 134 | //assert(wanted_stack_size % std.mem.page_size == 0); | |
| 135 | //// Allocate an extra page as the guard page. | |
| 136 | //const total_size = wanted_stack_size + std.mem.page_size; | |
| 137 | //const new_stack = std.os.mmap( | |
| 138 | // null, | |
| 139 | // total_size, | |
| 140 | // std.os.PROT_READ | std.os.PROT_WRITE, | |
| 141 | // std.os.MAP_PRIVATE | std.os.MAP_ANONYMOUS, | |
| 142 | // -1, | |
| 143 | // 0, | |
| 144 | //) catch @panic("out of memory"); | |
| 145 | //std.os.mprotect(new_stack[0..std.mem.page_size], std.os.PROT_NONE) catch {}; | |
| 146 | //std.os.exit(@newStackCall(new_stack, callMainWithArgs, argc, argv, envp)); | |
| 100 | 147 | } |
| 101 | 148 | |
| 102 | std.os.exit(callMainWithArgs(argc, argv, envp)); | |
| 149 | std.os.exit(@inlineCall(callMainWithArgs, argc, argv, envp)); | |
| 103 | 150 | } |
| 104 | 151 | |
| 105 | // This is marked inline because for some reason LLVM in release mode fails to inline it, | |
| 106 | // and we want fewer call frames in stack traces. | |
| 107 | inline fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 { | |
| 152 | fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 { | |
| 108 | 153 | std.os.argv = argv[0..argc]; |
| 109 | 154 | std.os.environ = envp; |
| 110 | 155 | |
| ... | ... | @@ -117,7 +162,7 @@ extern fn main(c_argc: i32, c_argv: [*][*]u8, c_envp: [*]?[*]u8) i32 { |
| 117 | 162 | var env_count: usize = 0; |
| 118 | 163 | while (c_envp[env_count] != null) : (env_count += 1) {} |
| 119 | 164 | const envp = @ptrCast([*][*]u8, c_envp)[0..env_count]; |
| 120 | return callMainWithArgs(@intCast(usize, c_argc), c_argv, envp); | |
| 165 | return @inlineCall(callMainWithArgs, @intCast(usize, c_argc), c_argv, envp); | |
| 121 | 166 | } |
| 122 | 167 | |
| 123 | 168 | // General error message for a malformed return type |
std/thread.zig+1-1| ... | ... | @@ -145,7 +145,7 @@ pub const Thread = struct { |
| 145 | 145 | if (builtin.single_threaded) @compileError("cannot spawn thread when building in single-threaded mode"); |
| 146 | 146 | // TODO compile-time call graph analysis to determine stack upper bound |
| 147 | 147 | // https://github.com/ziglang/zig/issues/157 |
| 148 | const default_stack_size = 8 * 1024 * 1024; | |
| 148 | const default_stack_size = 16 * 1024 * 1024; | |
| 149 | 149 | |
| 150 | 150 | const Context = @typeOf(context); |
| 151 | 151 | comptime assert(@ArgType(@typeOf(startFn), 0) == Context); |
std/zig/tokenizer.zig+10-1| ... | ... | @@ -222,9 +222,11 @@ pub const Tokenizer = struct { |
| 222 | 222 | }, |
| 223 | 223 | }; |
| 224 | 224 | } else { |
| 225 | // Skip the UTF-8 BOM if present | |
| 226 | const src_start = if (mem.startsWith(u8, buffer, "\xEF\xBB\xBF")) 3 else usize(0); | |
| 225 | 227 | return Tokenizer{ |
| 226 | 228 | .buffer = buffer, |
| 227 | .index = 0, | |
| 229 | .index = src_start, | |
| 228 | 230 | .pending_invalid_token = null, |
| 229 | 231 | }; |
| 230 | 232 | } |
| ... | ... | @@ -1455,6 +1457,13 @@ test "tokenizer - line comment followed by identifier" { |
| 1455 | 1457 | }); |
| 1456 | 1458 | } |
| 1457 | 1459 | |
| 1460 | test "tokenizer - UTF-8 BOM is recognized and skipped" { | |
| 1461 | testTokenize("\xEF\xBB\xBFa;\n", [_]Token.Id{ | |
| 1462 | Token.Id.Identifier, | |
| 1463 | Token.Id.Semicolon, | |
| 1464 | }); | |
| 1465 | } | |
| 1466 | ||
| 1458 | 1467 | fn testTokenize(source: []const u8, expected_tokens: []const Token.Id) void { |
| 1459 | 1468 | var tokenizer = Tokenizer.init(source); |
| 1460 | 1469 | for (expected_tokens) |expected_token_id| { |
test/stage1/behavior/enum.zig+23| ... | ... | @@ -1007,3 +1007,26 @@ test "enum literal casting to error union with payload enum" { |
| 1007 | 1007 | |
| 1008 | 1008 | expect((try bar) == Bar.B); |
| 1009 | 1009 | } |
| 1010 | ||
| 1011 | test "enum with one member and u1 tag type @enumToInt" { | |
| 1012 | const Enum = enum(u1) { | |
| 1013 | Test, | |
| 1014 | }; | |
| 1015 | expect(@enumToInt(Enum.Test) == 0); | |
| 1016 | } | |
| 1017 | ||
| 1018 | test "enum with comptime_int tag type" { | |
| 1019 | const Enum = enum(comptime_int) { | |
| 1020 | One = 3, | |
| 1021 | Two = 2, | |
| 1022 | Three = 1, | |
| 1023 | }; | |
| 1024 | comptime expect(@TagType(Enum) == comptime_int); | |
| 1025 | } | |
| 1026 | ||
| 1027 | test "enum with one member default to u0 tag type" { | |
| 1028 | const E0 = enum { | |
| 1029 | X, | |
| 1030 | }; | |
| 1031 | comptime expect(@TagType(E0) == u0); | |
| 1032 | } |
test/stage1/behavior/union.zig+19-3| ... | ... | @@ -324,7 +324,7 @@ test "union with only 1 field casted to its enum type" { |
| 324 | 324 | |
| 325 | 325 | var e = Expr{ .Literal = Literal{ .Bool = true } }; |
| 326 | 326 | const Tag = @TagType(Expr); |
| 327 | comptime expect(@TagType(Tag) == comptime_int); | |
| 327 | comptime expect(@TagType(Tag) == u0); | |
| 328 | 328 | var t = Tag(e); |
| 329 | 329 | expect(t == Expr.Literal); |
| 330 | 330 | } |
| ... | ... | @@ -335,7 +335,7 @@ test "union with only 1 field casted to its enum type which has enum value speci |
| 335 | 335 | Bool: bool, |
| 336 | 336 | }; |
| 337 | 337 | |
| 338 | const Tag = enum { | |
| 338 | const Tag = enum(comptime_int) { | |
| 339 | 339 | Literal = 33, |
| 340 | 340 | }; |
| 341 | 341 | |
| ... | ... | @@ -469,7 +469,7 @@ test "union no tag with struct member" { |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | fn testComparison() void { |
| 472 | var x = Payload{.A = 42}; | |
| 472 | var x = Payload{ .A = 42 }; | |
| 473 | 473 | expect(x == .A); |
| 474 | 474 | expect(x != .B); |
| 475 | 475 | expect(x != .C); |
| ... | ... | @@ -494,3 +494,19 @@ test "packed union generates correctly aligned LLVM type" { |
| 494 | 494 | }; |
| 495 | 495 | foo[0].f1(); |
| 496 | 496 | } |
| 497 | ||
| 498 | test "union with one member defaults to u0 tag type" { | |
| 499 | const U0 = union(enum) { | |
| 500 | X: u32, | |
| 501 | }; | |
| 502 | comptime expect(@TagType(@TagType(U0)) == u0); | |
| 503 | } | |
| 504 | ||
| 505 | test "union with comptime_int tag" { | |
| 506 | const Union = union(enum(comptime_int)) { | |
| 507 | X: u32, | |
| 508 | Y: u16, | |
| 509 | Z: u8, | |
| 510 | }; | |
| 511 | comptime expect(@TagType(@TagType(Union)) == comptime_int); | |
| 512 | } |