Page 2 of 2
Re: Bootloader - USB Flash drive FAT32 reading problems
Posted: Mon Apr 08, 2013 3:10 am
by bluemoon
USB does not naturally support CHS addressing mode, so if an BIOS is decent enough to support USB HDD, it's very odd that it does not work with LBA; I would doubt if CHS translation is otherwise working.
Re: Bootloader - USB Flash drive FAT32 reading problems
Posted: Mon Apr 08, 2013 7:53 am
by makuc9
Hmmm, I was opening it as a logical disk and not physical (funny, or sadly, but last time I was looking I couldn't find the same strings using Find function in HxD ... I guess I was really careless.
). This is the problem than, I guess. So this means I still have to figure out how to discover location of logical first sector on a physical drive. Or is it always 128? But than how about multiple partitions? I guess I am just discovering what a noob I am.
And I though I was getting hang of assembly...
Thanks for your responses, specially you DavidCooper. I finally feel like I am getting somewhere again.
Now I'll try re-implement the direct LBA adressing (mostly because of what bluemoon said). Of course I'll start with interrupt 41h. Will keep you posted.
Re: Bootloader - USB Flash drive FAT32 reading problems
Posted: Mon Apr 08, 2013 10:26 am
by Mikemk
makuc9 wrote:Or is it always 128?
No, it's always 1. Make sense?
But than how about multiple partitions?
Partitions are just represented by the data stored on the disk, they aren't physical separations.
Re: Bootloader - USB Flash drive FAT32 reading problems
Posted: Mon Apr 08, 2013 1:24 pm
by DavidCooper
makuc9 wrote:Hmmm, I was opening it as a logical disk and not physical
That catches out a lot of people, including me when I first used HxD. We take it in turns here to be the first to suggest it as the potential cause of the problem in a thread.
So this means I still have to figure out how to discover location of logical first sector on a physical drive. Or is it always 128? But than how about multiple partitions? I guess I am just discovering what a noob I am.
The logical first sector is the one pointed to by the first entry of the partition table found in sector 0 of the physical drive. Read up on
MBR and more importantly the
partition table to find out how HxD determines where the logical drive begins.
And I though I was getting hang of assembly...
You're better at it than I am. I've spotted something else in your code though:-
mov ax, 0x8c00 ; We can't set es register directly
mov es, ax ; Therefore we set it in ax first
xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
mov ah, 02h
mov al, 1
mov ch, BYTE[aTrack]
mov cl, BYTE[aSector]
mov dh, BYTE[aHead]
mov dl, [BOOT_DRIVE]
jc .error
mov ax, [0x8c00]
call print_int
call print_nl
With 8c00 in ES it's going to load the sector in sixteen times higher up memory than the location where you later look to see if it loaded in.
Re: Bootloader - USB Flash drive FAT32 reading problems
Posted: Mon Apr 08, 2013 2:17 pm
by makuc9
I've went through microsoft's "FAT: General Overview of On-Disk Format" again ('Boot Sector and BPB Structure' chapter) and I think I've found the problem in determing location of actual address of ROOT directory. I should add BPB_HiddSec to LBA calculation. Now I'll have to run a few more test.
I've also reimplemented 41h function of BIOS int 13h to check for extension support (I've run it on another PC, newer - only 1 year old - and it passed the test. I'll have to re-check support on previous PC to make sure, but for now I am OK with this). I've also finally found a perfect way of running USB on VirtualBox, if anyone is interested, check
http://www.rmprepusb.com/tutorials/how- ... are-server.
Now I am back to rebuilding direct LBA read function.
David, I don't think I really understood what you meant with:
"With 8c00 in ES it's going to load the sector in sixteen times higher up memory than the location where you later look to see if it loaded in."
I loaded it in 8c00h and I read what was stored at address 8c00h and simply print that. No jumps or anything and I should be able to access 1MB of memory from address I was loaded in, right? Or did I missed something else, too? (Since what I printed was always 0, I believe this makes sense ... 8192 sector is zeroed ... But than again, I might be wrong.)
Re: Bootloader - USB Flash drive FAT32 reading problems
Posted: Mon Apr 08, 2013 5:42 pm
by DavidCooper
makuc9 wrote:David, I don't think I really understood what you meant with:
"With 8c00 in ES it's going to load the sector in sixteen times higher up memory than the location where you later look to see if it loaded in."
If you put 8c00 in ax and then mov it into ES and couple that with a BX containing zero to give the BIOS an address to load the sector to, that gives you the address 8c000, and that's a little over half way up the first megabyte of memory in the machine. When you then read the byte at 8c00, that's a byte located a little over half way up the first 64K segment of memory in the machine, 16 times lower down than the location the sector was loaded to. Well, it's either that or my mind's gone (and I'm always open to that possibility).
Re: Bootloader - USB Flash drive FAT32 reading problems
Posted: Tue Apr 09, 2013 7:16 am
by makuc9
Hmmm, I am not really sure anymore, but I just tested all of the new changes that I have made (I completed direct LBA reading function) and it works. I successfully read the disk and printed the RIGHT character.
I always thought that addressing works like this: ES+BX, where set segment to a fixed value and in use offset only to increase the range (in case I read multiple sectors, so I have to read it to a different location - ES+512)...
I mean i have always zeroed one and used only one for addressing ... everything seems easier this way. Am I really wrong? Than how can this work as I want it to?
PS:
Thank you all for helping me fix bootloader and made me see my mistake. I am really grateful.
Re: Bootloader - USB Flash drive FAT32 reading problems
Posted: Tue Apr 09, 2013 8:14 am
by JAAman
makuc9 wrote:Hmmm, I am not really sure anymore, but I just tested all of the new changes that I have made (I completed direct LBA reading function) and it works. I successfully read the disk and printed the RIGHT character.
I always thought that addressing works like this: ES+BX, where set segment to a fixed value and in use offset only to increase the range (in case I read multiple sectors, so I have to read it to a different location - ES+512)...
I mean i have always zeroed one and used only one for addressing ... everything seems easier this way. Am I really wrong? Than how can this work as I want it to?
PS:
Thank you all for helping me fix bootloader and made me see my mistake. I am really grateful.
no, BIOS loads the sector to ES:BX not ES+BX (think about it for a minute, if it was the later, how would you load data higher than 128k?)
in RMode addressing, segment is multiplied by 0x10 (16) and added to offset, so basically where BIOS is loading to is ES*16+BX
therefore, in your example ES= 0x8C00, BX=0
address ==
0x8C00 (segment register << 4 (multiplied by 16)
+0x0000 (offset added)
------------
0x8C000 (resulting physical address)
you will therefore have to set DS to 0x7C01 or higher to access the value (or use a seg override to use ES) -- most probably load DS=0x8C00 and then access address 0 (the same way you loaded it)
Re: Bootloader - USB Flash drive FAT32 reading problems
Posted: Wed Apr 10, 2013 2:14 pm
by makuc9
Hmm, thanks. That helped. i guess I'll have to take a closer look to all of this, than.