I am writing a simple bootloader with masm.
I add a disk in linux, use "fdisk -l" command, and see it contains 16 heads, 63 sectors per track, 406 cylinders.

And I found the linux kernel is in LBA sector 82569 on this disk, I use INT 13H, service 42H and LBA 82569 to read it, it returns correct kernel data.
But I use CHS to access the disk, due to LBA->CHS translation:
cylinder = LBA / (heads_per_cylinder * sectors_per_track)
temp = LBA % (heads_per_cylinder * sectors_per_track)
head = temp / sectors_per_track
sector = temp % sectors_per_track + 1

so, cylinder=82569/(16*63)=81, temp=82569%(16*63)=921
head=921/63=14, sector=921%63+1=40
the CHS is 81/14/40

But while I pass this CHS value to INT 13H,service 02H, it returns incorrect data.

I want to know whether the CHS value I calculated is the real CHS value should be passed to INT 13H, service 02H, if not, what's the correct CHS value.
Posted on 2007-06-02 06:54:20 by qexing
It looks like your calculation is correct from a brief glance over it.  All I can suggest is to make sure that you're following the slightly counter-intuitive format of storing the cylinders and sectors in CX:

              <--CH--> <--CL-->
cylinder bit: 76543210 98------
sector bit:  -------- --543210

Best of luck to ya!
Posted on 2007-06-05 02:15:12 by hackulous