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

Last change on this file since 616 was 614, checked in by Krister Nordvall, 3 years ago

Changes:

  • BIOSDRVS should now build again (broke in r613).
  • Removed the NO_ATAID_CORRECTION define from the Tiny build.
  • Added a new configuration option to skip detection of slave drives.
  • Made FLASH_SIGNATURE 2 bytes shorter to free up ROM space.
  • "Auto Configure" in XTIDECFG should now detect if running on an Olivetti M24, AT&T PC6300, Xerox 6060 or Logabax Persona 1600 and automatically select the fastest compatible transfer mode/device type for any IDE controllers found in the system.
  • Cleaned out some duplicate/unused definitions.
File size: 9.3 KB
Line 
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-2013 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
22SECTION .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
43AtaID_PopESSIandFixIllegalValuesFromESSI:
44 pop si
45 pop es
46%endif
47AtaID_FixIllegalValuesFromESSI:
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 MIN_U WORD [es:si+ATA1.wCylCnt], MAX_PCHS_CYLINDERS ; Limit to max allowed value
52
53 ; Note! There are ATA ID words 54-58 that also need to be modified! However,
54 ; the drive itself should modify them when we do Initialize Device Parameters command at AH=9h.
55 ; Verification from real drive needed before we fix them manually
56
57 clc ; Return success
58.Return:
59 ret
60%endif ; NO_ATAID_CORRECTION
61
62
63%ifndef EXCLUDE_FROM_BIOSDRVS
64;--------------------------------------------------------------------
65; AtaID_VerifyFromESSI
66; Parameters:
67; ES:SI: Ptr to 512-byte ATA information read from the drive
68; Returns:
69; ZF: Set if ATA-ID verified successfully
70; Cleared if failed to verify ATA-ID
71; Corrupts registers:
72; AX, BX, CX
73;--------------------------------------------------------------------
74%ifndef NO_ATAID_VALIDATION
75AtaID_VerifyFromESSI:
76 ; We cannot start by reading ATA version since the ID might be
77 ; corrupted. We start by making sure P-CHS values are valid.
78 ; If they are, we assume the ATA ID to be valid. Fortunately we can do
79 ; further checking for ATA-5 and later since they contain signature and
80 ; checksum bytes. Those are not available for ATA-4 and older.
81
82 ; Verify P-CHS cylinders
83 mov bx, ATA1.wCylCnt
84 mov ax, MAX_PCHS_CYLINDERS
85 call .CompareCHorSfromOffsetBXtoMaxValueInAX
86
87 mov bl, ATA1.wHeadCnt & 0FFh
88 mov ax, MAX_PCHS_HEADS
89 call .CompareCHorSfromOffsetBXtoMaxValueInAX
90
91 mov bl, ATA1.wSPT & 0FFh
92 mov al, MAX_PCHS_SECTORS_PER_TRACK
93 call .CompareCHorSfromOffsetBXtoMaxValueInAX
94
95 ; Check signature byte. It is only found on ATA-5 and later. It should be zero on
96 ; ATA-4 and older.
97 mov al, [es:si+ATA6.bSignature]
98 test al, al
99 jz SHORT .AtaIDverifiedSuccessfully ; Old ATA so Signature and Checksum is not available
100 cmp al, A6_wIntegrity_SIGNATURE
101 jne SHORT .FailedToVerifyAtaID
102
103 ; Check checksum byte since signature was present
104 mov cx, ATA6_size
105 jmp Memory_SumCXbytesFromESSItoAL ; Returns with ZF set according to result
106
107;--------------------------------------------------------------------
108; .CompareCHorSfromOffsetBXtoMaxValueInAX
109; Parameters:
110; AX: Maximum valid C, H or S value
111; BX: C, H or S offset to ATA-ID
112; ES:SI: Ptr to 512-byte ATA information read from the drive
113; Returns:
114; Exits from AtaID_VerifyFromESSI with ZF cleared if invalid value
115; Corrupts registers:
116; CX
117;--------------------------------------------------------------------
118.CompareCHorSfromOffsetBXtoMaxValueInAX:
119 mov cx, [es:bx+si]
120 jcxz .InvalidPCHorSinOffsetBX
121 cmp cx, ax ; Compare to max valid value
122 jbe SHORT .ValidPCHorSinOffsetBX
123.InvalidPCHorSinOffsetBX:
124 pop cx ; Clear return address for this function
125 inc cx ; Clear ZF to indicate invalid ATA-ID (safe to do since return address in CX will never be FFFFh)
126.AtaIDverifiedSuccessfully:
127.FailedToVerifyAtaID:
128.ValidPCHorSinOffsetBX:
129 ret
130%endif ; NO_ATAID_VALIDATION
131
132
133;--------------------------------------------------------------------
134; Writes user defined limits from ROMVARS to ATA ID read from the drive.
135; Modifying the ATA ID reduces code and possibilities for bugs since
136; only little further checks are needed elsewhere.
137;
138; AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX
139; Parameters:
140; DS:DI: Ptr to incomplete Disk Parameter Table
141; ES:SI: Ptr to 512-byte ATA information read from the drive
142; CS:BP: Ptr to IDEVARS for the controller
143; Returns:
144; DX: User defined P-CHS to L-CHS translate mode
145; Corrupts registers:
146; AX, BX
147;--------------------------------------------------------------------
148AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX:
149 call AccessDPT_GetPointerToDRVPARAMStoCSBX
150 push ds
151
152 push cs
153 pop ds
154
155 ; Load User Defined CHS or LBA to BX:AX
156 mov dl, [bx+DRVPARAMS.wFlags] ; Only load the flags we actually need
157 mov ax, [bx+DRVPARAMS.wCylinders] ; Or .dwMaximumLBA
158 mov bx, [bx+DRVPARAMS.wHeadsAndSectors] ; Or .dwMaximumLBA+2
159
160 push es
161 pop ds ; DS:SI now points to ATA information
162
163 ; * User defined CHS *
164 test dl, FLG_DRVPARAMS_USERCHS
165 jz SHORT .NoUserDefinedCHS
166
167 ; Apply new CHS and disable LBA (we also want to set CHS addressing)
168 mov [si+ATA1.wCylCnt], ax
169 eMOVZX ax, bl
170 mov [si+ATA1.wHeadCnt], ax
171 mov al, bh
172 mov [si+ATA1.wSPT], ax
173 and BYTE [si+ATA1.wCaps+1], ~(A1_wCaps_LBA>>8)
174 and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
175.NoUserDefinedCHS:
176
177 ; * User defined LBA *
178 test dl, FLG_DRVPARAMS_USERLBA
179 jz SHORT .NoUserDefinedLBA
180
181 ; Apply new LBA and disable LBA48
182 cmp bx, [si+ATA1.dwLBACnt+2]
183 ja SHORT .NoUserDefinedLBA ; Do not set larger than drive
184 jb SHORT .StoreNewLBA
185 cmp ax, [si+ATA1.dwLBACnt]
186 ja SHORT .NoUserDefinedLBA ; Allow same size to disable LBA48
187.StoreNewLBA:
188 mov [si+ATA1.dwLBACnt], ax
189 mov [si+ATA1.dwLBACnt+2], bx
190 and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
191.NoUserDefinedLBA:
192
193 ; * Load P-CHS to L-CHS translate mode to DX *
194 and dx, BYTE MASK_DRVPARAMS_TRANSLATEMODE
195 eSHR_IM dx, TRANSLATEMODE_FIELD_POSITION
196
197 pop ds
198 ret
199
200
201%ifdef MODULE_ADVANCED_ATA
202;--------------------------------------------------------------------
203; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
204; Parameters:
205; ES:SI: Ptr to 512-byte ATA information read from the drive
206; Returns:
207; AL: Max supported PIO mode
208; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
209; CX: Minimum Cycle Time in nanosecs
210; Corrupts registers:
211; BX
212;--------------------------------------------------------------------
213AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
214 ; Get PIO mode and cycle time for PIO 0...2
215%ifdef USE_386
216 movzx ax, [es:si+ATA1.bPioMode] ; AH = 0, AL = PIO mode 0, 1 or 2
217%else
218 mov al, [es:si+ATA1.bPioMode]
219 cbw
220%endif
221 mov bx, ax
222 eSHL_IM bx, 1 ; Shift for WORD lookup
223 mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
224
225 ; Check if IORDY is supported
226 test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
227 jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
228 mov ah, FLGH_DPT_IORDY ; *FIXME* Actually, CF specification v4.1 says that use of IORDY is invalid for PIO modes 5 and 6.
229
230 ; Check if Advanced PIO modes are supported (3 and above)
231 test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
232 jz SHORT .ReturnPioTimings
233
234 ; Get Advanced PIO mode (Hard Disks supports up to 4 but CF cards can support 5 and 6)
235 or bh, [es:si+ATA2.bPIOSupp]
236 jz SHORT .ReturnPioTimings
237.CheckNextFlag:
238 inc ax
239 shr bh, 1
240 jnz SHORT .CheckNextFlag
241 MIN_U al, 6 ; Make sure not above lookup tables
242 mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
243.ReturnPioTimings:
244 ret
245
246.rgwPio0to2CycleTimeInNanosecs:
247 dw PIO_0_MIN_CYCLE_TIME_NS
248 dw PIO_1_MIN_CYCLE_TIME_NS
249 dw PIO_2_MIN_CYCLE_TIME_NS
250
251
252;--------------------------------------------------------------------
253; AtaID_GetActiveTimeToAXfromPioModeInBX
254; Parameters:
255; BX: PIO Mode
256; Returns:
257; AX: Active Time in nanosecs
258; Corrupts registers:
259; Nothing
260;--------------------------------------------------------------------
261AtaID_GetActiveTimeToAXfromPioModeInBX:
262 eMOVZX ax, [cs:bx+.rgbPioModeToActiveTimeNs]
263 ret
264
265.rgbPioModeToActiveTimeNs:
266 db PIO_0_MIN_ACTIVE_TIME_NS
267 db PIO_1_MIN_ACTIVE_TIME_NS
268 db PIO_2_MIN_ACTIVE_TIME_NS
269 db PIO_3_MIN_ACTIVE_TIME_NS
270 db PIO_4_MIN_ACTIVE_TIME_NS
271 db PIO_5_MIN_ACTIVE_TIME_NS
272 db PIO_6_MIN_ACTIVE_TIME_NS
273
274%endif ; MODULE_ADVANCED_ATA
275
276%endif ; EXCLUDE_FROM_BIOSDRVS
Note: See TracBrowser for help on using the repository browser.