Work on repairing multiboot with flat binary kernel

This commit is contained in:
Maciej Krzyżanowski 2024-09-18 20:30:35 +02:00
parent 81540ef99d
commit c5ccb29b58
5 changed files with 15 additions and 20 deletions

View File

@ -28,6 +28,7 @@ pub fn build(b: *std.Build) void {
.code_model = .kernel, .code_model = .kernel,
}); });
kernel_elf.setLinkerScript(b.path("src/linker.ld")); kernel_elf.setLinkerScript(b.path("src/linker.ld"));
kernel_elf.addAssemblyFile(b.path("src/boot.s"));
const kernel_elf_artifact = b.addInstallArtifact(kernel_elf, .{}); const kernel_elf_artifact = b.addInstallArtifact(kernel_elf, .{});
@ -44,7 +45,7 @@ pub fn build(b: *std.Build) void {
kernel_bin_copy.step.dependOn(&kernel_bin.step); kernel_bin_copy.step.dependOn(&kernel_bin.step);
const kernel_step_elf = b.step("elf", "Build the kernel ELF"); const kernel_step_elf = b.step("elf", "Build the kernel ELF");
kernel_step_elf.dependOn(&kernel_elf.step); kernel_step_elf.dependOn(&kernel_elf_artifact.step);
const kernel_step_bin = b.step("bin", "Build the kernel BIN (with objcopy)"); const kernel_step_bin = b.step("bin", "Build the kernel BIN (with objcopy)");
kernel_step_bin.dependOn(&kernel_bin_copy.step); kernel_step_bin.dependOn(&kernel_bin_copy.step);

11
src/boot.s Normal file
View File

@ -0,0 +1,11 @@
.set ALIGN, 1<<0
.set MEMINFO, 1<<1
.set FLAGS, ALIGN
.set MAGIC, 0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM

View File

@ -1,3 +1,3 @@
menuentry "Zig Bare Bones" { menuentry "Zig Bare Bones" {
multiboot /boot/kernel.elf multiboot /boot/kernel.bin
} }

View File

@ -1,22 +1,5 @@
const console = @import("console.zig"); const console = @import("console.zig");
const ALIGN = 1 << 0;
const MEMINFO = 1 << 1;
const MAGIC = 0x1BADB002;
const FLAGS = ALIGN | MEMINFO;
const MultibootHeader = packed struct {
magic: i32 = MAGIC,
flags: i32,
checksum: i32,
padding: u32 = 0,
};
export var multiboot align(4) linksection(".multiboot") = MultibootHeader{
.flags = FLAGS,
.checksum = -(MAGIC + FLAGS),
};
export var stack_bytes: [16 * 1024]u8 align(16) linksection(".bss") = undefined; export var stack_bytes: [16 * 1024]u8 align(16) linksection(".bss") = undefined;
const stack_bytes_slice = stack_bytes[0..]; const stack_bytes_slice = stack_bytes[0..];