source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm@ 418

Last change on this file since 418 was 410, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • Hotkey Bar now support color attributes even when not including MODULE_BOOT_MENU.
  • Cleaned AH=09h code a bit.
  • MODULE_ADVANCED_ATA now properly changes the device type to 32-bit.
  • BSY and RDY timeouts are now 2500 ms.
File size: 7.5 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Int 13h function AH=9h, Initialize Drive Parameters.
3
4;
5; XTIDE Universal BIOS and Associated Tools
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.
12;
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
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
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;--------------------------------------------------------------------
45; Int 13h function AH=9h, Initialize Drive Parameters.
46;
47; AH9h_HandlerForInitializeDriveParameters
48; Parameters:
49; DL: Translated Drive number
50; DS:DI: Ptr to DPT (in RAMVARS segment)
51; SS:BP: Ptr to IDEPACK
52; Returns with INTPACK:
53; AH: Int 13h return status
54; CF: 0 if successful, 1 if error
55;--------------------------------------------------------------------
56AH9h_HandlerForInitializeDriveParameters:
57%ifndef USE_186
58 call AH9h_InitializeDriveForUse
59 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
60%else
61 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
62 ; Fall to AH9h_InitializeDriveForUse
63%endif
64
65
66;--------------------------------------------------------------------
67; Initialize drive to be ready for use.
68;
69; AH9h_InitializeDriveForUse
70; Parameters:
71; DS:DI: Ptr to DPT (in RAMVARS segment)
72; SS:BP: Ptr to IDEPACK
73; Returns:
74; AH: Int 13h return status
75; CF: 0 if successful, 1 if error
76; Corrupts registers:
77; AL, BX, CX, DX
78;--------------------------------------------------------------------
79AH9h_InitializeDriveForUse:
80 xor ax, ax ; Clear AH to assume no errors
81
82%ifdef MODULE_ADVANCED_ATA
83 ; Clear Initialization Error flags from DPT
84 mov [di+DPT_ADVANCED_ATA.bInitError], al
85%endif
86
87%ifdef MODULE_SERIAL
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
92.ContinueInitialization:
93%endif
94
95 push es
96 push si
97
98
99;;; SelectDrive
100 ; Try to select drive and wait until ready
101 call AccessDPT_GetDriveSelectByteToAL
102 mov [bp+IDEPACK.bDrvAndHead], al
103 call Device_SelectDrive
104 STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SELECT_DRIVE
105 jnc SHORT .ContinueInitializationSinceDriveSelectedSuccesfully
106 jmp .ReturnWithErrorCodeInAH
107.ContinueInitializationSinceDriveSelectedSuccesfully:
108
109
110;;; InitializeDeviceParameters
111 ; Initialize CHS parameters if LBA is not used
112 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
113 jnz SHORT .SkipInitializeDeviceParameters ; No need to initialize CHS parameters if LBA mode enabled
114
115 ; Initialize Logical Sectors per Track and Max Head number
116 mov ah, [di+DPT.bPchsHeads]
117 dec ah ; Max Head number
118 mov dl, [di+DPT.bPchsSectors] ; Sectors per Track
119 mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
120 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
121 call Idepack_StoreNonExtParametersAndIssueCommandFromAL
122 STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS
123.SkipInitializeDeviceParameters:
124
125
126;;; SetWriteCache
127 ; Enable or Disable Write Cache
128 call AccessDPT_GetPointerToDRVPARAMStoCSBX
129 mov bl, [cs:bx+DRVPARAMS.wFlags]
130 push bx ; Save .wFlags for later use in InitializeBlockMode
131 and bx, BYTE MASK_DRVPARAMS_WRITECACHE
132 jz SHORT .SkipSetWriteCache ; DEFAULT_WRITE_CACHE
133 mov si, [cs:bx+.rgbWriteCacheCommands]
134 call AH23h_SetControllerFeatures
135 STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE
136.SkipSetWriteCache:
137
138
139;;; RecalibrateDrive
140 ; Recalibrate drive by seeking to cylinder 0
141 call AH11h_RecalibrateDrive
142 STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE
143
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
161 STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
162.BlockModeNotSupportedOrDisabled:
163.SupportedBlockSizeFound:
164
165
166%ifdef MODULE_ADVANCED_ATA
167;;; InitializePioMode
168 ; Initialize fastest supported PIO mode
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:
178 mov si, FEATURE_SET_TRANSFER_MODE
179 call AH23h_SetControllerFeatures
180 STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_SET_PIO_MODE
181%endif ; MODULE_ADVANCED_ATA
182
183
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
188 jz SHORT .NoPowerManagementSupport
189
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
194 STORE_ERROR_FLAG_TO_DPT FLG_INITERROR_FAILED_TO_INITIALIZE_STANDBY_TIMER
195.NoPowerManagementSupport:
196%endif ; MODULE_FEATURE_SETS
197
198
199 ; There might have been several errors so just return one error code for them all
200.ReturnWithErrorCodeInAH:
201%ifdef MODULE_ADVANCED_ATA
202 mov ah, [di+DPT_ADVANCED_ATA.bInitError]
203 test ah, ah ; Clears CF
204 jz SHORT .ReturnWithSuccess
205 mov ah, RET_HD_RESETFAIL
206 stc
207.ReturnWithSuccess:
208%endif
209
210 pop si
211 pop es
212 ret
213
214
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
222%ifdef MODULE_ADVANCED_ATA
223;--------------------------------------------------------------------
224; SetErrorFlagFromALwithErrorCodeInAH
225; Parameters:
226; AH: BIOS Error Code
227; AL: Error flag to set
228; DS:DI: Ptr to DPT
229; CF: Set if error code in AH
230; Clear if AH = 0
231; Returns:
232; CF: Clear if no error
233; Set if error flag was set
234; Corrupts registers:
235; Nothing
236;--------------------------------------------------------------------
237IgnoreInvalidCommandError:
238 xor ah, ah ; Clears CF
239SetErrorFlagFromALwithErrorCodeInAH:
240 jnc SHORT .NoErrorFlagToSet
241 cmp ah, RET_HD_INVALID
242 jbe SHORT IgnoreInvalidCommandError
243
244 or [di+DPT_ADVANCED_ATA.bInitError], al
245 stc
246.NoErrorFlagToSet:
247 ret
248
249%endif
Note: See TracBrowser for help on using the repository browser.