Changeset 399 in xtideuniversalbios for trunk/XTIDE_Universal_BIOS/Src/Handlers


Ignore:
Timestamp:
Apr 19, 2012, 10:39:44 PM (13 years ago)
Author:
krille_n_@…
google:author:
krille_n_@hotmail.com
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm

    r376 r399  
    33
    44;
    5 ; XTIDE Universal BIOS and Associated Tools 
     5; XTIDE Universal BIOS and Associated Tools
    66; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
    77;
     
    1010; the Free Software Foundation; either version 2 of the License, or
    1111; (at your option) any later version.
    12 ; 
     12;
    1313; This program is distributed in the hope that it will be useful,
    1414; but WITHOUT ANY WARRANTY; without even the implied warranty of
    1515; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16 ; GNU General Public License for more details.     
     16; GNU General Public License for more details.
    1717; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    18 ;       
     18;
    1919
    2020; Section containing code
     
    4444
    4545;--------------------------------------------------------------------
    46 ; Initialized drive to be ready for use.
     46; Initialize drive to be ready for use.
    4747;
    4848; AH9h_InitializeDriveForUse
     
    5757;--------------------------------------------------------------------
    5858AH9h_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
    5972    push    es
    6073    push    si
    6174
    62 %ifdef MODULE_SERIAL
    63     ; no need to do this for serial devices
    64     xor     ah, ah
    65     test    byte [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE    ; Clears CF
    66     jnz     .ReturnWithErrorCodeInAH
    67 
    68 %else
    69     ; Clear Initialization Error flags from DPT
    70     mov     BYTE [di+DPT_ATA.bInitError], 0
    71 %endif
    72 
     75;;; SelectDrive
    7376    ; Try to select drive and wait until ready
    7477    call    AccessDPT_GetDriveSelectByteToAL
    7578    mov     [bp+IDEPACK.bDrvAndHead], al
    7679    call    Device_SelectDrive
     80
    7781    mov     al, FLG_INITERROR_FAILED_TO_SELECT_DRIVE
    78     call    SetErrorFlagFromALwithErrorCodeInAH
    79     jc      SHORT .ReturnWithErrorCodeInAH
    80 
     82    call    .SetErrorFlagFromALwithErrorCodeInAH
     83    jc      .ReturnWithErrorCodeInAH
     84
     85;;; InitializeDeviceParameters
    8186    ; Initialize CHS parameters if LBA is not used
    82     call    InitializeDeviceParameters
    83     mov     al, FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS
    84     call    SetErrorFlagFromALwithErrorCodeInAH
    85 
    86     ; Enable or Disable Write Cache
    87     call    SetWriteCache
    88     mov     al, FLG_INITERROR_FAILED_TO_SET_WRITE_CACHE
    89     call    SetErrorFlagFromALwithErrorCodeInAH
    90 
    91     ; Recalibrate drive by seeking to cylinder 0
    92 .RecalibrateDrive:
    93     call    AH11h_RecalibrateDrive
    94     mov     al, FLG_INITERROR_FAILED_TO_RECALIBRATE_DRIVE
    95     call    SetErrorFlagFromALwithErrorCodeInAH
    96 
    97     ; Initialize block mode transfers
    98 .InitializeBlockMode:
    99     call    InitializeBlockMode
    100     mov     al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
    101     call    SetErrorFlagFromALwithErrorCodeInAH
    102 
    103 %ifdef MODULE_ADVANCED_ATA
    104 ; Initialize fastest supported PIO mode
    105 .InitializePioMode:
    106     call    InitializePioMode
    107     mov     al, FLG_INITERROR_FAILED_TO_SET_PIO_MODE
    108     call    SetErrorFlagFromALwithErrorCodeInAH
    109 %endif
    110 
    111     ; There might have been several errors so just return
    112     ; one error code for them all
    113     cmp     BYTE [di+DPT_ATA.bInitError], 0
    114     je      SHORT .ReturnWithErrorCodeInAH
    115     mov     ah, RET_HD_RESETFAIL
    116     stc
    117 
    118 .ReturnWithErrorCodeInAH:
    119     pop     si
    120     pop     es
    121     ret
    122 
    123 
    124 ;--------------------------------------------------------------------
    125 ; InitializeDeviceParameters
    126 ;   Parameters:
    127 ;       DS:DI:  Ptr to DPT (in RAMVARS segment)
    128 ;       SS:BP:  Ptr to IDEPACK
    129 ;   Returns:
    130 ;       AH:     BIOS Error code
    131 ;       CF:     Cleared if successful
    132 ;               Set if any error
    133 ;   Corrupts registers:
    134 ;       AL, BX, CX, DX
    135 ;--------------------------------------------------------------------
    136 InitializeDeviceParameters:
    137     ; No need to initialize CHS parameters if LBA mode enabled
    138     test    BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA   ; Clear CF
    139     jnz     SHORT ReturnSuccessSinceInitializationNotNeeded
     87    test    BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
     88    jnz     SHORT .SkipInitializeDeviceParameters       ; No need to initialize CHS parameters if LBA mode enabled
    14089
    14190    ; Initialize Logical Sectors per Track and Max Head number
     
    14594    mov     al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
    14695    mov     bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
    147     jmp     Idepack_StoreNonExtParametersAndIssueCommandFromAL
    148 
    149 
    150 ;--------------------------------------------------------------------
    151 ; SetWriteCache
    152 ;   Parameters:
    153 ;       DS:DI:  Ptr to DPT (in RAMVARS segment)
    154 ;   Returns:
    155 ;       AH:     BIOS Error code
    156 ;       CF:     Cleared if successful
    157 ;               Set if any error
    158 ;   Corrupts registers:
    159 ;       AL, BX, CX, DX, SI
    160 ;--------------------------------------------------------------------
    161 SetWriteCache:
     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
    162104    call    AccessDPT_GetPointerToDRVPARAMStoCSBX
    163105    mov     bl, [cs:bx+DRVPARAMS.wFlags]
     106    push    bx  ; Save .wFlags for later use in InitializeBlockMode
    164107    and     bx, BYTE MASK_DRVPARAMS_WRITECACHE
    165     jz      SHORT ReturnSuccessSinceInitializationNotNeeded     ; DEFAULT_WRITE_CACHE
     108    jz      SHORT .SkipSetWriteCache        ; DEFAULT_WRITE_CACHE
    166109    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 
    175 %ifdef MODULE_ADVANCED_ATA
    176 ;--------------------------------------------------------------------
    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 ;--------------------------------------------------------------------
    187 InitializePioMode:
    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:
    197     mov     si, FEATURE_SET_TRANSFER_MODE
    198     jmp     AH23h_SetControllerFeatures
    199 %endif
    200 
    201 
    202 ;--------------------------------------------------------------------
    203 ; InitializeBlockMode
    204 ;   Parameters:
    205 ;       DS:DI:  Ptr to DPT (in RAMVARS segment)
    206 ;   Returns:
    207 ;       AH:     BIOS Error code
    208 ;       CF:     Cleared if successful
    209 ;               Set if any error
    210 ;   Corrupts registers:
    211 ;       AL, BX, CX, DX
    212 ;--------------------------------------------------------------------
    213 InitializeBlockMode:
    214     test    BYTE [di+DPT.bFlagsHigh], FLGH_DPT_BLOCK_MODE_SUPPORTED ; Clear CF
     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
    215127    jz      SHORT .BlockModeNotSupportedOrDisabled
    216     call    AccessDPT_GetPointerToDRVPARAMStoCSBX
    217     test    BYTE [cs:bx+DRVPARAMS.wFlags], FLG_DRVPARAMS_BLOCKMODE
     128    test    al, FLG_DRVPARAMS_BLOCKMODE
    218129    jz      SHORT .BlockModeNotSupportedOrDisabled
    219130
     
    222133.TryNextBlockSize:
    223134    mov     al, bl
    224     call    AH24h_SetBlockSize
     135    call    AH24h_SetBlockSize  ; Stores block size to DPT
    225136    jnc     SHORT .SupportedBlockSizeFound
    226     shr     bl, 1                       ; Try next size
    227     jmp     SHORT .TryNextBlockSize
     137    shr     bl, 1
     138    jnc     SHORT .TryNextBlockSize
     139
     140    mov     al, FLG_INITERROR_FAILED_TO_SET_BLOCK_MODE
     141    call    .SetErrorFlagFromALwithErrorCodeInAH
     142.BlockModeNotSupportedOrDisabled:
    228143.SupportedBlockSizeFound:
    229     mov     [di+DPT_ATA.bBlockSize], bl
    230 .BlockModeNotSupportedOrDisabled:
    231 ReturnSuccessSinceInitializationNotNeeded:
     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
    232190    ret
    233191
    234192
    235193;--------------------------------------------------------------------
    236 ; SetErrorFlagFromALwithErrorCodeInAH
     194; .SetErrorFlagFromALwithErrorCodeInAH
    237195;   Parameters:
    238196;       AH:     BIOS Error Code
     
    245203;       Nothing
    246204;--------------------------------------------------------------------
    247 SetErrorFlagFromALwithErrorCodeInAH:
     205.IgnoreInvalidCommandError:
     206    xor     ah, ah  ; Clears CF
     207
     208.SetErrorFlagFromALwithErrorCodeInAH:
    248209    jnc     SHORT .NoErrorFlagToSet
    249210    cmp     ah, RET_HD_INVALID
     
    252213    or      [di+DPT_ATA.bInitError], al
    253214    stc
    254     ret
    255 .IgnoreInvalidCommandError:
    256     xor     ah, ah
    257215.NoErrorFlagToSet:
    258216    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 TracChangeset for help on using the changeset viewer.