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

Last change on this file since 577 was 568, checked in by krille_n_@…, 10 years ago

Changes:

  • SerDrive: Using named pipe mode (serdrive -p) now works under Windows XP/2000/Server 2003.
  • checksum.pl: Added a compatibility fix for 3Com 3C503 cards.
  • XTIDECFG will now scan every possible segment address to find and load the BIOS and/or its settings from EEPROM. This should simplify things for people using combined option ROMs.
  • Fixed a bug from r521 in BootSector.asm where the BIOS would not display a timeout error if it failed to load the boot sector from harddrive.
  • Fixed a bug from r541 in CompatibleDPT.asm where CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI would generate an invalid checksum in the DPTE.
  • Optimizations and other fixes.
File size: 8.4 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; AtaID_VerifyFromESSI
26; Parameters:
27; ES:SI: Ptr to 512-byte ATA information read from the drive
28; Returns:
29; ZF: Set if ATA-ID verified successfully
30; Cleared if failed to verify ATA-ID
31; Corrupts registers:
32; AX, BX, CX
33;--------------------------------------------------------------------
34AtaID_VerifyFromESSI:
35 ; We cannot start by reading ATA version since the ID might be
36 ; corrupted. We start by making sure P-CHS values are valid.
37 ; If they are, we assume the ATA ID to be valid. Fortunately we can do
38 ; further checking for ATA-5 and later since they contain signature and
39 ; checksum bytes. Those are not available for ATA-4 and older.
40
41 ; Verify P-CHS cylinders
42 mov bx, ATA1.wCylCnt
43 mov ax, MAX_VALID_PCHS_CYLINDERS
44 call .CompareCHorSfromOffsetBXtoMaxValueInAX
45
46 mov bl, ATA1.wHeadCnt & 0FFh
47 mov ax, MAX_VALID_PCHS_HEADS
48 call .CompareCHorSfromOffsetBXtoMaxValueInAX
49
50 mov bl, ATA1.wSPT & 0FFh
51 mov al, MAX_VALID_PCHS_SECTORS_PER_TRACK
52 call .CompareCHorSfromOffsetBXtoMaxValueInAX
53
54 ; Check signature byte. It is only found on ATA-5 and later. It should be zero on
55 ; ATA-4 and older.
56 mov al, [es:si+ATA6.bSignature]
57 test al, al
58 jz SHORT .AtaIDverifiedSuccessfully ; Old ATA so Signature and Checksum is not available
59 cmp al, A6_wIntegrity_SIGNATURE
60 jne SHORT .FailedToVerifyAtaID
61
62 ; Check checksum byte since signature was present
63 mov cx, ATA6_size
64 jmp Memory_SumCXbytesFromESSItoAL ; Returns with ZF set according to result
65
66;--------------------------------------------------------------------
67; .CompareCHorSfromOffsetBXtoMaxValueInAX
68; Parameters:
69; AX: Maximum valid C, H or S value
70; BX: C, H or S offset to ATA-ID
71; ES:SI: Ptr to 512-byte ATA information read from the drive
72; Returns:
73; Exits from AtaID_VerifyFromESSI with ZF cleared if invalid value
74; Corrupts registers:
75; CX
76;--------------------------------------------------------------------
77.CompareCHorSfromOffsetBXtoMaxValueInAX:
78 mov cx, [es:bx+si]
79 jcxz .InvalidPCHorSinOffsetBX
80 cmp cx, ax ; Compare to max valid value
81 jbe SHORT .ValidPCHorSinOffsetBX
82.InvalidPCHorSinOffsetBX:
83 pop cx ; Clear return address for this function
84 inc cx ; Clear ZF to indicate invalid ATA-ID (safe to do since return address in CX will never be FFFFh)
85.AtaIDverifiedSuccessfully:
86.FailedToVerifyAtaID:
87.ValidPCHorSinOffsetBX:
88 ret
89
90
91;--------------------------------------------------------------------
92; Writes user defined limits from ROMVARS to ATA ID read from the drive.
93; Modifying the ATA ID reduces code and possibilities for bugs since
94; only little further checks are needed elsewhere.
95;
96; AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX
97; Parameters:
98; DS:DI: Ptr to incomplete Disk Parameter Table
99; ES:SI: Ptr to 512-byte ATA information read from the drive
100; CS:BP: Ptr to IDEVARS for the controller
101; Returns:
102; DX: User defined P-CHS to L-CHS translate mode
103; Corrupts registers:
104; AX, BX, CX
105;--------------------------------------------------------------------
106AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX:
107 call AccessDPT_GetPointerToDRVPARAMStoCSBX
108 push ds
109
110 push cs
111 pop ds
112
113 ; Load User Defined CHS or LBA to CX:AX
114 mov dx, [bx+DRVPARAMS.wFlags]
115 mov ax, [bx+DRVPARAMS.wCylinders] ; Or .dwMaximumLBA
116 mov cx, [bx+DRVPARAMS.wHeadsAndSectors] ; Or .dwMaximumLBA+2
117
118 push es
119 pop ds ; DS:SI now points to ATA information
120
121 ; * User defined CHS *
122 test dl, FLG_DRVPARAMS_USERCHS
123 jz SHORT .NoUserDefinedCHS
124
125 ; Apply new CHS and disable LBA (we also want to set CHS addressing)
126 mov [si+ATA1.wCylCnt], ax
127 eMOVZX ax, cl
128 mov [si+ATA1.wHeadCnt], ax
129 mov al, ch
130 mov [si+ATA1.wSPT], ax
131 and BYTE [si+ATA1.wCaps+1], ~(A1_wCaps_LBA>>8)
132 and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
133.NoUserDefinedCHS:
134
135 ; * User defined LBA *
136 test dl, FLG_DRVPARAMS_USERLBA
137 jz SHORT .NoUserDefinedLBA
138
139 ; Apply new LBA and disable LBA48
140 cmp cx, [si+ATA1.dwLBACnt+2]
141 ja SHORT .NoUserDefinedLBA ; Do not set larger than drive
142 jb SHORT .StoreNewLBA
143 cmp ax, [si+ATA1.dwLBACnt]
144 ja SHORT .NoUserDefinedLBA ; Allow same size to disable LBA48
145.StoreNewLBA:
146 mov [si+ATA1.dwLBACnt], ax
147 mov [si+ATA1.dwLBACnt+2], cx
148 and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
149.NoUserDefinedLBA:
150
151 ; * Load P-CHS to L-CHS translate mode to DX *
152 and dx, BYTE MASK_DRVPARAMS_TRANSLATEMODE
153 eSHR_IM dx, TRANSLATEMODE_FIELD_POSITION
154
155 pop ds
156 ret
157
158
159%ifdef MODULE_ADVANCED_ATA
160;--------------------------------------------------------------------
161; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
162; Parameters:
163; ES:SI: Ptr to 512-byte ATA information read from the drive
164; Returns:
165; AL: Max supported PIO mode
166; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
167; CX: Minimum Cycle Time in nanosecs
168; Corrupts registers:
169; BX
170;--------------------------------------------------------------------
171AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
172 ; Get PIO mode and cycle time for PIO 0...2
173 mov bx, [es:si+ATA1.bPioMode]
174 mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
175 eSHL_IM bx, 1 ; Shift for WORD lookup
176 mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
177
178 ; Check if IORDY is supported
179 test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
180 jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
181 mov ah, FLGH_DPT_IORDY
182
183 ; Check if Advanced PIO modes are supported (3 and above)
184 test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
185 jz SHORT .ReturnPioTimings
186
187 ; Get Advanced PIO mode
188 ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
189 mov bl, [es:si+ATA2.bPIOSupp]
190.CheckNextFlag:
191 inc ax
192 shr bl, 1
193 jnz SHORT .CheckNextFlag
194 MIN_U al, 6 ; Make sure not above lookup tables
195 mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
196.ReturnPioTimings:
197 ret
198
199.rgwPio0to2CycleTimeInNanosecs:
200 dw PIO_0_MIN_CYCLE_TIME_NS
201 dw PIO_1_MIN_CYCLE_TIME_NS
202 dw PIO_2_MIN_CYCLE_TIME_NS
203
204
205;--------------------------------------------------------------------
206; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
207; Parameters:
208; BX: PIO Mode
209; CX: PIO Cycle Time in nanosecs
210; Returns:
211; AX: Active Time in nanosecs
212; Corrupts registers:
213; BX, CX
214;--------------------------------------------------------------------
215AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX:
216 call AtaID_GetActiveTimeToAXfromPioModeInBX
217 mov bl, [cs:bx+.rgbPioModeToAddressValidTimeNs]
218 sub cx, bx ; Cycle Time (t0) - Address Valid Time (t1)
219 sub cx, ax ; - Active Time (t2)
220 xchg ax, cx ; AX = Recovery Time (t2i)
221 ret
222
223.rgbPioModeToAddressValidTimeNs:
224 db PIO_0_MIN_ADDRESS_VALID_NS
225 db PIO_1_MIN_ADDRESS_VALID_NS
226 db PIO_2_MIN_ADDRESS_VALID_NS
227 db PIO_3_MIN_ADDRESS_VALID_NS
228 db PIO_4_MIN_ADDRESS_VALID_NS
229 db PIO_5_MIN_ADDRESS_VALID_NS
230 db PIO_6_MIN_ADDRESS_VALID_NS
231
232
233;--------------------------------------------------------------------
234; AtaID_GetActiveTimeToAXfromPioModeInBX
235; Parameters:
236; BX: PIO Mode
237; Returns:
238; AX: Active Time in nanosecs
239; Corrupts registers:
240; Nothing
241;--------------------------------------------------------------------
242AtaID_GetActiveTimeToAXfromPioModeInBX:
243 eMOVZX ax, [cs:bx+.rgbPioModeToActiveTimeNs]
244 ret
245
246.rgbPioModeToActiveTimeNs:
247 db PIO_0_MIN_ACTIVE_TIME_NS
248 db PIO_1_MIN_ACTIVE_TIME_NS
249 db PIO_2_MIN_ACTIVE_TIME_NS
250 db PIO_3_MIN_ACTIVE_TIME_NS
251 db PIO_4_MIN_ACTIVE_TIME_NS
252 db PIO_5_MIN_ACTIVE_TIME_NS
253 db PIO_6_MIN_ACTIVE_TIME_NS
254
255%endif ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.