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

Last change on this file since 27 was 27, checked in by aitotat, 14 years ago
  • v1.1.1 broke booting from foreign drives, it is now fixed.
  • Fixed a bug where Disk Parameter Table was accessed with wrong pointer register after writing last block.
  • Cleaned AH=00h, Disk Controller Reset a bit.
  • Timeout errors might now get translated for better error codes on certain situations.
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   :   28.7.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_GetErrorCodeToAHforBitPollingTimeout
13;   Parameters:
14;       AL:     IDE Status Register contents
15;       DX:     IDE Status Register Address
16;   Returns:
17;       AH:     Hard disk BIOS error code
18;       CF:     Set since error
19;   Corrupts registers:
20;       AL, CX
21;--------------------------------------------------------------------
22ALIGN JUMP_ALIGN
23HError_GetErrorCodeToAHforBitPollingTimeout:
24    test    al, FLG_IDE_ST_BSY                      ; Other bits undefined when BSY set
25    jnz     SHORT HError_GetErrorCodeForStatusReg   ; Busy, normal timeout
26    test    al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
27    jnz     SHORT HError_GetErrorCodeForStatusReg   ; Not busy but some error
28    or      al, FLG_IDE_ST_BSY                      ; Polled bit got never set, force timeout
29    ; Fall to HError_GetErrorCodeForStatusReg
30
31;--------------------------------------------------------------------
32; Converts Status Register error to BIOS error code.
33;
34; HError_GetErrorCodeForStatusReg
35;   Parameters:
36;       AL:     IDE Status Register contents
37;       DX:     IDE Status Register Address
38;   Returns:
39;       AH:     Hard disk BIOS error code
40;       CF:     0 if no errors (AH=RET_HD_SUCCESS)
41;               1 if some error
42;   Corrupts registers:
43;       AL, CX
44;--------------------------------------------------------------------
45ALIGN JUMP_ALIGN
46HError_GetErrorCodeForStatusReg:
47    ; Get Error Register contents to AH
48    mov     ah, al                              ; Backup Status Reg to AH
49    sub     dx, BYTE REGR_IDE_ST-REGR_IDE_ERROR ; Status Reg to Error Reg
50    in      al, dx                              ; Read Error Register to AL
51    xchg    al, ah                              ; Swap status and error
52    add     dx, BYTE REGR_IDE_ST-REGR_IDE_ERROR ; Restore DX
53
54    ; Store Register contents to BDA
55    push    ds
56    LOAD_BDA_SEGMENT_TO ds, cx
57    mov     [HDBDA.wHDStAndErr], ax         ; Store Status and Error to BDA
58    pop     ds
59    ; Fall to HError_ConvertIdeErrorToBiosRet
60
61;--------------------------------------------------------------------
62; Converts error flags from IDE status and error register contents
63; to BIOS Int 13h return value.
64;
65; HError_ConvertIdeErrorToBiosRet
66;   Parameters:
67;       AL:     Status Register Contents
68;       AH:     Error Register Contents
69;   Returns:
70;       AH:     Hard disk BIOS error code
71;       CF:     0 if no errors (AH=RET_HD_SUCCESS)
72;               1 if any error
73;   Corrupts registers:
74;       AL
75;--------------------------------------------------------------------
76ALIGN JUMP_ALIGN
77HError_ConvertIdeErrorToBiosRet:
78    test    al, FLG_IDE_ST_BSY
79    jnz     SHORT .TimeoutError
80    test    al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
81    jnz     SHORT .ReadErrorFromStatusReg
82    xor     ah, ah                  ; No errors, zero AH and CF
83    ret
84
85.TimeoutError:
86    mov     ah, RET_HD_TIMEOUT
87    stc
88    ret
89
90; Convert error code based on status or error register
91.ReadErrorFromStatusReg:
92    test    al, FLG_IDE_ST_ERR      ; Error specified in Error register?
93    jnz     SHORT .ReadErrorFromErrorReg
94    mov     ah, RET_HD_ECC          ; Assume ECC corrected error
95    test    al, FLG_IDE_ST_CORR     ; ECC corrected error?
96    jnz     SHORT .Return
97    mov     ah, RET_HD_CONTROLLER   ; Must be Device Fault
98    jmp     SHORT .Return
99
100; Convert error register to bios error code
101.ReadErrorFromErrorReg:
102    push    bx
103    mov     al, ah                  ; Copy error reg to AL...
104    xor     ah, ah                  ; ...and zero extend to AX
105    eBSF    bx, ax                  ; Get bit index to BX
106    mov     ah, RET_HD_STATUSERR    ; Error code if Error Reg is zero
107    jz      SHORT .SkipLookup       ; Return if error register is zero
108    mov     ah, [cs:bx+.rgbRetCodeLookup]
109.SkipLookup:
110    pop     bx
111.Return:
112    stc                             ; Set CF since error
113    ret
114
115.rgbRetCodeLookup:
116    db  RET_HD_ADDRMARK     ; Bit0=AMNF, Address Mark Not Found
117    db  RET_HD_SEEK_FAIL    ; Bit1=TK0NF, Track 0 Not Found
118    db  RET_HD_INVALID      ; Bit2=ABRT, Aborted Command
119    db  RET_HD_NOTLOCKED    ; Bit3=MCR, Media Change Requested
120    db  RET_HD_NOT_FOUND    ; Bit4=IDNF, ID Not Found
121    db  RET_HD_LOCKED       ; Bit5=MC, Media Changed
122    db  RET_HD_UNCORRECC    ; Bit6=UNC, Uncorrectable Data Error
123    db  RET_HD_BADSECTOR    ; Bit7=BBK, Bad Block Detected
Note: See TracBrowser for help on using the repository browser.