summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig50
1 files changed, 50 insertions, 0 deletions
diff --git a/build.zig b/build.zig
new file mode 100644
index 0000000..536762d
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,50 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+ const target = b.resolveTargetQuery(.{
+ .cpu_arch = .riscv64,
+ .abi = .none,
+ .os_tag = .freestanding,
+ .ofmt = .elf,
+ });
+ const optimize = b.standardOptimizeOption(.{});
+
+ const exe = b.addExecutable(.{
+ .name = "kernel",
+ .root_module = b.createModule(.{
+ .root_source_file = b.path("src/main.zig"),
+ .target = target,
+ .optimize = optimize,
+ .code_model = .medany,
+ }),
+ });
+ exe.root_module.addAssemblyFile(b.path("src/asm/boot.S"));
+ exe.root_module.addAssemblyFile(b.path("src/asm/trap.S"));
+ exe.linker_script = b.path("src/ld/virt.ld");
+ b.installArtifact(exe);
+
+ const run_step = b.step("run", "Run the app");
+ const run_cmd = b.addSystemCommand(&.{
+ // zig fmt: off
+ "qemu-system-riscv64",
+ "-machine", "virt",
+ "-cpu", "rv64",
+ "-smp", "4",
+ "-m", "128M",
+ // "-drive", "if=none,format=raw,file=hdd.dsk,id=foo",
+ // "-device", "virtio-blk-device,scsi=off,drive=foo",
+ "-nographic",
+ "-serial", "mon:stdio",
+ "-bios", "none",
+ "-device", "virtio-rng-device",
+ "-device", "virtio-net-device",
+ "-device", "virtio-tablet-device",
+ "-device", "virtio-keyboard-device",
+ "-S", "-s",
+ "-kernel"
+ // zig fmt: on
+ });
+ run_cmd.addArtifactArg(exe);
+ run_step.dependOn(&run_cmd.step);
+ run_cmd.step.dependOn(b.getInstallStep());
+}