From 3630de865c31de326c15171dd680fc2ffebf7ec7 Mon Sep 17 00:00:00 2001 From: David Gonzalez Martin Date: Sun, 9 Jul 2023 14:46:04 -0600 Subject: [PATCH] ovmf: take out of the repo by downloading --- .gitignore | 1 + build.zig | 13 ------------ build.zig.zon | 4 ++++ config/default.json | 2 +- src/bootloader/rise/uefi/main.zig | 4 ++-- src/bootloader/uefi.zig | 2 +- src/host.zig | 3 +++ src/host/runner/main.zig | 35 ++++++++++++++++++++++++++++++- src/user.zig | 2 +- 9 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 build.zig.zon diff --git a/.gitignore b/.gitignore index e0f2feb..a54d037 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ debug_disk bochsout.txt *.hdd loopback_device +tools/OVMF.fd diff --git a/build.zig b/build.zig index f3a07b2..a4a8075 100644 --- a/build.zig +++ b/build.zig @@ -512,19 +512,6 @@ pub fn build(b_arg: *Build) !void { } } } - - if (os == .linux) { - const generate_command = b.addSystemCommand(&.{ "dot", "-Tpng" }); - generate_command.addFileSourceArg(FileSource.relative("capabilities.dot")); - generate_command.addArg("-o"); - const png = generate_command.addOutputFileArg("capabilities.png"); - - const visualize_command = b.addSystemCommand(&.{"xdg-open"}); - visualize_command.addFileSourceArg(png); - - const dot_command = b.step("dot", "TEMPORARY: (developers only) Generate a graph and visualize it"); - dot_command.dependOn(&visualize_command.step); - } } const Options = struct { diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..3e42193 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,4 @@ +.{ + .name = "birth", + .version = "0.1.0", +} diff --git a/config/default.json b/config/default.json index 12994fc..aeb3374 100644 --- a/config/default.json +++ b/config/default.json @@ -1,7 +1,7 @@ { "architecture": "x86_64", "bootloader": "rise", - "boot_protocol": "bios", + "boot_protocol": "uefi", "execution_environment": "qemu", "optimize_mode": "Debug", "execution_type": "emulated", diff --git a/src/bootloader/rise/uefi/main.zig b/src/bootloader/rise/uefi/main.zig index eec4563..4ddd70d 100644 --- a/src/bootloader/rise/uefi/main.zig +++ b/src/bootloader/rise/uefi/main.zig @@ -157,7 +157,7 @@ const MemoryMap = extern struct { pub fn next(memory_map: *MemoryMap) !?bootloader.MemoryMapEntry { if (memory_map.offset < memory_map.size) { - const entry = @as(*MemoryDescriptor, @ptrCast(@alignCast(@alignOf(MemoryDescriptor), memory_map.buffer[memory_map.offset..].ptr))).*; + const entry = @as(*MemoryDescriptor, @ptrCast(@alignCast(memory_map.buffer[memory_map.offset..].ptr))).*; memory_map.offset += memory_map.descriptor_size; const result = bootloader.MemoryMapEntry{ .region = PhysicalMemoryRegion.new(.{ @@ -295,7 +295,7 @@ const Initialization = struct { .x86_64 => .{ .rsdp = for (system_table.configuration_table[0..system_table.number_of_table_entries]) |configuration_table| { if (configuration_table.vendor_guid.eql(ConfigurationTable.acpi_20_table_guid)) { - break @as(*ACPI.RSDP.Descriptor1, @ptrCast(@alignCast(@alignOf(ACPI.RSDP.Descriptor1), configuration_table.vendor_table))); + break @as(*ACPI.RSDP.Descriptor1, @ptrCast(@alignCast(configuration_table.vendor_table))); } } else return Error.rsdp_not_found, }, diff --git a/src/bootloader/uefi.zig b/src/bootloader/uefi.zig index 2e1e46d..3ac8fc8 100644 --- a/src/bootloader/uefi.zig +++ b/src/bootloader/uefi.zig @@ -70,7 +70,7 @@ pub const Protocol = struct { } fn cast(comptime ProtocolT: type, ptr: ?*anyopaque) *ProtocolT { - return @as(*ProtocolT, @ptrCast(@alignCast(@alignOf(ProtocolT), ptr))); + return @as(*ProtocolT, @ptrCast(@alignCast(ptr))); } }; diff --git a/src/host.zig b/src/host.zig index 5ca1104..762ec36 100644 --- a/src/host.zig +++ b/src/host.zig @@ -28,6 +28,9 @@ pub const ArrayListAligned = std.ArrayListAligned; pub const time = std.time; +pub const http = std.http; +pub const Uri = std.Uri; + // Build imports pub const build = std.build; diff --git a/src/host/runner/main.zig b/src/host/runner/main.zig index 1e16588..5b0612b 100644 --- a/src/host/runner/main.zig +++ b/src/host/runner/main.zig @@ -130,7 +130,40 @@ pub fn main() anyerror!void { } switch (arguments_result.configuration.boot_protocol) { - .uefi => try argument_list.appendSlice(&.{ "-bios", "tools/OVMF_CODE-pure-efi.fd" }), + .uefi => { + const ovmf_path = "tools/OVMF.fd"; + if (host.cwd().openFile(ovmf_path, .{})) |file_descriptor| { + file_descriptor.close(); + } else |_| { + const url = "https://retrage.github.io/edk2-nightly/bin/RELEASEX64_OVMF.fd"; + const uri = try host.Uri.parse(url); + + var http_client = host.http.Client{ .allocator = wrapped_allocator.zigUnwrap() }; + defer http_client.deinit(); + + var request_headers = host.http.Headers{ .allocator = wrapped_allocator.zigUnwrap() }; + defer request_headers.deinit(); + + var request = try http_client.request(.GET, uri, request_headers, .{}); + defer request.deinit(); + + try request.start(); + try request.wait(); + + if (request.response.status != .ok) return error.ResponseNotOk; + const content_length = request.response.content_length orelse return error.OutOfMemory; + + const buffer = try wrapped_allocator.zigUnwrap().alloc(u8, content_length); + const read_byte_count = try request.readAll(buffer); + if (read_byte_count != buffer.len) { + return error.OutOfMemory; + } + + try host.cwd().writeFile(ovmf_path, buffer); + } + + try argument_list.appendSlice(&.{ "-bios", ovmf_path }); + }, else => {}, } diff --git a/src/user.zig b/src/user.zig index 09f7c6b..90b2c43 100644 --- a/src/user.zig +++ b/src/user.zig @@ -85,8 +85,8 @@ pub export fn start(scheduler: *arch.Scheduler, arg_init: bool) callconv(.C) nor } assert(scheduler.common.generic.disabled); scheduler.initDisabled(); - @panic("TWTQWD"); // command_buffer = Syscall(.cpu, .get_command_buffer).blocking(&command_buffer) catch @panic("Unable to get command buffer"); + Syscall(.cpu, .shutdown).blocking({}) catch unreachable; } // export fn riseInitializeDisabled(scheduler: *arch.Scheduler, arg_init: bool) callconv(.C) noreturn {