rework
This commit is contained in:
parent
b8c7fc5674
commit
5be9186a2d
1 changed files with 51 additions and 14 deletions
65
build.zig
65
build.zig
|
@ -7,14 +7,21 @@ pub fn build(b: *std.Build) void {
|
||||||
const initramfs = addNasmFiles(b, AddNasmFilesOptions{
|
const initramfs = addNasmFiles(b, AddNasmFilesOptions{
|
||||||
.filename = "src/initramfs.asm",
|
.filename = "src/initramfs.asm",
|
||||||
.outputname = "initramfs.bin",
|
.outputname = "initramfs.bin",
|
||||||
.addAsObjFile = false,
|
.flags = &.{"-f bin"},
|
||||||
|
});
|
||||||
|
const kernel = addNasmFiles(b, AddNasmFilesOptions{
|
||||||
|
.filename = "src/kernel.asm",
|
||||||
|
.outputname = "kernel.bin",
|
||||||
.flags = &.{"-f bin"},
|
.flags = &.{"-f bin"},
|
||||||
});
|
});
|
||||||
|
|
||||||
const initramfs_install = b.addInstallBinFile(initramfs.obj, "initramfs.img");
|
var floppy = createFloppy(b, "main_floppy.img");
|
||||||
initramfs_install.step.dependOn(&truncate(b, initramfs).step);
|
floppy.run = formatFloppyFat12(b, floppy);
|
||||||
|
|
||||||
b.getInstallStep().dependOn(&initramfs_install.step);
|
const img_install = b.addInstallBinFile(floppy.obj, "main_floppy.img");
|
||||||
|
img_install.step.dependOn(&installImgToFloppy(b, floppy, initramfs, kernel).step);
|
||||||
|
|
||||||
|
b.getInstallStep().dependOn(&img_install.step);
|
||||||
|
|
||||||
const run = b.addSystemCommand(&.{ "qemu-system-i386", "-fda" });
|
const run = b.addSystemCommand(&.{ "qemu-system-i386", "-fda" });
|
||||||
run.addFileArg(b.path("zig-out/bin/initramfs.img"));
|
run.addFileArg(b.path("zig-out/bin/initramfs.img"));
|
||||||
|
@ -26,7 +33,6 @@ pub fn build(b: *std.Build) void {
|
||||||
const AddNasmFilesOptions = struct {
|
const AddNasmFilesOptions = struct {
|
||||||
filename: []const u8,
|
filename: []const u8,
|
||||||
outputname: ?[]const u8 = null,
|
outputname: ?[]const u8 = null,
|
||||||
addAsObjFile: bool = true,
|
|
||||||
flags: []const []const u8 = &.{},
|
flags: []const []const u8 = &.{},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,6 +41,46 @@ const NasmFile = struct {
|
||||||
obj: std.Build.LazyPath,
|
obj: std.Build.LazyPath,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Floppydisk = NasmFile;
|
||||||
|
|
||||||
|
fn createFloppy(b: *std.Build, name: []const u8) Floppydisk {
|
||||||
|
const dd = b.addSystemCommand(&.{ "dd", "if=/dev/zero" });
|
||||||
|
const Floppy = dd.addPrefixedOutputFileArg("of=", name);
|
||||||
|
dd.addArgs(&.{ "bs=512", "count=2880" });
|
||||||
|
|
||||||
|
return Floppydisk{
|
||||||
|
.run = dd,
|
||||||
|
.obj = Floppy,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn formatFloppyFat12(b: *std.Build, floppy: Floppydisk) *std.Build.Step.Run {
|
||||||
|
const mkfs = b.addSystemCommand(&.{ "mkfs.fat", "-F12", "-nNBOS" });
|
||||||
|
mkfs.addFileArg(floppy.obj);
|
||||||
|
|
||||||
|
mkfs.step.dependOn(&floppy.run.step);
|
||||||
|
|
||||||
|
return mkfs;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn installImgToFloppy(b: *std.Build, floppy: Floppydisk, bootloader: NasmFile, kernel: NasmFile) *std.Build.Step.Run {
|
||||||
|
const dd = b.addSystemCommand(&.{"dd"});
|
||||||
|
dd.addPrefixedFileArg("if=", bootloader.obj);
|
||||||
|
dd.addPrefixedFileArg("of=", floppy.obj);
|
||||||
|
dd.addArg("conv=notrunc");
|
||||||
|
dd.step.dependOn(&floppy.run.step);
|
||||||
|
dd.step.dependOn(&bootloader.run.step);
|
||||||
|
|
||||||
|
const mcopy = b.addSystemCommand(&.{"mcopy"});
|
||||||
|
mcopy.addPrefixedFileArg("-i", floppy.obj);
|
||||||
|
mcopy.addFileArg(kernel.obj);
|
||||||
|
mcopy.addArg("::kernel.bin");
|
||||||
|
mcopy.step.dependOn(&dd.step);
|
||||||
|
mcopy.step.dependOn(&kernel.run.step);
|
||||||
|
|
||||||
|
return mcopy;
|
||||||
|
}
|
||||||
|
|
||||||
// adapted from https://codeberg.org/raddari/zig-nasm-lib.git
|
// adapted from https://codeberg.org/raddari/zig-nasm-lib.git
|
||||||
fn addNasmFiles(b: *std.Build, options: AddNasmFilesOptions) NasmFile {
|
fn addNasmFiles(b: *std.Build, options: AddNasmFilesOptions) NasmFile {
|
||||||
std.debug.assert(!std.fs.path.isAbsolute(options.filename));
|
std.debug.assert(!std.fs.path.isAbsolute(options.filename));
|
||||||
|
@ -52,12 +98,3 @@ fn addNasmFiles(b: *std.Build, options: AddNasmFilesOptions) NasmFile {
|
||||||
.obj = obj,
|
.obj = obj,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn truncate(b: *std.Build, bin: NasmFile) *std.Build.Step.Run {
|
|
||||||
const exec = b.addSystemCommand(&.{"truncate"});
|
|
||||||
exec.addArgs(&.{ "-s", "1440k" });
|
|
||||||
exec.addFileArg(bin.obj);
|
|
||||||
exec.step.dependOn(&bin.run.step);
|
|
||||||
|
|
||||||
return exec;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue