[3] | 1 | ; File name : HError.asm |
---|
| 2 | ; Project name : IDE BIOS |
---|
| 3 | ; Created date : 30.11.2007 |
---|
[35] | 4 | ; Last update : 24.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_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit |
---|
| 13 | ; HError_ProcessErrorsAfterPollingBSY |
---|
[3] | 14 | ; Parameters: |
---|
[28] | 15 | ; DS: RAMVARS segment |
---|
[3] | 16 | ; Returns: |
---|
[28] | 17 | ; AH: BIOS error code |
---|
| 18 | ; CF: Set if error |
---|
| 19 | ; Cleared if no error |
---|
[3] | 20 | ; Corrupts registers: |
---|
[28] | 21 | ; AL |
---|
[3] | 22 | ;-------------------------------------------------------------------- |
---|
| 23 | ALIGN JUMP_ALIGN |
---|
[28] | 24 | HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit: |
---|
| 25 | call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA |
---|
| 26 | call GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX |
---|
[35] | 27 | jc SHORT .ReturnErrorCodeInAH |
---|
[28] | 28 | mov ah, RET_HD_TIMEOUT ; Force timeout since no actual error... |
---|
| 29 | stc ; ...but wanted bit was never set |
---|
[35] | 30 | .ReturnErrorCodeInAH: |
---|
| 31 | ret |
---|
[28] | 32 | |
---|
| 33 | |
---|
| 34 | ALIGN JUMP_ALIGN |
---|
| 35 | HError_ProcessErrorsAfterPollingBSY: |
---|
| 36 | call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA |
---|
[35] | 37 | jmp SHORT GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX |
---|
[28] | 38 | |
---|
[3] | 39 | |
---|
| 40 | ;-------------------------------------------------------------------- |
---|
[28] | 41 | ; HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA |
---|
[3] | 42 | ; Parameters: |
---|
[28] | 43 | ; DS: RAMVARS segment |
---|
[3] | 44 | ; Returns: |
---|
[28] | 45 | ; AL: IDE Status Register contents |
---|
| 46 | ; AH: IDE Error Register contents |
---|
[3] | 47 | ; Corrupts registers: |
---|
[35] | 48 | ; Nothing |
---|
[3] | 49 | ;-------------------------------------------------------------------- |
---|
| 50 | ALIGN JUMP_ALIGN |
---|
[28] | 51 | HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA: |
---|
[35] | 52 | push ds |
---|
| 53 | push dx |
---|
| 54 | |
---|
[28] | 55 | mov dx, [RAMVARS.wIdeBase] ; Load IDE base port address |
---|
| 56 | inc dx ; Increment to Error Register |
---|
| 57 | in al, dx ; Read Error Register... |
---|
| 58 | mov ah, al ; ...and copy it to AH |
---|
| 59 | add dx, BYTE REGR_IDE_ST - REGR_IDE_ERROR |
---|
| 60 | in al, dx ; Read Status Register to AL |
---|
| 61 | |
---|
| 62 | LOAD_BDA_SEGMENT_TO ds, dx |
---|
| 63 | mov [HDBDA.wHDStAndErr], ax |
---|
[35] | 64 | |
---|
| 65 | pop dx |
---|
| 66 | pop ds |
---|
[28] | 67 | ret |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | ;-------------------------------------------------------------------- |
---|
| 71 | ; GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX |
---|
| 72 | ; Parameters: |
---|
| 73 | ; AL: IDE Status Register contents |
---|
| 74 | ; AH: IDE Error Register contents |
---|
| 75 | ; Returns: |
---|
| 76 | ; AH: BIOS INT 13h error code |
---|
| 77 | ; CF: Set if error |
---|
| 78 | ; Cleared if no error |
---|
| 79 | ; Corrupts registers: |
---|
| 80 | ; Nothing |
---|
| 81 | ;-------------------------------------------------------------------- |
---|
| 82 | ALIGN JUMP_ALIGN |
---|
| 83 | GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX: |
---|
[27] | 84 | test al, FLG_IDE_ST_BSY |
---|
[28] | 85 | jz SHORT .CheckErrorBitsFromStatusRegisterInAL |
---|
| 86 | mov ah, RET_HD_TIMEOUT |
---|
| 87 | jmp SHORT .ReturnBiosErrorCodeInAH |
---|
| 88 | |
---|
| 89 | ALIGN JUMP_ALIGN |
---|
| 90 | .CheckErrorBitsFromStatusRegisterInAL: |
---|
[3] | 91 | test al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR |
---|
[28] | 92 | jnz SHORT .ProcessErrorFromStatusRegisterInAL |
---|
[3] | 93 | xor ah, ah ; No errors, zero AH and CF |
---|
| 94 | ret |
---|
| 95 | |
---|
[28] | 96 | .ProcessErrorFromStatusRegisterInAL: |
---|
[3] | 97 | test al, FLG_IDE_ST_ERR ; Error specified in Error register? |
---|
[28] | 98 | jnz SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH |
---|
[3] | 99 | mov ah, RET_HD_ECC ; Assume ECC corrected error |
---|
| 100 | test al, FLG_IDE_ST_CORR ; ECC corrected error? |
---|
[28] | 101 | jnz SHORT .ReturnBiosErrorCodeInAH |
---|
[3] | 102 | mov ah, RET_HD_CONTROLLER ; Must be Device Fault |
---|
[28] | 103 | jmp SHORT .ReturnBiosErrorCodeInAH |
---|
[3] | 104 | |
---|
[28] | 105 | .ConvertBiosErrorToAHfromErrorRegisterInAH: |
---|
[3] | 106 | push bx |
---|
[28] | 107 | mov bx, .rgbRetCodeLookup |
---|
| 108 | .ErrorBitLoop: |
---|
| 109 | rcr ah, 1 ; Set CF if error bit set |
---|
| 110 | jc SHORT .LookupErrorCode |
---|
| 111 | inc bx |
---|
| 112 | cmp bx, .rgbRetCodeLookup + 8 |
---|
| 113 | jb SHORT .ErrorBitLoop ; Loop until all bits checked |
---|
| 114 | .LookupErrorCode: |
---|
[3] | 115 | mov ah, [cs:bx+.rgbRetCodeLookup] |
---|
| 116 | pop bx |
---|
[28] | 117 | |
---|
| 118 | .ReturnBiosErrorCodeInAH: |
---|
[3] | 119 | stc ; Set CF since error |
---|
| 120 | ret |
---|
| 121 | |
---|
| 122 | .rgbRetCodeLookup: |
---|
| 123 | db RET_HD_ADDRMARK ; Bit0=AMNF, Address Mark Not Found |
---|
| 124 | db RET_HD_SEEK_FAIL ; Bit1=TK0NF, Track 0 Not Found |
---|
| 125 | db RET_HD_INVALID ; Bit2=ABRT, Aborted Command |
---|
| 126 | db RET_HD_NOTLOCKED ; Bit3=MCR, Media Change Requested |
---|
| 127 | db RET_HD_NOT_FOUND ; Bit4=IDNF, ID Not Found |
---|
| 128 | db RET_HD_LOCKED ; Bit5=MC, Media Changed |
---|
| 129 | db RET_HD_UNCORRECC ; Bit6=UNC, Uncorrectable Data Error |
---|
| 130 | db RET_HD_BADSECTOR ; Bit7=BBK, Bad Block Detected |
---|
[28] | 131 | db RET_HD_STATUSERR ; When Error Register is zero |
---|