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