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

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

Changes to XTIDE Universal BIOS:

  • Moved 8-bit device support to MODULE_8BIT_IDE.
  • JR-IDE/ISA support requires a lot less bytes.
  • AT builds now always use full operating mode.
File size: 7.2 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; Initialize 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 xor ax, ax
60
61%ifdef MODULE_ADVANCED_ATA
62 ; Clear Initialization Error flags from DPT
63 mov [di+DPT_ADVANCED_ATA.bInitError], al
64%endif
65
66%ifdef MODULE_SERIAL
67 ; No need to do this for serial devices
68 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE ; Clears CF
69 jz SHORT .ContinueInitialization
70 ret ; With AH and CF cleared
71 .ContinueInitialization:
72%endif
73
74 push es
75 push si
76
77;;; SelectDrive
78 ; Try to select drive and wait until ready
79 call AccessDPT_GetDriveSelectByteToAL
80 mov [bp+IDEPACK.bDrvAndHead], al
81 call Device_SelectDrive
82
83%ifdef MODULE_ADVANCED_ATA
84 mov al, FLG_INITERROR_FAILED_TO_SELECT_DRIVE
85 call .SetErrorFlagFromALwithErrorCodeInAH
86%endif
87 jc .ReturnWithErrorCodeInAH
88
89;;; InitializeDeviceParameters
90 ; Initialize CHS parameters if LBA is not used
91 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
92 jnz SHORT .SkipInitializeDeviceParameters ; No need to initialize CHS parameters if LBA mode enabled
93
94 ; Initialize Logical Sectors per Track and Max Head number
95 mov ah, [di+DPT.bPchsHeads]
96 dec ah ; Max Head number
97 mov dl, [di+DPT.bPchsSectors] ; Sectors per Track
98 mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
99 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
100 call Idepack_StoreNonExtParametersAndIssueCommandFromAL
101
102%ifdef MODULE_ADVANCED_ATA
103 mov al, FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS
104 call .SetErrorFlagFromALwithErrorCodeInAH
105%endif
106.SkipInitializeDeviceParameters:
107
108;;; SetWriteCache
109 ; Enable or Disable Write Cache
110 call AccessDPT_GetPointerToDRVPARAMStoCSBX
111 mov bl, [cs:bx+DRVPARAMS.wFlags]
112 push bx ; Save .wFlags for later use in InitializeBlockMode
113 and bx, BYTE MASK_DRVPARAMS_WRITECACHE
114 jz SHORT .SkipSetWriteCache ; DEFAULT_WRITE_CACHE
115 mov si, [cs:bx+.rgbWriteCacheCommands]
116 call AH23h_SetControllerFeatures
117
118%ifdef MODULE_ADVANCED_ATA
119 mov al, FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE
120 call .SetErrorFlagFromALwithErrorCodeInAH
121%endif
122.SkipSetWriteCache:
123
124;;; RecalibrateDrive
125 ; Recalibrate drive by seeking to cylinder 0
126 call AH11h_RecalibrateDrive
127
128%ifdef MODULE_ADVANCED_ATA
129 mov al, FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE
130 call .SetErrorFlagFromALwithErrorCodeInAH
131%endif
132
133;;; InitializeBlockMode
134 ; Initialize block mode transfers
135 pop ax ; Restore .wFlags saved in SetWriteCache
136 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
137 jz SHORT .BlockModeNotSupportedOrDisabled
138 test al, FLG_DRVPARAMS_BLOCKMODE
139 jz SHORT .BlockModeNotSupportedOrDisabled
140
141 ; Try block sizes until we find largest possible supported by drive
142 mov bl, 128
143.TryNextBlockSize:
144 mov al, bl
145 call AH24h_SetBlockSize ; Stores block size to DPT
146 jnc SHORT .SupportedBlockSizeFound
147 shr bl, 1
148 jnc SHORT .TryNextBlockSize
149
150%ifdef MODULE_ADVANCED_ATA
151 mov al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
152 call .SetErrorFlagFromALwithErrorCodeInAH
153%endif
154.BlockModeNotSupportedOrDisabled:
155.SupportedBlockSizeFound:
156
157%ifdef MODULE_ADVANCED_ATA
158;;; InitializePioMode
159 ; Initialize fastest supported PIO mode
160 mov dl, PIO_DEFAULT_MODE_DISABLE_IORDY
161 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_IORDY
162 jz SHORT .IordyNotSupported
163
164 ; Advanced PIO mode 3 and above
165 mov dl, [di+DPT_ADVANCED_ATA.bPioMode]
166 or dl, PIO_FLOW_CONTROL_MODE_xxx
167
168.IordyNotSupported:
169 mov si, FEATURE_SET_TRANSFER_MODE
170 call AH23h_SetControllerFeatures
171
172 mov al, FLG_INITERROR_FAILED_TO_SET_PIO_MODE
173 call .SetErrorFlagFromALwithErrorCodeInAH
174%endif ; MODULE_ADVANCED_ATA
175
176%ifdef MODULE_FEATURE_SETS
177;;; InitStandbyTimer
178 ; Initialize the standby timer (if supported)
179 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_POWER_MANAGEMENT_SUPPORTED
180 jz .NoPowerManagementSupport
181
182 mov al, COMMAND_IDLE
183 mov dl, [cs:ROMVARS.bIdleTimeout]
184 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
185 call Idepack_StoreNonExtParametersAndIssueCommandFromAL
186
187%ifdef MODULE_ADVANCED_ATA
188 mov al, FLG_INITERROR_FAILED_TO_INITIALIZE_STANDBY_TIMER
189 call .SetErrorFlagFromALwithErrorCodeInAH
190%endif
191.NoPowerManagementSupport:
192%endif ; MODULE_FEATURE_SETS
193
194 ; There might have been several errors so just return one error code for them all
195%ifdef MODULE_ADVANCED_ATA
196 mov ah, [di+DPT_ADVANCED_ATA.bInitError]
197 test ah, ah ; Clears CF
198 jz SHORT .ReturnWithErrorCodeInAH
199 mov ah, RET_HD_RESETFAIL
200 stc
201%endif
202
203.ReturnWithErrorCodeInAH:
204 pop si
205 pop es
206 ret
207
208
209%ifdef MODULE_ADVANCED_ATA
210;--------------------------------------------------------------------
211; .SetErrorFlagFromALwithErrorCodeInAH
212; Parameters:
213; AH: BIOS Error Code
214; AL: Error flag to set
215; DS:DI: Ptr to DPT
216; Returns:
217; CF: Clear if no error
218; Set if error flag was set
219; Corrupts registers:
220; Nothing
221;--------------------------------------------------------------------
222.IgnoreInvalidCommandError:
223 xor ah, ah ; Clears CF
224
225.SetErrorFlagFromALwithErrorCodeInAH:
226 jnc SHORT .NoErrorFlagToSet
227 cmp ah, RET_HD_INVALID
228 jbe SHORT .IgnoreInvalidCommandError
229
230 or [di+DPT_ADVANCED_ATA.bInitError], al
231 stc
232.NoErrorFlagToSet:
233 ret
234
235%endif
236
237
238.rgbWriteCacheCommands:
239 db 0 ; DEFAULT_WRITE_CACHE
240 db FEATURE_DISABLE_WRITE_CACHE ; DISABLE_WRITE_CACHE
241 db FEATURE_ENABLE_WRITE_CACHE ; ENABLE_WRITE_CACHE
Note: See TracBrowser for help on using the repository browser.