Hello, for a school project I’m making a small kernel in Zig 0.12. It works perfectly fine in Debug mode but for wathever reason when I compile it in any Release mode and then boot it in grub I get the error no multiboot header found
.
Here’s my boot code :
const ALIGN = 1 << 0;
const MEMINFO = 1 << 1;
const MAGIC = 0x1BADB002;
const FLAGS = ALIGN | MEMINFO;
const MultiBoot = packed struct
{
magic: i32 = MAGIC,
flags: i32,
checksum: i32,
_: i32 = 0, // doesn't compile without it in 0.12
};
export var multiboot align(4) linksection(".multiboot") = MultiBoot
{
.flags = FLAGS,
.checksum = -(MAGIC + FLAGS),
};
export var kernel_stack: [16 * 1024]u8 align(16) linksection(".bss") = undefined;
extern fn kmain() void;
export fn _start() align(16) linksection(".text.boot") callconv(.Naked) noreturn
{
// Setup the stack and call kernel
asm volatile (
\\ movl %[stk], %esp
\\ call kmain
:
: [stk] "{ecx}" (@intFromPtr(&kernel_stack) + @sizeOf(@TypeOf(kernel_stack))),
);
while(true) {}
}
and here’s my linker script :
ENTRY(_start)
SECTIONS
{
. = 2M;
.text : ALIGN(4K)
{
*(.multiboot)
*(.text)
}
.rodata : ALIGN(4K)
{
*(.rodata)
}
.data : ALIGN(4K)
{
*(.data)
}
.bss : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
}
I don’t really know if this is a compiler issue. Any help would be pleased. This is not a real issue as my kernel works fine in debug, I just find it weird.
I even tried to replace the multiboot header by a comptime inline asm in the boot code with no success:
comptime
{
asm (
\\ .set ALIGN, 1 << 0
\\ .set MEMINFO, 1 << 1
\\ .set FLAGS, ALIGN | MEMINFO
\\ .set MAGIC, 0x1BADB002
\\ .set CHECKSUM, -(MAGIC + FLAGS)
\\
\\ .section .multiboot
\\ .align 4
\\ .long MAGIC
\\ .long FLAGS
\\ .long CHECKSUM
);
}