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