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
RevLine 
[99]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for accessing ATA information read with
3; IDENTIFY DEVICE command.
4
[376]5;
[445]6; XTIDE Universal BIOS and Associated Tools
[526]7; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]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.
[445]13;
[376]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
[445]17; GNU General Public License for more details.
[376]18; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[445]19;
[376]20
[3]21; Section containing code
22SECTION .text
23
[441]24;--------------------------------------------------------------------
25; AtaID_VerifyFromESSI
26; Parameters:
27; ES:SI: Ptr to 512-byte ATA information read from the drive
28; Returns:
[567]29; ZF: Set if ATA-ID verified successfully
30; Cleared if failed to verify ATA-ID
[441]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
[491]38 ; further checking for ATA-5 and later since they contain signature and
[441]39 ; checksum bytes. Those are not available for ATA-4 and older.
40
41 ; Verify P-CHS cylinders
42 mov bx, ATA1.wCylCnt
[567]43 mov ax, MAX_VALID_PCHS_CYLINDERS
44 call .CompareCHorSfromOffsetBXtoMaxValueInAX
[441]45
[445]46 mov bl, ATA1.wHeadCnt & 0FFh
[567]47 mov ax, MAX_VALID_PCHS_HEADS
48 call .CompareCHorSfromOffsetBXtoMaxValueInAX
[441]49
[445]50 mov bl, ATA1.wSPT & 0FFh
[567]51 mov al, MAX_VALID_PCHS_SECTORS_PER_TRACK
52 call .CompareCHorSfromOffsetBXtoMaxValueInAX
[441]53
[487]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
[441]60 jne SHORT .FailedToVerifyAtaID
61
[487]62 ; Check checksum byte since signature was present
[441]63 mov cx, ATA6_size
[567]64 jmp Memory_SumCXbytesFromESSItoAL ; Returns with ZF set according to result
[441]65
66;--------------------------------------------------------------------
[567]67; .CompareCHorSfromOffsetBXtoMaxValueInAX
[441]68; Parameters:
[567]69; AX: Maximum valid C, H or S value
[441]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:
[567]73; Exits from AtaID_VerifyFromESSI with ZF cleared if invalid value
[441]74; Corrupts registers:
[567]75; CX
[441]76;--------------------------------------------------------------------
[567]77.CompareCHorSfromOffsetBXtoMaxValueInAX:
78 mov cx, [es:bx+si]
79 jcxz .InvalidPCHorSinOffsetBX
80 cmp cx, ax ; Compare to max valid value
[441]81 jbe SHORT .ValidPCHorSinOffsetBX
82.InvalidPCHorSinOffsetBX:
[567]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:
[441]86.FailedToVerifyAtaID:
87.ValidPCHorSinOffsetBX:
88 ret
89
90
[542]91;--------------------------------------------------------------------
92; Writes user defined limits from ROMVARS to ATA ID read from the drive.
[567]93; Modifying the ATA ID reduces code and possibilities for bugs since
94; only little further checks are needed elsewhere.
[542]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
[568]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
[542]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
[363]159%ifdef MODULE_ADVANCED_ATA
160;--------------------------------------------------------------------
[364]161; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
[363]162; Parameters:
163; ES:SI: Ptr to 512-byte ATA information read from the drive
164; Returns:
[364]165; AL: Max supported PIO mode
166; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
167; CX: Minimum Cycle Time in nanosecs
[363]168; Corrupts registers:
169; BX
170;--------------------------------------------------------------------
[364]171AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
[363]172 ; Get PIO mode and cycle time for PIO 0...2
173 mov bx, [es:si+ATA1.bPioMode]
[370]174 mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
[445]175 eSHL_IM bx, 1 ; Shift for WORD lookup
[364]176 mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
[363]177
[364]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
[363]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
[364]188 ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
[370]189 mov bl, [es:si+ATA2.bPIOSupp]
[363]190.CheckNextFlag:
191 inc ax
[370]192 shr bl, 1
[363]193 jnz SHORT .CheckNextFlag
[364]194 MIN_U al, 6 ; Make sure not above lookup tables
195 mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
[363]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;--------------------------------------------------------------------
[364]206; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
[363]207; Parameters:
[364]208; BX: PIO Mode
209; CX: PIO Cycle Time in nanosecs
[363]210; Returns:
[364]211; AX: Active Time in nanosecs
[363]212; Corrupts registers:
[364]213; BX, CX
[363]214;--------------------------------------------------------------------
[364]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)
[363]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
[364]229 db PIO_5_MIN_ADDRESS_VALID_NS
230 db PIO_6_MIN_ADDRESS_VALID_NS
[363]231
[364]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:
[445]243 eMOVZX ax, [cs:bx+.rgbPioModeToActiveTimeNs]
[364]244 ret
245
[445]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
[363]254
255%endif ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.