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

Last change on this file since 400 was 400, checked in by aitotat@…, 12 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
RevLine 
[148]1; Project name  :   XTIDE Universal BIOS
[3]2; Description   :   Int 13h function AH=9h, Initialize Drive Parameters.
3
[376]4;
[399]5; XTIDE Universal BIOS and Associated Tools
[376]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.
[399]12;
[376]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
[399]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[399]18;
[376]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;--------------------------------------------------------------------
[399]46; Initialize drive to be ready for use.
[3]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:
[399]59    xor     ax, ax
[3]60
[400]61%ifdef MODULE_ADVANCED_ATA
[399]62    ; Clear Initialization Error flags from DPT
[400]63    mov     [di+DPT_ADVANCED_ATA.bInitError], al
64%endif
[399]65
[258]66%ifdef MODULE_SERIAL
[399]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:
[258]72%endif
[294]73
[399]74    push    es
75    push    si
76
77;;; SelectDrive
[3]78    ; Try to select drive and wait until ready
[150]79    call    AccessDPT_GetDriveSelectByteToAL
80    mov     [bp+IDEPACK.bDrvAndHead], al
81    call    Device_SelectDrive
[399]82
[400]83%ifdef MODULE_ADVANCED_ATA
[365]84    mov     al, FLG_INITERROR_FAILED_TO_SELECT_DRIVE
[399]85    call    .SetErrorFlagFromALwithErrorCodeInAH
[400]86%endif
[399]87    jc      .ReturnWithErrorCodeInAH
[3]88
[399]89;;; InitializeDeviceParameters
[3]90    ; Initialize CHS parameters if LBA is not used
[399]91    test    BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
92    jnz     SHORT .SkipInitializeDeviceParameters       ; No need to initialize CHS parameters if LBA mode enabled
[3]93
[157]94    ; Initialize Logical Sectors per Track and Max Head number
[227]95    mov     ah, [di+DPT.bPchsHeads]
[150]96    dec     ah                          ; Max Head number
[227]97    mov     dl, [di+DPT.bPchsSectors]   ; Sectors per Track
[150]98    mov     al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
99    mov     bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
[399]100    call    Idepack_StoreNonExtParametersAndIssueCommandFromAL
[3]101
[400]102%ifdef MODULE_ADVANCED_ATA
[399]103    mov     al, FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS
104    call    .SetErrorFlagFromALwithErrorCodeInAH
[400]105%endif
[399]106.SkipInitializeDeviceParameters:
[3]107
[399]108;;; SetWriteCache
109    ; Enable or Disable Write Cache
[276]110    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
111    mov     bl, [cs:bx+DRVPARAMS.wFlags]
[399]112    push    bx  ; Save .wFlags for later use in InitializeBlockMode
[276]113    and     bx, BYTE MASK_DRVPARAMS_WRITECACHE
[399]114    jz      SHORT .SkipSetWriteCache        ; DEFAULT_WRITE_CACHE
[276]115    mov     si, [cs:bx+.rgbWriteCacheCommands]
[399]116    call    AH23h_SetControllerFeatures
[276]117
[400]118%ifdef MODULE_ADVANCED_ATA
[399]119    mov     al, FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE
120    call    .SetErrorFlagFromALwithErrorCodeInAH
[400]121%endif
[399]122.SkipSetWriteCache:
[276]123
[399]124;;; RecalibrateDrive
125    ; Recalibrate drive by seeking to cylinder 0
126    call    AH11h_RecalibrateDrive
[276]127
[400]128%ifdef MODULE_ADVANCED_ATA
[399]129    mov     al, FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE
130    call    .SetErrorFlagFromALwithErrorCodeInAH
[400]131%endif
[399]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
[400]150%ifdef MODULE_ADVANCED_ATA
[399]151    mov     al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
152    call    .SetErrorFlagFromALwithErrorCodeInAH
[400]153%endif
[399]154.BlockModeNotSupportedOrDisabled:
155.SupportedBlockSizeFound:
156
[363]157%ifdef MODULE_ADVANCED_ATA
[399]158;;; InitializePioMode
159    ; Initialize fastest supported PIO mode
[364]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:
[363]169    mov     si, FEATURE_SET_TRANSFER_MODE
[399]170    call    AH23h_SetControllerFeatures
[363]171
[399]172    mov     al, FLG_INITERROR_FAILED_TO_SET_PIO_MODE
173    call    .SetErrorFlagFromALwithErrorCodeInAH
174%endif ; MODULE_ADVANCED_ATA
[363]175
[399]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
[363]181
[399]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
[400]187%ifdef MODULE_ADVANCED_ATA
[399]188    mov     al, FLG_INITERROR_FAILED_TO_INITIALIZE_STANDBY_TIMER
189    call    .SetErrorFlagFromALwithErrorCodeInAH
[400]190%endif
[399]191.NoPowerManagementSupport:
192%endif ; MODULE_FEATURE_SETS
193
194    ; There might have been several errors so just return one error code for them all
[400]195%ifdef MODULE_ADVANCED_ATA
196    mov     ah, [di+DPT_ADVANCED_ATA.bInitError]
[399]197    test    ah, ah  ; Clears CF
198    jz      SHORT .ReturnWithErrorCodeInAH
199    mov     ah, RET_HD_RESETFAIL
200    stc
[400]201%endif
[399]202
203.ReturnWithErrorCodeInAH:
204    pop     si
205    pop     es
[363]206    ret
207
208
[400]209%ifdef MODULE_ADVANCED_ATA
[363]210;--------------------------------------------------------------------
[399]211; .SetErrorFlagFromALwithErrorCodeInAH
[363]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:
[370]220;       Nothing
[363]221;--------------------------------------------------------------------
[399]222.IgnoreInvalidCommandError:
223    xor     ah, ah  ; Clears CF
224
225.SetErrorFlagFromALwithErrorCodeInAH:
[365]226    jnc     SHORT .NoErrorFlagToSet
[363]227    cmp     ah, RET_HD_INVALID
228    jbe     SHORT .IgnoreInvalidCommandError
229
[400]230    or      [di+DPT_ADVANCED_ATA.bInitError], al
[363]231    stc
[365]232.NoErrorFlagToSet:
[3]233    ret
[399]234
[400]235%endif
[399]236
[400]237
[399]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.