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