source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Initialization/AtaID.asm@ 285

Last change on this file since 285 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 5.1 KB
RevLine 
[99]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for accessing ATA information read with
3; IDENTIFY DEVICE command.
4
5; Section containing code
6SECTION .text
7
8;--------------------------------------------------------------------
[173]9; LBA assist calculation:
10; this is how to fit a big drive into INT13's skimpy size requirements,
11; with a maximum of 8.4G available.
[174]12;
13; total LBAs (as obtained by words 60+61)
[173]14; divided by 63 (sectors per track) (save as value A)
15; Sub 1 from A
[174]16; divide A by 1024 + truncate.
[173]17; == total number of heads to use.
18; add 1
19; this value must be either 16, 32, 64, 128, or 256 (round up)
20; then take the value A above and divide by # of heads
[174]21; to get the # of cylinders to use.
[173]22;
23;
24; so a LBA28 drive will have 268,435,456 as maximum LBAs
[174]25;
[173]26; 10000000h / 63 = 410410h (total cylinders or tracks)
27; 410410h / 1024 = 1041h, which is way more than 256 heads, but 256 is max.
28; 410410h / 256 = 4104h cylinders
29;
30; there's a wealth of information at: http://www.mossywell.com/boot-sequence
31; they show a slightly different approach to LBA assist calulations, but
32; the method here provides compatibility with phoenix BIOS
33;
34; we're using the values from 60+61 here because we're topping out at 8.4G
35; anyway, so there's no need to use the 48bit LBA values.
36;
[174]37; AtaID_GetLbaAssistedCHStoDXAXBLBH:
[173]38; Parameters:
39; BX:DX:AX: Total number of sectors
40; Returns:
41; DX:AX: Number of cylinders
42; BH: Number of sectors per track (always 63)
43; BL: Number of heads (16, 32, 64, 128 or 255)
44; Corrupts registers:
45; CX
46;--------------------------------------------------------------------
47AtaID_GetLbaAssistedCHStoDXAXBLBH:
48 push bp
49 push si
50
51 ; Value A = Total sector count / 63
52 xor cx, cx
53 push cx ; Push zero for bits 48...63
54 push bx
55 push dx
56 push ax ; 64-bit sector count now in stack
57 mov cl, LBA_ASSIST_SPT
58 mov bp, sp ; SS:BP now points sector count
59 call Math_DivQWatSSBPbyCX ; Temporary value A now in stack
60
61 ; BX = Number of heads = A / 1024
62 mov ax, [bp]
63 mov dx, [bp+2]
64 mov bx, [bp+4]
65 call Size_DivideSizeInBXDXAXby1024andIncrementMagnitudeInCX
66
67 ; Heads must be 16, 32, 64, 128 or 256 (round up)
68 mov bx, 256 ; Max number of heads
69 test dx, dx ; 65536 or more heads?
70 jnz SHORT .GetNumberOfCylinders
71 mov cx, 128 ; Half BX for rounding up
72.FindMostSignificantBitForHeadSize:
73 cmp ax, cx
74 jae SHORT .GetNumberOfCylinders
75 shr cx, 1
76 shr bx, 1 ; Halve number of heads
77 jmp SHORT .FindMostSignificantBitForHeadSize
78
79 ; DX:AX = Number of cylinders = A / number of heads
80.GetNumberOfCylinders:
81 mov cx, bx
82 call Math_DivQWatSSBPbyCX
83 mov ax, [bp]
84 mov dx, [bp+2] ; Cylinders now in DX:AX
85
86 ; Return LBA assisted CHS
87 add sp, BYTE 8 ; Clean stack
88 sub bl, bh ; Limit heads to 255
89 mov bh, LBA_ASSIST_SPT
90 pop si
91 pop bp
92 ret
93
94
95;--------------------------------------------------------------------
[169]96; AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI
[3]97; Parameters:
98; ES:SI: Ptr to 512-byte ATA information read from the drive
99; Returns:
100; AX: Number of user specified P-CHS cylinders
[99]101; BH: Number of user specified P-CHS sectors per track
102; BL: Number of user specified P-CHS heads
[3]103; Corrupts registers:
104; Nothing
105;--------------------------------------------------------------------
[169]106AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI:
[3]107 mov ax, [es:si+ATA1.wCylCnt] ; Cylinders (1...16383)
[99]108 mov bl, [es:si+ATA1.wHeadCnt] ; Heads (1...16)
109 mov bh, [es:si+ATA1.wSPT] ; Sectors per Track (1...63)
[3]110 ret
111
112
113;--------------------------------------------------------------------
[165]114; AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI
[3]115; Parameters:
116; ES:SI: Ptr to 512-byte ATA information read from the drive
117; Returns:
118; BX:DX:AX: 48-bit sector count
119; Corrupts registers:
120; Nothing
121;--------------------------------------------------------------------
[165]122AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI:
[181]123 mov bx, Registers_ExchangeDSSIwithESDI
124 call bx ; ATA info now in DS:DI
125 push bx ; We will return via Registers_ExchangeDSSIwithESDI
[3]126 xor bx, bx
[173]127 test BYTE [di+ATA1.wCaps+1], A1_wCaps_LBA>>8
[99]128 jz SHORT .GetChsSectorCount
129 ; Fall to .GetLbaSectorCount
[3]130
131;--------------------------------------------------------------------
[99]132; .GetLbaSectorCount
[173]133; .GetLba28SectorCount
134; .GetChsSectorCount
[3]135; Parameters:
136; BX: Zero
[181]137; DS:DI: Ptr to 512-byte ATA information read from the drive
[3]138; Returns:
139; BX:DX:AX: 48-bit sector count
140; Corrupts registers:
141; Nothing
142;--------------------------------------------------------------------
[99]143.GetLbaSectorCount:
[173]144 test BYTE [di+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8
[3]145 jz SHORT .GetLba28SectorCount
[173]146 mov ax, [di+ATA6.qwLBACnt]
147 mov dx, [di+ATA6.qwLBACnt+2]
148 mov bx, [di+ATA6.qwLBACnt+4]
[181]149 ret
[173]150
[3]151.GetLba28SectorCount:
[173]152 mov ax, [di+ATA1.dwLBACnt]
153 mov dx, [di+ATA1.dwLBACnt+2]
[181]154 ret
[3]155
[99]156.GetChsSectorCount:
[173]157 mov al, [di+ATA1.wSPT] ; AL=Sectors per track
158 mul BYTE [di+ATA1.wHeadCnt] ; AX=Sectors per track * number of heads
159 mul WORD [di+ATA1.wCylCnt] ; DX:AX=Sectors per track * number of heads * number of cylinders
[181]160 ret
Note: See TracBrowser for help on using the repository browser.