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 | ;--------------------------------------------------------------------
|
---|
8 | ; HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit
|
---|
9 | ; HError_ProcessErrorsAfterPollingBSY
|
---|
10 | ; Parameters:
|
---|
11 | ; DS: RAMVARS segment
|
---|
12 | ; Returns:
|
---|
13 | ; AH: BIOS error code
|
---|
14 | ; CF: Set if error
|
---|
15 | ; Cleared if no error
|
---|
16 | ; Corrupts registers:
|
---|
17 | ; AL
|
---|
18 | ;--------------------------------------------------------------------
|
---|
19 | ALIGN JUMP_ALIGN
|
---|
20 | HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit:
|
---|
21 | call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
|
---|
22 | call GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
|
---|
23 | jc SHORT .ReturnErrorCodeInAH
|
---|
24 | mov ah, RET_HD_TIMEOUT ; Force timeout since no actual error...
|
---|
25 | stc ; ...but wanted bit was never set
|
---|
26 | .ReturnErrorCodeInAH:
|
---|
27 | ret
|
---|
28 |
|
---|
29 |
|
---|
30 | ALIGN JUMP_ALIGN
|
---|
31 | HError_ProcessErrorsAfterPollingBSY:
|
---|
32 | %ifndef USE_186
|
---|
33 | call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
|
---|
34 | jmp SHORT GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
|
---|
35 | %else
|
---|
36 | push GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
|
---|
37 | ; Fall through to HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
|
---|
38 | %endif
|
---|
39 |
|
---|
40 |
|
---|
41 | ;--------------------------------------------------------------------
|
---|
42 | ; HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
|
---|
43 | ; Parameters:
|
---|
44 | ; DS: RAMVARS segment
|
---|
45 | ; Returns:
|
---|
46 | ; AL: IDE Status Register contents
|
---|
47 | ; AH: IDE Error Register contents
|
---|
48 | ; Corrupts registers:
|
---|
49 | ; Nothing
|
---|
50 | ;--------------------------------------------------------------------
|
---|
51 | ALIGN JUMP_ALIGN
|
---|
52 | HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA:
|
---|
53 | push ds
|
---|
54 | push dx
|
---|
55 |
|
---|
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
|
---|
65 |
|
---|
66 | pop dx
|
---|
67 | pop ds
|
---|
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:
|
---|
85 | test al, FLG_IDE_ST_BSY
|
---|
86 | jz SHORT .CheckErrorBitsFromStatusRegisterInAL
|
---|
87 | mov ah, RET_HD_TIMEOUT
|
---|
88 | jmp SHORT .ReturnBiosErrorCodeInAH
|
---|
89 |
|
---|
90 | ALIGN JUMP_ALIGN
|
---|
91 | .CheckErrorBitsFromStatusRegisterInAL:
|
---|
92 | test al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
|
---|
93 | jnz SHORT .ProcessErrorFromStatusRegisterInAL
|
---|
94 | xor ah, ah ; No errors, zero AH and CF
|
---|
95 | ret
|
---|
96 |
|
---|
97 | .ProcessErrorFromStatusRegisterInAL:
|
---|
98 | test al, FLG_IDE_ST_ERR ; Error specified in Error register?
|
---|
99 | jnz SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH
|
---|
100 | mov ah, RET_HD_ECC ; Assume ECC corrected error
|
---|
101 | test al, FLG_IDE_ST_CORR ; ECC corrected error?
|
---|
102 | jnz SHORT .ReturnBiosErrorCodeInAH
|
---|
103 | mov ah, RET_HD_CONTROLLER ; Must be Device Fault
|
---|
104 | jmp SHORT .ReturnBiosErrorCodeInAH
|
---|
105 |
|
---|
106 | .ConvertBiosErrorToAHfromErrorRegisterInAH:
|
---|
107 | push bx
|
---|
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:
|
---|
116 | mov ah, [cs:bx+.rgbRetCodeLookup]
|
---|
117 | pop bx
|
---|
118 |
|
---|
119 | .ReturnBiosErrorCodeInAH:
|
---|
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
|
---|
132 | db RET_HD_STATUSERR ; When Error Register is zero
|
---|