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