[3] | 1 | ; File name : HError.asm
|
---|
| 2 | ; Project name : IDE BIOS
|
---|
| 3 | ; Created date : 30.11.2007
|
---|
[28] | 4 | ; Last update : 1.8.2010
|
---|
[3] | 5 | ; Author : Tomi Tilli
|
---|
| 6 | ; Description : Error checking functions for BIOS Hard disk functions.
|
---|
| 7 |
|
---|
| 8 | ; Section containing code
|
---|
| 9 | SECTION .text
|
---|
| 10 |
|
---|
| 11 | ;--------------------------------------------------------------------
|
---|
[28] | 12 | ; HError_ProcessErrorsAfterPollingTaskFlag
|
---|
[27] | 13 | ; Parameters:
|
---|
[28] | 14 | ; DS: RAMVARS segment
|
---|
| 15 | ; ES: BDA segment (zero)
|
---|
| 16 | ; CF: Set if timeout
|
---|
| 17 | ; Cleared if task flag was properly set
|
---|
[27] | 18 | ; Returns:
|
---|
[28] | 19 | ; AH: BIOS error code
|
---|
| 20 | ; CF: Set if error
|
---|
| 21 | ; Cleared if no error
|
---|
[27] | 22 | ; Corrupts registers:
|
---|
[28] | 23 | ; AL
|
---|
[27] | 24 | ;--------------------------------------------------------------------
|
---|
| 25 | ALIGN JUMP_ALIGN
|
---|
[28] | 26 | HError_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
|
---|
[27] | 33 |
|
---|
| 34 | ;--------------------------------------------------------------------
|
---|
[28] | 35 | ; HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit
|
---|
| 36 | ; HError_ProcessErrorsAfterPollingBSY
|
---|
[3] | 37 | ; Parameters:
|
---|
[28] | 38 | ; DS: RAMVARS segment
|
---|
[3] | 39 | ; Returns:
|
---|
[28] | 40 | ; AH: BIOS error code
|
---|
| 41 | ; CF: Set if error
|
---|
| 42 | ; Cleared if no error
|
---|
[3] | 43 | ; Corrupts registers:
|
---|
[28] | 44 | ; AL
|
---|
[3] | 45 | ;--------------------------------------------------------------------
|
---|
| 46 | ALIGN JUMP_ALIGN
|
---|
[28] | 47 | HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit:
|
---|
| 48 | push ds
|
---|
| 49 | push dx
|
---|
[3] | 50 |
|
---|
[28] | 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 |
|
---|
| 59 | ALIGN JUMP_ALIGN
|
---|
| 60 | HError_ProcessErrorsAfterPollingBSY:
|
---|
[3] | 61 | push ds
|
---|
[28] | 62 | push dx
|
---|
| 63 |
|
---|
| 64 | call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
|
---|
| 65 | call GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
|
---|
| 66 | StoreErrorCodeFromAHtoBDA:
|
---|
| 67 | mov [BDA.bHDLastSt], ah ; Store BIOS error code to BDA
|
---|
| 68 |
|
---|
| 69 | pop dx
|
---|
[3] | 70 | pop ds
|
---|
[28] | 71 | ret
|
---|
[3] | 72 |
|
---|
[28] | 73 |
|
---|
[3] | 74 | ;--------------------------------------------------------------------
|
---|
[28] | 75 | ; HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
|
---|
[3] | 76 | ; Parameters:
|
---|
[28] | 77 | ; DS: RAMVARS segment
|
---|
[3] | 78 | ; Returns:
|
---|
[28] | 79 | ; AL: IDE Status Register contents
|
---|
| 80 | ; AH: IDE Error Register contents
|
---|
| 81 | ; DS: BDA segment
|
---|
[3] | 82 | ; Corrupts registers:
|
---|
[28] | 83 | ; DX
|
---|
[3] | 84 | ;--------------------------------------------------------------------
|
---|
| 85 | ALIGN JUMP_ALIGN
|
---|
[28] | 86 | HError_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 | ;--------------------------------------------------------------------
|
---|
| 123 | ALIGN JUMP_ALIGN
|
---|
| 124 | GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX:
|
---|
[27] | 125 | test al, FLG_IDE_ST_BSY
|
---|
[28] | 126 | jz SHORT .CheckErrorBitsFromStatusRegisterInAL
|
---|
| 127 | mov ah, RET_HD_TIMEOUT
|
---|
| 128 | jmp SHORT .ReturnBiosErrorCodeInAH
|
---|
| 129 |
|
---|
| 130 | ALIGN JUMP_ALIGN
|
---|
| 131 | .CheckErrorBitsFromStatusRegisterInAL:
|
---|
[3] | 132 | test al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
|
---|
[28] | 133 | jnz SHORT .ProcessErrorFromStatusRegisterInAL
|
---|
[3] | 134 | xor ah, ah ; No errors, zero AH and CF
|
---|
| 135 | ret
|
---|
| 136 |
|
---|
[28] | 137 | .ProcessErrorFromStatusRegisterInAL:
|
---|
[3] | 138 | test al, FLG_IDE_ST_ERR ; Error specified in Error register?
|
---|
[28] | 139 | jnz SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH
|
---|
[3] | 140 | mov ah, RET_HD_ECC ; Assume ECC corrected error
|
---|
| 141 | test al, FLG_IDE_ST_CORR ; ECC corrected error?
|
---|
[28] | 142 | jnz SHORT .ReturnBiosErrorCodeInAH
|
---|
[3] | 143 | mov ah, RET_HD_CONTROLLER ; Must be Device Fault
|
---|
[28] | 144 | jmp SHORT .ReturnBiosErrorCodeInAH
|
---|
[3] | 145 |
|
---|
[28] | 146 | .ConvertBiosErrorToAHfromErrorRegisterInAH:
|
---|
[3] | 147 | push bx
|
---|
[28] | 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:
|
---|
[3] | 156 | mov ah, [cs:bx+.rgbRetCodeLookup]
|
---|
| 157 | pop bx
|
---|
[28] | 158 |
|
---|
| 159 | .ReturnBiosErrorCodeInAH:
|
---|
[3] | 160 | stc ; Set CF since error
|
---|
| 161 | ret
|
---|
| 162 |
|
---|
| 163 | .rgbRetCodeLookup:
|
---|
| 164 | db RET_HD_ADDRMARK ; Bit0=AMNF, Address Mark Not Found
|
---|
| 165 | db RET_HD_SEEK_FAIL ; Bit1=TK0NF, Track 0 Not Found
|
---|
| 166 | db RET_HD_INVALID ; Bit2=ABRT, Aborted Command
|
---|
| 167 | db RET_HD_NOTLOCKED ; Bit3=MCR, Media Change Requested
|
---|
| 168 | db RET_HD_NOT_FOUND ; Bit4=IDNF, ID Not Found
|
---|
| 169 | db RET_HD_LOCKED ; Bit5=MC, Media Changed
|
---|
| 170 | db RET_HD_UNCORRECC ; Bit6=UNC, Uncorrectable Data Error
|
---|
| 171 | db RET_HD_BADSECTOR ; Bit7=BBK, Bad Block Detected
|
---|
[28] | 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 | ;--------------------------------------------------------------------
|
---|
| 184 | ALIGN JUMP_ALIGN
|
---|
| 185 | HError_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
|
---|