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

Last change on this file since 67 was 35, checked in by Tomi Tilli, 14 years ago

Cleaned recent changes a bit to save few bytes.

File size: 4.1 KB
Line 
1; File name : HError.asm
2; Project name : IDE BIOS
3; Created date : 30.11.2007
4; Last update : 24.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_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;--------------------------------------------------------------------
23ALIGN JUMP_ALIGN
24HError_ProcessTimeoutAfterPollingBSYandSomeOtherStatusBit:
25 call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
26 call GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
27 jc SHORT .ReturnErrorCodeInAH
28 mov ah, RET_HD_TIMEOUT ; Force timeout since no actual error...
29 stc ; ...but wanted bit was never set
30.ReturnErrorCodeInAH:
31 ret
32
33
34ALIGN JUMP_ALIGN
35HError_ProcessErrorsAfterPollingBSY:
36 call HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
37 jmp SHORT GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
38
39
40;--------------------------------------------------------------------
41; HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
42; Parameters:
43; DS: RAMVARS segment
44; Returns:
45; AL: IDE Status Register contents
46; AH: IDE Error Register contents
47; Corrupts registers:
48; Nothing
49;--------------------------------------------------------------------
50ALIGN JUMP_ALIGN
51HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA:
52 push ds
53 push dx
54
55 mov dx, [RAMVARS.wIdeBase] ; Load IDE base port address
56 inc dx ; Increment to Error Register
57 in al, dx ; Read Error Register...
58 mov ah, al ; ...and copy it to AH
59 add dx, BYTE REGR_IDE_ST - REGR_IDE_ERROR
60 in al, dx ; Read Status Register to AL
61
62 LOAD_BDA_SEGMENT_TO ds, dx
63 mov [HDBDA.wHDStAndErr], ax
64
65 pop dx
66 pop ds
67 ret
68
69
70;--------------------------------------------------------------------
71; GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
72; Parameters:
73; AL: IDE Status Register contents
74; AH: IDE Error Register contents
75; Returns:
76; AH: BIOS INT 13h error code
77; CF: Set if error
78; Cleared if no error
79; Corrupts registers:
80; Nothing
81;--------------------------------------------------------------------
82ALIGN JUMP_ALIGN
83GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX:
84 test al, FLG_IDE_ST_BSY
85 jz SHORT .CheckErrorBitsFromStatusRegisterInAL
86 mov ah, RET_HD_TIMEOUT
87 jmp SHORT .ReturnBiosErrorCodeInAH
88
89ALIGN JUMP_ALIGN
90.CheckErrorBitsFromStatusRegisterInAL:
91 test al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
92 jnz SHORT .ProcessErrorFromStatusRegisterInAL
93 xor ah, ah ; No errors, zero AH and CF
94 ret
95
96.ProcessErrorFromStatusRegisterInAL:
97 test al, FLG_IDE_ST_ERR ; Error specified in Error register?
98 jnz SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH
99 mov ah, RET_HD_ECC ; Assume ECC corrected error
100 test al, FLG_IDE_ST_CORR ; ECC corrected error?
101 jnz SHORT .ReturnBiosErrorCodeInAH
102 mov ah, RET_HD_CONTROLLER ; Must be Device Fault
103 jmp SHORT .ReturnBiosErrorCodeInAH
104
105.ConvertBiosErrorToAHfromErrorRegisterInAH:
106 push bx
107 mov bx, .rgbRetCodeLookup
108.ErrorBitLoop:
109 rcr ah, 1 ; Set CF if error bit set
110 jc SHORT .LookupErrorCode
111 inc bx
112 cmp bx, .rgbRetCodeLookup + 8
113 jb SHORT .ErrorBitLoop ; Loop until all bits checked
114.LookupErrorCode:
115 mov ah, [cs:bx+.rgbRetCodeLookup]
116 pop bx
117
118.ReturnBiosErrorCodeInAH:
119 stc ; Set CF since error
120 ret
121
122.rgbRetCodeLookup:
123 db RET_HD_ADDRMARK ; Bit0=AMNF, Address Mark Not Found
124 db RET_HD_SEEK_FAIL ; Bit1=TK0NF, Track 0 Not Found
125 db RET_HD_INVALID ; Bit2=ABRT, Aborted Command
126 db RET_HD_NOTLOCKED ; Bit3=MCR, Media Change Requested
127 db RET_HD_NOT_FOUND ; Bit4=IDNF, ID Not Found
128 db RET_HD_LOCKED ; Bit5=MC, Media Changed
129 db RET_HD_UNCORRECC ; Bit6=UNC, Uncorrectable Data Error
130 db RET_HD_BADSECTOR ; Bit7=BBK, Bad Block Detected
131 db RET_HD_STATUSERR ; When Error Register is zero
Note: See TracBrowser for help on using the repository browser.