[150] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : IDE Device error functions.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[526] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 7 | ;
|
---|
| 8 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 9 | ; it under the terms of the GNU General Public License as published by
|
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 11 | ; (at your option) any later version.
|
---|
[526] | 12 | ;
|
---|
[376] | 13 | ; This program is distributed in the hope that it will be useful,
|
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | ; GNU General Public License for more details.
|
---|
[526] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 18 | ;
|
---|
[376] | 19 |
|
---|
[150] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
[567] | 23 | %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
|
---|
| 24 | %if $ <> PollBsyOnly.End
|
---|
| 25 | %error "IdeError.asm must come immediately after IdeWait.asm (PollBsyOnly falls into IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL)!"
|
---|
| 26 | %endif
|
---|
| 27 | %endif
|
---|
| 28 |
|
---|
[150] | 29 | ;--------------------------------------------------------------------
|
---|
| 30 | ; IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
| 31 | ; Parameters:
|
---|
| 32 | ; AL: IDE Status Register contents
|
---|
| 33 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 34 | ; Returns:
|
---|
| 35 | ; AH: BIOS error code
|
---|
| 36 | ; CF: Set if error
|
---|
| 37 | ; Cleared if no error
|
---|
| 38 | ; Corrupts registers:
|
---|
| 39 | ; AL, BX, DX
|
---|
| 40 | ;--------------------------------------------------------------------
|
---|
| 41 | ALIGN JUMP_ALIGN
|
---|
[400] | 42 | IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL:
|
---|
[150] | 43 | mov ah, al ; IDE Status Register to AH
|
---|
[267] | 44 | INPUT_TO_AL_FROM_IDE_REGISTER ERROR_REGISTER_in
|
---|
[150] | 45 | xchg al, ah ; Status Register now in AL, Error Register now in AH
|
---|
| 46 | ; Fall to GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
|
---|
| 47 |
|
---|
[267] | 48 |
|
---|
[150] | 49 | ;--------------------------------------------------------------------
|
---|
| 50 | ; GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
|
---|
| 51 | ; Parameters:
|
---|
| 52 | ; AL: IDE Status Register contents
|
---|
| 53 | ; AH: IDE Error Register contents
|
---|
| 54 | ; Returns:
|
---|
| 55 | ; AH: BIOS INT 13h error code
|
---|
| 56 | ; CF: Set if error
|
---|
| 57 | ; Cleared if no error
|
---|
| 58 | ; Corrupts registers:
|
---|
| 59 | ; BX
|
---|
| 60 | ;--------------------------------------------------------------------
|
---|
| 61 | ALIGN JUMP_ALIGN
|
---|
| 62 | GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX:
|
---|
[566] | 63 | test al, FLG_STATUS_BSY | FLG_STATUS_DF | FLG_STATUS_CORR | FLG_STATUS_ERR ; Clears CF
|
---|
| 64 | jnz SHORT .CheckErrorBitsFromStatusRegisterInAL
|
---|
| 65 | ; The MSB of AL (FLG_STATUS_BSY) is cleared at this point.
|
---|
| 66 | cbw ; No errors, zero AH (CF already cleared)
|
---|
| 67 | ret
|
---|
[150] | 68 |
|
---|
| 69 | ALIGN JUMP_ALIGN
|
---|
| 70 | .CheckErrorBitsFromStatusRegisterInAL:
|
---|
[566] | 71 | js SHORT .Flg_Status_Bsy ; Jump if FLG_STATUS_BSY
|
---|
[150] | 72 | test al, FLG_STATUS_ERR ; Error specified in Error register?
|
---|
| 73 | jnz SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH
|
---|
| 74 | mov ah, RET_HD_ECC ; Assume ECC corrected error
|
---|
| 75 | test al, FLG_STATUS_CORR ; ECC corrected error?
|
---|
| 76 | jnz SHORT .ReturnBiosErrorCodeInAH
|
---|
| 77 | mov ah, RET_HD_CONTROLLER ; Must be Device Fault
|
---|
[566] | 78 | SKIP2B bx
|
---|
| 79 | .Flg_Status_Bsy:
|
---|
| 80 | mov ah, RET_HD_TIMEOUT
|
---|
| 81 | .ReturnBiosErrorCodeInAH:
|
---|
| 82 | stc
|
---|
| 83 | ret
|
---|
[150] | 84 |
|
---|
| 85 | .ConvertBiosErrorToAHfromErrorRegisterInAH:
|
---|
[566] | 86 | stc ; Needed in case Error register (AH) is zero
|
---|
| 87 | mov bx, .rgbRetCodeLookup-1
|
---|
[150] | 88 | .ErrorBitLoop:
|
---|
| 89 | inc bx
|
---|
[566] | 90 | rcr ah, 1
|
---|
| 91 | jnc SHORT .ErrorBitLoop ; CF will be set eventually
|
---|
| 92 | mov ah, [cs:bx]
|
---|
[150] | 93 | ret
|
---|
| 94 |
|
---|
[566] | 95 |
|
---|
[150] | 96 | .rgbRetCodeLookup:
|
---|
| 97 | db RET_HD_ADDRMARK ; Bit0=AMNF, Address Mark Not Found
|
---|
| 98 | db RET_HD_SEEK_FAIL ; Bit1=TK0NF, Track 0 Not Found
|
---|
| 99 | db RET_HD_INVALID ; Bit2=ABRT, Aborted Command
|
---|
| 100 | db RET_HD_NOTLOCKED ; Bit3=MCR, Media Change Requested
|
---|
| 101 | db RET_HD_NOT_FOUND ; Bit4=IDNF, ID Not Found
|
---|
| 102 | db RET_HD_LOCKED ; Bit5=MC, Media Changed
|
---|
| 103 | db RET_HD_UNCORRECC ; Bit6=UNC, Uncorrectable Data Error
|
---|
| 104 | db RET_HD_BADSECTOR ; Bit7=BBK, Bad Block Detected
|
---|
| 105 | db RET_HD_STATUSERR ; When Error Register is zero
|
---|