From 5ff1344f895b2188a15806a9198470566e2a0fc9 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Tue, 5 Dec 2023 23:56:23 -0600 Subject: [PATCH] wip --- .gitignore | 2 ++ Makefile | 11 +++++++++++ build.zig | 29 +++++++++++++++++++++++++++++ src/entry.zig | 3 +++ src/kernel.ld | 5 +++++ src/main.zig | 1 + 6 files changed, 51 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 build.zig create mode 100644 src/entry.zig create mode 100644 src/kernel.ld create mode 100644 src/main.zig diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44dbeed --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +zig-cache +zig-out \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a84f8c1 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +ifndef CPUS +CPUS := 3 +endif + +qemu: + qemu-system-aarch64 \ + -machine virt \ + -kernel zig-out/bin/kernel \ + -m 128M \ + -smp $(CPUS) \ + -nographic diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..e9f0659 --- /dev/null +++ b/build.zig @@ -0,0 +1,29 @@ +const std = @import("std"); +const Builder = @import("std").build.Builder; +const LazyPath = @import("std").build.LazyPath; +const Target = @import("std").Target; +const CrossTarget = @import("std").zig.CrossTarget; +const Feature = @import("std").Target.Cpu.Feature; + +pub fn build(b: *Builder) void { + const arch = Target.Cpu.Arch.aarch64; + const tag = Target.Os.Tag.freestanding; + const target = CrossTarget.fromTarget(.{ + .cpu = .{ + .arch = arch, + .model = Target.Cpu.Model.generic(arch), + .features = Feature.Set.empty, + }, + .os = .{ .tag = tag, .version_range = Target.Os.VersionRange.default(tag, arch) }, + .ofmt = Target.ObjectFormat.raw, + .abi = Target.Abi.none, + }); + + const result = b.addExecutable(.{ + .name = "kernel.elf", + .root_source_file = .{ .path = "src/entry.zig" }, + .target = target, + }); + result.setLinkerScript(.{ .path = "src/kernel.ld" }); + b.installArtifact(result); +} diff --git a/src/entry.zig b/src/entry.zig new file mode 100644 index 0000000..8af254b --- /dev/null +++ b/src/entry.zig @@ -0,0 +1,3 @@ +export fn _entry() noreturn { + while (true) {} +} diff --git a/src/kernel.ld b/src/kernel.ld new file mode 100644 index 0000000..440d820 --- /dev/null +++ b/src/kernel.ld @@ -0,0 +1,5 @@ +ENTRY(_entry) + +SECTIONS +{ +} diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..2a4bf5a --- /dev/null +++ b/src/main.zig @@ -0,0 +1 @@ +pub fn main() noreturn {}