From 951ef07b9bac01fec7462ca25e0500beeffbf81e Mon Sep 17 00:00:00 2001 From: Sam Tebbs Date: Sat, 20 Jun 2020 15:48:55 +0100 Subject: [PATCH] Fix x86 payload passing --- src/kernel/arch/x86/boot.zig | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/kernel/arch/x86/boot.zig b/src/kernel/arch/x86/boot.zig index d5ba0b0..8cc075a 100644 --- a/src/kernel/arch/x86/boot.zig +++ b/src/kernel/arch/x86/boot.zig @@ -1,4 +1,5 @@ const constants = @import("constants"); +const multiboot_info = @import("multiboot.zig").multiboot_info_t; /// The multiboot header const MultiBoot = packed struct { @@ -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 @@ -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) {} }