Page 1 of 1

Floppy LBA to CHS

Posted: Sat Nov 19, 2005 3:01 am
by pradeep
I used the following LBA to CHS code. It's working fine in Bochs. In real hardware there seems to be problem when LBA value is >= 9000 (LBA sector count >= 46). The LBA to CHS routine converts this LBA value into
02 - track(cylinder)
01 - sector
00 - head
Assume 18 sectors per track.
I am having doubt with the head value since it is 1 for LBA Sector value < 71. But if it is wrong how can bochs display the file correctly? I am confused with LBA to CHS translation. I just adopted an LBAtoCHS tutorial.

Code: Select all

LBAtoCHS:
;[in AX=LBA Sector]
;[out DX,CX]
   xor     cx,cx
   xor     dx,dx
   div   word [BOOT_SECTOR.sectorspertrack]
   inc     dx                    
   mov     cl,dl   ;sectors
   xor     dx,dx
   div   word [BOOT_SECTOR.heads]
   mov     dh,dl   ;head
   mov     ch,al   ;track
   xor     dl,dl   ;drive
         ret 

Re:Floppy LBA to CHS

Posted: Sat Nov 19, 2005 6:49 am
by Brendan
Hi,

If the LBA is 9216 then (for a 1440 KB floppy) you'd get sector 1, head 0 and cylinder 256. Cylinder number 256 doesn't fit into CH, so it'd be truncated to zero.

Of course this is way past the end of the floppy - the last sector of a 1440 KB floppy would have LBA 2879 (or cylinder 79, head 1, sector 18).

The LBA to CHS conversion code looks fine for floppies. For hard drives the highest 2 bits of the (10 bit) cylinder number is put in the highest 2 bits of CL. This allows for up to 1024 cylinders and limits it to 63 sectors per track.


Cheers,

Brendan

Re:Floppy LBA to CHS

Posted: Sun Nov 20, 2005 1:04 am
by pradeep
The error found was WCYL(Wrong cylinder) in ResultST2 and No data in ResultST1, ResultST0 contains the value 0x40 i.e Abnormal Termination. Cylinder 2,head 0,Sector 1 is the CHS value. For cylinder 2 the error occurs. I am talking about the LBA 0x48.
Brendan: I should have confused you with 0x9000. It is nothing but 0x48 * 512 bytes. I haven't even read the 2 cylinder itself.

Re:Floppy LBA to CHS

Posted: Sun Nov 20, 2005 12:59 pm
by Brendan
Hi,
pradeep wrote: The error found was WCYL(Wrong cylinder) in ResultST2 and No data in ResultST1, ResultST0 contains the value 0x40 i.e Abnormal Termination. Cylinder 2,head 0,Sector 1 is the CHS value. For cylinder 2 the error occurs. I am talking about the LBA 0x48.
Brendan: I should have confused you with 0x9000. It is nothing but 0x48 * 512 bytes. I haven't even read the 2 cylinder itself.
I still can't find anything wrong with the LBA -> CHS conversion code itself. Are you sure the problem isn't somewhere else?


Cheers,

Brendan

Re:Floppy LBA to CHS

Posted: Sun Nov 20, 2005 1:11 pm
by Candy
You could check what the code exactly dumps by using the Bochs debugger after the conversion runs, so you can check whether it gives the right result.

Re:Floppy LBA to CHS

Posted: Tue Nov 22, 2005 3:53 am
by pradeep
Bochs doesn't say any problems.
Bochs is displaying the contents correctly and no problem in bochs. But these problems happen in real hardware. So i couldn't debug. If something works in Bochs and not in real hardware means it is mostly because of delay.Suppose that there is a problem with seek, it would generate an error after timeout. Those timeout error also doesn't occurs.
Since i am implementing(...) vfs it's hard to debug

Re:Floppy LBA to CHS

Posted: Wed Nov 23, 2005 12:11 am
by pradeep
Could the problem be that delay is not introduced in proper position. fdc driver reads track 0,1 but not track >=2 while both bochs and vmware reads it happily for me. Seek operation is success and after issuing read command it waits for an interrupt to happen. should there be any delays inserted. Soon i will check it on other test system.

<edited on 30/11/05>
The problem is related to driver implementation. It works without any problem when called directly. But if i make call through VFS this problem occurs. First of all i have to implement VFS completely, Anyway thanks for those guys who answered for this thread.
</edited on 30/11/05>