[148] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : Int 13h function AH=9h, Initialize Drive Parameters. |
---|
| 3 | |
---|
[376] | 4 | ; |
---|
[399] | 5 | ; XTIDE Universal BIOS and Associated Tools |
---|
[376] | 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team. |
---|
| 7 | ; |
---|
| 8 | ; This program is free software; you can redistribute it and/or modify |
---|
| 9 | ; it under the terms of the GNU General Public License as published by |
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | ; (at your option) any later version. |
---|
[399] | 12 | ; |
---|
[376] | 13 | ; This program is distributed in the hope that it will be useful, |
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[399] | 16 | ; GNU General Public License for more details. |
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
[399] | 18 | ; |
---|
[376] | 19 | |
---|
[3] | 20 | ; Section containing code |
---|
| 21 | SECTION .text |
---|
| 22 | |
---|
| 23 | ;-------------------------------------------------------------------- |
---|
[410] | 24 | ; STORE_ERROR_FLAG_TO_DPT |
---|
| 25 | ; Parameters: |
---|
| 26 | ; %1: Error flag to set |
---|
| 27 | ; AH: BIOS Error Code |
---|
| 28 | ; DS:DI: Ptr to DPT |
---|
| 29 | ; CF: Set if error code in AH |
---|
| 30 | ; Returns: |
---|
| 31 | ; CF: Clear if no error |
---|
| 32 | ; Set if error flag was set |
---|
| 33 | ; Corrupts registers: |
---|
| 34 | ; Nothing |
---|
| 35 | ;-------------------------------------------------------------------- |
---|
| 36 | %macro STORE_ERROR_FLAG_TO_DPT 1 |
---|
| 37 | %ifdef MODULE_ADVANCED_ATA |
---|
| 38 | mov al, %1 |
---|
| 39 | call SetErrorFlagFromALwithErrorCodeInAH |
---|
| 40 | %endif |
---|
| 41 | %endmacro |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | ;-------------------------------------------------------------------- |
---|
[3] | 45 | ; Int 13h function AH=9h, Initialize Drive Parameters. |
---|
| 46 | ; |
---|
| 47 | ; AH9h_HandlerForInitializeDriveParameters |
---|
| 48 | ; Parameters: |
---|
[148] | 49 | ; DL: Translated Drive number |
---|
| 50 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
[150] | 51 | ; SS:BP: Ptr to IDEPACK |
---|
| 52 | ; Returns with INTPACK: |
---|
[3] | 53 | ; AH: Int 13h return status |
---|
[294] | 54 | ; CF: 0 if successful, 1 if error |
---|
[3] | 55 | ;-------------------------------------------------------------------- |
---|
| 56 | AH9h_HandlerForInitializeDriveParameters: |
---|
[84] | 57 | %ifndef USE_186 |
---|
[3] | 58 | call AH9h_InitializeDriveForUse |
---|
[148] | 59 | jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
[84] | 60 | %else |
---|
[148] | 61 | push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
[162] | 62 | ; Fall to AH9h_InitializeDriveForUse |
---|
[84] | 63 | %endif |
---|
[3] | 64 | |
---|
| 65 | |
---|
| 66 | ;-------------------------------------------------------------------- |
---|
[399] | 67 | ; Initialize drive to be ready for use. |
---|
[3] | 68 | ; |
---|
| 69 | ; AH9h_InitializeDriveForUse |
---|
| 70 | ; Parameters: |
---|
[148] | 71 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
[150] | 72 | ; SS:BP: Ptr to IDEPACK |
---|
[3] | 73 | ; Returns: |
---|
| 74 | ; AH: Int 13h return status |
---|
[294] | 75 | ; CF: 0 if successful, 1 if error |
---|
[3] | 76 | ; Corrupts registers: |
---|
[363] | 77 | ; AL, BX, CX, DX |
---|
[3] | 78 | ;-------------------------------------------------------------------- |
---|
| 79 | AH9h_InitializeDriveForUse: |
---|
[410] | 80 | xor ax, ax ; Clear AH to assume no errors |
---|
[3] | 81 | |
---|
[400] | 82 | %ifdef MODULE_ADVANCED_ATA |
---|
[399] | 83 | ; Clear Initialization Error flags from DPT |
---|
[400] | 84 | mov [di+DPT_ADVANCED_ATA.bInitError], al |
---|
| 85 | %endif |
---|
[399] | 86 | |
---|
[258] | 87 | %ifdef MODULE_SERIAL |
---|
[399] | 88 | ; No need to do this for serial devices |
---|
| 89 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE ; Clears CF |
---|
| 90 | jz SHORT .ContinueInitialization |
---|
| 91 | ret ; With AH and CF cleared |
---|
[410] | 92 | .ContinueInitialization: |
---|
[258] | 93 | %endif |
---|
[294] | 94 | |
---|
[399] | 95 | push es |
---|
| 96 | push si |
---|
| 97 | |
---|
[410] | 98 | |
---|
[399] | 99 | ;;; SelectDrive |
---|
[3] | 100 | ; Try to select drive and wait until ready |
---|
[150] | 101 | call AccessDPT_GetDriveSelectByteToAL |
---|
| 102 | mov [bp+IDEPACK.bDrvAndHead], al |
---|
| 103 | call Device_SelectDrive |
---|
[410] | 104 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SELECT_DRIVE |
---|
| 105 | jnc SHORT .ContinueInitializationSinceDriveSelectedSuccesfully |
---|
| 106 | jmp .ReturnWithErrorCodeInAH |
---|
| 107 | .ContinueInitializationSinceDriveSelectedSuccesfully: |
---|
[399] | 108 | |
---|
[3] | 109 | |
---|
[399] | 110 | ;;; InitializeDeviceParameters |
---|
[3] | 111 | ; Initialize CHS parameters if LBA is not used |
---|
[399] | 112 | test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA |
---|
| 113 | jnz SHORT .SkipInitializeDeviceParameters ; No need to initialize CHS parameters if LBA mode enabled |
---|
[3] | 114 | |
---|
[157] | 115 | ; Initialize Logical Sectors per Track and Max Head number |
---|
[227] | 116 | mov ah, [di+DPT.bPchsHeads] |
---|
[150] | 117 | dec ah ; Max Head number |
---|
[227] | 118 | mov dl, [di+DPT.bPchsSectors] ; Sectors per Track |
---|
[150] | 119 | mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS |
---|
| 120 | mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY) |
---|
[399] | 121 | call Idepack_StoreNonExtParametersAndIssueCommandFromAL |
---|
[410] | 122 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS |
---|
[399] | 123 | .SkipInitializeDeviceParameters: |
---|
[3] | 124 | |
---|
[410] | 125 | |
---|
[399] | 126 | ;;; SetWriteCache |
---|
| 127 | ; Enable or Disable Write Cache |
---|
[276] | 128 | call AccessDPT_GetPointerToDRVPARAMStoCSBX |
---|
| 129 | mov bl, [cs:bx+DRVPARAMS.wFlags] |
---|
[399] | 130 | push bx ; Save .wFlags for later use in InitializeBlockMode |
---|
[276] | 131 | and bx, BYTE MASK_DRVPARAMS_WRITECACHE |
---|
[399] | 132 | jz SHORT .SkipSetWriteCache ; DEFAULT_WRITE_CACHE |
---|
[276] | 133 | mov si, [cs:bx+.rgbWriteCacheCommands] |
---|
[399] | 134 | call AH23h_SetControllerFeatures |
---|
[410] | 135 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE |
---|
[399] | 136 | .SkipSetWriteCache: |
---|
[276] | 137 | |
---|
[410] | 138 | |
---|
[399] | 139 | ;;; RecalibrateDrive |
---|
| 140 | ; Recalibrate drive by seeking to cylinder 0 |
---|
| 141 | call AH11h_RecalibrateDrive |
---|
[410] | 142 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE |
---|
[276] | 143 | |
---|
[399] | 144 | |
---|
| 145 | ;;; InitializeBlockMode |
---|
| 146 | ; Initialize block mode transfers |
---|
| 147 | pop ax ; Restore .wFlags saved in SetWriteCache |
---|
| 148 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED |
---|
| 149 | jz SHORT .BlockModeNotSupportedOrDisabled |
---|
| 150 | test al, FLG_DRVPARAMS_BLOCKMODE |
---|
| 151 | jz SHORT .BlockModeNotSupportedOrDisabled |
---|
| 152 | |
---|
| 153 | ; Try block sizes until we find largest possible supported by drive |
---|
| 154 | mov bl, 128 |
---|
| 155 | .TryNextBlockSize: |
---|
| 156 | mov al, bl |
---|
| 157 | call AH24h_SetBlockSize ; Stores block size to DPT |
---|
| 158 | jnc SHORT .SupportedBlockSizeFound |
---|
| 159 | shr bl, 1 |
---|
| 160 | jnc SHORT .TryNextBlockSize |
---|
[410] | 161 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE |
---|
[399] | 162 | .BlockModeNotSupportedOrDisabled: |
---|
| 163 | .SupportedBlockSizeFound: |
---|
| 164 | |
---|
[410] | 165 | |
---|
[363] | 166 | %ifdef MODULE_ADVANCED_ATA |
---|
[399] | 167 | ;;; InitializePioMode |
---|
| 168 | ; Initialize fastest supported PIO mode |
---|
[364] | 169 | mov dl, PIO_DEFAULT_MODE_DISABLE_IORDY |
---|
| 170 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_IORDY |
---|
| 171 | jz SHORT .IordyNotSupported |
---|
| 172 | |
---|
| 173 | ; Advanced PIO mode 3 and above |
---|
| 174 | mov dl, [di+DPT_ADVANCED_ATA.bPioMode] |
---|
| 175 | or dl, PIO_FLOW_CONTROL_MODE_xxx |
---|
| 176 | |
---|
| 177 | .IordyNotSupported: |
---|
[363] | 178 | mov si, FEATURE_SET_TRANSFER_MODE |
---|
[399] | 179 | call AH23h_SetControllerFeatures |
---|
[410] | 180 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SET_PIO_MODE |
---|
[399] | 181 | %endif ; MODULE_ADVANCED_ATA |
---|
[363] | 182 | |
---|
[410] | 183 | |
---|
[399] | 184 | %ifdef MODULE_FEATURE_SETS |
---|
| 185 | ;;; InitStandbyTimer |
---|
| 186 | ; Initialize the standby timer (if supported) |
---|
| 187 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_POWER_MANAGEMENT_SUPPORTED |
---|
[410] | 188 | jz SHORT .NoPowerManagementSupport |
---|
[363] | 189 | |
---|
[399] | 190 | mov al, COMMAND_IDLE |
---|
| 191 | mov dl, [cs:ROMVARS.bIdleTimeout] |
---|
| 192 | mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY) |
---|
| 193 | call Idepack_StoreNonExtParametersAndIssueCommandFromAL |
---|
[410] | 194 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_INITIALIZE_STANDBY_TIMER |
---|
[399] | 195 | .NoPowerManagementSupport: |
---|
| 196 | %endif ; MODULE_FEATURE_SETS |
---|
| 197 | |
---|
[410] | 198 | |
---|
[399] | 199 | ; There might have been several errors so just return one error code for them all |
---|
[410] | 200 | .ReturnWithErrorCodeInAH: |
---|
[400] | 201 | %ifdef MODULE_ADVANCED_ATA |
---|
| 202 | mov ah, [di+DPT_ADVANCED_ATA.bInitError] |
---|
[399] | 203 | test ah, ah ; Clears CF |
---|
[410] | 204 | jz SHORT .ReturnWithSuccess |
---|
[399] | 205 | mov ah, RET_HD_RESETFAIL |
---|
| 206 | stc |
---|
[410] | 207 | .ReturnWithSuccess: |
---|
[400] | 208 | %endif |
---|
[399] | 209 | |
---|
| 210 | pop si |
---|
| 211 | pop es |
---|
[363] | 212 | ret |
---|
| 213 | |
---|
| 214 | |
---|
[410] | 215 | .rgbWriteCacheCommands: |
---|
| 216 | db 0 ; DEFAULT_WRITE_CACHE |
---|
| 217 | db FEATURE_DISABLE_WRITE_CACHE ; DISABLE_WRITE_CACHE |
---|
| 218 | db FEATURE_ENABLE_WRITE_CACHE ; ENABLE_WRITE_CACHE |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | |
---|
[400] | 222 | %ifdef MODULE_ADVANCED_ATA |
---|
[363] | 223 | ;-------------------------------------------------------------------- |
---|
[410] | 224 | ; SetErrorFlagFromALwithErrorCodeInAH |
---|
[363] | 225 | ; Parameters: |
---|
| 226 | ; AH: BIOS Error Code |
---|
| 227 | ; AL: Error flag to set |
---|
| 228 | ; DS:DI: Ptr to DPT |
---|
[410] | 229 | ; CF: Set if error code in AH |
---|
| 230 | ; Clear if AH = 0 |
---|
[363] | 231 | ; Returns: |
---|
| 232 | ; CF: Clear if no error |
---|
| 233 | ; Set if error flag was set |
---|
| 234 | ; Corrupts registers: |
---|
[370] | 235 | ; Nothing |
---|
[363] | 236 | ;-------------------------------------------------------------------- |
---|
[410] | 237 | IgnoreInvalidCommandError: |
---|
[399] | 238 | xor ah, ah ; Clears CF |
---|
[410] | 239 | SetErrorFlagFromALwithErrorCodeInAH: |
---|
[365] | 240 | jnc SHORT .NoErrorFlagToSet |
---|
[363] | 241 | cmp ah, RET_HD_INVALID |
---|
[410] | 242 | jbe SHORT IgnoreInvalidCommandError |
---|
[363] | 243 | |
---|
[400] | 244 | or [di+DPT_ADVANCED_ATA.bInitError], al |
---|
[363] | 245 | stc |
---|
[365] | 246 | .NoErrorFlagToSet: |
---|
[3] | 247 | ret |
---|
[399] | 248 | |
---|
[400] | 249 | %endif |
---|