Changeset 399 in xtideuniversalbios for trunk/XTIDE_Universal_BIOS/Src/Handlers
- Timestamp:
- Apr 19, 2012, 10:39:44 PM (13 years ago)
- google:author:
- krille_n_@hotmail.com
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm
r376 r399 3 3 4 4 ; 5 ; XTIDE Universal BIOS and Associated Tools 5 ; XTIDE Universal BIOS and Associated Tools 6 6 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team. 7 7 ; … … 10 10 ; the Free Software Foundation; either version 2 of the License, or 11 11 ; (at your option) any later version. 12 ; 12 ; 13 13 ; This program is distributed in the hope that it will be useful, 14 14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ; GNU General Public License for more details. 16 ; GNU General Public License for more details. 17 17 ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 18 ; 18 ; 19 19 20 20 ; Section containing code … … 44 44 45 45 ;-------------------------------------------------------------------- 46 ; Initialize ddrive to be ready for use.46 ; Initialize drive to be ready for use. 47 47 ; 48 48 ; AH9h_InitializeDriveForUse … … 57 57 ;-------------------------------------------------------------------- 58 58 AH9h_InitializeDriveForUse: 59 xor ax, ax 60 61 ; Clear Initialization Error flags from DPT 62 mov [di+DPT_ATA.bInitError], al 63 64 %ifdef MODULE_SERIAL 65 ; No need to do this for serial devices 66 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE ; Clears CF 67 jz SHORT .ContinueInitialization 68 ret ; With AH and CF cleared 69 .ContinueInitialization: 70 %endif 71 59 72 push es 60 73 push si 61 74 62 %ifdef MODULE_SERIAL 63 ; no need to do this for serial devices 64 xor ah, ah 65 test byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE ; Clears CF 66 jnz .ReturnWithErrorCodeInAH 67 68 %else 69 ; Clear Initialization Error flags from DPT 70 mov BYTE [di+DPT_ATA.bInitError], 0 71 %endif 72 75 ;;; SelectDrive 73 76 ; Try to select drive and wait until ready 74 77 call AccessDPT_GetDriveSelectByteToAL 75 78 mov [bp+IDEPACK.bDrvAndHead], al 76 79 call Device_SelectDrive 80 77 81 mov al, FLG_INITERROR_FAILED_TO_SELECT_DRIVE 78 call SetErrorFlagFromALwithErrorCodeInAH 79 jc SHORT .ReturnWithErrorCodeInAH 80 82 call .SetErrorFlagFromALwithErrorCodeInAH 83 jc .ReturnWithErrorCodeInAH 84 85 ;;; InitializeDeviceParameters 81 86 ; Initialize CHS parameters if LBA is not used 82 call InitializeDeviceParameters 83 mov al, FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS 84 call SetErrorFlagFromALwithErrorCodeInAH 85 86 ; Enable or Disable Write Cache 87 call SetWriteCache 88 mov al, FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE 89 call SetErrorFlagFromALwithErrorCodeInAH 90 91 ; Recalibrate drive by seeking to cylinder 0 92 .RecalibrateDrive: 93 call AH11h_RecalibrateDrive 94 mov al, FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE 95 call SetErrorFlagFromALwithErrorCodeInAH 96 97 ; Initialize block mode transfers 98 .InitializeBlockMode: 99 call InitializeBlockMode 100 mov al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE 101 call SetErrorFlagFromALwithErrorCodeInAH 102 103 %ifdef MODULE_ADVANCED_ATA 104 ; Initialize fastest supported PIO mode 105 .InitializePioMode: 106 call InitializePioMode 107 mov al, FLG_INITERROR_FAILED_TO_SET_PIO_MODE 108 call SetErrorFlagFromALwithErrorCodeInAH 109 %endif 110 111 ; There might have been several errors so just return 112 ; one error code for them all 113 cmp BYTE [di+DPT_ATA.bInitError], 0 114 je SHORT .ReturnWithErrorCodeInAH 115 mov ah, RET_HD_RESETFAIL 116 stc 117 118 .ReturnWithErrorCodeInAH: 119 pop si 120 pop es 121 ret 122 123 124 ;-------------------------------------------------------------------- 125 ; InitializeDeviceParameters 126 ; Parameters: 127 ; DS:DI: Ptr to DPT (in RAMVARS segment) 128 ; SS:BP: Ptr to IDEPACK 129 ; Returns: 130 ; AH: BIOS Error code 131 ; CF: Cleared if successful 132 ; Set if any error 133 ; Corrupts registers: 134 ; AL, BX, CX, DX 135 ;-------------------------------------------------------------------- 136 InitializeDeviceParameters: 137 ; No need to initialize CHS parameters if LBA mode enabled 138 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA ; Clear CF 139 jnz SHORT ReturnSuccessSinceInitializationNotNeeded 87 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA 88 jnz SHORT .SkipInitializeDeviceParameters ; No need to initialize CHS parameters if LBA mode enabled 140 89 141 90 ; Initialize Logical Sectors per Track and Max Head number … … 145 94 mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS 146 95 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY) 147 jmp Idepack_StoreNonExtParametersAndIssueCommandFromAL 148 149 150 ;-------------------------------------------------------------------- 151 ; SetWriteCache 152 ; Parameters: 153 ; DS:DI: Ptr to DPT (in RAMVARS segment) 154 ; Returns: 155 ; AH: BIOS Error code 156 ; CF: Cleared if successful 157 ; Set if any error 158 ; Corrupts registers: 159 ; AL, BX, CX, DX, SI 160 ;-------------------------------------------------------------------- 161 SetWriteCache: 96 call Idepack_StoreNonExtParametersAndIssueCommandFromAL 97 98 mov al, FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS 99 call .SetErrorFlagFromALwithErrorCodeInAH 100 .SkipInitializeDeviceParameters: 101 102 ;;; SetWriteCache 103 ; Enable or Disable Write Cache 162 104 call AccessDPT_GetPointerToDRVPARAMStoCSBX 163 105 mov bl, [cs:bx+DRVPARAMS.wFlags] 106 push bx ; Save .wFlags for later use in InitializeBlockMode 164 107 and bx, BYTE MASK_DRVPARAMS_WRITECACHE 165 jz SHORT ReturnSuccessSinceInitializationNotNeeded; DEFAULT_WRITE_CACHE108 jz SHORT .SkipSetWriteCache ; DEFAULT_WRITE_CACHE 166 109 mov si, [cs:bx+.rgbWriteCacheCommands] 167 jmp AH23h_SetControllerFeatures 168 169 .rgbWriteCacheCommands: 170 db 0 ; DEFAULT_WRITE_CACHE 171 db FEATURE_DISABLE_WRITE_CACHE ; DISABLE_WRITE_CACHE 172 db FEATURE_ENABLE_WRITE_CACHE ; ENABLE_WRITE_CACHE 173 174 175 %ifdef MODULE_ADVANCED_ATA 176 ;-------------------------------------------------------------------- 177 ; InitializePioMode 178 ; Parameters: 179 ; DS:DI: Ptr to DPT (in RAMVARS segment) 180 ; Returns: 181 ; AH: BIOS Error code 182 ; CF: Cleared if successful 183 ; Set if any error 184 ; Corrupts registers: 185 ; AL, BX, CX, DX 186 ;-------------------------------------------------------------------- 187 InitializePioMode: 188 mov dl, PIO_DEFAULT_MODE_DISABLE_IORDY 189 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_IORDY 190 jz SHORT .IordyNotSupported 191 192 ; Advanced PIO mode 3 and above 193 mov dl, [di+DPT_ADVANCED_ATA.bPioMode] 194 or dl, PIO_FLOW_CONTROL_MODE_xxx 195 196 .IordyNotSupported: 197 mov si, FEATURE_SET_TRANSFER_MODE 198 jmp AH23h_SetControllerFeatures 199 %endif 200 201 202 ;-------------------------------------------------------------------- 203 ; InitializeBlockMode 204 ; Parameters: 205 ; DS:DI: Ptr to DPT (in RAMVARS segment) 206 ; Returns: 207 ; AH: BIOS Error code 208 ; CF: Cleared if successful 209 ; Set if any error 210 ; Corrupts registers: 211 ; AL, BX, CX, DX 212 ;-------------------------------------------------------------------- 213 InitializeBlockMode: 214 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED ; Clear CF 110 call AH23h_SetControllerFeatures 111 112 mov al, FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE 113 call .SetErrorFlagFromALwithErrorCodeInAH 114 .SkipSetWriteCache: 115 116 ;;; RecalibrateDrive 117 ; Recalibrate drive by seeking to cylinder 0 118 call AH11h_RecalibrateDrive 119 120 mov al, FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE 121 call .SetErrorFlagFromALwithErrorCodeInAH 122 123 ;;; InitializeBlockMode 124 ; Initialize block mode transfers 125 pop ax ; Restore .wFlags saved in SetWriteCache 126 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED 215 127 jz SHORT .BlockModeNotSupportedOrDisabled 216 call AccessDPT_GetPointerToDRVPARAMStoCSBX 217 test BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_BLOCKMODE 128 test al, FLG_DRVPARAMS_BLOCKMODE 218 129 jz SHORT .BlockModeNotSupportedOrDisabled 219 130 … … 222 133 .TryNextBlockSize: 223 134 mov al, bl 224 call AH24h_SetBlockSize 135 call AH24h_SetBlockSize ; Stores block size to DPT 225 136 jnc SHORT .SupportedBlockSizeFound 226 shr bl, 1 ; Try next size 227 jmp SHORT .TryNextBlockSize 137 shr bl, 1 138 jnc SHORT .TryNextBlockSize 139 140 mov al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE 141 call .SetErrorFlagFromALwithErrorCodeInAH 142 .BlockModeNotSupportedOrDisabled: 228 143 .SupportedBlockSizeFound: 229 mov [di+DPT_ATA.bBlockSize], bl 230 .BlockModeNotSupportedOrDisabled: 231 ReturnSuccessSinceInitializationNotNeeded: 144 145 %ifdef MODULE_ADVANCED_ATA 146 ;;; InitializePioMode 147 ; Initialize fastest supported PIO mode 148 mov dl, PIO_DEFAULT_MODE_DISABLE_IORDY 149 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_IORDY 150 jz SHORT .IordyNotSupported 151 152 ; Advanced PIO mode 3 and above 153 mov dl, [di+DPT_ADVANCED_ATA.bPioMode] 154 or dl, PIO_FLOW_CONTROL_MODE_xxx 155 156 .IordyNotSupported: 157 mov si, FEATURE_SET_TRANSFER_MODE 158 call AH23h_SetControllerFeatures 159 160 mov al, FLG_INITERROR_FAILED_TO_SET_PIO_MODE 161 call .SetErrorFlagFromALwithErrorCodeInAH 162 %endif ; MODULE_ADVANCED_ATA 163 164 %ifdef MODULE_FEATURE_SETS 165 ;;; InitStandbyTimer 166 ; Initialize the standby timer (if supported) 167 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_POWER_MANAGEMENT_SUPPORTED 168 jz .NoPowerManagementSupport 169 170 mov al, COMMAND_IDLE 171 mov dl, [cs:ROMVARS.bIdleTimeout] 172 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY) 173 call Idepack_StoreNonExtParametersAndIssueCommandFromAL 174 175 mov al, FLG_INITERROR_FAILED_TO_INITIALIZE_STANDBY_TIMER 176 call .SetErrorFlagFromALwithErrorCodeInAH 177 .NoPowerManagementSupport: 178 %endif ; MODULE_FEATURE_SETS 179 180 ; There might have been several errors so just return one error code for them all 181 mov ah, [di+DPT_ATA.bInitError] 182 test ah, ah ; Clears CF 183 jz SHORT .ReturnWithErrorCodeInAH 184 mov ah, RET_HD_RESETFAIL 185 stc 186 187 .ReturnWithErrorCodeInAH: 188 pop si 189 pop es 232 190 ret 233 191 234 192 235 193 ;-------------------------------------------------------------------- 236 ; SetErrorFlagFromALwithErrorCodeInAH194 ; .SetErrorFlagFromALwithErrorCodeInAH 237 195 ; Parameters: 238 196 ; AH: BIOS Error Code … … 245 203 ; Nothing 246 204 ;-------------------------------------------------------------------- 247 SetErrorFlagFromALwithErrorCodeInAH: 205 .IgnoreInvalidCommandError: 206 xor ah, ah ; Clears CF 207 208 .SetErrorFlagFromALwithErrorCodeInAH: 248 209 jnc SHORT .NoErrorFlagToSet 249 210 cmp ah, RET_HD_INVALID … … 252 213 or [di+DPT_ATA.bInitError], al 253 214 stc 254 ret255 .IgnoreInvalidCommandError:256 xor ah, ah257 215 .NoErrorFlagToSet: 258 216 ret 217 218 219 .rgbWriteCacheCommands: 220 db 0 ; DEFAULT_WRITE_CACHE 221 db FEATURE_DISABLE_WRITE_CACHE ; DISABLE_WRITE_CACHE 222 db FEATURE_ENABLE_WRITE_CACHE ; ENABLE_WRITE_CACHE 223
Note:
See TracChangeset
for help on using the changeset viewer.