diff --git a/build.zig b/build.zig index ee95b69..bb6acf2 100644 --- a/build.zig +++ b/build.zig @@ -10,11 +10,11 @@ pub fn build(b: *std.Build) void { .outputname = "bootloader.bin", .flags = &.{"-f bin"}, }); - //const kernel = addNasmFiles(b, AddNasmFilesOptions{ - // .filename = "src/kernel.asm", - // .outputname = "kernel.bin", - // .flags = &.{"-f bin"}, - //}); + const kernel = addNasmFiles(b, AddNasmFilesOptions{ + .filename = "src/kernel.asm", + .outputname = "kernel.bin", + .flags = &.{"-f bin"}, + }); const target = b.standardTargetOptions(.{ .default_target = .{ @@ -23,22 +23,10 @@ pub fn build(b: *std.Build) void { }, }); - const kernel_mod = b.addModule("kernel", .{ - .root_source_file = b.path("src/kernel.zig"), - .target = target, - }); - - const kernel = b.addExecutable(.{ - .root_module = kernel_mod, - .linkage = .static, - .name = "kernel", - }); - const floppy = createFloppy(b, "main_floppy.img"); - formatFloppyFat12(b, floppy); var installToFloppy = installImgToFloppy(b, floppy, bootloader, &.{ - NamedFile{ .file = kernel.getEmittedBin(), .name = "::kernel.bin" }, + NamedFile{ .file = kernel, .name = "::kernel.bin" }, NamedFile{ .file = b.path("src/reference_implementations/test.txt"), .name = "::test.txt" }, }); @@ -91,16 +79,16 @@ fn createFloppy(b: *std.Build, name: []const u8) LazyPath { return Floppy; } -fn formatFloppyFat12(b: *std.Build, floppy: LazyPath) void { +fn installImgToFloppy(b: *std.Build, floppy: LazyPath, bootloader: LazyPath, additional_files: []const NamedFile) *std.Build.Step.Run { const mkfs = b.addSystemCommand(&.{ "mkfs.fat", "-F12", "-nNBOS" }); mkfs.addFileArg(floppy); -} + mkfs.has_side_effects = true; -fn installImgToFloppy(b: *std.Build, floppy: LazyPath, bootloader: LazyPath, additional_files: []const NamedFile) *std.Build.Step.Run { const dd = b.addSystemCommand(&.{"dd"}); dd.addPrefixedFileArg("if=", bootloader); dd.addPrefixedFileArg("of=", floppy); dd.addArg("conv=notrunc"); + dd.step.dependOn(&mkfs.step); var last_step = dd; for (additional_files) |f| { diff --git a/src/bootloader.asm b/src/bootloader.asm index 3ac094e..c3a7e6a 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -37,7 +37,6 @@ ebr_system_id: db 'FAT12 ' ; 8 bytes - start: ; setup data segments mov ax, 0 ; use ax as and intermediary as we can't write to es/ds directly @@ -364,7 +363,6 @@ disk_reset: popa ret - msg_loading: db 'starting zos', ENDL, 0 msg_read_failed: db 'error on floppy read', ENDL, 0 msg_kernel_not_found: db 'kernel.bin not found', ENDL, 0 diff --git a/src/definitions.asm b/src/kernel.asm similarity index 68% rename from src/definitions.asm rename to src/kernel.asm index 87b2f9b..fa4647e 100644 --- a/src/definitions.asm +++ b/src/kernel.asm @@ -2,26 +2,38 @@ org 0x0 bits 16 + +%define ENDL 0x0D, 0x0A + + +start: + mov si, msg_init + call echo + +.halt: + cli + hlt + +; ; echo: ; print something to the screen ; - ds:si points to string ; -global _echo:function -_echo: +echo: ; save the registers we want to modify push si push ax push bx - mov ah, 0xe - mov bh, 0 - .loop: lodsb ; load byte from ds:si to al or al, al ; check if next char is null jz .done + mov ah, 0x0E + mov bh, 0 int 0x10 + jmp .loop .done: @@ -29,3 +41,5 @@ _echo: pop ax pop si ret + +msg_init: db 'started kernel', ENDL, 0 diff --git a/src/kernel.zig b/src/kernel.zig deleted file mode 100644 index 690655e..0000000 --- a/src/kernel.zig +++ /dev/null @@ -1,25 +0,0 @@ -fn BIOSprint(string: []const u8) void { - asm volatile ( - \\pushw %%ax - \\pushw %%bx - ); - for (string) |char| { - asm volatile ( - \\movb $0x0E, %%ah - \\movb $0, %%bh - \\int $0x10 - : - : [arg1] "{al}" (char), - ); - } - asm volatile ( - \\popw %%bx - \\popw %%ax - ); -} - -const std = @import("std"); - -pub fn main() void { - BIOSprint("kernel loaded"); -}