Page 1 of 1

failed to load file

Posted: Thu Nov 04, 2004 7:23 am
by McZ
I can't figure out what I'm doing wrong in my bootsector code, it failes to load the boot loader.. I'm trying to load it through the FAT12 filesystem but it failes to load it


source:
www.hig.se/~hco03phe/bootsctr.asm

Re:failed to load file

Posted: Thu Nov 04, 2004 8:32 am
by Curufir
Your code to calculate the size of the root dir is wrong.

The calculation is:

Root_Dir_Size = ( (BPB_DirEntries * 32) / 512) rounded up

You're currently using:

Root_Dir_Size = ( ( (BPB_DirEntries * 32) + 512 - 1) / 512)

This is horribly wrong.

So use something like:

Code: Select all

MOV DX, [BPB_DirEntries]
AND DX, 0xF
JZ .1
ADD DX, 0x10
.1
SHR DX, 0x4
That error pretty much screws anything else you're trying to do.

Re:failed to load file

Posted: Thu Nov 04, 2004 9:48 am
by bakery2k
Curufir wrote: The calculation is:

Root_Dir_Size = ( (BPB_DirEntries * 32) / 512) rounded up

You're currently using:

Root_Dir_Size = ( ( (BPB_DirEntries * 32) + 512 - 1) / 512)

This is horribly wrong.
Err...No. His calculation will produce the same result as yours.

Re:failed to load file

Posted: Thu Nov 04, 2004 10:12 am
by Curufir
Yeah you're correct of course (Basic algebra coming back to haunt me :)).

Hell, it'd be boring to be right all the time.

Waiter! More coffee.

Re:failed to load file

Posted: Thu Nov 04, 2004 10:18 am
by Curufir
In penance I took another look.

This is one of the more amusing bugs I've seen.

Code: Select all

   div word[BPB_SectorsPerTrack]   ; divide AX with SectorsPerTrack (LBA / SPT)    inc dl                          ; increase the remainder of the division
There's no line break before the 'inc dl' instruction.

This means NASM interprets it as part of the comment and it's never assembled.

Which means all the LBAtoCHS conversions are wrong.

Nasty.

Re:failed to load file

Posted: Thu Nov 04, 2004 11:59 am
by McZ
Curufir wrote: In penance I took another look.

This is one of the more amusing bugs I've seen.

Code: Select all

   div word[BPB_SectorsPerTrack]   ; divide AX with SectorsPerTrack (LBA / SPT)    inc dl                          ; increase the remainder of the division
There's no line break before the 'inc dl' instruction.

This means NASM interprets it as part of the comment and it's never assembled.

Which means all the LBAtoCHS conversions are wrong.

Nasty.

oh.. I can't remember there is missing a linebreak but I have to make sure as soon as I get home :)

but lets say there is a line break there is there anything else that can be wrong then?

Re:failed to load file

Posted: Sat Nov 06, 2004 8:17 pm
by McZ
so I have been trying to fix the problem with my file loader... but so far no success... altough I have found out that it looks like it doesn't load anything from disk, I used my bPrintHex16 function to print out the stuff in the FAT_BUFF and it writes only 0000 for each value.. wich wont be correct becouse I have one file that is 1kb in size, then it would be fitted into 2 sectors, but how come the 1 entry I should get in the FAT_BUFF is empty or 0000 ? shouldn't it be some other value?