1 | ; Project name : XTIDE Universal BIOS |
---|
2 | ; Description : Functions for accessing ATA information read with |
---|
3 | ; IDENTIFY DEVICE command. |
---|
4 | |
---|
5 | ; Section containing code |
---|
6 | SECTION .text |
---|
7 | |
---|
8 | ;-------------------------------------------------------------------- |
---|
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. |
---|
12 | ; |
---|
13 | ; total LBAs (as obtained by words 60+61) |
---|
14 | ; divided by 63 (sectors per track) (save as value A) |
---|
15 | ; Sub 1 from A |
---|
16 | ; divide A by 1024 + truncate. |
---|
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 |
---|
21 | ; to get the # of cylinders to use. |
---|
22 | ; |
---|
23 | ; |
---|
24 | ; so a LBA28 drive will have 268,435,456 as maximum LBAs |
---|
25 | ; |
---|
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 | ; |
---|
37 | ; AtaID_GetLbaAssistedCHStoDXAXBLBH: |
---|
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 | ;-------------------------------------------------------------------- |
---|
47 | AtaID_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 | ;-------------------------------------------------------------------- |
---|
96 | ; AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI |
---|
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 |
---|
101 | ; BH: Number of user specified P-CHS sectors per track |
---|
102 | ; BL: Number of user specified P-CHS heads |
---|
103 | ; Corrupts registers: |
---|
104 | ; Nothing |
---|
105 | ;-------------------------------------------------------------------- |
---|
106 | AtaID_GetPCHStoAXBLBHfromAtaInfoInESSI: |
---|
107 | mov ax, [es:si+ATA1.wCylCnt] ; Cylinders (1...16383) |
---|
108 | mov bl, [es:si+ATA1.wHeadCnt] ; Heads (1...16) |
---|
109 | mov bh, [es:si+ATA1.wSPT] ; Sectors per Track (1...63) |
---|
110 | ret |
---|
111 | |
---|
112 | |
---|
113 | ;-------------------------------------------------------------------- |
---|
114 | ; AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI |
---|
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 | ;-------------------------------------------------------------------- |
---|
122 | AtaID_GetTotalSectorCountToBXDXAXfromAtaInfoInESSI: |
---|
123 | mov bx, Registers_ExchangeDSSIwithESDI |
---|
124 | call bx ; ATA info now in DS:DI |
---|
125 | push bx ; We will return via Registers_ExchangeDSSIwithESDI |
---|
126 | xor bx, bx |
---|
127 | test BYTE [di+ATA1.wCaps+1], A1_wCaps_LBA>>8 |
---|
128 | jz SHORT .GetChsSectorCount |
---|
129 | ; Fall to .GetLbaSectorCount |
---|
130 | |
---|
131 | ;-------------------------------------------------------------------- |
---|
132 | ; .GetLbaSectorCount |
---|
133 | ; .GetLba28SectorCount |
---|
134 | ; .GetChsSectorCount |
---|
135 | ; Parameters: |
---|
136 | ; BX: Zero |
---|
137 | ; DS:DI: Ptr to 512-byte ATA information read from the drive |
---|
138 | ; Returns: |
---|
139 | ; BX:DX:AX: 48-bit sector count |
---|
140 | ; Corrupts registers: |
---|
141 | ; Nothing |
---|
142 | ;-------------------------------------------------------------------- |
---|
143 | .GetLbaSectorCount: |
---|
144 | test BYTE [di+ATA6.wSetSup83+1], A6_wSetSup83_LBA48>>8 |
---|
145 | jz SHORT .GetLba28SectorCount |
---|
146 | mov ax, [di+ATA6.qwLBACnt] |
---|
147 | mov dx, [di+ATA6.qwLBACnt+2] |
---|
148 | mov bx, [di+ATA6.qwLBACnt+4] |
---|
149 | ret |
---|
150 | |
---|
151 | .GetLba28SectorCount: |
---|
152 | mov ax, [di+ATA1.dwLBACnt] |
---|
153 | mov dx, [di+ATA1.dwLBACnt+2] |
---|
154 | ret |
---|
155 | |
---|
156 | .GetChsSectorCount: |
---|
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 |
---|
160 | ret |
---|