Hard Disk query
Hard Disk query
Is there any reliable method to obtain a hard-disks parameters (cyl,head,sect) in pmode or is the BIOS the best way to do so? the BIOS seems to have several functions for this. I was just wondering whether i can implement any one of them or is any one more reliable covering a wider range of hdd's?
I read you can directly probe the HDC but the function 0xEC (get drive params) was listed as "optional" may not be supported on some drives.
Please help.
I read you can directly probe the HDC but the function 0xEC (get drive params) was listed as "optional" may not be supported on some drives.
Please help.
Only Human
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Hard Disk query
i would say talking to the IDE drive and requesting the info packet is the best way, and it will aslo tell you if the disk supports LBA, ultra-dma, etc. asking the BIOS may return you 'fake' values for some disk/BIOSes that simulate a CHS but actually work with LBA (and thus the amount of cylinders will not reflect the *physical* amount of cylinders)
AFAI can see, only the non-ATA drives (yeah, we used to have dedicated ISA disk controller cards before IDE become the standard will require a BIOS probe ...
AFAI can see, only the non-ATA drives (yeah, we used to have dedicated ISA disk controller cards before IDE become the standard will require a BIOS probe ...
Re:Hard Disk query
IDENTIFY DEVICE (0xEC) definitely isn't optional: the standard says it is "Mandatory for all devices". Similarly IDENTIFY PACKET DEVICE (0xA1) is "Mandatory for devices implementing the PACKET Command feature".
These should be your sources of information on ATA and ATAPI drives. The BIOS parameters are likely to be fudged. For one thing, any modern drive is LBA, whereas the BIOS still deals in cylinders, heads and sectors.
These should be your sources of information on ATA and ATAPI drives. The BIOS parameters are likely to be fudged. For one thing, any modern drive is LBA, whereas the BIOS still deals in cylinders, heads and sectors.
Re:Hard Disk query
I guess my info was wrong.
Anyway while we're at it I tried reading the BIOS with some strange results
I first called the int13h with AH=0x41 (Extensions Installation Check) and got the following values as result
I concluded that the int13h 0x48 function was also supported(acording to Ralph Brown list). So i now tried the 0x48 function(Get Drive Params) but keep getting an err code of 1(i.e invalid function in AH or invalid parameter)
btw the params are right here's the code
is there anything wrong here? or is this an example of the problem with using the BIOS ints?
Anyway while we're at it I tried reading the BIOS with some strange results
I first called the int13h with AH=0x41 (Extensions Installation Check) and got the following values as result
Code: Select all
AX=0x2100(Major version no.)
BX=0xAA55(success)
CX=0x5(support bitmap)
DX=0x80(extension version)
btw the params are right here's the code
Code: Select all
[bits 16]
[org 0x7c00]
jmp start
nop
start:
mov ax,0
mov ds,ax
mov si,buffer
mov ah,0x48
mov dl,0x80
int 13h
jc end
cmp ah,0
jne end
jmp $
end:
mov si,ende
call bios_print
jmp $
bios_print:
push ax
push bx
ploop:
cld
lodsb
or al, al
jz short pstop
mov ah, 0eh
mov bx, 0007h
int 10h
jmp short ploop
pstop:
pop bx
pop ax
retn
ende db 13,'Err',0
buffer resb 100
times 510-($-$$) db 0
sig dw 0xAA55
Code: Select all
Only Human
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Hard Disk query
I had that feeling too, but the ataInterface.pdf i have here tagged it as "optional" ... however, i now realize that what i got (i think it was from OSRC) is not the _standard_ but a _working draft_ ... hence the differenceTim Robinson wrote: the standard says it is "Mandatory for all devices". Similarly IDENTIFY PACKET DEVICE (0xA1) is "Mandatory for devices implementing the PACKET Command feature".
Re:Hard Disk query
I'm working from release 7 of the standard. Maybe at some point it stopped being optional and became mandatory.
But then again, if it was ever optional: how could you ever know (in software) the parameters for a drive? I remember old drives used to have the C:H:S numbers written on top, and the really old ones were one of about 50 numbered hard drive types.
But then again, if it was ever optional: how could you ever know (in software) the parameters for a drive? I remember old drives used to have the C:H:S numbers written on top, and the really old ones were one of about 50 numbered hard drive types.
Re:Hard Disk query
I'm a bit confused about implementing the "identify drive command(0xEC)" the document says this
i then tried reading printing(also examining the memory) buffer variable but got nothing? so what's wrong here?
so if i'm correct then this buffer has to be read at once using the "read buffer command(0xE4)". Now the document says this about the "read buffer"When the host issues this command, the drive sets BUSY, stores the required parameter information in the sector buffer, sets DRQ and generates an interrupt. The host then reads the information from the sector buffer.
Considering this, is the algorithm below for identifying the drive parameters correct?When the host issues this command, the drive sets BUSY, sets up the sector buffer for a read operation, sets DRQ, clears BUSY, and generates an interrupt. The host then reads up to 512 bytes of data from the buffer.
Code: Select all
1) Issue an "Identify drive" command
2) when an IRQ is generated check to see if the previous command is an "Identify drive" command.
3) if so then issue a "Read Buffer" command.
4) when an IRQ is generated check to see if the previous command is a "Read Buffer" command.
5) if so read 512 bytes(1 sector) of data from the DATA register to a buffer variable
Only Human
Re:Hard Disk query
Go to this site it has asm code for harddrive and cddrive
detection.
http://www.singlix.com/trdos/ataid.html
It is written in masm, if you need a fasm conversion let me no.
detection.
http://www.singlix.com/trdos/ataid.html
It is written in masm, if you need a fasm conversion let me no.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Hard Disk query
@neo: you indeed got it wrong. the controller will send you an IRQ as soon as it made the "identify response" ready, and then you can read it through the data port *as if you sent a read-buffer* command, but you must not send a "read-buffer" command, or it will (in the best case) scratch the identify response the controller prepared for you ...
Re:Hard Disk query
Thanks Pype I'm able to read the parameters now.
I have another question now though. Among the parameters returned are CHS values in the "default translation" mode this gives me 16383,16,63 resply. Now this comes to an 8GB drive but its real capacity is much more than this(40GB). So if the controller returns the BIOS compatible CHS values then how do i get the real values so that i can write my own functions to read the HDD etc?
@ASHLEY:- any chance of getting the source in NASM, i can't understand the MASM one.
I have another question now though. Among the parameters returned are CHS values in the "default translation" mode this gives me 16383,16,63 resply. Now this comes to an 8GB drive but its real capacity is much more than this(40GB). So if the controller returns the BIOS compatible CHS values then how do i get the real values so that i can write my own functions to read the HDD etc?
@ASHLEY:- any chance of getting the source in NASM, i can't understand the MASM one.
Only Human
Re:Hard Disk query
Ignore the CHS values if the drive supports LBA. CHS is not supported at all in the latest ATA/ATAPI spec, and in previous versions LBA is preferred.
Re:Hard Disk query
how do i check if the drive supports LBA. and are there any LBA programming links you know?
Only Human
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Hard Disk query
check out the "capabilities" word in the identify sector (ATACAP_LBA is 512). then, set the LBA bit in the drive & head register and you can give LBA address instead of Cylinder:Head:Sector ...
LBA is fairly simple: it just gives each logical sector contiguous identifiers...
You should really refer to
http://www.t13.org/docs2002/d1410r3b.pdf (ATA/ATAPI-6) for more info about ATA-identify
LBA is fairly simple: it just gives each logical sector contiguous identifiers...
You should really refer to
http://www.t13.org/docs2002/d1410r3b.pdf (ATA/ATAPI-6) for more info about ATA-identify
Re:Hard Disk query
Going through Hales site he seems to favour CHS more than LBA saying that it in some cases this is even slower. So is it good trying to program the drive in LBA mode? is there anything else i need to know before i start trying LBA programming. and what about older 4GB drives etc?
@Pype The document at ttp://www.nondot.org/sabre/os/files/Disk/IDE-tech.html does not have any 'identify sector' command and nothing about any ATACAP_LBA word.(I'm downloading the doc at the URL you've given above I hope that has all this info).
@Pype The document at ttp://www.nondot.org/sabre/os/files/Disk/IDE-tech.html does not have any 'identify sector' command and nothing about any ATACAP_LBA word.(I'm downloading the doc at the URL you've given above I hope that has all this info).
Only Human