[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 |
---|
| 22 | SECTION .text |
---|
| 23 | |
---|
[441] | 24 | ;-------------------------------------------------------------------- |
---|
[613] | 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: |
---|
| 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_VALID_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 | ;-------------------------------------------------------------------- |
---|
[441] | 65 | ; AtaID_VerifyFromESSI |
---|
| 66 | ; Parameters: |
---|
| 67 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
| 68 | ; Returns: |
---|
[567] | 69 | ; ZF: Set if ATA-ID verified successfully |
---|
| 70 | ; Cleared if failed to verify ATA-ID |
---|
[441] | 71 | ; Corrupts registers: |
---|
| 72 | ; AX, BX, CX |
---|
| 73 | ;-------------------------------------------------------------------- |
---|
[580] | 74 | %ifndef NO_ATAID_VALIDATION |
---|
[441] | 75 | AtaID_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 |
---|
[491] | 79 | ; further checking for ATA-5 and later since they contain signature and |
---|
[441] | 80 | ; checksum bytes. Those are not available for ATA-4 and older. |
---|
| 81 | |
---|
| 82 | ; Verify P-CHS cylinders |
---|
| 83 | mov bx, ATA1.wCylCnt |
---|
[567] | 84 | mov ax, MAX_VALID_PCHS_CYLINDERS |
---|
| 85 | call .CompareCHorSfromOffsetBXtoMaxValueInAX |
---|
[441] | 86 | |
---|
[445] | 87 | mov bl, ATA1.wHeadCnt & 0FFh |
---|
[567] | 88 | mov ax, MAX_VALID_PCHS_HEADS |
---|
| 89 | call .CompareCHorSfromOffsetBXtoMaxValueInAX |
---|
[441] | 90 | |
---|
[445] | 91 | mov bl, ATA1.wSPT & 0FFh |
---|
[567] | 92 | mov al, MAX_VALID_PCHS_SECTORS_PER_TRACK |
---|
| 93 | call .CompareCHorSfromOffsetBXtoMaxValueInAX |
---|
[441] | 94 | |
---|
[487] | 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 |
---|
[441] | 101 | jne SHORT .FailedToVerifyAtaID |
---|
| 102 | |
---|
[487] | 103 | ; Check checksum byte since signature was present |
---|
[441] | 104 | mov cx, ATA6_size |
---|
[567] | 105 | jmp Memory_SumCXbytesFromESSItoAL ; Returns with ZF set according to result |
---|
[441] | 106 | |
---|
| 107 | ;-------------------------------------------------------------------- |
---|
[567] | 108 | ; .CompareCHorSfromOffsetBXtoMaxValueInAX |
---|
[441] | 109 | ; Parameters: |
---|
[567] | 110 | ; AX: Maximum valid C, H or S value |
---|
[441] | 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: |
---|
[567] | 114 | ; Exits from AtaID_VerifyFromESSI with ZF cleared if invalid value |
---|
[441] | 115 | ; Corrupts registers: |
---|
[567] | 116 | ; CX |
---|
[441] | 117 | ;-------------------------------------------------------------------- |
---|
[567] | 118 | .CompareCHorSfromOffsetBXtoMaxValueInAX: |
---|
| 119 | mov cx, [es:bx+si] |
---|
| 120 | jcxz .InvalidPCHorSinOffsetBX |
---|
| 121 | cmp cx, ax ; Compare to max valid value |
---|
[441] | 122 | jbe SHORT .ValidPCHorSinOffsetBX |
---|
| 123 | .InvalidPCHorSinOffsetBX: |
---|
[567] | 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: |
---|
[441] | 127 | .FailedToVerifyAtaID: |
---|
| 128 | .ValidPCHorSinOffsetBX: |
---|
| 129 | ret |
---|
[580] | 130 | %endif ; NO_ATAID_VALIDATION |
---|
[441] | 131 | |
---|
| 132 | |
---|
[542] | 133 | ;-------------------------------------------------------------------- |
---|
| 134 | ; Writes user defined limits from ROMVARS to ATA ID read from the drive. |
---|
[567] | 135 | ; Modifying the ATA ID reduces code and possibilities for bugs since |
---|
| 136 | ; only little further checks are needed elsewhere. |
---|
[542] | 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: |
---|
[592] | 146 | ; AX, BX |
---|
[542] | 147 | ;-------------------------------------------------------------------- |
---|
| 148 | AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX: |
---|
| 149 | call AccessDPT_GetPointerToDRVPARAMStoCSBX |
---|
| 150 | push ds |
---|
[568] | 151 | |
---|
| 152 | push cs |
---|
| 153 | pop ds |
---|
| 154 | |
---|
[592] | 155 | ; Load User Defined CHS or LBA to BX:AX |
---|
| 156 | mov dl, [bx+DRVPARAMS.wFlags] ; Only load the flags we actually need |
---|
[568] | 157 | mov ax, [bx+DRVPARAMS.wCylinders] ; Or .dwMaximumLBA |
---|
[592] | 158 | mov bx, [bx+DRVPARAMS.wHeadsAndSectors] ; Or .dwMaximumLBA+2 |
---|
[568] | 159 | |
---|
[542] | 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 |
---|
[592] | 169 | eMOVZX ax, bl |
---|
[542] | 170 | mov [si+ATA1.wHeadCnt], ax |
---|
[592] | 171 | mov al, bh |
---|
[542] | 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 |
---|
[592] | 182 | cmp bx, [si+ATA1.dwLBACnt+2] |
---|
[542] | 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 |
---|
[592] | 189 | mov [si+ATA1.dwLBACnt+2], bx |
---|
[542] | 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 | |
---|
[363] | 201 | %ifdef MODULE_ADVANCED_ATA |
---|
| 202 | ;-------------------------------------------------------------------- |
---|
[364] | 203 | ; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX |
---|
[363] | 204 | ; Parameters: |
---|
| 205 | ; ES:SI: Ptr to 512-byte ATA information read from the drive |
---|
| 206 | ; Returns: |
---|
[364] | 207 | ; AL: Max supported PIO mode |
---|
| 208 | ; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise |
---|
| 209 | ; CX: Minimum Cycle Time in nanosecs |
---|
[363] | 210 | ; Corrupts registers: |
---|
| 211 | ; BX |
---|
| 212 | ;-------------------------------------------------------------------- |
---|
[364] | 213 | AtaID_GetMaxPioModeToAXandMinCycleTimeToCX: |
---|
[363] | 214 | ; Get PIO mode and cycle time for PIO 0...2 |
---|
[592] | 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 |
---|
[364] | 223 | mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs] |
---|
[363] | 224 | |
---|
[364] | 225 | ; Check if IORDY is supported |
---|
| 226 | test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8 |
---|
[592] | 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. |
---|
[364] | 229 | |
---|
[363] | 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 | |
---|
[592] | 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 |
---|
[363] | 237 | .CheckNextFlag: |
---|
| 238 | inc ax |
---|
[592] | 239 | shr bh, 1 |
---|
[363] | 240 | jnz SHORT .CheckNextFlag |
---|
[364] | 241 | MIN_U al, 6 ; Make sure not above lookup tables |
---|
| 242 | mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY |
---|
[363] | 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 | ;-------------------------------------------------------------------- |
---|
[364] | 253 | ; AtaID_GetActiveTimeToAXfromPioModeInBX |
---|
| 254 | ; Parameters: |
---|
| 255 | ; BX: PIO Mode |
---|
| 256 | ; Returns: |
---|
| 257 | ; AX: Active Time in nanosecs |
---|
| 258 | ; Corrupts registers: |
---|
| 259 | ; Nothing |
---|
| 260 | ;-------------------------------------------------------------------- |
---|
| 261 | AtaID_GetActiveTimeToAXfromPioModeInBX: |
---|
[445] | 262 | eMOVZX ax, [cs:bx+.rgbPioModeToActiveTimeNs] |
---|
[364] | 263 | ret |
---|
| 264 | |
---|
[445] | 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 |
---|
[363] | 273 | |
---|
| 274 | %endif ; MODULE_ADVANCED_ATA |
---|
[613] | 275 | |
---|
| 276 | %endif ; EXCLUDE_FROM_BIOSDRVS |
---|