Microkernel thing OS experiment (Zig ⚡)
at dev 3.0 kB view raw
1const std = @import("std"); 2const build_helpers = @import("build_helpers"); 3 4pub fn build(b: *std.Build) void { 5 const arch = b.option(build_helpers.Architecture, "arch", "The target architecture") orelse .amd64; 6 7 const ukernel_dep = b.dependency("ukernel", .{ 8 .arch = arch, 9 }); 10 const ukernel_artifact = ukernel_dep.artifact("ukernel"); 11 const ukernel_inst = b.addInstallFile(ukernel_artifact.getEmittedBin(), arch.kernelExeName()); 12 b.getInstallStep().dependOn(&ukernel_inst.step); 13 14 const root_69 = b.dependency("root_server", .{ 15 .arch = arch, 16 .number = 0x69, 17 }).artifact("root_server"); 18 const root_69_inst = b.addInstallFile(root_69.getEmittedBin(), "root-69.elf"); 19 b.getInstallStep().dependOn(&root_69_inst.step); 20 21 const root_420 = b.dependency("root_server", .{ 22 .arch = arch, 23 .number = 0x420, 24 }).artifact("root_server"); 25 const root_420_inst = b.addInstallFile(root_420.getEmittedBin(), "root-420.elf"); 26 b.getInstallStep().dependOn(&root_420_inst.step); 27 28 // Run in QEMU 29 run_blk: { 30 // Step 1: Install edk2 files to zig-out 31 const ovmf_code, const ovmf_vars = blk: { 32 const ovmf_dep = b.lazyDependency("edk2_binary", .{}) orelse break :run_blk; 33 break :blk .{ 34 ovmf_dep.path("bin/RELEASEX64_OVMF_CODE.fd"), 35 ovmf_dep.path("bin/RELEASEX64_OVMF_VARS.fd"), 36 }; 37 }; 38 39 const loader_path = blk: { 40 const limine_dep = b.lazyDependency("limine_binary", .{}) orelse break :run_blk; 41 break :blk limine_dep.path("BOOTX64.EFI"); 42 }; 43 44 // Install Required dependencies 45 const code_install = b.addInstallFile(ovmf_code, "OVMF_CODE_X64.fd"); 46 const vars_install = b.addInstallFile(ovmf_vars, "OVMF_VARS_X64.fd"); 47 const loader_install = b.addInstallFileWithDir(loader_path, .{ .custom = "EFI/BOOT" }, "BOOTX64.EFI"); 48 const config_install = b.addInstallFileWithDir(b.path("assets/limine.conf"), .{ .custom = "limine" }, "limine.conf"); 49 50 const qemu_cmd = b.addSystemCommand(&.{ "qemu-system-x86_64", "-smp", "4", "-m", "4G", "-monitor", "stdio", "-drive", "format=raw,file=fat:rw:zig-out", "-drive", "if=pflash,format=raw,readonly=on,file=zig-out/OVMF_CODE_X64.fd", "-drive", "if=pflash,format=raw,file=zig-out/OVMF_VARS_X64.fd" }); 51 52 // Depend on the install step (ukernel and root task) 53 qemu_cmd.step.dependOn(b.getInstallStep()); 54 // Depend on OVMF code+vars, Limine bootloader, and Limine cfg 55 qemu_cmd.step.dependOn(&code_install.step); 56 qemu_cmd.step.dependOn(&vars_install.step); 57 qemu_cmd.step.dependOn(&loader_install.step); 58 qemu_cmd.step.dependOn(&config_install.step); 59 60 // Create the actual public callable step and depend on our command 61 const qemu_step = b.step("qemu", "Run in QEMU"); 62 qemu_step.dependOn(&qemu_cmd.step); 63 } 64}