Page 1 of 1

How get hard drive info from BIOS?

Posted: Sun Mar 06, 2016 9:26 am
by bilsch01
To write a partition table and format a hard drive I need to find the number of sectors info - hopefully BIOS has this info. Ralf Brown Int List says int 13h ah=15h returns # of sectors in cx:dx. I wrote code to access the info and it doesn't return a reasonable number (see code below). For a 320 GB internal hd on a laptop the value of cx:dx is 00000080h. RBIL is apparently wrong. How can I find the # of sectors? Also I need to determine how many hard drives and flash drives are attached at start up time. Also the number of sectors on a flash drive.

Thanks. Bill S.

Code: Select all

;dsecs.asm	nasm -f bin dsecs.asm -o dsecs.bin

bits 16
 org 0x7C00   ; add 0x7C00 to label addresses
    mov ax, 0  ; set up segments
   mov ds, ax
   mov es, ax
   mov ss, ax     ; setup stack
   mov sp, 0x7C00 ; stack grows downwards from 0x7C00
 
 	mov ah,0x15
	mov dl,0x80		;bit 7 = hd
	int 0x13		;returns #sectors in cx:dx
	push dx
	mov dx,cx		;operate on cx as dx
	xor cx,cx		;cx counts to 1
	mov bx,i2xt		;point to table
getcxdx:
	rol dx,4		;put hi hex digit on r. side
	and dl,0x0f		;get digit, put it in al
	mov al,dl		;index into table
	xlat			;table result in al
	mov ah,0xe			
	int 0x10		;write
	rol dx,4		;put next hex digit on r. side
	and dl,0x0f
	mov al,dl		;index into table			
	xlat			;table result in al
	mov ah,0xe			
	int 0x10		;write
	rol dx,4		;put next hex digit on r. side
	and dl,0x0f		;get digit
	mov al,dl		;index into table
	xlat			;table result in al
	mov ah,0xe			
	int 0x10		;write
	rol dl,4		;put next hex digit on r. side
	and dl,0x0f
	mov al,dl		;index into table			
	xlat			;table result in al
	mov ah,0xe			
	int 0x10		;write

	cmp cx,0
	jne crlf
	inc cx
	pop dx		
	jmp getcxdx
crlf:
	mov al,0xd		;go to left end
	mov ah,0xe		;
	int 0x10		;write
	mov al,0xa		;go to next line
	mov ah,0xe		;
	int 0x10		;write

i2xt	db	'0123456789ABCDEF'

Re: How get hard drive info from BIOS?

Posted: Sun Mar 06, 2016 2:46 pm
by BrightLight
Use INT 0x13 AH = 0x48.

Re: How get hard drive info from BIOS?

Posted: Sun Mar 06, 2016 3:31 pm
by Octocontrabass
bilsch01 wrote:Ralf Brown Int List says int 13h ah=15h returns # of sectors in cx:dx.
Not quite. It says INT 0x13 AH=0x15 returns the number of sectors in CX:DX, but only when it also returns CF clear and AH=0x03. Since you aren't checking the values of CF or AH, you have no way of knowing what the BIOS is trying to return.

Re: How get hard drive info from BIOS?

Posted: Sun Mar 06, 2016 3:42 pm
by bilsch01
Not quite. It says INT 0x13 AH=0x15 returns the number of sectors in CX:DX, but only when it also returns CF clear and AH=0x03. Since you aren't checking the values of CF or AH, you have no way of knowing what the BIOS is trying to return.
I checked AH and it is 0x01 - a floppy drive !

Re: How get hard drive info from BIOS?

Posted: Sun Mar 06, 2016 3:47 pm
by Octocontrabass
Did you also check CF?

Re: How get hard drive info from BIOS?

Posted: Sun Mar 06, 2016 3:59 pm
by bilsch01
omarrx024 wrote:Use INT 0x13 AH = 0x48.
It looks good - thanks.

Re: How get hard drive info from BIOS?

Posted: Mon Mar 07, 2016 6:25 am
by bilsch01
Octocontrabass wrote:Did you also check CF?
CF= 1. Therefore AH (drive type) = 01 is not drive type but an error code instead. I cant tell what it means because the link on the RBIL page went dead. The error is a disappointment because I wanted to experiment in real mode - which is not possible with int 13h/AH=48

Re: How get hard drive info from BIOS?

Posted: Mon Mar 07, 2016 7:31 am
by Octocontrabass
bilsch01 wrote:I cant tell what it means because the link on the RBIL page went dead.
I found this that says the error means "invalid function in AH or invalid parameter". Your BIOS probably doesn't support this function properly. It's a very uncommon function, so it's not surprising. (Most software uses INT 0x13 AH=0x08 or INT 0x13 AH=0x48.)
bilsch01 wrote:The error is a disappointment because I wanted to experiment in real mode - which is not possible with int 13h/AH=48
INT 0x13 AH=0x48 only works in real mode. You must be in real mode to use it.

You can also use INT 0x13 AH=0x08, but it doesn't support disks larger than about 8GB.