int 13h gets wrong disk geometry

I use bochs to run my own toy os. When it boots up, I use int 13h to

get some hard drive geometry info. However, the cylinder number seems

wrong.

Here's my code (written in NASM):

xor eax, eax

mov ah, 08h ; Code for drive parameters

mov dx, 80h ; hard drive

int 0x13

jb .hderr ; No such drive?

;; cylinder number

xor ax, ax ; ax <- 0

mov ah, cl ; ax <- cl

shr ah, 6

and ah, 3 ; cl bits 7-6: high two bits of

maximum cylinder number

mov al, ch ; CH = low eight bits of maximum

cylinder number

;; sector number

and cl, 3Fh ; cl bits 5-0: max sector number (1-

origin)

;; head number

inc dh ; dh = 1 + max head number (0-origin)

mov [_dwNrHead], dh

mov [_dwNrSector], cl

mov [_dwNrCylinder], ax

jmp .hdok

..hderr:

... ... ...

..hdok:

Here's what I get: Cylinder: 404, Head: 16, Sector: 63

and here's ata configuration in the bochsrc:

ata0-master: type=disk, path="hd.img", mode=flat, cylinders=406,

heads=16, spt=63

Why the int 13h gets 404 but not 406??

Thank you in advance.

Forrest

Re: int 13h gets wrong disk geometry

forrest <forrest.yu@gmail.com> writes:[color=blue]

> and ah, 3 ; cl bits 7-6: high two bits of maximum cylinder number

> mov al, ch ; CH = low eight bits of maximum cylinder number

>

> Here's what I get: Cylinder: 404, Head: 16, Sector: 63

>

> and here's ata configuration in the bochsrc:

>

> ata0-master: type=disk, path="hd.img", mode=flat, cylinders=406,

> heads=16, spt=63

>

> Why the int 13h gets 404 but not 406??[/color]

Out by one is perfectly understandable, and expected, as a

maximum cylinder number would be one less than the number

of cylinders, as 0 is a valid cylinder number. Out by two

is a bit curious tho'.

Phil

--

Dear aunt, let's set so double the killer delete select all.

-- Microsoft voice recognition live demonstration