USB-HDD bug, or a code bug?
Posted: Sat Jan 03, 2009 2:06 am
I've been looking into alternatives to floppies for testing on real hardware recently. I decided on putting my OS on a bootable USB stick and trying that out as all the docs say that it's very similar to booting a floppy using INT 0x13 (read sector). The USB stick I have is an PNY OPTIMA Pro Attach'e 4GB and is read by my supermicro serverboard's BIOS as a USB-HDD 4GB.
My code also detects it as a HDD (DL == 0x80), and AH = 0x08, DL = 0x80, INT 0x13 reports typical results for a HDD (63 sect/head, 255 heads).
When I read sector 1 of head 0 in sector 0, I get garbage bytes in the buffer at ES:BX. If I read sector 1 of head 1 in sector 0, I get the expected bootloader hex code in ES:BX. All the docs I've read have not mentioned the need to set head (DH) to 1 for HDD or USB-HDD, and I'm pretty sure it's not supposed to be 1 for the *first* sector of the drive.
here's some stripped down code from my load_kernel function.
this sets up INT 0x13 to read from sector 1, head 1, cylinder 0, and tells it to use the buffer 0x1000:0x0000, and to read the max sectors (63 in this case), and to use the HDD device (0x80 in this case).
[0x7B00] == 0x80
[0x7B04] == 63
I use that space for storing the device parameters from the previous INT 0x13.
The above returns the proper bootsector that the system booted from, and all the sectors are correct (as I can also boot my kernel with it). But if the above code changes DH to 0, it reads garbage on the USB-HDD. viceversa happens with a floppy (DH = 0 works, and DH = 1 fails as expected).
any ideas as to why this is happening?
btw, I'm in unreal mode during that. The floppy code (similar to the above) has worked forever and didn't have any noticable problems when dealing with physical or emulated floppies.
My code also detects it as a HDD (DL == 0x80), and AH = 0x08, DL = 0x80, INT 0x13 reports typical results for a HDD (63 sect/head, 255 heads).
When I read sector 1 of head 0 in sector 0, I get garbage bytes in the buffer at ES:BX. If I read sector 1 of head 1 in sector 0, I get the expected bootloader hex code in ES:BX. All the docs I've read have not mentioned the need to set head (DH) to 1 for HDD or USB-HDD, and I'm pretty sure it's not supposed to be 1 for the *first* sector of the drive.
here's some stripped down code from my load_kernel function.
this sets up INT 0x13 to read from sector 1, head 1, cylinder 0, and tells it to use the buffer 0x1000:0x0000, and to read the max sectors (63 in this case), and to use the HDD device (0x80 in this case).
[0x7B00] == 0x80
[0x7B04] == 63
I use that space for storing the device parameters from the previous INT 0x13.
Code: Select all
mov dh, 1 ; start head
mov ax, 0
mov ds, ax ; makes sure DS == 0 (for memory references)
mov ch, 0 ; start cylinder
.LOAD_KERNEL:
xor bx, bx ; buffer == ES:BX (0x1000:0x0000)
mov cl, 1 ; start sector
mov dl, byte [0x7B00] ; drive number
mov ax, 0x1000 ; set ES to 0x1000
mov es, ax
mov ah, 0x02 ; function 0x02
mov al, byte [0x7B04] ; sectors to read (max sectors reported by INT 0x13/AH=0x08)
INT 0x13
jc .LOAD_KERNEL
any ideas as to why this is happening?
btw, I'm in unreal mode during that. The floppy code (similar to the above) has worked forever and didn't have any noticable problems when dealing with physical or emulated floppies.