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