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

Last change on this file since 421 was 421, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Addressing modes are now NORMAL, LARGE and LBA.
  • L-CHS parameters are now generated differently for drives with 8192 or less cylinders.
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; 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_GetDriveSelectByteForOldInt13hToAL
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 and
112    ; user has specified P-CHS parameters
113    test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_ASSISTED_LBA
114    jnz     SHORT .SkipInitializeDeviceParameters       ; No need to initialize CHS parameters if LBA mode enabled
115    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
116    test    BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_USERCHS    ; User specified P-CHS?
117    jz      SHORT .SkipInitializeDeviceParameters
118
119    ; Initialize Logical Sectors per Track and Max Head number
120    mov     ax, [cs:bx+DRVPARAMS.wHeadsAndSectors]
121    dec     ax                          ; Max Head number
122    xchg    al, ah                      ; Heads now in AH
123    mov     dx, ax                      ; Sectors per Track now in DL
124    mov     al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
125    mov     bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
126    call    Idepack_StoreNonExtParametersAndIssueCommandFromAL
127    STORE_ERROR_FLAG_TO_DPT     FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS
128.SkipInitializeDeviceParameters:
129
130
131;;; SetWriteCache
132    ; Enable or Disable Write Cache
133    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
134    mov     bl, [cs:bx+DRVPARAMS.wFlags]
135    push    bx  ; Save .wFlags for later use in InitializeBlockMode
136    and     bx, BYTE MASK_DRVPARAMS_WRITECACHE
137    jz      SHORT .SkipSetWriteCache        ; DEFAULT_WRITE_CACHE
138    mov     si, [cs:bx+.rgbWriteCacheCommands]
139    call    AH23h_SetControllerFeatures
140    STORE_ERROR_FLAG_TO_DPT     FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE
141.SkipSetWriteCache:
142
143
144;;; RecalibrateDrive
145    ; Recalibrate drive by seeking to cylinder 0
146    call    AH11h_RecalibrateDrive
147    STORE_ERROR_FLAG_TO_DPT     FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE
148
149
150;;; InitializeBlockMode
151    ; Initialize block mode transfers
152    pop     ax  ; Restore .wFlags saved in SetWriteCache
153    test    BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED
154    jz      SHORT .BlockModeNotSupportedOrDisabled
155    test    al, FLG_DRVPARAMS_BLOCKMODE
156    jz      SHORT .BlockModeNotSupportedOrDisabled
157
158    ; Try block sizes until we find largest possible supported by drive
159    mov     bl, 128
160.TryNextBlockSize:
161    mov     al, bl
162    call    AH24h_SetBlockSize  ; Stores block size to DPT
163    jnc     SHORT .SupportedBlockSizeFound
164    shr     bl, 1
165    jnc     SHORT .TryNextBlockSize
166    STORE_ERROR_FLAG_TO_DPT     FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
167.BlockModeNotSupportedOrDisabled:
168.SupportedBlockSizeFound:
169
170
171%ifdef MODULE_ADVANCED_ATA
172;;; InitializePioMode
173    ; Initialize fastest supported PIO mode
174    mov     dl, PIO_DEFAULT_MODE_DISABLE_IORDY
175    test    BYTE [di+DPT.bFlagsHigh], FLGH_DPT_IORDY
176    jz      SHORT .IordyNotSupported
177
178    ; Advanced PIO mode 3 and above
179    mov     dl, [di+DPT_ADVANCED_ATA.bPioMode]
180    or      dl, PIO_FLOW_CONTROL_MODE_xxx
181
182.IordyNotSupported:
183    mov     si, FEATURE_SET_TRANSFER_MODE
184    call    AH23h_SetControllerFeatures
185    STORE_ERROR_FLAG_TO_DPT     FLG_INITERROR_FAILED_TO_SET_PIO_MODE
186%endif ; MODULE_ADVANCED_ATA
187
188
189%ifdef MODULE_FEATURE_SETS
190;;; InitStandbyTimer
191    ; Initialize the standby timer (if supported)
192    test    BYTE [di+DPT.bFlagsHigh], FLGH_DPT_POWER_MANAGEMENT_SUPPORTED
193    jz      SHORT .NoPowerManagementSupport
194
195    mov     al, COMMAND_IDLE
196    mov     dl, [cs:ROMVARS.bIdleTimeout]
197    mov     bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
198    call    Idepack_StoreNonExtParametersAndIssueCommandFromAL
199    STORE_ERROR_FLAG_TO_DPT     FLG_INITERROR_FAILED_TO_INITIALIZE_STANDBY_TIMER
200.NoPowerManagementSupport:
201%endif ; MODULE_FEATURE_SETS
202
203
204    ; There might have been several errors so just return one error code for them all
205.ReturnWithErrorCodeInAH:
206%ifdef MODULE_ADVANCED_ATA
207    mov     ah, [di+DPT_ADVANCED_ATA.bInitError]
208    test    ah, ah  ; Clears CF
209    jz      SHORT .ReturnWithSuccess
210    mov     ah, RET_HD_RESETFAIL
211    stc
212.ReturnWithSuccess:
213%endif
214
215    pop     si
216    pop     es
217    ret
218
219
220.rgbWriteCacheCommands:
221    db      0                               ; DEFAULT_WRITE_CACHE
222    db      FEATURE_DISABLE_WRITE_CACHE     ; DISABLE_WRITE_CACHE
223    db      FEATURE_ENABLE_WRITE_CACHE      ; ENABLE_WRITE_CACHE
224
225
226
227%ifdef MODULE_ADVANCED_ATA
228;--------------------------------------------------------------------
229; SetErrorFlagFromALwithErrorCodeInAH
230;   Parameters:
231;       AH:     BIOS Error Code
232;       AL:     Error flag to set
233;       DS:DI:  Ptr to DPT
234;       CF:     Set if error code in AH
235;               Clear if AH = 0
236;   Returns:
237;       CF:     Clear if no error
238;               Set if error flag was set
239;   Corrupts registers:
240;       Nothing
241;--------------------------------------------------------------------
242IgnoreInvalidCommandError:
243    xor     ah, ah  ; Clears CF
244SetErrorFlagFromALwithErrorCodeInAH:
245    jnc     SHORT .NoErrorFlagToSet
246    cmp     ah, RET_HD_INVALID
247    jbe     SHORT IgnoreInvalidCommandError
248
249    or      [di+DPT_ADVANCED_ATA.bInitError], al
250    stc
251.NoErrorFlagToSet:
252    ret
253
254%endif
Note: See TracBrowser for help on using the repository browser.