1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for accessing ATA information read with
|
---|
3 | ; IDENTIFY DEVICE command.
|
---|
4 |
|
---|
5 | ;
|
---|
6 | ; XTIDE Universal BIOS and Associated Tools
|
---|
7 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2023 by XTIDE Universal BIOS Team.
|
---|
8 | ;
|
---|
9 | ; This program is free software; you can redistribute it and/or modify
|
---|
10 | ; it under the terms of the GNU General Public License as published by
|
---|
11 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
12 | ; (at your option) any later version.
|
---|
13 | ;
|
---|
14 | ; This program is distributed in the hope that it will be useful,
|
---|
15 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | ; GNU General Public License for more details.
|
---|
18 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
19 | ;
|
---|
20 |
|
---|
21 | ; Section containing code
|
---|
22 | SECTION .text
|
---|
23 |
|
---|
24 | ;--------------------------------------------------------------------
|
---|
25 | ; Adjust ATA information for compatibility, debug, etc purposes.
|
---|
26 | ; We can also completely ignore the drive if necessary.
|
---|
27 | ;
|
---|
28 | ; AtaID_FixIllegalValuesFromESSI
|
---|
29 | ; Parameters:
|
---|
30 | ; AH: INT 13h Error Code from reading ATA information
|
---|
31 | ; CF: Cleared if successfully read ATA information,
|
---|
32 | ; Set if failed to read ATA information
|
---|
33 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
34 | ; Returns:
|
---|
35 | ; ES:SI: Ata information with possible corrections made
|
---|
36 | ; AH: INT 13h Error Code from reading ATA information
|
---|
37 | ; CF Cleared if drive now accepted
|
---|
38 | ; Corrupts registers:
|
---|
39 | ; AL, BX, CX, DX, DI
|
---|
40 | ;--------------------------------------------------------------------
|
---|
41 | %ifndef NO_ATAID_CORRECTION
|
---|
42 | %ifndef EXCLUDE_FROM_BIOSDRVS
|
---|
43 | AtaID_PopESSIandFixIllegalValuesFromESSI:
|
---|
44 | pop si
|
---|
45 | pop es
|
---|
46 | %endif
|
---|
47 | AtaID_FixIllegalValuesFromESSI: ; Unused entrypoint OK
|
---|
48 | jc SHORT .Return ; Nothing to fix since failed to read ATA Info
|
---|
49 |
|
---|
50 | ; Only correct cylinders since there are no reports that head or sectors could be wrong
|
---|
51 | mov cx, MAX_PCHS_CYLINDERS
|
---|
52 | MIN_U [es:si+ATA1.wCylCnt], cx ; Limit to max allowed value
|
---|
53 |
|
---|
54 | ; Note! There are ATA ID words 54-58 that also need to be modified! However,
|
---|
55 | ; the drive itself should modify them when we do Initialize Device Parameters command at AH=9h.
|
---|
56 | ; Verification from real drive needed before we fix them manually
|
---|
57 |
|
---|
58 | clc ; Return success
|
---|
59 | .Return:
|
---|
60 | ret
|
---|
61 | %endif ; NO_ATAID_CORRECTION
|
---|
62 |
|
---|
63 |
|
---|
64 | %ifndef EXCLUDE_FROM_BIOSDRVS
|
---|
65 | ;--------------------------------------------------------------------
|
---|
66 | ; AtaID_VerifyFromESSI
|
---|
67 | ; Parameters:
|
---|
68 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
69 | ; Returns:
|
---|
70 | ; ZF: Set if ATA-ID verified successfully
|
---|
71 | ; Cleared if failed to verify ATA-ID
|
---|
72 | ; Corrupts registers:
|
---|
73 | ; AX, BX, CX
|
---|
74 | ;--------------------------------------------------------------------
|
---|
75 | %ifndef NO_ATAID_VALIDATION
|
---|
76 | AtaID_VerifyFromESSI:
|
---|
77 | ; We cannot start by reading ATA version since the ID might be
|
---|
78 | ; corrupted. We start by making sure P-CHS values are valid.
|
---|
79 | ; If they are, we assume the ATA ID to be valid. Fortunately we can do
|
---|
80 | ; further checking for ATA-5 and later since they contain signature and
|
---|
81 | ; checksum bytes. Those are not available for ATA-4 and older.
|
---|
82 |
|
---|
83 | ; Verify P-CHS cylinders
|
---|
84 | mov bx, ATA1.wCylCnt
|
---|
85 | mov ax, MAX_PCHS_CYLINDERS
|
---|
86 | call .CompareCHorSfromOffsetBXtoMaxValueInAX
|
---|
87 |
|
---|
88 | mov bl, ATA1.wHeadCnt & 0FFh
|
---|
89 | mov ax, MAX_PCHS_HEADS
|
---|
90 | call .CompareCHorSfromOffsetBXtoMaxValueInAX
|
---|
91 |
|
---|
92 | mov bl, ATA1.wSPT & 0FFh
|
---|
93 | mov al, MAX_PCHS_SECTORS_PER_TRACK
|
---|
94 | call .CompareCHorSfromOffsetBXtoMaxValueInAX
|
---|
95 |
|
---|
96 | ; Check signature byte. It is only found on ATA-5 and later. It should be zero on
|
---|
97 | ; ATA-4 and older.
|
---|
98 | mov al, [es:si+ATA6.bSignature]
|
---|
99 | test al, al
|
---|
100 | jz SHORT .AtaIDverifiedSuccessfully ; Old ATA so Signature and Checksum is not available
|
---|
101 | cmp al, A6_wIntegrity_SIGNATURE
|
---|
102 | jne SHORT .FailedToVerifyAtaID
|
---|
103 |
|
---|
104 | ; Check checksum byte since signature was present
|
---|
105 | mov cx, ATA6_size
|
---|
106 | jmp Memory_SumCXbytesFromESSItoAL ; Returns with ZF set according to result
|
---|
107 |
|
---|
108 | ;--------------------------------------------------------------------
|
---|
109 | ; .CompareCHorSfromOffsetBXtoMaxValueInAX
|
---|
110 | ; Parameters:
|
---|
111 | ; AX: Maximum valid C, H or S value
|
---|
112 | ; BX: C, H or S offset to ATA-ID
|
---|
113 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
114 | ; Returns:
|
---|
115 | ; Exits from AtaID_VerifyFromESSI with ZF cleared if invalid value
|
---|
116 | ; Corrupts registers:
|
---|
117 | ; CX
|
---|
118 | ;--------------------------------------------------------------------
|
---|
119 | .CompareCHorSfromOffsetBXtoMaxValueInAX:
|
---|
120 | mov cx, [es:bx+si]
|
---|
121 | jcxz .InvalidPCHorSinOffsetBX
|
---|
122 | cmp cx, ax ; Compare to max valid value
|
---|
123 | jbe SHORT .ValidPCHorSinOffsetBX
|
---|
124 | .InvalidPCHorSinOffsetBX:
|
---|
125 | pop cx ; Clear return address for this function
|
---|
126 | inc cx ; Clear ZF to indicate invalid ATA-ID (safe to do since return address in CX will never be FFFFh)
|
---|
127 | .AtaIDverifiedSuccessfully:
|
---|
128 | .FailedToVerifyAtaID:
|
---|
129 | .ValidPCHorSinOffsetBX:
|
---|
130 | ret
|
---|
131 | %endif ; NO_ATAID_VALIDATION
|
---|
132 |
|
---|
133 |
|
---|
134 | ;--------------------------------------------------------------------
|
---|
135 | ; Writes user defined limits from ROMVARS to ATA ID read from the drive.
|
---|
136 | ; Modifying the ATA ID reduces code and possibilities for bugs since
|
---|
137 | ; only little further checks are needed elsewhere.
|
---|
138 | ;
|
---|
139 | ; AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX
|
---|
140 | ; Parameters:
|
---|
141 | ; DS:DI: Ptr to incomplete Disk Parameter Table
|
---|
142 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
143 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
144 | ; Returns:
|
---|
145 | ; DX: User defined P-CHS to L-CHS translate mode
|
---|
146 | ; Corrupts registers:
|
---|
147 | ; AX, BX
|
---|
148 | ;--------------------------------------------------------------------
|
---|
149 | AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX:
|
---|
150 | call AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
151 | push ds
|
---|
152 |
|
---|
153 | push cs
|
---|
154 | pop ds
|
---|
155 |
|
---|
156 | ; Load User Defined CHS or LBA to BX:AX
|
---|
157 | mov dl, [bx+DRVPARAMS.wFlags] ; Only load the flags we actually need
|
---|
158 | mov ax, [bx+DRVPARAMS.wCylinders] ; Or .dwMaximumLBA
|
---|
159 | mov bx, [bx+DRVPARAMS.wHeadsAndSectors] ; Or .dwMaximumLBA+2
|
---|
160 |
|
---|
161 | push es
|
---|
162 | pop ds ; DS:SI now points to ATA information
|
---|
163 |
|
---|
164 | ; * User defined CHS *
|
---|
165 | test dl, FLG_DRVPARAMS_USERCHS
|
---|
166 | jz SHORT .NoUserDefinedCHS
|
---|
167 |
|
---|
168 | ; Apply new CHS and disable LBA (we also want to set CHS addressing)
|
---|
169 | mov [si+ATA1.wCylCnt], ax
|
---|
170 | eMOVZX ax, bl
|
---|
171 | mov [si+ATA1.wHeadCnt], ax
|
---|
172 | mov al, bh
|
---|
173 | mov [si+ATA1.wSPT], ax
|
---|
174 | and BYTE [si+ATA1.wCaps+1], ~(A1_wCaps_LBA>>8)
|
---|
175 | and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
|
---|
176 | .NoUserDefinedCHS:
|
---|
177 |
|
---|
178 | ; * User defined LBA *
|
---|
179 | test dl, FLG_DRVPARAMS_USERLBA
|
---|
180 | jz SHORT .NoUserDefinedLBA
|
---|
181 |
|
---|
182 | ; Apply new LBA and disable LBA48
|
---|
183 | cmp bx, [si+ATA1.dwLBACnt+2]
|
---|
184 | ja SHORT .NoUserDefinedLBA ; Do not set larger than drive
|
---|
185 | jb SHORT .StoreNewLBA
|
---|
186 | cmp ax, [si+ATA1.dwLBACnt]
|
---|
187 | ja SHORT .NoUserDefinedLBA ; Allow same size to disable LBA48
|
---|
188 | .StoreNewLBA:
|
---|
189 | mov [si+ATA1.dwLBACnt], ax
|
---|
190 | mov [si+ATA1.dwLBACnt+2], bx
|
---|
191 | and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
|
---|
192 | .NoUserDefinedLBA:
|
---|
193 |
|
---|
194 | ; * Load P-CHS to L-CHS translate mode to DX *
|
---|
195 | and dx, BYTE MASK_DRVPARAMS_TRANSLATEMODE
|
---|
196 | eSHR_IM dx, TRANSLATEMODE_FIELD_POSITION
|
---|
197 |
|
---|
198 | pop ds
|
---|
199 | ret
|
---|
200 |
|
---|
201 |
|
---|
202 | %ifdef MODULE_ADVANCED_ATA
|
---|
203 | ;--------------------------------------------------------------------
|
---|
204 | ; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
|
---|
205 | ; Parameters:
|
---|
206 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
207 | ; Returns:
|
---|
208 | ; AL: Max supported PIO mode
|
---|
209 | ; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
|
---|
210 | ; CX: Minimum Cycle Time in nanosecs
|
---|
211 | ; Corrupts registers:
|
---|
212 | ; BX
|
---|
213 | ;--------------------------------------------------------------------
|
---|
214 | AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
|
---|
215 | ; Get PIO mode and cycle time for PIO 0...2
|
---|
216 | %ifdef USE_386
|
---|
217 | movzx ax, [es:si+ATA1.bPioMode] ; AH = 0, AL = PIO mode 0, 1 or 2
|
---|
218 | %else
|
---|
219 | mov al, [es:si+ATA1.bPioMode]
|
---|
220 | cbw
|
---|
221 | %endif
|
---|
222 | mov bx, ax
|
---|
223 | eSHL_IM bx, 1 ; Shift for WORD lookup
|
---|
224 | mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
|
---|
225 |
|
---|
226 | ; Check if IORDY is supported
|
---|
227 | test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
|
---|
228 | jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
|
---|
229 | mov ah, FLGH_DPT_IORDY ; *FIXME* Actually, CF specification v4.1 says that use of IORDY is invalid for PIO modes 5 and 6.
|
---|
230 |
|
---|
231 | ; Check if Advanced PIO modes are supported (3 and above)
|
---|
232 | test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
|
---|
233 | jz SHORT .ReturnPioTimings
|
---|
234 |
|
---|
235 | ; Get Advanced PIO mode (Hard Disks supports up to 4 but CF cards can support 5 and 6)
|
---|
236 | or bh, [es:si+ATA2.bPIOSupp]
|
---|
237 | jz SHORT .ReturnPioTimings
|
---|
238 | .CheckNextFlag:
|
---|
239 | inc ax
|
---|
240 | shr bh, 1
|
---|
241 | jnz SHORT .CheckNextFlag
|
---|
242 | MIN_U al, 6 ; Make sure not above lookup tables
|
---|
243 | mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
|
---|
244 | .ReturnPioTimings:
|
---|
245 | ret
|
---|
246 |
|
---|
247 | .rgwPio0to2CycleTimeInNanosecs:
|
---|
248 | dw PIO_0_MIN_CYCLE_TIME_NS
|
---|
249 | dw PIO_1_MIN_CYCLE_TIME_NS
|
---|
250 | dw PIO_2_MIN_CYCLE_TIME_NS
|
---|
251 |
|
---|
252 |
|
---|
253 | ;--------------------------------------------------------------------
|
---|
254 | ; AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
255 | ; Parameters:
|
---|
256 | ; BX: PIO Mode
|
---|
257 | ; Returns:
|
---|
258 | ; AX: Active Time in nanosecs
|
---|
259 | ; Corrupts registers:
|
---|
260 | ; Nothing
|
---|
261 | ;--------------------------------------------------------------------
|
---|
262 | AtaID_GetActiveTimeToAXfromPioModeInBX:
|
---|
263 | eMOVZX ax, [cs:bx+.rgbPioModeToActiveTimeNs]
|
---|
264 | ret
|
---|
265 |
|
---|
266 | .rgbPioModeToActiveTimeNs:
|
---|
267 | db PIO_0_MIN_ACTIVE_TIME_NS
|
---|
268 | db PIO_1_MIN_ACTIVE_TIME_NS
|
---|
269 | db PIO_2_MIN_ACTIVE_TIME_NS
|
---|
270 | db PIO_3_MIN_ACTIVE_TIME_NS
|
---|
271 | db PIO_4_MIN_ACTIVE_TIME_NS
|
---|
272 | db PIO_5_MIN_ACTIVE_TIME_NS
|
---|
273 | db PIO_6_MIN_ACTIVE_TIME_NS
|
---|
274 |
|
---|
275 | %endif ; MODULE_ADVANCED_ATA
|
---|
276 |
|
---|
277 | %endif ; EXCLUDE_FROM_BIOSDRVS
|
---|