actually maybe let's not just yet

This commit is contained in:
Dario48 2025-07-25 22:59:11 +02:00
parent 2dd27016f4
commit c8ce196828
4 changed files with 28 additions and 53 deletions

View file

@ -10,11 +10,11 @@ pub fn build(b: *std.Build) void {
.outputname = "bootloader.bin", .outputname = "bootloader.bin",
.flags = &.{"-f bin"}, .flags = &.{"-f bin"},
}); });
//const kernel = addNasmFiles(b, AddNasmFilesOptions{ const kernel = addNasmFiles(b, AddNasmFilesOptions{
// .filename = "src/kernel.asm", .filename = "src/kernel.asm",
// .outputname = "kernel.bin", .outputname = "kernel.bin",
// .flags = &.{"-f bin"}, .flags = &.{"-f bin"},
//}); });
const target = b.standardTargetOptions(.{ const target = b.standardTargetOptions(.{
.default_target = .{ .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"); const floppy = createFloppy(b, "main_floppy.img");
formatFloppyFat12(b, floppy);
var installToFloppy = installImgToFloppy(b, floppy, bootloader, &.{ 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" }, 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; 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" }); const mkfs = b.addSystemCommand(&.{ "mkfs.fat", "-F12", "-nNBOS" });
mkfs.addFileArg(floppy); 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"}); const dd = b.addSystemCommand(&.{"dd"});
dd.addPrefixedFileArg("if=", bootloader); dd.addPrefixedFileArg("if=", bootloader);
dd.addPrefixedFileArg("of=", floppy); dd.addPrefixedFileArg("of=", floppy);
dd.addArg("conv=notrunc"); dd.addArg("conv=notrunc");
dd.step.dependOn(&mkfs.step);
var last_step = dd; var last_step = dd;
for (additional_files) |f| { for (additional_files) |f| {

View file

@ -37,7 +37,6 @@ ebr_system_id: db 'FAT12 ' ; 8 bytes
start: start:
; setup data segments ; setup data segments
mov ax, 0 ; use ax as and intermediary as we can't write to es/ds directly mov ax, 0 ; use ax as and intermediary as we can't write to es/ds directly
@ -364,7 +363,6 @@ disk_reset:
popa popa
ret ret
msg_loading: db 'starting zos', ENDL, 0 msg_loading: db 'starting zos', ENDL, 0
msg_read_failed: db 'error on floppy read', ENDL, 0 msg_read_failed: db 'error on floppy read', ENDL, 0
msg_kernel_not_found: db 'kernel.bin not found', ENDL, 0 msg_kernel_not_found: db 'kernel.bin not found', ENDL, 0

View file

@ -2,26 +2,38 @@
org 0x0 org 0x0
bits 16 bits 16
%define ENDL 0x0D, 0x0A
start:
mov si, msg_init
call echo
.halt:
cli
hlt
;
; echo: ; echo:
; print something to the screen ; print something to the screen
; - ds:si points to string ; - ds:si points to string
; ;
global _echo:function echo:
_echo:
; save the registers we want to modify ; save the registers we want to modify
push si push si
push ax push ax
push bx push bx
mov ah, 0xe
mov bh, 0
.loop: .loop:
lodsb ; load byte from ds:si to al lodsb ; load byte from ds:si to al
or al, al ; check if next char is null or al, al ; check if next char is null
jz .done jz .done
mov ah, 0x0E
mov bh, 0
int 0x10 int 0x10
jmp .loop jmp .loop
.done: .done:
@ -29,3 +41,5 @@ _echo:
pop ax pop ax
pop si pop si
ret ret
msg_init: db 'started kernel', ENDL, 0

View file

@ -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");
}