[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 | ;--------------------------------------------------------------------
|
---|
[580] | 34 | %ifndef NO_ATAID_VALIDATION
|
---|
[441] | 35 | AtaID_VerifyFromESSI:
|
---|
| 36 | ; We cannot start by reading ATA version since the ID might be
|
---|
| 37 | ; corrupted. We start by making sure P-CHS values are valid.
|
---|
| 38 | ; If they are, we assume the ATA ID to be valid. Fortunately we can do
|
---|
[491] | 39 | ; further checking for ATA-5 and later since they contain signature and
|
---|
[441] | 40 | ; checksum bytes. Those are not available for ATA-4 and older.
|
---|
| 41 |
|
---|
| 42 | ; Verify P-CHS cylinders
|
---|
| 43 | mov bx, ATA1.wCylCnt
|
---|
[567] | 44 | mov ax, MAX_VALID_PCHS_CYLINDERS
|
---|
| 45 | call .CompareCHorSfromOffsetBXtoMaxValueInAX
|
---|
[441] | 46 |
|
---|
[445] | 47 | mov bl, ATA1.wHeadCnt & 0FFh
|
---|
[567] | 48 | mov ax, MAX_VALID_PCHS_HEADS
|
---|
| 49 | call .CompareCHorSfromOffsetBXtoMaxValueInAX
|
---|
[441] | 50 |
|
---|
[445] | 51 | mov bl, ATA1.wSPT & 0FFh
|
---|
[567] | 52 | mov al, MAX_VALID_PCHS_SECTORS_PER_TRACK
|
---|
| 53 | call .CompareCHorSfromOffsetBXtoMaxValueInAX
|
---|
[441] | 54 |
|
---|
[487] | 55 | ; Check signature byte. It is only found on ATA-5 and later. It should be zero on
|
---|
| 56 | ; ATA-4 and older.
|
---|
| 57 | mov al, [es:si+ATA6.bSignature]
|
---|
| 58 | test al, al
|
---|
| 59 | jz SHORT .AtaIDverifiedSuccessfully ; Old ATA so Signature and Checksum is not available
|
---|
| 60 | cmp al, A6_wIntegrity_SIGNATURE
|
---|
[441] | 61 | jne SHORT .FailedToVerifyAtaID
|
---|
| 62 |
|
---|
[487] | 63 | ; Check checksum byte since signature was present
|
---|
[441] | 64 | mov cx, ATA6_size
|
---|
[567] | 65 | jmp Memory_SumCXbytesFromESSItoAL ; Returns with ZF set according to result
|
---|
[441] | 66 |
|
---|
| 67 | ;--------------------------------------------------------------------
|
---|
[567] | 68 | ; .CompareCHorSfromOffsetBXtoMaxValueInAX
|
---|
[441] | 69 | ; Parameters:
|
---|
[567] | 70 | ; AX: Maximum valid C, H or S value
|
---|
[441] | 71 | ; BX: C, H or S offset to ATA-ID
|
---|
| 72 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 73 | ; Returns:
|
---|
[567] | 74 | ; Exits from AtaID_VerifyFromESSI with ZF cleared if invalid value
|
---|
[441] | 75 | ; Corrupts registers:
|
---|
[567] | 76 | ; CX
|
---|
[441] | 77 | ;--------------------------------------------------------------------
|
---|
[567] | 78 | .CompareCHorSfromOffsetBXtoMaxValueInAX:
|
---|
| 79 | mov cx, [es:bx+si]
|
---|
| 80 | jcxz .InvalidPCHorSinOffsetBX
|
---|
| 81 | cmp cx, ax ; Compare to max valid value
|
---|
[441] | 82 | jbe SHORT .ValidPCHorSinOffsetBX
|
---|
| 83 | .InvalidPCHorSinOffsetBX:
|
---|
[567] | 84 | pop cx ; Clear return address for this function
|
---|
| 85 | inc cx ; Clear ZF to indicate invalid ATA-ID (safe to do since return address in CX will never be FFFFh)
|
---|
| 86 | .AtaIDverifiedSuccessfully:
|
---|
[441] | 87 | .FailedToVerifyAtaID:
|
---|
| 88 | .ValidPCHorSinOffsetBX:
|
---|
| 89 | ret
|
---|
[580] | 90 | %endif ; NO_ATAID_VALIDATION
|
---|
[441] | 91 |
|
---|
| 92 |
|
---|
[542] | 93 | ;--------------------------------------------------------------------
|
---|
| 94 | ; Writes user defined limits from ROMVARS to ATA ID read from the drive.
|
---|
[567] | 95 | ; Modifying the ATA ID reduces code and possibilities for bugs since
|
---|
| 96 | ; only little further checks are needed elsewhere.
|
---|
[542] | 97 | ;
|
---|
| 98 | ; AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX
|
---|
| 99 | ; Parameters:
|
---|
| 100 | ; DS:DI: Ptr to incomplete Disk Parameter Table
|
---|
| 101 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 102 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
| 103 | ; Returns:
|
---|
| 104 | ; DX: User defined P-CHS to L-CHS translate mode
|
---|
| 105 | ; Corrupts registers:
|
---|
[592] | 106 | ; AX, BX
|
---|
[542] | 107 | ;--------------------------------------------------------------------
|
---|
| 108 | AtaID_ModifyESSIforUserDefinedLimitsAndReturnTranslateModeInDX:
|
---|
| 109 | call AccessDPT_GetPointerToDRVPARAMStoCSBX
|
---|
| 110 | push ds
|
---|
[568] | 111 |
|
---|
| 112 | push cs
|
---|
| 113 | pop ds
|
---|
| 114 |
|
---|
[592] | 115 | ; Load User Defined CHS or LBA to BX:AX
|
---|
| 116 | mov dl, [bx+DRVPARAMS.wFlags] ; Only load the flags we actually need
|
---|
[568] | 117 | mov ax, [bx+DRVPARAMS.wCylinders] ; Or .dwMaximumLBA
|
---|
[592] | 118 | mov bx, [bx+DRVPARAMS.wHeadsAndSectors] ; Or .dwMaximumLBA+2
|
---|
[568] | 119 |
|
---|
[542] | 120 | push es
|
---|
| 121 | pop ds ; DS:SI now points to ATA information
|
---|
| 122 |
|
---|
| 123 | ; * User defined CHS *
|
---|
| 124 | test dl, FLG_DRVPARAMS_USERCHS
|
---|
| 125 | jz SHORT .NoUserDefinedCHS
|
---|
| 126 |
|
---|
| 127 | ; Apply new CHS and disable LBA (we also want to set CHS addressing)
|
---|
| 128 | mov [si+ATA1.wCylCnt], ax
|
---|
[592] | 129 | eMOVZX ax, bl
|
---|
[542] | 130 | mov [si+ATA1.wHeadCnt], ax
|
---|
[592] | 131 | mov al, bh
|
---|
[542] | 132 | mov [si+ATA1.wSPT], ax
|
---|
| 133 | and BYTE [si+ATA1.wCaps+1], ~(A1_wCaps_LBA>>8)
|
---|
| 134 | and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
|
---|
| 135 | .NoUserDefinedCHS:
|
---|
| 136 |
|
---|
| 137 | ; * User defined LBA *
|
---|
| 138 | test dl, FLG_DRVPARAMS_USERLBA
|
---|
| 139 | jz SHORT .NoUserDefinedLBA
|
---|
| 140 |
|
---|
| 141 | ; Apply new LBA and disable LBA48
|
---|
[592] | 142 | cmp bx, [si+ATA1.dwLBACnt+2]
|
---|
[542] | 143 | ja SHORT .NoUserDefinedLBA ; Do not set larger than drive
|
---|
| 144 | jb SHORT .StoreNewLBA
|
---|
| 145 | cmp ax, [si+ATA1.dwLBACnt]
|
---|
| 146 | ja SHORT .NoUserDefinedLBA ; Allow same size to disable LBA48
|
---|
| 147 | .StoreNewLBA:
|
---|
| 148 | mov [si+ATA1.dwLBACnt], ax
|
---|
[592] | 149 | mov [si+ATA1.dwLBACnt+2], bx
|
---|
[542] | 150 | and BYTE [si+ATA6.wSetSup83+1], ~(A6_wSetSup83_LBA48>>8)
|
---|
| 151 | .NoUserDefinedLBA:
|
---|
| 152 |
|
---|
| 153 | ; * Load P-CHS to L-CHS translate mode to DX *
|
---|
| 154 | and dx, BYTE MASK_DRVPARAMS_TRANSLATEMODE
|
---|
| 155 | eSHR_IM dx, TRANSLATEMODE_FIELD_POSITION
|
---|
| 156 |
|
---|
| 157 | pop ds
|
---|
| 158 | ret
|
---|
| 159 |
|
---|
| 160 |
|
---|
[363] | 161 | %ifdef MODULE_ADVANCED_ATA
|
---|
| 162 | ;--------------------------------------------------------------------
|
---|
[364] | 163 | ; AtaID_GetMaxPioModeToAXandMinCycleTimeToCX
|
---|
[363] | 164 | ; Parameters:
|
---|
| 165 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
| 166 | ; Returns:
|
---|
[364] | 167 | ; AL: Max supported PIO mode
|
---|
| 168 | ; AH: FLGH_DPT_IORDY if IORDY supported, zero otherwise
|
---|
| 169 | ; CX: Minimum Cycle Time in nanosecs
|
---|
[363] | 170 | ; Corrupts registers:
|
---|
| 171 | ; BX
|
---|
| 172 | ;--------------------------------------------------------------------
|
---|
[364] | 173 | AtaID_GetMaxPioModeToAXandMinCycleTimeToCX:
|
---|
[363] | 174 | ; Get PIO mode and cycle time for PIO 0...2
|
---|
[592] | 175 | %ifdef USE_386
|
---|
| 176 | movzx ax, [es:si+ATA1.bPioMode] ; AH = 0, AL = PIO mode 0, 1 or 2
|
---|
| 177 | %else
|
---|
| 178 | mov al, [es:si+ATA1.bPioMode]
|
---|
| 179 | cbw
|
---|
| 180 | %endif
|
---|
| 181 | mov bx, ax
|
---|
| 182 | eSHL_IM bx, 1 ; Shift for WORD lookup
|
---|
[364] | 183 | mov cx, [cs:bx+.rgwPio0to2CycleTimeInNanosecs]
|
---|
[363] | 184 |
|
---|
[364] | 185 | ; Check if IORDY is supported
|
---|
| 186 | test BYTE [es:si+ATA2.wCaps+1], A2_wCaps_IORDY >> 8
|
---|
[592] | 187 | jz SHORT .ReturnPioTimings ; No PIO 3 or higher if no IORDY
|
---|
| 188 | 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] | 189 |
|
---|
[363] | 190 | ; Check if Advanced PIO modes are supported (3 and above)
|
---|
| 191 | test BYTE [es:si+ATA2.wFields], A2_wFields_64to70
|
---|
| 192 | jz SHORT .ReturnPioTimings
|
---|
| 193 |
|
---|
[592] | 194 | ; Get Advanced PIO mode (Hard Disks supports up to 4 but CF cards can support 5 and 6)
|
---|
| 195 | or bh, [es:si+ATA2.bPIOSupp]
|
---|
| 196 | jz SHORT .ReturnPioTimings
|
---|
[363] | 197 | .CheckNextFlag:
|
---|
| 198 | inc ax
|
---|
[592] | 199 | shr bh, 1
|
---|
[363] | 200 | jnz SHORT .CheckNextFlag
|
---|
[364] | 201 | MIN_U al, 6 ; Make sure not above lookup tables
|
---|
| 202 | mov cx, [es:si+ATA2.wPIOMinCyF] ; Advanced modes use IORDY
|
---|
[363] | 203 | .ReturnPioTimings:
|
---|
| 204 | ret
|
---|
| 205 |
|
---|
| 206 | .rgwPio0to2CycleTimeInNanosecs:
|
---|
| 207 | dw PIO_0_MIN_CYCLE_TIME_NS
|
---|
| 208 | dw PIO_1_MIN_CYCLE_TIME_NS
|
---|
| 209 | dw PIO_2_MIN_CYCLE_TIME_NS
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | ;--------------------------------------------------------------------
|
---|
[364] | 213 | ; AtaID_GetActiveTimeToAXfromPioModeInBX
|
---|
| 214 | ; Parameters:
|
---|
| 215 | ; BX: PIO Mode
|
---|
| 216 | ; Returns:
|
---|
| 217 | ; AX: Active Time in nanosecs
|
---|
| 218 | ; Corrupts registers:
|
---|
| 219 | ; Nothing
|
---|
| 220 | ;--------------------------------------------------------------------
|
---|
| 221 | AtaID_GetActiveTimeToAXfromPioModeInBX:
|
---|
[445] | 222 | eMOVZX ax, [cs:bx+.rgbPioModeToActiveTimeNs]
|
---|
[364] | 223 | ret
|
---|
| 224 |
|
---|
[445] | 225 | .rgbPioModeToActiveTimeNs:
|
---|
| 226 | db PIO_0_MIN_ACTIVE_TIME_NS
|
---|
| 227 | db PIO_1_MIN_ACTIVE_TIME_NS
|
---|
| 228 | db PIO_2_MIN_ACTIVE_TIME_NS
|
---|
| 229 | db PIO_3_MIN_ACTIVE_TIME_NS
|
---|
| 230 | db PIO_4_MIN_ACTIVE_TIME_NS
|
---|
| 231 | db PIO_5_MIN_ACTIVE_TIME_NS
|
---|
| 232 | db PIO_6_MIN_ACTIVE_TIME_NS
|
---|
[363] | 233 |
|
---|
| 234 | %endif ; MODULE_ADVANCED_ATA
|
---|