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