feat: add initial impl of efi-stub and kernel
This commit is contained in:
86
arch/x86/boot/build.zig
Normal file
86
arch/x86/boot/build.zig
Normal file
@@ -0,0 +1,86 @@
|
||||
const std = @import("std");
|
||||
const kernel_build = @import("../../../kernel/build.zig");
|
||||
const Step = std.Build.Step;
|
||||
|
||||
pub fn buildSetup(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, kcapsule: *Step.Compile) *Step.Compile {
|
||||
const offset_generate = b.addSystemCommand(&[_][]const u8{
|
||||
"sh",
|
||||
"arch/x86/boot/helper.sh",
|
||||
"generate_offset_header",
|
||||
});
|
||||
offset_generate.addFileArg(kcapsule.getEmittedBin());
|
||||
offset_generate.step.dependOn(&kcapsule.step);
|
||||
const setup = b.addExecutable(.{
|
||||
.name = "setup",
|
||||
.use_lld = true,
|
||||
.use_llvm = true,
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("arch/x86/boot/setup/stage1.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
}),
|
||||
});
|
||||
setup.step.dependOn(&offset_generate.step);
|
||||
setup.step.addWatchInput(b.path("arch/x86/boot/offset.h")) catch {};
|
||||
setup.addAssemblyFile(b.path("arch/x86/boot/header.S"));
|
||||
setup.addIncludePath(b.path("include"));
|
||||
setup.addIncludePath(b.path("arch/x86/boot"));
|
||||
setup.setLinkerScript(b.path("arch/x86/boot/setup.ld"));
|
||||
return setup;
|
||||
}
|
||||
pub fn buildKcapsule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *Step.Compile {
|
||||
const kernel = kernel_build.buildKernelBin(b, target, optimize);
|
||||
const kcapsule = b.addExecutable(.{
|
||||
.name = "kcapsule",
|
||||
.use_lld = true,
|
||||
.use_llvm = true,
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("arch/x86/boot/extractor.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.pic = true,
|
||||
}),
|
||||
});
|
||||
const efi_target = b.resolveTargetQuery(.{
|
||||
.cpu_arch = .x86_64,
|
||||
.os_tag = .freestanding,
|
||||
.abi = .msvc,
|
||||
});
|
||||
const efi_loader = b.addObject(.{
|
||||
.name = "efi_loader",
|
||||
.use_lld = true,
|
||||
.use_llvm = true,
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("drivers/firmware/efi/x86.zig"),
|
||||
.target = efi_target,
|
||||
.optimize = optimize,
|
||||
.pic = true,
|
||||
}),
|
||||
});
|
||||
kcapsule.pie = true;
|
||||
kcapsule.entry = .{ .symbol_name = "efi_pe_entry" };
|
||||
kcapsule.addObject(efi_loader);
|
||||
kcapsule.addAssemblyFile(b.path("arch/x86/boot/payload.S"));
|
||||
kcapsule.setLinkerScript(b.path("arch/x86/boot/kcapsule.ld"));
|
||||
kcapsule.step.dependOn(&kernel.step);
|
||||
|
||||
return kcapsule;
|
||||
}
|
||||
pub fn buildImage(b: *std.Build, optimize: std.builtin.OptimizeMode) *Step {
|
||||
const target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, .os_tag = .freestanding, .abi = .none });
|
||||
|
||||
const kcapsule = buildKcapsule(b, target, optimize);
|
||||
const setup = buildSetup(b, target, optimize, kcapsule);
|
||||
const image = b.addSystemCommand(&[_][]const u8{
|
||||
"sh",
|
||||
"arch/x86/boot/helper.sh",
|
||||
"build_image",
|
||||
});
|
||||
|
||||
image.addFileArg(setup.getEmittedBin());
|
||||
image.addFileArg(kcapsule.getEmittedBin());
|
||||
image.step.dependOn(&setup.step);
|
||||
image.step.dependOn(&kcapsule.step);
|
||||
|
||||
return &image.step;
|
||||
}
|
||||
Reference in New Issue
Block a user