How get hard drive info from BIOS?

Programming, for all ages and all languages.
Post Reply
bilsch01
Member
Member
Posts: 42
Joined: Sat Dec 19, 2015 10:48 am

How get hard drive info from BIOS?

Post 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'
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How get hard drive info from BIOS?

Post by BrightLight »

Use INT 0x13 AH = 0x48.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: How get hard drive info from BIOS?

Post 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.
bilsch01
Member
Member
Posts: 42
Joined: Sat Dec 19, 2015 10:48 am

Re: How get hard drive info from BIOS?

Post 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 !
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: How get hard drive info from BIOS?

Post by Octocontrabass »

Did you also check CF?
bilsch01
Member
Member
Posts: 42
Joined: Sat Dec 19, 2015 10:48 am

Re: How get hard drive info from BIOS?

Post by bilsch01 »

omarrx024 wrote:Use INT 0x13 AH = 0x48.
It looks good - thanks.
bilsch01
Member
Member
Posts: 42
Joined: Sat Dec 19, 2015 10:48 am

Re: How get hard drive info from BIOS?

Post 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
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: How get hard drive info from BIOS?

Post 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.
Post Reply