Bootloader does not work on real hardware

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: Bootloader does not work on real hardware

Post by Octocontrabass »

Bonfra wrote:How can I check if that memory is available? is there some interrupt for it?
Try INT 0x12.
Bonfra wrote:AX is the number of sectors to read and for some reason, I was loading both the tables in memory so instead, the value should've been 0x40. In fact, with the right calculation (without multiplying by two) it boots up in VMWare.
The FAT can be bigger than 0x7F sectors, but some BIOSes can't read more than 0x7F sectors at once.
rdos
Member
Member
Posts: 3297
Joined: Wed Oct 01, 2008 1:55 pm

Re: Bootloader does not work on real hardware

Post by rdos »

Bonfra wrote:Ok, I've finally tested the OS in the real hardware, and... it doesn't work :(
the VBR seems to work in fact the second stage bootloader prints a string but then nothing, maybe the VBR does not load correctly all the file: the instruction right after the print is a call to a function very deep in the code...
I don't know I need to do some more testing... If you notice something weird in this code let me know but I'm pretty sure about that, maybe is the fact that I assume that the memory that could be used by the EBDA is free, I may need to move around some bits
You should implement exception vectors that allow you to insert int 3 into the code and dump register state & halt. You should also print register state on faults. It's not so hard to do and definitely should be used in the second stage boot loader and forward. Since I never had the luxury of emulators with this built-in, I learned this the hard way on real hardware.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: Bootloader does not work on real hardware

Post by Bonfra »

rdos wrote: You should implement exception vectors that allow you to insert int 3 into the code and dump register state & halt. You should also print register state on faults. It's not so hard to do and definitely should be used in the second stage boot loader and forward. Since I never had the luxury of emulators with this built-in, I learned this the hard way on real hardware.
Yes, I yet have this dump in the kernel and I'm planning to add it also to the second stage but the problem here is in the first stage not loading correctly the second stage.
I've also tried to move the address where I save the FS things to a lower address but still nothing
Regards, Bonfra.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: Bootloader does not work on real hardware

Post by Bonfra »

Some updates: I've managed to boot the image using BOCHS (but can't figure out how to build it with the debugger so I'm single-stepping with `jmp $`).
It stops to a different part of the code but still, I'm pretty sure it has to do with the VBR not loading correctly the second stage so it must be something in the FAT16 driver I wrote (or the read disk function but it works for the VBR...). Do you spot something weird or some wrong assumptions I took in this code?
Regards, Bonfra.
sj95126
Member
Member
Posts: 151
Joined: Tue Aug 11, 2020 12:14 pm

Re: Bootloader does not work on real hardware

Post by sj95126 »

Bonfra wrote:Some updates: I've managed to boot the image using BOCHS (but can't figure out how to build it with the debugger so I'm single-stepping with `jmp $`).
I wish the release would include a binary for gdb debugging in addition to the one for the built-in debugger, or restructure their code so you can pick one or the other at runtime. But I'm not sure it would help here. Unless I'm doing something wrong, gdb is completely useless until I've entered the kernel.

I don't see anything obviously wrong at a cursory glance. The only thing I can suggest is to not assume that a BIOS call isn't trashing registers and throwing off a looped read. Maybe set a Bochs magic breakpoint (or regular breakpoint) after a call to ReadSectorsLBA and make sure everything is still what it should be.
User avatar
Bonfra
Member
Member
Posts: 270
Joined: Wed Feb 19, 2020 1:08 pm
Libera.chat IRC: Bonfra
Location: Italy

Re: Bootloader does not work on real hardware

Post by Bonfra »

sj95126 wrote: The only thing I can suggest is to not assume that a BIOS call isn't trashing registers and throwing off a looped read. Maybe set a Bochs magic breakpoint (or regular breakpoint) after a call to ReadSectorsLBA and make sure everything is still what it should be.
It stays the same and nothing is touched but just to be sure and avoid future problems I've added pusha at the beginning end popa at the end of ReadSectorsLBA.
Regards, Bonfra.
Post Reply