[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 |
---|
[421] | 101 | call AccessDPT_GetDriveSelectByteForOldInt13hToAL |
---|
[150] | 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 |
---|
[421] | 111 | ; Initialize CHS parameters if LBA is not used and |
---|
| 112 | ; user has specified P-CHS parameters |
---|
| 113 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_ASSISTED_LBA |
---|
[399] | 114 | jnz SHORT .SkipInitializeDeviceParameters ; No need to initialize CHS parameters if LBA mode enabled |
---|
[421] | 115 | call AccessDPT_GetPointerToDRVPARAMStoCSBX |
---|
| 116 | test BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS ; User specified P-CHS? |
---|
| 117 | jz SHORT .SkipInitializeDeviceParameters |
---|
[3] | 118 | |
---|
[157] | 119 | ; Initialize Logical Sectors per Track and Max Head number |
---|
[421] | 120 | mov ax, [cs:bx+DRVPARAMS.wHeadsAndSectors] |
---|
| 121 | dec ax ; Max Head number |
---|
| 122 | xchg al, ah ; Heads now in AH |
---|
| 123 | mov dx, ax ; Sectors per Track now in DL |
---|
[150] | 124 | mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS |
---|
| 125 | mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY) |
---|
[399] | 126 | call Idepack_StoreNonExtParametersAndIssueCommandFromAL |
---|
[410] | 127 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS |
---|
[399] | 128 | .SkipInitializeDeviceParameters: |
---|
[3] | 129 | |
---|
[410] | 130 | |
---|
[399] | 131 | ;;; SetWriteCache |
---|
| 132 | ; Enable or Disable Write Cache |
---|
[276] | 133 | call AccessDPT_GetPointerToDRVPARAMStoCSBX |
---|
| 134 | mov bl, [cs:bx+DRVPARAMS.wFlags] |
---|
[399] | 135 | push bx ; Save .wFlags for later use in InitializeBlockMode |
---|
[276] | 136 | and bx, BYTE MASK_DRVPARAMS_WRITECACHE |
---|
[399] | 137 | jz SHORT .SkipSetWriteCache ; DEFAULT_WRITE_CACHE |
---|
[276] | 138 | mov si, [cs:bx+.rgbWriteCacheCommands] |
---|
[399] | 139 | call AH23h_SetControllerFeatures |
---|
[410] | 140 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE |
---|
[399] | 141 | .SkipSetWriteCache: |
---|
[276] | 142 | |
---|
[410] | 143 | |
---|
[399] | 144 | ;;; RecalibrateDrive |
---|
| 145 | ; Recalibrate drive by seeking to cylinder 0 |
---|
| 146 | call AH11h_RecalibrateDrive |
---|
[410] | 147 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE |
---|
[276] | 148 | |
---|
[399] | 149 | |
---|
| 150 | ;;; InitializeBlockMode |
---|
| 151 | ; Initialize block mode transfers |
---|
| 152 | pop ax ; Restore .wFlags saved in SetWriteCache |
---|
| 153 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED |
---|
| 154 | jz SHORT .BlockModeNotSupportedOrDisabled |
---|
| 155 | test al, FLG_DRVPARAMS_BLOCKMODE |
---|
| 156 | jz SHORT .BlockModeNotSupportedOrDisabled |
---|
| 157 | |
---|
| 158 | ; Try block sizes until we find largest possible supported by drive |
---|
| 159 | mov bl, 128 |
---|
| 160 | .TryNextBlockSize: |
---|
| 161 | mov al, bl |
---|
| 162 | call AH24h_SetBlockSize ; Stores block size to DPT |
---|
| 163 | jnc SHORT .SupportedBlockSizeFound |
---|
| 164 | shr bl, 1 |
---|
| 165 | jnc SHORT .TryNextBlockSize |
---|
[410] | 166 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE |
---|
[399] | 167 | .BlockModeNotSupportedOrDisabled: |
---|
| 168 | .SupportedBlockSizeFound: |
---|
| 169 | |
---|
[410] | 170 | |
---|
[363] | 171 | %ifdef MODULE_ADVANCED_ATA |
---|
[399] | 172 | ;;; InitializePioMode |
---|
| 173 | ; Initialize fastest supported PIO mode |
---|
[364] | 174 | mov dl, PIO_DEFAULT_MODE_DISABLE_IORDY |
---|
| 175 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_IORDY |
---|
| 176 | jz SHORT .IordyNotSupported |
---|
| 177 | |
---|
| 178 | ; Advanced PIO mode 3 and above |
---|
| 179 | mov dl, [di+DPT_ADVANCED_ATA.bPioMode] |
---|
| 180 | or dl, PIO_FLOW_CONTROL_MODE_xxx |
---|
| 181 | |
---|
| 182 | .IordyNotSupported: |
---|
[363] | 183 | mov si, FEATURE_SET_TRANSFER_MODE |
---|
[399] | 184 | call AH23h_SetControllerFeatures |
---|
[410] | 185 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SET_PIO_MODE |
---|
[399] | 186 | %endif ; MODULE_ADVANCED_ATA |
---|
[363] | 187 | |
---|
[410] | 188 | |
---|
[399] | 189 | %ifdef MODULE_FEATURE_SETS |
---|
| 190 | ;;; InitStandbyTimer |
---|
| 191 | ; Initialize the standby timer (if supported) |
---|
| 192 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_POWER_MANAGEMENT_SUPPORTED |
---|
[410] | 193 | jz SHORT .NoPowerManagementSupport |
---|
[363] | 194 | |
---|
[399] | 195 | mov al, COMMAND_IDLE |
---|
| 196 | mov dl, [cs:ROMVARS.bIdleTimeout] |
---|
| 197 | mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY) |
---|
| 198 | call Idepack_StoreNonExtParametersAndIssueCommandFromAL |
---|
[410] | 199 | STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_INITIALIZE_STANDBY_TIMER |
---|
[399] | 200 | .NoPowerManagementSupport: |
---|
| 201 | %endif ; MODULE_FEATURE_SETS |
---|
| 202 | |
---|
[410] | 203 | |
---|
[399] | 204 | ; There might have been several errors so just return one error code for them all |
---|
[410] | 205 | .ReturnWithErrorCodeInAH: |
---|
[400] | 206 | %ifdef MODULE_ADVANCED_ATA |
---|
| 207 | mov ah, [di+DPT_ADVANCED_ATA.bInitError] |
---|
[399] | 208 | test ah, ah ; Clears CF |
---|
[410] | 209 | jz SHORT .ReturnWithSuccess |
---|
[399] | 210 | mov ah, RET_HD_RESETFAIL |
---|
| 211 | stc |
---|
[410] | 212 | .ReturnWithSuccess: |
---|
[400] | 213 | %endif |
---|
[399] | 214 | |
---|
| 215 | pop si |
---|
| 216 | pop es |
---|
[363] | 217 | ret |
---|
| 218 | |
---|
| 219 | |
---|
[410] | 220 | .rgbWriteCacheCommands: |
---|
| 221 | db 0 ; DEFAULT_WRITE_CACHE |
---|
| 222 | db FEATURE_DISABLE_WRITE_CACHE ; DISABLE_WRITE_CACHE |
---|
| 223 | db FEATURE_ENABLE_WRITE_CACHE ; ENABLE_WRITE_CACHE |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | |
---|
[400] | 227 | %ifdef MODULE_ADVANCED_ATA |
---|
[363] | 228 | ;-------------------------------------------------------------------- |
---|
[410] | 229 | ; SetErrorFlagFromALwithErrorCodeInAH |
---|
[363] | 230 | ; Parameters: |
---|
| 231 | ; AH: BIOS Error Code |
---|
| 232 | ; AL: Error flag to set |
---|
| 233 | ; DS:DI: Ptr to DPT |
---|
[410] | 234 | ; CF: Set if error code in AH |
---|
| 235 | ; Clear if AH = 0 |
---|
[363] | 236 | ; Returns: |
---|
| 237 | ; CF: Clear if no error |
---|
| 238 | ; Set if error flag was set |
---|
| 239 | ; Corrupts registers: |
---|
[370] | 240 | ; Nothing |
---|
[363] | 241 | ;-------------------------------------------------------------------- |
---|
[410] | 242 | IgnoreInvalidCommandError: |
---|
[399] | 243 | xor ah, ah ; Clears CF |
---|
[410] | 244 | SetErrorFlagFromALwithErrorCodeInAH: |
---|
[365] | 245 | jnc SHORT .NoErrorFlagToSet |
---|
[363] | 246 | cmp ah, RET_HD_INVALID |
---|
[410] | 247 | jbe SHORT IgnoreInvalidCommandError |
---|
[363] | 248 | |
---|
[400] | 249 | or [di+DPT_ADVANCED_ATA.bInitError], al |
---|
[363] | 250 | stc |
---|
[365] | 251 | .NoErrorFlagToSet: |
---|
[3] | 252 | ret |
---|
[399] | 253 | |
---|
[400] | 254 | %endif |
---|