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

Last change on this file since 387 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

File size: 7.8 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; Int 13h function AH=9h, Initialize Drive Parameters.
25;
26; AH9h_HandlerForInitializeDriveParameters
27; Parameters:
28; DL: Translated Drive number
29; DS:DI: Ptr to DPT (in RAMVARS segment)
30; SS:BP: Ptr to IDEPACK
31; Returns with INTPACK:
32; AH: Int 13h return status
33; CF: 0 if successful, 1 if error
34;--------------------------------------------------------------------
35AH9h_HandlerForInitializeDriveParameters:
36%ifndef USE_186
37 call AH9h_InitializeDriveForUse
38 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
39%else
40 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
41 ; Fall to AH9h_InitializeDriveForUse
42%endif
43
44
45;--------------------------------------------------------------------
46; Initialized drive to be ready for use.
47;
48; AH9h_InitializeDriveForUse
49; Parameters:
50; DS:DI: Ptr to DPT (in RAMVARS segment)
51; SS:BP: Ptr to IDEPACK
52; Returns:
53; AH: Int 13h return status
54; CF: 0 if successful, 1 if error
55; Corrupts registers:
56; AL, BX, CX, DX
57;--------------------------------------------------------------------
58AH9h_InitializeDriveForUse:
59 push es
60 push si
61
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
73 ; Try to select drive and wait until ready
74 call AccessDPT_GetDriveSelectByteToAL
75 mov [bp+IDEPACK.bDrvAndHead], al
76 call Device_SelectDrive
77 mov al, FLG_INITERROR_FAILED_TO_SELECT_DRIVE
78 call SetErrorFlagFromALwithErrorCodeInAH
79 jc SHORT .ReturnWithErrorCodeInAH
80
81 ; 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;--------------------------------------------------------------------
136InitializeDeviceParameters:
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
140
141 ; Initialize Logical Sectors per Track and Max Head number
142 mov ah, [di+DPT.bPchsHeads]
143 dec ah ; Max Head number
144 mov dl, [di+DPT.bPchsSectors] ; Sectors per Track
145 mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
146 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;--------------------------------------------------------------------
161SetWriteCache:
162 call AccessDPT_GetPointerToDRVPARAMStoCSBX
163 mov bl, [cs:bx+DRVPARAMS.wFlags]
164 and bx, BYTE MASK_DRVPARAMS_WRITECACHE
165 jz SHORT ReturnSuccessSinceInitializationNotNeeded ; DEFAULT_WRITE_CACHE
166 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;--------------------------------------------------------------------
187InitializePioMode:
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;--------------------------------------------------------------------
213InitializeBlockMode:
214 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED ; Clear CF
215 jz SHORT .BlockModeNotSupportedOrDisabled
216 call AccessDPT_GetPointerToDRVPARAMStoCSBX
217 test BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_BLOCKMODE
218 jz SHORT .BlockModeNotSupportedOrDisabled
219
220 ; Try block sizes until we find largest possible supported by drive
221 mov bl, 128
222.TryNextBlockSize:
223 mov al, bl
224 call AH24h_SetBlockSize
225 jnc SHORT .SupportedBlockSizeFound
226 shr bl, 1 ; Try next size
227 jmp SHORT .TryNextBlockSize
228.SupportedBlockSizeFound:
229 mov [di+DPT_ATA.bBlockSize], bl
230.BlockModeNotSupportedOrDisabled:
231ReturnSuccessSinceInitializationNotNeeded:
232 ret
233
234
235;--------------------------------------------------------------------
236; SetErrorFlagFromALwithErrorCodeInAH
237; Parameters:
238; AH: BIOS Error Code
239; AL: Error flag to set
240; DS:DI: Ptr to DPT
241; Returns:
242; CF: Clear if no error
243; Set if error flag was set
244; Corrupts registers:
245; Nothing
246;--------------------------------------------------------------------
247SetErrorFlagFromALwithErrorCodeInAH:
248 jnc SHORT .NoErrorFlagToSet
249 cmp ah, RET_HD_INVALID
250 jbe SHORT .IgnoreInvalidCommandError
251
252 or [di+DPT_ATA.bInitError], al
253 stc
254 ret
255.IgnoreInvalidCommandError:
256 xor ah, ah
257.NoErrorFlagToSet:
258 ret
Note: See TracBrowser for help on using the repository browser.