[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 | ;--------------------------------------------------------------------
|
---|
| 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 | ;--------------------------------------------------------------------
|
---|
| 34 | AtaID_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 | ;--------------------------------------------------------------------
|
---|
| 106 | AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX:
|
---|
| 107 | call AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
| 108 | push ds
|
---|
| 109 | push es
|
---|
| 110 | pop ds ; DS:SI now points to ATA information
|
---|
| 111 |
|
---|
| 112 | ; Load User Defined CHS or LBA to CX:AX
|
---|
| 113 | mov dx, [cs:bx+DRVPARAMS.wFlags]
|
---|
| 114 | mov ax, [cs:bx+DRVPARAMS.wCylinders] ; Or .dwMaximumLBA
|
---|
| 115 | mov cx, [cs:bx+DRVPARAMS.wHeadsAndSectors] ; Or .dwMaximumLBA+2
|
---|
| 116 |
|
---|
| 117 | ; * User defined CHS *
|
---|
| 118 | test dl, FLG_DRVPARAMS_USERCHS
|
---|
| 119 | jz SHORT .NoUserDefinedCHS
|
---|
| 120 |
|
---|
| 121 | ; Apply new CHS and disable LBA (we also want to set CHS addressing)
|
---|
| 122 | mov [si+ATA1.wCylCnt], ax
|
---|
| 123 | eMOVZX ax, cl
|
---|
| 124 | mov [si+ATA1.wHeadCnt], ax
|
---|
| 125 | mov al, ch
|
---|
| 126 | mov [si+ATA1.wSPT], ax
|
---|
| 127 | and BYTE [si+ATA1.wCaps+1], ~(A1_wCaps_LBA>>8)
|
---|
| 128 | and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
|
---|
| 129 | .NoUserDefinedCHS:
|
---|
| 130 |
|
---|
| 131 | ; * User defined LBA *
|
---|
| 132 | test dl, FLG_DRVPARAMS_USERLBA
|
---|
| 133 | jz SHORT .NoUserDefinedLBA
|
---|
| 134 |
|
---|
| 135 | ; Apply new LBA and disable LBA48
|
---|
| 136 | cmp cx, [si+ATA1.dwLBACnt+2]
|
---|
| 137 | ja SHORT .NoUserDefinedLBA ; Do not set larger than drive
|
---|
| 138 | jb SHORT .StoreNewLBA
|
---|
| 139 | cmp ax, [si+ATA1.dwLBACnt]
|
---|
| 140 | ja SHORT .NoUserDefinedLBA ; Allow same size to disable LBA48
|
---|
| 141 | .StoreNewLBA:
|
---|
| 142 | mov [si+ATA1.dwLBACnt], ax
|
---|
| 143 | mov [si+ATA1.dwLBACnt+2], cx
|
---|
| 144 | and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
|
---|
| 145 | .NoUserDefinedLBA:
|
---|
| 146 |
|
---|
| 147 | ; * Load P-CHS to L-CHS translate mode to DX *
|
---|
| 148 | and dx, BYTE MASK_DRVPARAMS_TRANSLATEMODE
|
---|
| 149 | eSHR_IM dx, TRANSLATEMODE_FIELD_POSITION
|
---|
| 150 |
|
---|
| 151 | pop ds
|
---|
| 152 | ret
|
---|
| 153 |
|
---|
| 154 |
|
---|
[363] | 155 | %ifdef MODULE_ADVANCED_ATA
|
---|
| 156 | ;--------------------------------------------------------------------
|
---|
[364] | 157 | ; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
|
---|
[363] | 158 | ; Parameters:
|
---|
| 159 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 160 | ; Returns:
|
---|
[364] | 161 | ; AL: Max supported PIO mode
|
---|
| 162 | ; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
|
---|
| 163 | ; CX: Minimum Cycle Time in nanosecs
|
---|
[363] | 164 | ; Corrupts registers:
|
---|
| 165 | ; BX
|
---|
| 166 | ;--------------------------------------------------------------------
|
---|
[364] | 167 | AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
|
---|
[363] | 168 | ; Get PIO mode and cycle time for PIO 0...2
|
---|
| 169 | mov bx, [es:si+ATA1.bPioMode]
|
---|
[370] | 170 | mov ax, bx ; AH = 0, AL = PIO mode 0, 1 or 2
|
---|
[445] | 171 | eSHL_IM bx, 1 ; Shift for WORD lookup
|
---|
[364] | 172 | mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
|
---|
[363] | 173 |
|
---|
[364] | 174 | ; Check if IORDY is supported
|
---|
| 175 | test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
|
---|
| 176 | jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
|
---|
| 177 | mov ah, FLGH_DPT_IORDY
|
---|
| 178 |
|
---|
[363] | 179 | ; Check if Advanced PIO modes are supported (3 and above)
|
---|
| 180 | test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
|
---|
| 181 | jz SHORT .ReturnPioTimings
|
---|
| 182 |
|
---|
| 183 | ; Get Advanced PIO mode
|
---|
[364] | 184 | ; (Hard Disks supports up to 4 but CF cards can support 5 and 6)
|
---|
[370] | 185 | mov bl, [es:si+ATA2.bPIOSupp]
|
---|
[363] | 186 | .CheckNextFlag:
|
---|
| 187 | inc ax
|
---|
[370] | 188 | shr bl, 1
|
---|
[363] | 189 | jnz SHORT .CheckNextFlag
|
---|
[364] | 190 | MIN_U al, 6 ; Make sure not above lookup tables
|
---|
| 191 | mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
|
---|
[363] | 192 | .ReturnPioTimings:
|
---|
| 193 | ret
|
---|
| 194 |
|
---|
| 195 | .rgwPio0to2CycleTimeInNanosecs:
|
---|
| 196 | dw PIO_0_MIN_CYCLE_TIME_NS
|
---|
| 197 | dw PIO_1_MIN_CYCLE_TIME_NS
|
---|
| 198 | dw PIO_2_MIN_CYCLE_TIME_NS
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | ;--------------------------------------------------------------------
|
---|
[364] | 202 | ; AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX
|
---|
[363] | 203 | ; Parameters:
|
---|
[364] | 204 | ; BX: PIO Mode
|
---|
| 205 | ; CX: PIO Cycle Time in nanosecs
|
---|
[363] | 206 | ; Returns:
|
---|
[364] | 207 | ; AX: Active Time in nanosecs
|
---|
[363] | 208 | ; Corrupts registers:
|
---|
[364] | 209 | ; BX, CX
|
---|
[363] | 210 | ;--------------------------------------------------------------------
|
---|
[364] | 211 | AtaID_GetRecoveryTimeToAXfromPioModeInBXandCycleTimeInCX:
|
---|
| 212 | call AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
| 213 | mov bl, [cs:bx+.rgbPioModeToAddressValidTimeNs]
|
---|
| 214 | sub cx, bx ; Cycle Time (t0) - Address Valid Time (t1)
|
---|
| 215 | sub cx, ax ; - Active Time (t2)
|
---|
| 216 | xchg ax, cx ; AX = Recovery Time (t2i)
|
---|
[363] | 217 | ret
|
---|
| 218 |
|
---|
| 219 | .rgbPioModeToAddressValidTimeNs:
|
---|
| 220 | db PIO_0_MIN_ADDRESS_VALID_NS
|
---|
| 221 | db PIO_1_MIN_ADDRESS_VALID_NS
|
---|
| 222 | db PIO_2_MIN_ADDRESS_VALID_NS
|
---|
| 223 | db PIO_3_MIN_ADDRESS_VALID_NS
|
---|
| 224 | db PIO_4_MIN_ADDRESS_VALID_NS
|
---|
[364] | 225 | db PIO_5_MIN_ADDRESS_VALID_NS
|
---|
| 226 | db PIO_6_MIN_ADDRESS_VALID_NS
|
---|
[363] | 227 |
|
---|
[364] | 228 |
|
---|
| 229 | ;--------------------------------------------------------------------
|
---|
| 230 | ; AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
| 231 | ; Parameters:
|
---|
| 232 | ; BX: PIO Mode
|
---|
| 233 | ; Returns:
|
---|
| 234 | ; AX: Active Time in nanosecs
|
---|
| 235 | ; Corrupts registers:
|
---|
| 236 | ; Nothing
|
---|
| 237 | ;--------------------------------------------------------------------
|
---|
| 238 | AtaID_GetActiveTimeToAXfromPioModeInBX:
|
---|
[445] | 239 | eMOVZX ax, [cs:bx+.rgbPioModeToActiveTimeNs]
|
---|
[364] | 240 | ret
|
---|
| 241 |
|
---|
[445] | 242 | .rgbPioModeToActiveTimeNs:
|
---|
| 243 | db PIO_0_MIN_ACTIVE_TIME_NS
|
---|
| 244 | db PIO_1_MIN_ACTIVE_TIME_NS
|
---|
| 245 | db PIO_2_MIN_ACTIVE_TIME_NS
|
---|
| 246 | db PIO_3_MIN_ACTIVE_TIME_NS
|
---|
| 247 | db PIO_4_MIN_ACTIVE_TIME_NS
|
---|
| 248 | db PIO_5_MIN_ACTIVE_TIME_NS
|
---|
| 249 | db PIO_6_MIN_ACTIVE_TIME_NS
|
---|
[363] | 250 |
|
---|
| 251 | %endif ; MODULE_ADVANCED_ATA
|
---|