source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HError.asm@ 29

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