Ignore:
Timestamp:
Aug 1, 2010, 5:57:24 PM (14 years ago)
Author:
aitotat
google:author:
aitotat
Message:
  • v1.1.1 broke booting from foreign drives, it is now fixed.
  • Improved error handling a bit.
  • Longer DRQ and IRQ timeouts to minimize write timouts with some (bad) CF cards.
  • Default boot menu drive should now be properly selected.
File:
1 edited

Legend:

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

    r27 r28  
    22; Project name  :   IDE BIOS
    33; Created date  :   30.11.2007
    4 ; Last update   :   28.7.2010
     4; Last update   :   1.8.2010
    55; Author        :   Tomi Tilli
    66; Description   :   Error checking functions for BIOS Hard disk functions.
     
    1010
    1111;--------------------------------------------------------------------
    12 ; HError_GetErrorCodeToAHforBitPollingTimeout
     12; HError_ProcessErrorsAfterPollingTaskFlag
    1313;   Parameters:
    14 ;       AL:     IDE Status Register contents
    15 ;       DX:     IDE Status Register Address
     14;       DS:     RAMVARS segment
     15;       ES:     BDA segment (zero)
     16;       CF:     Set if timeout
     17;               Cleared if task flag was properly set
    1618;   Returns:
    17 ;       AH:     Hard disk BIOS error code
    18 ;       CF:     Set since error
    19 ;   Corrupts registers:
    20 ;       AL, CX
    21 ;--------------------------------------------------------------------
    22 ALIGN JUMP_ALIGN
    23 HError_GetErrorCodeToAHforBitPollingTimeout:
    24     test    al, FLG_IDE_ST_BSY                      ; Other bits undefined when BSY set
    25     jnz     SHORT HError_GetErrorCodeForStatusReg   ; Busy, normal timeout
    26     test    al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
    27     jnz     SHORT HError_GetErrorCodeForStatusReg   ; Not busy but some error
    28     or      al, FLG_IDE_ST_BSY                      ; Polled bit got never set, force timeout
    29     ; Fall to HError_GetErrorCodeForStatusReg
    30 
    31 ;--------------------------------------------------------------------
    32 ; Converts Status Register error to BIOS error code.
    33 ;
    34 ; HError_GetErrorCodeForStatusReg
    35 ;   Parameters:
    36 ;       AL:     IDE Status Register contents
    37 ;       DX:     IDE Status Register Address
    38 ;   Returns:
    39 ;       AH:     Hard disk BIOS error code
    40 ;       CF:     0 if no errors (AH=RET_HD_SUCCESS)
    41 ;               1 if some error
    42 ;   Corrupts registers:
    43 ;       AL, CX
    44 ;--------------------------------------------------------------------
    45 ALIGN JUMP_ALIGN
    46 HError_GetErrorCodeForStatusReg:
    47     ; Get Error Register contents to AH
    48     mov     ah, al                              ; Backup Status Reg to AH
    49     sub     dx, BYTE REGR_IDE_ST-REGR_IDE_ERROR ; Status Reg to Error Reg
    50     in      al, dx                              ; Read Error Register to AL
    51     xchg    al, ah                              ; Swap status and error
    52     add     dx, BYTE REGR_IDE_ST-REGR_IDE_ERROR ; Restore DX
    53 
    54     ; Store Register contents to BDA
    55     push    ds
    56     LOAD_BDA_SEGMENT_TO ds, cx
    57     mov     [HDBDA.wHDStAndErr], ax         ; Store Status and Error to BDA
    58     pop     ds
    59     ; Fall to HError_ConvertIdeErrorToBiosRet
    60 
    61 ;--------------------------------------------------------------------
    62 ; Converts error flags from IDE status and error register contents
    63 ; to BIOS Int 13h return value.
    64 ;
    65 ; HError_ConvertIdeErrorToBiosRet
    66 ;   Parameters:
    67 ;       AL:     Status Register Contents
    68 ;       AH:     Error Register Contents
    69 ;   Returns:
    70 ;       AH:     Hard disk BIOS error code
    71 ;       CF:     0 if no errors (AH=RET_HD_SUCCESS)
    72 ;               1 if any error
     19;       AH:     BIOS error code
     20;       CF:     Set if error
     21;               Cleared if no error
    7322;   Corrupts registers:
    7423;       AL
    7524;--------------------------------------------------------------------
    7625ALIGN JUMP_ALIGN
    77 HError_ConvertIdeErrorToBiosRet:
     26HError_ProcessErrorsAfterPollingTaskFlag:
     27    jc      SHORT HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit
     28    mov     ax, [es:HDBDA.wHDStAndErr]
     29    call    GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
     30    mov     [es:BDA.bHDLastSt], ah
     31    mov     BYTE [es:BDA.bHDTaskFlg], 0
     32    ret
     33
     34;--------------------------------------------------------------------
     35; HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit
     36; HError_ProcessErrorsAfterPollingBSY
     37;   Parameters:
     38;       DS:     RAMVARS segment
     39;   Returns:
     40;       AH:     BIOS error code
     41;       CF:     Set if error
     42;               Cleared if no error
     43;   Corrupts registers:
     44;       AL
     45;--------------------------------------------------------------------
     46ALIGN JUMP_ALIGN
     47HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit:
     48    push    ds
     49    push    dx
     50
     51    call    HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
     52    call    GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
     53    jc      SHORT StoreErrorCodeFromAHtoBDA
     54    mov     ah, RET_HD_TIMEOUT          ; Force timeout since no actual error...
     55    stc                                 ; ...but wanted bit was never set
     56    jmp     SHORT StoreErrorCodeFromAHtoBDA
     57
     58
     59ALIGN JUMP_ALIGN
     60HError_ProcessErrorsAfterPollingBSY:
     61    push    ds
     62    push    dx
     63
     64    call    HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
     65    call    GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
     66StoreErrorCodeFromAHtoBDA:
     67    mov     [BDA.bHDLastSt], ah         ; Store BIOS error code to BDA
     68
     69    pop     dx
     70    pop     ds
     71    ret
     72
     73
     74;--------------------------------------------------------------------
     75; HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
     76;   Parameters:
     77;       DS:     RAMVARS segment
     78;   Returns:
     79;       AL:     IDE Status Register contents
     80;       AH:     IDE Error Register contents
     81;       DS:     BDA segment
     82;   Corrupts registers:
     83;       DX
     84;--------------------------------------------------------------------
     85ALIGN JUMP_ALIGN
     86HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA:
     87    mov     dx, [RAMVARS.wIdeBase]      ; Load IDE base port address
     88    inc     dx                          ; Increment to Error Register
     89    in      al, dx                      ; Read Error Register...
     90    mov     ah, al                      ; ...and copy it to AH
     91    add     dx, BYTE REGR_IDE_ST - REGR_IDE_ERROR
     92    in      al, dx                      ; Read Status Register to AL
     93    ; Fall to .StoreStatusAndErrorRegistersFromAXtoBDA
     94
     95;--------------------------------------------------------------------
     96; .StoreStatusAndErrorRegistersFromAXtoBDA
     97;   Parameters:
     98;       AL:     IDE Status Register contents
     99;       AH:     IDE Error Register contents
     100;   Returns:
     101;       DS:     BDA segment (zero)
     102;   Corrupts registers:
     103;       DX
     104;--------------------------------------------------------------------
     105.StoreStatusAndErrorRegistersFromAXtoBDA:
     106    LOAD_BDA_SEGMENT_TO ds, dx
     107    mov     [HDBDA.wHDStAndErr], ax
     108    ret
     109
     110
     111;--------------------------------------------------------------------
     112; GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
     113;   Parameters:
     114;       AL:     IDE Status Register contents
     115;       AH:     IDE Error Register contents
     116;   Returns:
     117;       AH:     BIOS INT 13h error code
     118;       CF:     Set if error
     119;               Cleared if no error
     120;   Corrupts registers:
     121;       Nothing
     122;--------------------------------------------------------------------
     123ALIGN JUMP_ALIGN
     124GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX:
    78125    test    al, FLG_IDE_ST_BSY
    79     jnz     SHORT .TimeoutError
     126    jz      SHORT .CheckErrorBitsFromStatusRegisterInAL
     127    mov     ah, RET_HD_TIMEOUT
     128    jmp     SHORT .ReturnBiosErrorCodeInAH
     129
     130ALIGN JUMP_ALIGN
     131.CheckErrorBitsFromStatusRegisterInAL:
    80132    test    al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
    81     jnz     SHORT .ReadErrorFromStatusReg
     133    jnz     SHORT .ProcessErrorFromStatusRegisterInAL
    82134    xor     ah, ah                  ; No errors, zero AH and CF
    83135    ret
    84136
    85 .TimeoutError:
    86     mov     ah, RET_HD_TIMEOUT
    87     stc
    88     ret
    89 
    90 ; Convert error code based on status or error register
    91 .ReadErrorFromStatusReg:
     137.ProcessErrorFromStatusRegisterInAL:
    92138    test    al, FLG_IDE_ST_ERR      ; Error specified in Error register?
    93     jnz     SHORT .ReadErrorFromErrorReg
     139    jnz     SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH
    94140    mov     ah, RET_HD_ECC          ; Assume ECC corrected error
    95141    test    al, FLG_IDE_ST_CORR     ; ECC corrected error?
    96     jnz     SHORT .Return
     142    jnz     SHORT .ReturnBiosErrorCodeInAH
    97143    mov     ah, RET_HD_CONTROLLER   ; Must be Device Fault
    98     jmp     SHORT .Return
     144    jmp     SHORT .ReturnBiosErrorCodeInAH
    99145
    100 ; Convert error register to bios error code
    101 .ReadErrorFromErrorReg:
     146.ConvertBiosErrorToAHfromErrorRegisterInAH:
    102147    push    bx
    103     mov     al, ah                  ; Copy error reg to AL...
    104     xor     ah, ah                  ; ...and zero extend to AX
    105     eBSF    bx, ax                  ; Get bit index to BX
    106     mov     ah, RET_HD_STATUSERR    ; Error code if Error Reg is zero
    107     jz      SHORT .SkipLookup       ; Return if error register is zero
     148    mov     bx, .rgbRetCodeLookup
     149.ErrorBitLoop:
     150    rcr     ah, 1                   ; Set CF if error bit set
     151    jc      SHORT .LookupErrorCode
     152    inc     bx
     153    cmp     bx, .rgbRetCodeLookup + 8
     154    jb      SHORT .ErrorBitLoop     ; Loop until all bits checked
     155.LookupErrorCode:
    108156    mov     ah, [cs:bx+.rgbRetCodeLookup]
    109 .SkipLookup:
    110157    pop     bx
    111 .Return:
     158
     159.ReturnBiosErrorCodeInAH:
    112160    stc                             ; Set CF since error
    113161    ret
     
    122170    db  RET_HD_UNCORRECC    ; Bit6=UNC, Uncorrectable Data Error
    123171    db  RET_HD_BADSECTOR    ; Bit7=BBK, Bad Block Detected
     172    db  RET_HD_STATUSERR    ; When Error Register is zero
     173
     174
     175;--------------------------------------------------------------------
     176; HError_StoreBiosErrorCodeFromAHtoBDA
     177;   Parameters:
     178;       AH:     BIOS error code
     179;   Returns:
     180;       Nothing
     181;   Corrupts registers:
     182;       DI
     183;--------------------------------------------------------------------
     184ALIGN JUMP_ALIGN
     185HError_StoreBiosErrorCodeFromAHtoBDA:
     186    push    ds
     187    mov     di, 0                   ; Zero DI and preserve FLAGS
     188    mov     ds, di                  ; Copy BDA segment to DS
     189    mov     [BDA.bHDLastSt], ah
     190    pop     ds
     191    ret
Note: See TracChangeset for help on using the changeset viewer.