Hello folks!
I'm trying to write a simple bootloader that loads a small (50k) kernel. The currently currently does nothing more than just print a few messages.
The bootloader is (obviously) on sector #1 of the disk and the kernel is stored on sectors #2 and onwards.
My bootloader iteraters through each sector (starting with #2) until the last sector of the kernel, and loads these to memory. I read from disk using the int 13h, function 02h.
What I'm seeing is that the kernel is loaded correctly for the first 30 or so sectors. But the remaining sectors aren't being read into memory. I am checking for errors after the call to int 13h by looking at the CF as well as by examining AL (should be 1, and is in fact 1) for every call. Neither of these are showing anything wrong (i.e., CF is not set and AL=1).
I see this behavior in BOCHS, but the same code works correctly in QEMU. I am seeing some weird mixture of the two on real hardware - BOCHS fails to read anything after sector 30 or so, while real hardware seems to be able to read some of these correctly.
Do you guys have advice on what I could be doing wrong?
Any advice on how I should be debugging something like this?
int 13h appears to succeed but doesn't actually work
-
- Posts: 3
- Joined: Tue Sep 20, 2011 9:39 pm
-
- Member
- Posts: 52
- Joined: Mon Oct 11, 2010 11:37 pm
- Location: Milwaukee, Wisconsin
Re: int 13h appears to succeed but doesn't actually work
Are you loading from a floppy or a hard drive, either real or emulated?
Since you are using function 02, what is your disk geometry, real or emulated? Function 02 uses CHS. If you are loading about 50Ki, or 100 sectors, you are almost certainly loading from multiple cylinders. Have you taken this into account?
Since you are using function 02, what is your disk geometry, real or emulated? Function 02 uses CHS. If you are loading about 50Ki, or 100 sectors, you are almost certainly loading from multiple cylinders. Have you taken this into account?
Microsoft is over if you want it.
Re: int 13h appears to succeed but doesn't actually work
With a real-mode segment being only 64K and your kernel being 50K, if you're not starting near the beginning of a segment your pointer is going to wrap round; have you taken that into account?
-
- Posts: 3
- Joined: Tue Sep 20, 2011 9:39 pm
Re: int 13h appears to succeed but doesn't actually work
Thanks for the suggestions.
I think I've taken into accounts both the fact that I need to read multiple tracks. There isn't any offset wraparound happening because the initial offset is 0.
This might be a dump question, but is it correct to assume that all tracks have the same number of sectors?
What I'm doing is something like this:
Is there something wrong with this approach?
I think I've taken into accounts both the fact that I need to read multiple tracks. There isn't any offset wraparound happening because the initial offset is 0.
This might be a dump question, but is it correct to assume that all tracks have the same number of sectors?
What I'm doing is something like this:
Code: Select all
sector = 2
track = 0
head = 0
loop:
read using int 13h
sector ++
if (sector > MAXSECTORSPERTRACK) /* obtained using int 13h function 08h)
{
sector = 1;
track++;
}
if (track == MAXTRACKS) {/* again from int 13h function 08h */
head++;
}
jmp loop;
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: int 13h appears to succeed but doesn't actually work
head 1 track 0 comes before head 0 track 1.
-
- Posts: 3
- Joined: Tue Sep 20, 2011 9:39 pm
Re: int 13h appears to succeed but doesn't actually work
You're right. Thanks a lot!Combuster wrote:head 1 track 0 comes before head 0 track 1.
Re: int 13h appears to succeed but doesn't actually work
Physically, no, not on modern disks. Logically, from the INT13H perspective, yes.tragicomix wrote: This might be a dump question, but is it correct to assume that all tracks have the same number of sectors?