Page 1 of 1

ReadMode HDD Access [SOLVED]

Posted: Sat Jun 07, 2008 11:44 am
by 01000101
I started to work on some code to install my OS to the HDD, but I'm having issues with the RealMode detection code (figures out if the HDD already has the OS on it or not). I put a arbitrary value at sector 1 of the HDD and wish to read it in my bootloader upon next bootup, but this is failing miserably. There is no error code being returned so it seeems fine, but the value is always 0. I'm not sure if it is my PMode HDD PIO driver that is misplacing the value or if it is my RealMode code.

Code: Select all

        mov ax, 0x1000    ; load sectors starting at 0x1000:0x0000
        mov es, ax
        mov bx, 0
        
        mov ah, 0x02       ; Read Function
        mov al, 16           ; load 16 sectors
        mov ch, 0            ; cylinder
        mov cl, 1             ; starting sector
        mov dh, 0            ; head
        mov dl, 0x80        ; drive #
        
        int 0x13
        or ah, ah
        jnz hdd_error       ; error

        mov ax, 0x1000   ; 0x1000:0x0000
        mov es, ax
        mov bx, 0
        cmp byte [es:bx], 0x0C    ; a pre-placed value
        jne boot_from_floppy       ; not there, boot off floppy

Posted: Sat Jun 07, 2008 1:05 pm
by svdmeer
I see you check the status of the int 13h operation by comparing AH with zero. The official way to do it with interrupt 13h is checking the carryflag, you can simply use "jc hdd_error". I have had a rare situation where carry=1, the sectors I wanted to read where not read right while AH was zero..

You read a sector and check if the first byte has value 0x0C in it.
What do you want to check? The bootsector of your OS?

If you read from harddisk, the firstsector is mostly the MBR (I assume that's also the case on your harddisk). You read 16 sectors in address 1000h:0000h, first sector cyl=0, head=0, sect=1, thats the first LBA=sector, so you are reading the MBR first and checking for a 0x0C.

Did you put that 0x0C value on the MBR of your harddisk or on the first sector of the partition of your OS?

Posted: Sat Jun 07, 2008 2:04 pm
by Dex
Try reading 1 sector and as pointed out use jc error
Also try puting another value at that address before do the int 13h read
eg:

Code: Select all

        mov ax, 0x1000   ; 0x1000:0x0000
        mov es, ax
        mov bx, 0
        mov byte [es:bx], 0x0F    ; a pre-placed value
This should test if you wrote any value there in the first place with the int 13h read or its the int 13h write that's at fault.

I have always found it best to read/write 1 sector at a time and loop.

Posted: Sat Jun 07, 2008 3:24 pm
by 01000101
@svdmeer
I put the value at sector 1, so where the MBR should be. It should be at the absolute beginning of the HDD.

@Dex
I will try to write with Int13 and read it back, I use HDD PIO using LBA28 to write the origional stuff though.

Posted: Sat Jun 07, 2008 3:45 pm
by svdmeer
01000101 wrote:@svdmeer
I put the value at sector 1, so where the MBR should be. It should be at the absolute beginning of the HDD.
Where is that "RealMode detection code" located? In the MBR? On the bootsector of a floppy? A utility running under an OS?

Posted: Sat Jun 07, 2008 3:55 pm
by 01000101
bootsect of a floppy.

Posted: Sat Jun 07, 2008 4:30 pm
by svdmeer
It's important to make clear what's goes wrong: Writing the sector or reading the sector.

Read the sector with a 3th-party program, like dd and hexedit with a Linux bootdisk. Check manually which value the first byte has. If that's ok you know for sure the problem is at the read program.

Try to read one sector instead of 16.

Posted: Sat Jun 07, 2008 8:36 pm
by 01000101
well... all is fixed.

sorry for wasting you're time all. =)

I ended up creating two seperate bootloaders, one for booting off of the floppy, and one that gets installed on the HDD, I had to tweak my linker a bit, but all is well now...

it is official, my OS can now be installed on a HDD and then booted.. yay =) lol.

Thanks again.

Posted: Sat Jun 07, 2008 9:27 pm
by Dex
Congratulations, its always a milestone when you can install your OS on a Hdd.