[3] | 1 | ; File name : HError.asm |
---|
| 2 | ; Project name : IDE BIOS |
---|
| 3 | ; Created date : 30.11.2007 |
---|
[33] | 4 | ; Last update : 23.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 | ; CF: Set if timeout |
---|
| 16 | ; Cleared if task flag was properly set |
---|
[27] | 17 | ; Returns: |
---|
[28] | 18 | ; AH: BIOS error code |
---|
| 19 | ; CF: Set if error |
---|
| 20 | ; Cleared if no error |
---|
[27] | 21 | ; Corrupts registers: |
---|
[28] | 22 | ; AL |
---|
[27] | 23 | ;-------------------------------------------------------------------- |
---|
| 24 | ALIGN JUMP_ALIGN |
---|
[28] | 25 | HError_ProcessErrorsAfterPollingTaskFlag: |
---|
[33] | 26 | jnc SHORT HError_ProcessErrorsAfterPollingBSY |
---|
| 27 | ; Fall to HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit |
---|
[27] | 28 | |
---|
| 29 | ;-------------------------------------------------------------------- |
---|
[28] | 30 | ; HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit |
---|
| 31 | ; HError_ProcessErrorsAfterPollingBSY |
---|
[3] | 32 | ; Parameters: |
---|
[28] | 33 | ; DS: RAMVARS segment |
---|
[3] | 34 | ; Returns: |
---|
[28] | 35 | ; AH: BIOS error code |
---|
| 36 | ; CF: Set if error |
---|
| 37 | ; Cleared if no error |
---|
[3] | 38 | ; Corrupts registers: |
---|
[28] | 39 | ; AL |
---|
[3] | 40 | ;-------------------------------------------------------------------- |
---|
| 41 | ALIGN JUMP_ALIGN |
---|
[28] | 42 | HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit: |
---|
| 43 | push ds |
---|
| 44 | push dx |
---|
[3] | 45 | |
---|
[28] | 46 | call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA |
---|
| 47 | call GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX |
---|
| 48 | jc SHORT StoreErrorCodeFromAHtoBDA |
---|
| 49 | mov ah, RET_HD_TIMEOUT ; Force timeout since no actual error... |
---|
| 50 | stc ; ...but wanted bit was never set |
---|
| 51 | jmp SHORT StoreErrorCodeFromAHtoBDA |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | ALIGN JUMP_ALIGN |
---|
| 55 | HError_ProcessErrorsAfterPollingBSY: |
---|
[3] | 56 | push ds |
---|
[28] | 57 | push dx |
---|
| 58 | |
---|
| 59 | call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA |
---|
| 60 | call GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX |
---|
| 61 | StoreErrorCodeFromAHtoBDA: |
---|
| 62 | mov [BDA.bHDLastSt], ah ; Store BIOS error code to BDA |
---|
| 63 | |
---|
| 64 | pop dx |
---|
[3] | 65 | pop ds |
---|
[28] | 66 | ret |
---|
[3] | 67 | |
---|
[28] | 68 | |
---|
[3] | 69 | ;-------------------------------------------------------------------- |
---|
[28] | 70 | ; HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA |
---|
[3] | 71 | ; Parameters: |
---|
[28] | 72 | ; DS: RAMVARS segment |
---|
[3] | 73 | ; Returns: |
---|
[28] | 74 | ; AL: IDE Status Register contents |
---|
| 75 | ; AH: IDE Error Register contents |
---|
| 76 | ; DS: BDA segment |
---|
[3] | 77 | ; Corrupts registers: |
---|
[28] | 78 | ; DX |
---|
[3] | 79 | ;-------------------------------------------------------------------- |
---|
| 80 | ALIGN JUMP_ALIGN |
---|
[28] | 81 | HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA: |
---|
| 82 | mov dx, [RAMVARS.wIdeBase] ; Load IDE base port address |
---|
| 83 | inc dx ; Increment to Error Register |
---|
| 84 | in al, dx ; Read Error Register... |
---|
| 85 | mov ah, al ; ...and copy it to AH |
---|
| 86 | add dx, BYTE REGR_IDE_ST - REGR_IDE_ERROR |
---|
| 87 | in al, dx ; Read Status Register to AL |
---|
| 88 | ; Fall to .StoreStatusAndErrorRegistersFromAXtoBDA |
---|
| 89 | |
---|
| 90 | ;-------------------------------------------------------------------- |
---|
| 91 | ; .StoreStatusAndErrorRegistersFromAXtoBDA |
---|
| 92 | ; Parameters: |
---|
| 93 | ; AL: IDE Status Register contents |
---|
| 94 | ; AH: IDE Error Register contents |
---|
| 95 | ; Returns: |
---|
| 96 | ; DS: BDA segment (zero) |
---|
| 97 | ; Corrupts registers: |
---|
| 98 | ; DX |
---|
| 99 | ;-------------------------------------------------------------------- |
---|
| 100 | .StoreStatusAndErrorRegistersFromAXtoBDA: |
---|
| 101 | LOAD_BDA_SEGMENT_TO ds, dx |
---|
| 102 | mov [HDBDA.wHDStAndErr], ax |
---|
| 103 | ret |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | ;-------------------------------------------------------------------- |
---|
| 107 | ; GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX |
---|
| 108 | ; Parameters: |
---|
| 109 | ; AL: IDE Status Register contents |
---|
| 110 | ; AH: IDE Error Register contents |
---|
| 111 | ; Returns: |
---|
| 112 | ; AH: BIOS INT 13h error code |
---|
| 113 | ; CF: Set if error |
---|
| 114 | ; Cleared if no error |
---|
| 115 | ; Corrupts registers: |
---|
| 116 | ; Nothing |
---|
| 117 | ;-------------------------------------------------------------------- |
---|
| 118 | ALIGN JUMP_ALIGN |
---|
| 119 | GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX: |
---|
[27] | 120 | test al, FLG_IDE_ST_BSY |
---|
[28] | 121 | jz SHORT .CheckErrorBitsFromStatusRegisterInAL |
---|
| 122 | mov ah, RET_HD_TIMEOUT |
---|
| 123 | jmp SHORT .ReturnBiosErrorCodeInAH |
---|
| 124 | |
---|
| 125 | ALIGN JUMP_ALIGN |
---|
| 126 | .CheckErrorBitsFromStatusRegisterInAL: |
---|
[3] | 127 | test al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR |
---|
[28] | 128 | jnz SHORT .ProcessErrorFromStatusRegisterInAL |
---|
[3] | 129 | xor ah, ah ; No errors, zero AH and CF |
---|
| 130 | ret |
---|
| 131 | |
---|
[28] | 132 | .ProcessErrorFromStatusRegisterInAL: |
---|
[3] | 133 | test al, FLG_IDE_ST_ERR ; Error specified in Error register? |
---|
[28] | 134 | jnz SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH |
---|
[3] | 135 | mov ah, RET_HD_ECC ; Assume ECC corrected error |
---|
| 136 | test al, FLG_IDE_ST_CORR ; ECC corrected error? |
---|
[28] | 137 | jnz SHORT .ReturnBiosErrorCodeInAH |
---|
[3] | 138 | mov ah, RET_HD_CONTROLLER ; Must be Device Fault |
---|
[28] | 139 | jmp SHORT .ReturnBiosErrorCodeInAH |
---|
[3] | 140 | |
---|
[28] | 141 | .ConvertBiosErrorToAHfromErrorRegisterInAH: |
---|
[3] | 142 | push bx |
---|
[28] | 143 | mov bx, .rgbRetCodeLookup |
---|
| 144 | .ErrorBitLoop: |
---|
| 145 | rcr ah, 1 ; Set CF if error bit set |
---|
| 146 | jc SHORT .LookupErrorCode |
---|
| 147 | inc bx |
---|
| 148 | cmp bx, .rgbRetCodeLookup + 8 |
---|
| 149 | jb SHORT .ErrorBitLoop ; Loop until all bits checked |
---|
| 150 | .LookupErrorCode: |
---|
[3] | 151 | mov ah, [cs:bx+.rgbRetCodeLookup] |
---|
| 152 | pop bx |
---|
[28] | 153 | |
---|
| 154 | .ReturnBiosErrorCodeInAH: |
---|
[3] | 155 | stc ; Set CF since error |
---|
| 156 | ret |
---|
| 157 | |
---|
| 158 | .rgbRetCodeLookup: |
---|
| 159 | db RET_HD_ADDRMARK ; Bit0=AMNF, Address Mark Not Found |
---|
| 160 | db RET_HD_SEEK_FAIL ; Bit1=TK0NF, Track 0 Not Found |
---|
| 161 | db RET_HD_INVALID ; Bit2=ABRT, Aborted Command |
---|
| 162 | db RET_HD_NOTLOCKED ; Bit3=MCR, Media Change Requested |
---|
| 163 | db RET_HD_NOT_FOUND ; Bit4=IDNF, ID Not Found |
---|
| 164 | db RET_HD_LOCKED ; Bit5=MC, Media Changed |
---|
| 165 | db RET_HD_UNCORRECC ; Bit6=UNC, Uncorrectable Data Error |
---|
| 166 | db RET_HD_BADSECTOR ; Bit7=BBK, Bad Block Detected |
---|
[28] | 167 | db RET_HD_STATUSERR ; When Error Register is zero |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | ;-------------------------------------------------------------------- |
---|
| 171 | ; HError_StoreBiosErrorCodeFromAHtoBDA |
---|
| 172 | ; Parameters: |
---|
| 173 | ; AH: BIOS error code |
---|
| 174 | ; Returns: |
---|
| 175 | ; Nothing |
---|
| 176 | ; Corrupts registers: |
---|
| 177 | ; DI |
---|
| 178 | ;-------------------------------------------------------------------- |
---|
| 179 | ALIGN JUMP_ALIGN |
---|
| 180 | HError_StoreBiosErrorCodeFromAHtoBDA: |
---|
| 181 | push ds |
---|
| 182 | mov di, 0 ; Zero DI and preserve FLAGS |
---|
| 183 | mov ds, di ; Copy BDA segment to DS |
---|
| 184 | mov [BDA.bHDLastSt], ah |
---|
| 185 | pop ds |
---|
| 186 | ret |
---|