OSDev.org
https://forum.osdev.org/

Hard Disk query
https://forum.osdev.org/viewtopic.php?f=1&t=9091
Page 1 of 3

Author:  Neo [ Sat Jan 17, 2004 12:43 am ]
Post subject:  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.

Author:  Pype.Clicker [ Sat Jan 17, 2004 5:15 am ]
Post subject:  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 ...

Author:  Tim [ Sat Jan 17, 2004 5:54 am ]
Post subject:  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.

Author:  Neo [ Sat Jan 17, 2004 11:27 am ]
Post subject:  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
Code:
AX=0x2100(Major version no.)
BX=0xAA55(success)
CX=0x5(support bitmap)
DX=0x80(extension version)

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
Code:
[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

is there anything wrong here? or is this an example of the problem with using the BIOS ints?
Code:

Author:  Pype.Clicker [ Sat Jan 17, 2004 2:30 pm ]
Post subject:  Re:Hard Disk query

Tim 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".


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 difference ;)

Author:  Tim [ Sat Jan 17, 2004 3:39 pm ]
Post subject:  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.

Author:  Neo [ Mon Jan 19, 2004 11:08 am ]
Post subject:  Re:Hard Disk query

I'm a bit confused about implementing the "identify drive command(0xEC)" the document says this
Quote:
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.

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"
Quote:
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.


Considering this, is the algorithm below for identifying the drive parameters correct?
Code:
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

i then tried reading printing(also examining the memory) buffer variable but got nothing? so what's wrong here?

Author:  ASHLEY4 [ Mon Jan 19, 2004 11:44 am ]
Post subject:  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.

Author:  Pype.Clicker [ Mon Jan 19, 2004 1:13 pm ]
Post subject:  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 ...

Author:  Neo [ Tue Jan 20, 2004 11:09 am ]
Post subject:  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.

Author:  Tim [ Tue Jan 20, 2004 11:58 am ]
Post subject:  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.

Author:  Neo [ Tue Jan 20, 2004 12:24 pm ]
Post subject:  Re:Hard Disk query

how do i check if the drive supports LBA. and are there any LBA programming links you know?

Author:  Pype.Clicker [ Tue Jan 20, 2004 3:43 pm ]
Post subject:  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

Author:  Neo [ Wed Jan 21, 2004 11:15 am ]
Post subject:  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).

Author:  Neo [ Fri Jan 23, 2004 11:20 am ]
Post subject:  Re:Hard Disk query

just wanted to know does the Execeute Diagnostic fire an IRQ?

Page 1 of 3 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/