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

Last change on this file since 399 was 399, checked in by krille_n_@…, 13 years ago

Changes:

  • Added Power Management (Standby Timer) support to the BIOS and made it part of an optional module (MODULE_FEATURE_SETS). The total amount of ROM space used by this feature is 37 bytes. UNTESTED
  • Size optimizations (mostly inlining of procedures) and fixed a few bugs in AH9h_HInit.asm:
    1. DPT_ATA.bInitError would be cleared only if MODULE_SERIAL was not defined.
    2. The FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE flag could never be set.
    3. InitializeBlockMode could potentially loop forever if there was an error.
  • Removed some odd looking code in .PushResetStatus in BootMenuPrintCfg.asm
  • Made some changes to XTIDECFG so it can be built.
File size: 6.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; 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 ; 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
72 push es
73 push si
74
75;;; SelectDrive
76 ; Try to select drive and wait until ready
77 call AccessDPT_GetDriveSelectByteToAL
78 mov [bp+IDEPACK.bDrvAndHead], al
79 call Device_SelectDrive
80
81 mov al, FLG_INITERROR_FAILED_TO_SELECT_DRIVE
82 call .SetErrorFlagFromALwithErrorCodeInAH
83 jc .ReturnWithErrorCodeInAH
84
85;;; InitializeDeviceParameters
86 ; Initialize CHS parameters if LBA is not used
87 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
88 jnz SHORT .SkipInitializeDeviceParameters ; No need to initialize CHS parameters if LBA mode enabled
89
90 ; Initialize Logical Sectors per Track and Max Head number
91 mov ah, [di+DPT.bPchsHeads]
92 dec ah ; Max Head number
93 mov dl, [di+DPT.bPchsSectors] ; Sectors per Track
94 mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
95 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
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
104 call AccessDPT_GetPointerToDRVPARAMStoCSBX
105 mov bl, [cs:bx+DRVPARAMS.wFlags]
106 push bx ; Save .wFlags for later use in InitializeBlockMode
107 and bx, BYTE MASK_DRVPARAMS_WRITECACHE
108 jz SHORT .SkipSetWriteCache ; DEFAULT_WRITE_CACHE
109 mov si, [cs:bx+.rgbWriteCacheCommands]
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
127 jz SHORT .BlockModeNotSupportedOrDisabled
128 test al, FLG_DRVPARAMS_BLOCKMODE
129 jz SHORT .BlockModeNotSupportedOrDisabled
130
131 ; Try block sizes until we find largest possible supported by drive
132 mov bl, 128
133.TryNextBlockSize:
134 mov al, bl
135 call AH24h_SetBlockSize ; Stores block size to DPT
136 jnc SHORT .SupportedBlockSizeFound
137 shr bl, 1
138 jnc SHORT .TryNextBlockSize
139
140 mov al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
141 call .SetErrorFlagFromALwithErrorCodeInAH
142.BlockModeNotSupportedOrDisabled:
143.SupportedBlockSizeFound:
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
190 ret
191
192
193;--------------------------------------------------------------------
194; .SetErrorFlagFromALwithErrorCodeInAH
195; Parameters:
196; AH: BIOS Error Code
197; AL: Error flag to set
198; DS:DI: Ptr to DPT
199; Returns:
200; CF: Clear if no error
201; Set if error flag was set
202; Corrupts registers:
203; Nothing
204;--------------------------------------------------------------------
205.IgnoreInvalidCommandError:
206 xor ah, ah ; Clears CF
207
208.SetErrorFlagFromALwithErrorCodeInAH:
209 jnc SHORT .NoErrorFlagToSet
210 cmp ah, RET_HD_INVALID
211 jbe SHORT .IgnoreInvalidCommandError
212
213 or [di+DPT_ATA.bInitError], al
214 stc
215.NoErrorFlagToSet:
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 TracBrowser for help on using the repository browser.