From d8b53a78fcb131235c1e83fe7d6600ab50560420 Mon Sep 17 00:00:00 2001 From: hachem Date: Thu, 10 Sep 2026 05:49:32 +0200 Subject: setup: initialize repo + limine as a bootloader --- build.zig | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 build.zig (limited to 'build.zig') diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..f49eb58 --- /dev/null +++ b/build.zig @@ -0,0 +1,46 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + // Default to ReleaseSafe because Debug pulls Zig's + // UBSan runtime and other sanitization, which needs + // f128/SSE ops, which i don't provide. + const optimize = b.option(std.builtin.OptimizeMode, "optimize", "optimize mode") orelse .ReleaseSafe; + + // The kernel must NOT touch SSE/MMX/AVX until it has + // enabled them itself, so I strip those features and + // let the compiler use a soft-float ABI. + // `code_model = .kernel` keeps relocations valid for + // the higher-half load address in boot/linker.ld. + // + // In other words. Going raw baby + var query: std.Target.Query = .{ + .cpu_arch = .x86_64, + .os_tag = .freestanding, + .abi = .none, + }; + const Feature = std.Target.x86.Feature; + query.cpu_features_sub.addFeature(@intFromEnum(Feature.mmx)); + query.cpu_features_sub.addFeature(@intFromEnum(Feature.sse)); + query.cpu_features_sub.addFeature(@intFromEnum(Feature.sse2)); + query.cpu_features_sub.addFeature(@intFromEnum(Feature.avx)); + query.cpu_features_sub.addFeature(@intFromEnum(Feature.avx2)); + query.cpu_features_add.addFeature(@intFromEnum(Feature.soft_float)); + + const kernel = b.addExecutable(.{ + .name = "revel", + .root_module = b.createModule(.{ + .root_source_file = b.path("boot/boot.zig"), + .target = b.resolveTargetQuery(query), + .optimize = optimize, + .code_model = .kernel, + .red_zone = false, + .single_threaded = true, + .link_libc = false, + }), + }); + kernel.entry = .{ .symbol_name = "_start" }; + kernel.pie = false; + kernel.setLinkerScript(b.path("boot/linker.ld")); + + b.installArtifact(kernel); +} -- cgit v1.3