source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeError.asm @ 566

Last change on this file since 566 was 566, checked in by krille_n_@…, 11 years ago

Changes to XTIDE Universal BIOS:

  • Fixed a very old bug (from r150) in IdeError.asm where GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX would return RET_HD_SEEK_FAIL instead of RET_HD_STATUSERR.
  • Optimizations and other fixes.
File size: 3.5 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   IDE Device error functions.
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
25;   Parameters:
26;       AL:     IDE Status Register contents
27;       DS:DI:  Ptr to DPT (in RAMVARS segment)
28;   Returns:
29;       AH:     BIOS error code
30;       CF:     Set if error
31;               Cleared if no error
32;   Corrupts registers:
33;       AL, BX, DX
34;--------------------------------------------------------------------
35ALIGN JUMP_ALIGN
36IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL:
37    mov     ah, al          ; IDE Status Register to AH
38    INPUT_TO_AL_FROM_IDE_REGISTER   ERROR_REGISTER_in
39    xchg    al, ah          ; Status Register now in AL, Error Register now in AH
40    ; Fall to GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
41
42
43;--------------------------------------------------------------------
44; GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
45;   Parameters:
46;       AL:     IDE Status Register contents
47;       AH:     IDE Error Register contents
48;   Returns:
49;       AH:     BIOS INT 13h error code
50;       CF:     Set if error
51;               Cleared if no error
52;   Corrupts registers:
53;       BX
54;--------------------------------------------------------------------
55ALIGN JUMP_ALIGN
56GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX:
57    test    al, FLG_STATUS_BSY | FLG_STATUS_DF | FLG_STATUS_CORR | FLG_STATUS_ERR   ; Clears CF
58    jnz     SHORT .CheckErrorBitsFromStatusRegisterInAL
59    ; The MSB of AL (FLG_STATUS_BSY) is cleared at this point.
60    cbw                             ; No errors, zero AH (CF already cleared)
61    ret
62
63ALIGN JUMP_ALIGN
64.CheckErrorBitsFromStatusRegisterInAL:
65    js      SHORT .Flg_Status_Bsy   ; Jump if FLG_STATUS_BSY
66    test    al, FLG_STATUS_ERR      ; Error specified in Error register?
67    jnz     SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH
68    mov     ah, RET_HD_ECC          ; Assume ECC corrected error
69    test    al, FLG_STATUS_CORR     ; ECC corrected error?
70    jnz     SHORT .ReturnBiosErrorCodeInAH
71    mov     ah, RET_HD_CONTROLLER   ; Must be Device Fault
72    SKIP2B  bx
73.Flg_Status_Bsy:
74    mov     ah, RET_HD_TIMEOUT
75.ReturnBiosErrorCodeInAH:
76    stc
77    ret
78
79.ConvertBiosErrorToAHfromErrorRegisterInAH:
80    stc                             ; Needed in case Error register (AH) is zero
81    mov     bx, .rgbRetCodeLookup-1
82.ErrorBitLoop:
83    inc     bx
84    rcr     ah, 1
85    jnc     SHORT .ErrorBitLoop     ; CF will be set eventually
86    mov     ah, [cs:bx]
87    ret
88
89
90.rgbRetCodeLookup:
91    db  RET_HD_ADDRMARK     ; Bit0=AMNF, Address Mark Not Found
92    db  RET_HD_SEEK_FAIL    ; Bit1=TK0NF, Track 0 Not Found
93    db  RET_HD_INVALID      ; Bit2=ABRT, Aborted Command
94    db  RET_HD_NOTLOCKED    ; Bit3=MCR, Media Change Requested
95    db  RET_HD_NOT_FOUND    ; Bit4=IDNF, ID Not Found
96    db  RET_HD_LOCKED       ; Bit5=MC, Media Changed
97    db  RET_HD_UNCORRECC    ; Bit6=UNC, Uncorrectable Data Error
98    db  RET_HD_BADSECTOR    ; Bit7=BBK, Bad Block Detected
99    db  RET_HD_STATUSERR    ; When Error Register is zero
Note: See TracBrowser for help on using the repository browser.