If you are new to OS Development, plan on spending some time here first before going into the other forums.
Moderator:Moderators
-
nikoj
- Posts:8
- Joined:Sat Oct 04, 2008 11:59 pm
LBA to CHS
Post
by nikoj » Sun Oct 05, 2008 12:11 am
http://www.brokenthorn.com/Resources/OSDev11.html
this tutorial confused me about tracks.in the tutorial the track is calculated with the formula:
absolute track = logical sector / (sectors per track * number of heads)
and it is written that 20-th sector "live" in sector 2, head 1, track 2.
if we use the formula, then the 20-th sector should be in sector 2, head 1, track 0.
is it a typo or i m wrong?
thanks
-
Andyhhp
- Moderator
- Posts:387
- Joined:Tue Oct 23, 2007 10:05 am
- Location:127.0.0.1
-
Contact:
Post
by Andyhhp » Sun Oct 05, 2008 11:19 am
Hi,
You seem to have some of your terminology confused.
CHS naming, is made of Cylinder, Head and Sector numbers.
Cylinder and Track mean almost the same thing, apart from the fact that Track refers to the current disk you are on whereas cylinder refers to all the 'same' tracks across all the disks (only applicable for Hard Disks which have more than 1 disk - ignore this for floppy drives)
Other than that, I would agree with you that this is probably a typo
Andrew
-
Mike
- Site Admin
- Posts:465
- Joined:Sat Oct 20, 2007 7:58 pm
-
Contact:
Post
by Mike » Sun Oct 05, 2008 2:47 pm
if we use the formula, then the 20-th sector should be in sector 2, head 1, track 0
How did you get that?
Code: Select all
absolute track = logical sector / (sectors per track * number of heads)
absolute track = 20 / (18 * 1)
absolute track = 20 / 18
absolute track = 1.1111111111111111111111111111111
...or, absolute track==1
and it is written that 20-th sector "live" in sector 2, head 1, track 2.
That looks like a typo
track should be 1 not 2. I'll see if I can fix that...
-
nikoj
- Posts:8
- Joined:Sat Oct 04, 2008 11:59 pm
Post
by nikoj » Mon Oct 06, 2008 12:59 am
another typo
standard 1.44mb floppy has 2 heads: head 0 and head 1
absolute track = 20 / (18 * 2)
absolute track = 20 / 36
absolute track = 0.555555555555555555555555555556
so track = 0
we can test this formula for correctness:
First we read track 0 head 0 sector 1 until we reach sector 18.
Next we read track 0 head 1 sector 1 until we reach sector 18, and so on...
here is the table
So our 20th sector should be in track 0 head 1 sector 2
Track 0 Head 0: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Track 0 Head 1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Track 1 Head 0: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
......
i guess now i m right
-
Andyhhp
- Moderator
- Posts:387
- Joined:Tue Oct 23, 2007 10:05 am
- Location:127.0.0.1
-
Contact:
Post
by Andyhhp » Tue Oct 07, 2008 10:10 am
Seconded - I agree with nikoj
-
Mike
- Site Admin
- Posts:465
- Joined:Sat Oct 20, 2007 7:58 pm
-
Contact:
Post
by Mike » Tue Oct 07, 2008 2:00 pm
You are correct - Ill see if I can fix those when I have the time
I actually want to update that tutorial as it has been skipped in the last revision as well.
-
nikoj
- Posts:8
- Joined:Sat Oct 04, 2008 11:59 pm
Post
by nikoj » Fri Oct 17, 2008 4:00 pm
huh, another dilemma
what if the logical sector is 36?
absolute sector = (logical sector / sectors per track) + 1
Code: Select all
LBA_to_CHS:
xor dx, dx
div word [SectorsPerTrack] ;36/18 = AX =2 DX =0
push ax
add dl, 1
mov cl, dl
pop ax
xor dx,dx
div word [Sides]
mov dh, dl
mov ch, al
mov dl, byte [drive_number]
ret
at the end... sector = 1 track=1 head = 0
and according the above table, this is wrong...
any discussion about this?