Compare commits

..

1 Commits
master ... dev

Author SHA1 Message Date
d5b68c53be Work on fixing multiboot with flat binary kernel 2024-09-18 22:07:54 +02:00
4 changed files with 30 additions and 20 deletions

View File

@ -44,7 +44,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);

View File

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

View File

@ -4,11 +4,15 @@ SECTIONS {
. = 2M; . = 2M;
.blob : ALIGN(4K) { .blob : ALIGN(4K) {
_header_addr = .;
*(.multiboot) *(.multiboot)
_text_start = .;
*(.text) *(.text)
*(.rodata) *(.rodata)
*(.data) *(.data)
_data_end = .;
*(COMMON) *(COMMON)
*(.bss) *(.bss)
_bss_end = .;
} }
} }

View File

@ -1,23 +1,27 @@
const console = @import("console.zig"); const console = @import("console.zig");
const ALIGN = 1 << 0; comptime {
const MEMINFO = 1 << 1; asm (
const MAGIC = 0x1BADB002; \\ .set ALIGN, 1<<0
const FLAGS = ALIGN | MEMINFO; \\ .set MEMINFO, 1<<1
\\ .set ADDRINFO, 1<<16
\\ .set FLAGS, ALIGN | MEMINFO | ADDRINFO
\\ .set MAGIC, 0x1BADB002
\\ .set CHECKSUM, -(MAGIC + FLAGS)
\\ .section .multiboot
\\ .align 4
\\ .long MAGIC
\\ .long FLAGS
\\ .long CHECKSUM
\\ .long _header_addr
\\ .long _text_start
\\ .long _data_end
\\ .long _bss_end
\\ .long _start
);
}
const MultibootHeader = packed struct { export var stack_bytes: [32 * 1024]u8 align(16) linksection(".bss") = undefined;
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;
const stack_bytes_slice = stack_bytes[0..]; const stack_bytes_slice = stack_bytes[0..];
export fn _start() callconv(.Naked) noreturn { export fn _start() callconv(.Naked) noreturn {
@ -34,4 +38,6 @@ export fn _start() callconv(.Naked) noreturn {
export fn kmain() void { export fn kmain() void {
console.initialize(); console.initialize();
console.puts("Hello world!"); console.puts("Hello world!");
console.puts("Hello world!");
console.puts("Hello world!");
} }