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

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

Changes:

  • Added some missing PIO mode timings to ATA_ID.inc (based on info from http://www.singlix.net/specs/cfspc4_0.pdf)
  • Updated Configuration_FullMode.txt but it may need additional changes as the Tandy info doesn't match the wiki.
  • Optimizations.
  • Excluded some unused code from XTIDECFG.
File size: 7.1 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Int 13h function AH=9h, Initialize Drive Parameters.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Int 13h function AH=9h, Initialize Drive Parameters.
9;
10; AH9h_HandlerForInitializeDriveParameters
11; Parameters:
12; DL: Translated Drive number
13; DS:DI: Ptr to DPT (in RAMVARS segment)
14; SS:BP: Ptr to IDEPACK
15; Returns with INTPACK:
16; AH: Int 13h return status
17; CF: 0 if successful, 1 if error
18;--------------------------------------------------------------------
19AH9h_HandlerForInitializeDriveParameters:
20%ifndef USE_186
21 call AH9h_InitializeDriveForUse
22 jmp Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
23%else
24 push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
25 ; Fall to AH9h_InitializeDriveForUse
26%endif
27
28
29;--------------------------------------------------------------------
30; Initialized drive to be ready for use.
31;
32; AH9h_InitializeDriveForUse
33; Parameters:
34; DS:DI: Ptr to DPT (in RAMVARS segment)
35; SS:BP: Ptr to IDEPACK
36; Returns:
37; AH: Int 13h return status
38; CF: 0 if successful, 1 if error
39; Corrupts registers:
40; AL, BX, CX, DX
41;--------------------------------------------------------------------
42AH9h_InitializeDriveForUse:
43 push es
44 push si
45
46%ifdef MODULE_SERIAL
47 ; no need to do this for serial devices
48 xor ah, ah
49 test byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE ; Clears CF
50 jnz .ReturnWithErrorCodeInAH
51
52%else
53 ; Clear Initialization Error flags from DPT
54 mov BYTE [di+DPT_ATA.bInitError], 0
55%endif
56
57 ; Try to select drive and wait until ready
58 call AccessDPT_GetDriveSelectByteToAL
59 mov [bp+IDEPACK.bDrvAndHead], al
60 call Device_SelectDrive
61 mov al, FLG_INITERROR_FAILED_TO_SELECT_DRIVE
62 call SetErrorFlagFromALwithErrorCodeInAH
63 jc SHORT .ReturnWithErrorCodeInAH
64
65 ; Initialize CHS parameters if LBA is not used
66 call InitializeDeviceParameters
67 mov al, FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS
68 call SetErrorFlagFromALwithErrorCodeInAH
69
70 ; Enable or Disable Write Cache
71 call SetWriteCache
72 mov al, FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE
73 call SetErrorFlagFromALwithErrorCodeInAH
74
75 ; Recalibrate drive by seeking to cylinder 0
76.RecalibrateDrive:
77 call AH11h_RecalibrateDrive
78 mov al, FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE
79 call SetErrorFlagFromALwithErrorCodeInAH
80
81 ; Initialize block mode transfers
82.InitializeBlockMode:
83 call InitializeBlockMode
84 mov al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
85 call SetErrorFlagFromALwithErrorCodeInAH
86
87%ifdef MODULE_ADVANCED_ATA
88; Initialize fastest supported PIO mode
89.InitializePioMode:
90 call InitializePioMode
91 mov al, FLG_INITERROR_FAILED_TO_SET_PIO_MODE
92 call SetErrorFlagFromALwithErrorCodeInAH
93%endif
94
95 ; There might have been several errors so just return
96 ; one error code for them all
97 cmp BYTE [di+DPT_ATA.bInitError], 0
98 je SHORT .ReturnWithErrorCodeInAH
99 mov ah, RET_HD_RESETFAIL
100 stc
101
102.ReturnWithErrorCodeInAH:
103 pop si
104 pop es
105 ret
106
107
108;--------------------------------------------------------------------
109; InitializeDeviceParameters
110; Parameters:
111; DS:DI: Ptr to DPT (in RAMVARS segment)
112; SS:BP: Ptr to IDEPACK
113; Returns:
114; AH: BIOS Error code
115; CF: Cleared if successful
116; Set if any error
117; Corrupts registers:
118; AL, BX, CX, DX
119;--------------------------------------------------------------------
120InitializeDeviceParameters:
121 ; No need to initialize CHS parameters if LBA mode enabled
122 test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA ; Clear CF
123 jnz SHORT ReturnSuccessSinceInitializationNotNeeded
124
125 ; Initialize Logical Sectors per Track and Max Head number
126 mov ah, [di+DPT.bPchsHeads]
127 dec ah ; Max Head number
128 mov dl, [di+DPT.bPchsSectors] ; Sectors per Track
129 mov al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
130 mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
131 jmp Idepack_StoreNonExtParametersAndIssueCommandFromAL
132
133
134;--------------------------------------------------------------------
135; SetWriteCache
136; Parameters:
137; DS:DI: Ptr to DPT (in RAMVARS segment)
138; Returns:
139; AH: BIOS Error code
140; CF: Cleared if successful
141; Set if any error
142; Corrupts registers:
143; AL, BX, CX, DX, SI
144;--------------------------------------------------------------------
145SetWriteCache:
146 call AccessDPT_GetPointerToDRVPARAMStoCSBX
147 mov bl, [cs:bx+DRVPARAMS.wFlags]
148 and bx, BYTE MASK_DRVPARAMS_WRITECACHE
149 jz SHORT ReturnSuccessSinceInitializationNotNeeded ; DEFAULT_WRITE_CACHE
150 mov si, [cs:bx+.rgbWriteCacheCommands]
151 jmp AH23h_SetControllerFeatures
152
153.rgbWriteCacheCommands:
154 db 0 ; DEFAULT_WRITE_CACHE
155 db FEATURE_DISABLE_WRITE_CACHE ; DISABLE_WRITE_CACHE
156 db FEATURE_ENABLE_WRITE_CACHE ; ENABLE_WRITE_CACHE
157
158
159%ifdef MODULE_ADVANCED_ATA
160;--------------------------------------------------------------------
161; InitializePioMode
162; Parameters:
163; DS:DI: Ptr to DPT (in RAMVARS segment)
164; Returns:
165; AH: BIOS Error code
166; CF: Cleared if successful
167; Set if any error
168; Corrupts registers:
169; AL, BX, CX, DX
170;--------------------------------------------------------------------
171InitializePioMode:
172 mov dl, PIO_DEFAULT_MODE_DISABLE_IORDY
173 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_IORDY
174 jz SHORT .IordyNotSupported
175
176 ; Advanced PIO mode 3 and above
177 mov dl, [di+DPT_ADVANCED_ATA.bPioMode]
178 or dl, PIO_FLOW_CONTROL_MODE_xxx
179
180.IordyNotSupported:
181 mov si, FEATURE_SET_TRANSFER_MODE
182 jmp AH23h_SetControllerFeatures
183%endif
184
185
186;--------------------------------------------------------------------
187; InitializeBlockMode
188; Parameters:
189; DS:DI: Ptr to DPT (in RAMVARS segment)
190; Returns:
191; AH: BIOS Error code
192; CF: Cleared if successful
193; Set if any error
194; Corrupts registers:
195; AL, BX, CX, DX
196;--------------------------------------------------------------------
197InitializeBlockMode:
198 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED ; Clear CF
199 jz SHORT .BlockModeNotSupportedOrDisabled
200 call AccessDPT_GetPointerToDRVPARAMStoCSBX
201 test BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_BLOCKMODE
202 jz SHORT .BlockModeNotSupportedOrDisabled
203
204 ; Try block sizes until we find largest possible supported by drive
205 mov bl, 128
206.TryNextBlockSize:
207 mov al, bl
208 call AH24h_SetBlockSize
209 jnc SHORT .SupportedBlockSizeFound
210 shr bl, 1 ; Try next size
211 jmp SHORT .TryNextBlockSize
212.SupportedBlockSizeFound:
213 mov [di+DPT_ATA.bBlockSize], bl
214.BlockModeNotSupportedOrDisabled:
215ReturnSuccessSinceInitializationNotNeeded:
216 ret
217
218
219;--------------------------------------------------------------------
220; SetErrorFlagFromALwithErrorCodeInAH
221; Parameters:
222; AH: BIOS Error Code
223; AL: Error flag to set
224; DS:DI: Ptr to DPT
225; Returns:
226; CF: Clear if no error
227; Set if error flag was set
228; Corrupts registers:
229; Nothing
230;--------------------------------------------------------------------
231SetErrorFlagFromALwithErrorCodeInAH:
232 jnc SHORT .NoErrorFlagToSet
233 cmp ah, RET_HD_INVALID
234 jbe SHORT .IgnoreInvalidCommandError
235
236 or [di+DPT_ATA.bInitError], al
237 stc
238 ret
239.IgnoreInvalidCommandError:
240 xor ah, ah
241.NoErrorFlagToSet:
242 ret
Note: See TracBrowser for help on using the repository browser.