OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 1:14 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How get hard drive info from BIOS?
PostPosted: Sun Mar 06, 2016 9:26 am 
Offline
Member
Member

Joined: Sat Dec 19, 2015 10:48 am
Posts: 42
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:
;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'


Top
 Profile  
 
 Post subject: Re: How get hard drive info from BIOS?
PostPosted: Sun Mar 06, 2016 2:46 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
Use INT 0x13 AH = 0x48.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: How get hard drive info from BIOS?
PostPosted: Sun Mar 06, 2016 3:31 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
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.


Top
 Profile  
 
 Post subject: Re: How get hard drive info from BIOS?
PostPosted: Sun Mar 06, 2016 3:42 pm 
Offline
Member
Member

Joined: Sat Dec 19, 2015 10:48 am
Posts: 42
Quote:
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 !


Top
 Profile  
 
 Post subject: Re: How get hard drive info from BIOS?
PostPosted: Sun Mar 06, 2016 3:47 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
Did you also check CF?


Top
 Profile  
 
 Post subject: Re: How get hard drive info from BIOS?
PostPosted: Sun Mar 06, 2016 3:59 pm 
Offline
Member
Member

Joined: Sat Dec 19, 2015 10:48 am
Posts: 42
omarrx024 wrote:
Use INT 0x13 AH = 0x48.


It looks good - thanks.


Top
 Profile  
 
 Post subject: Re: How get hard drive info from BIOS?
PostPosted: Mon Mar 07, 2016 6:25 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: How get hard drive info from BIOS?
PostPosted: Mon Mar 07, 2016 7:31 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group