Page 2 of 2

Re: Including an unused variable corrupts the multiboot kern

Posted: Thu Apr 18, 2024 9:51 am
by Markelov69
FrankRay78 wrote:Hello,

I've encountered a really strange bug in my nascent kernel development. Whilst PatienceOS is a C# bare metal kernel (nb. nothing close to an OS yet), the simplicity of the codebase and compilation to direct machine code means that it's nothing much more than the C barebones tutorial here.

Bootstrap Assembly: src
Linker template: src
Main function: src
Console struct: src
Build script: src

The checked-in code (above) builds and runs fine in QEMU. However, when I add a single line to the console struct (see below), a variable which is declared but never used/referenced, the kernel no longer boots in QEMU. Rather, the screen flashes as if the multiboot has been corrupted somehow.

Code: Select all

private byte foregroundColor = 0x0F;
I'm guessing it's something to do with the packing of the struct (see here) and/or the memory alignment in the linker template, perhaps.

To be honest, I'm a little out of my depth, but I would really appreciate any suggestions as to how I can practically troubleshoot the situation. I'm more interested in learning how to go about understanding how to fix this, rather than seeking a silver bullet.

Frank
I don't have the necessary build environment to construct this. Could you provide the kernel.elf file that functions correctly (prior to the change) and the kernel.elf file that does not work? You could place them in your GitHub repository for accessibility.