Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/kernel/arch/x86/boot.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const constants = @import("constants");
const multiboot_info = @import("multiboot.zig").multiboot_info_t;

/// The multiboot header
const MultiBoot = packed struct {
Expand Down Expand Up @@ -63,8 +64,9 @@ export var boot_page_directory: [1024]u32 align(4096) linksection(".rodata.boot"
};

export var kernel_stack: [16 * 1024]u8 align(16) linksection(".bss.stack") = undefined;
extern var KERNEL_ADDR_OFFSET: *u32;

extern fn kmain() void;
extern fn kmain(mb_info: *multiboot_info) void;

export fn _start() align(16) linksection(".text.boot") callconv(.Naked) noreturn {
// Set the page directory to the boot directory
Expand Down Expand Up @@ -99,15 +101,14 @@ export fn start_higher_half() callconv(.Naked) noreturn {
asm volatile (
\\.extern KERNEL_STACK_END
\\mov $KERNEL_STACK_END, %%esp
\\xor %%ebp, %%ebp
\\mov %%esp, %%ebp
);

// Push the multiboot header address with virtual offset
asm volatile (
\\.extern KERNEL_ADDR_OFFSET
\\add $KERNEL_ADDR_OFFSET, %%ebx
\\push %%ebx
);
kmain();
// Get the multiboot header address and add the virtual offset
const mb_info_addr = asm (
\\mov %%ebx, %[res]
: [res] "=r" (-> usize)
) + @ptrToInt(&KERNEL_ADDR_OFFSET);
kmain(@intToPtr(*multiboot_info, mb_info_addr));
while (true) {}
}