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

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

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

File size: 7.8 KB
RevLine 
[148]1; Project name  :   XTIDE Universal BIOS
[3]2; Description   :   Int 13h function AH=9h, Initialize Drive Parameters.
3
[376]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
[3]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Int 13h function AH=9h, Initialize Drive Parameters.
25;
26; AH9h_HandlerForInitializeDriveParameters
27;   Parameters:
[148]28;       DL:     Translated Drive number
29;       DS:DI:  Ptr to DPT (in RAMVARS segment)
[150]30;       SS:BP:  Ptr to IDEPACK
31;   Returns with INTPACK:
[3]32;       AH:     Int 13h return status
[294]33;       CF:     0 if successful, 1 if error
[3]34;--------------------------------------------------------------------
35AH9h_HandlerForInitializeDriveParameters:
[84]36%ifndef USE_186
[3]37    call    AH9h_InitializeDriveForUse
[148]38    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[84]39%else
[148]40    push    Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[162]41    ; Fall to AH9h_InitializeDriveForUse
[84]42%endif
[3]43
44
45;--------------------------------------------------------------------
46; Initialized drive to be ready for use.
47;
48; AH9h_InitializeDriveForUse
49;   Parameters:
[148]50;       DS:DI:  Ptr to DPT (in RAMVARS segment)
[150]51;       SS:BP:  Ptr to IDEPACK
[3]52;   Returns:
53;       AH:     Int 13h return status
[294]54;       CF:     0 if successful, 1 if error
[3]55;   Corrupts registers:
[363]56;       AL, BX, CX, DX
[3]57;--------------------------------------------------------------------
58AH9h_InitializeDriveForUse:
[363]59    push    es
[276]60    push    si
[3]61
[258]62%ifdef MODULE_SERIAL
[363]63    ; no need to do this for serial devices
[258]64    xor     ah, ah
65    test    byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE    ; Clears CF
[363]66    jnz     .ReturnWithErrorCodeInAH
67
68%else
[365]69    ; Clear Initialization Error flags from DPT
70    mov     BYTE [di+DPT_ATA.bInitError], 0
[258]71%endif
[294]72
[3]73    ; Try to select drive and wait until ready
[150]74    call    AccessDPT_GetDriveSelectByteToAL
75    mov     [bp+IDEPACK.bDrvAndHead], al
76    call    Device_SelectDrive
[365]77    mov     al, FLG_INITERROR_FAILED_TO_SELECT_DRIVE
78    call    SetErrorFlagFromALwithErrorCodeInAH
[363]79    jc      SHORT .ReturnWithErrorCodeInAH
[3]80
81    ; Initialize CHS parameters if LBA is not used
[150]82    call    InitializeDeviceParameters
[365]83    mov     al, FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS
84    call    SetErrorFlagFromALwithErrorCodeInAH
[3]85
[276]86    ; Enable or Disable Write Cache
[279]87    call    SetWriteCache
[365]88    mov     al, FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE
89    call    SetErrorFlagFromALwithErrorCodeInAH
[276]90
[3]91    ; Recalibrate drive by seeking to cylinder 0
92.RecalibrateDrive:
93    call    AH11h_RecalibrateDrive
[365]94    mov     al, FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE
95    call    SetErrorFlagFromALwithErrorCodeInAH
[3]96
97    ; Initialize block mode transfers
98.InitializeBlockMode:
[150]99    call    InitializeBlockMode
[365]100    mov     al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
101    call    SetErrorFlagFromALwithErrorCodeInAH
[3]102
[363]103%ifdef MODULE_ADVANCED_ATA
104; Initialize fastest supported PIO mode
105.InitializePioMode:
106    call    InitializePioMode
[365]107    mov     al, FLG_INITERROR_FAILED_TO_SET_PIO_MODE
108    call    SetErrorFlagFromALwithErrorCodeInAH
[363]109%endif
110
111    ; There might have been several errors so just return
112    ; one error code for them all
[365]113    cmp     BYTE [di+DPT_ATA.bInitError], 0
114    je      SHORT .ReturnWithErrorCodeInAH
[363]115    mov     ah, RET_HD_RESETFAIL
116    stc
117
118.ReturnWithErrorCodeInAH:
[276]119    pop     si
[363]120    pop     es
[3]121    ret
122
123
124;--------------------------------------------------------------------
[150]125; InitializeDeviceParameters
[3]126;   Parameters:
[150]127;       DS:DI:  Ptr to DPT (in RAMVARS segment)
128;       SS:BP:  Ptr to IDEPACK
[3]129;   Returns:
130;       AH:     BIOS Error code
[294]131;       CF:     Cleared if successful
[3]132;               Set if any error
133;   Corrupts registers:
[150]134;       AL, BX, CX, DX
[3]135;--------------------------------------------------------------------
[150]136InitializeDeviceParameters:
[3]137    ; No need to initialize CHS parameters if LBA mode enabled
[158]138    test    BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA   ; Clear CF
[150]139    jnz     SHORT ReturnSuccessSinceInitializationNotNeeded
[3]140
[157]141    ; Initialize Logical Sectors per Track and Max Head number
[227]142    mov     ah, [di+DPT.bPchsHeads]
[150]143    dec     ah                          ; Max Head number
[227]144    mov     dl, [di+DPT.bPchsSectors]   ; Sectors per Track
[150]145    mov     al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
146    mov     bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
147    jmp     Idepack_StoreNonExtParametersAndIssueCommandFromAL
[3]148
149
150;--------------------------------------------------------------------
[276]151; SetWriteCache
152;   Parameters:
153;       DS:DI:  Ptr to DPT (in RAMVARS segment)
154;   Returns:
155;       AH:     BIOS Error code
[294]156;       CF:     Cleared if successful
[276]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
[363]175%ifdef MODULE_ADVANCED_ATA
[276]176;--------------------------------------------------------------------
[363]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:
[364]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:
[363]197    mov     si, FEATURE_SET_TRANSFER_MODE
198    jmp     AH23h_SetControllerFeatures
199%endif
200
201
202;--------------------------------------------------------------------
[150]203; InitializeBlockMode
[3]204;   Parameters:
[150]205;       DS:DI:  Ptr to DPT (in RAMVARS segment)
[3]206;   Returns:
207;       AH:     BIOS Error code
[294]208;       CF:     Cleared if successful
[3]209;               Set if any error
210;   Corrupts registers:
211;       AL, BX, CX, DX
212;--------------------------------------------------------------------
[150]213InitializeBlockMode:
[158]214    test    BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED ; Clear CF
[365]215    jz      SHORT .BlockModeNotSupportedOrDisabled
[276]216    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
217    test    BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_BLOCKMODE
[365]218    jz      SHORT .BlockModeNotSupportedOrDisabled
[363]219
[365]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:
[363]232    ret
233
234
235;--------------------------------------------------------------------
[365]236; SetErrorFlagFromALwithErrorCodeInAH
[363]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:
[370]245;       Nothing
[363]246;--------------------------------------------------------------------
[365]247SetErrorFlagFromALwithErrorCodeInAH:
248    jnc     SHORT .NoErrorFlagToSet
[363]249    cmp     ah, RET_HD_INVALID
250    jbe     SHORT .IgnoreInvalidCommandError
251
[365]252    or      [di+DPT_ATA.bInitError], al
[363]253    stc
254    ret
255.IgnoreInvalidCommandError:
[276]256    xor     ah, ah
[365]257.NoErrorFlagToSet:
[3]258    ret
Note: See TracBrowser for help on using the repository browser.