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

Last change on this file since 238 was 238, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Makefile now builds small (8k) and large versions.
  • Completely untested support for JR-IDE/ISA.
File size: 3.1 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   IDE Device error functions.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
9;   Parameters:
10;       AL:     IDE Status Register contents
11;       DS:DI:  Ptr to DPT (in RAMVARS segment)
12;   Returns:
13;       AH:     BIOS error code
14;       CF:     Set if error
15;               Cleared if no error
16;   Corrupts registers:
17;       AL, BX, DX
18;--------------------------------------------------------------------
19ALIGN JUMP_ALIGN
20IDEDEVICE%+Error_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL:
21    mov     ah, al          ; IDE Status Register to AH
22    INPUT_TO_AL_FROM_IDE_REGISTER ERROR_REGISTER_in
23    xchg    al, ah          ; Status Register now in AL, Error Register now in AH
24
25    ; I don't think anything actually reads these from BDA
26    push    ds
27    LOAD_BDA_SEGMENT_TO ds, dx
28    mov     [HDBDA.wHDStAndErr], ax
29    pop     ds
30
31    ; Fall to GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
32
33
34;--------------------------------------------------------------------
35; GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
36;   Parameters:
37;       AL:     IDE Status Register contents
38;       AH:     IDE Error Register contents
39;   Returns:
40;       AH:     BIOS INT 13h error code
41;       CF:     Set if error
42;               Cleared if no error
43;   Corrupts registers:
44;       BX
45;--------------------------------------------------------------------
46%ifdef ASSEMBLE_SHARED_IDE_DEVICE_FUNCTIONS
47ALIGN JUMP_ALIGN
48GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX:
49    test    al, FLG_STATUS_BSY
50    jz      SHORT .CheckErrorBitsFromStatusRegisterInAL
51    mov     ah, RET_HD_TIMEOUT
52    jmp     SHORT .ReturnBiosErrorCodeInAH
53
54ALIGN JUMP_ALIGN
55.CheckErrorBitsFromStatusRegisterInAL:
56    test    al, FLG_STATUS_DF | FLG_STATUS_CORR | FLG_STATUS_ERR
57    jnz     SHORT .ProcessErrorFromStatusRegisterInAL
58    xor     ah, ah                  ; No errors, zero AH and CF
59    ret
60
61.ProcessErrorFromStatusRegisterInAL:
62    test    al, FLG_STATUS_ERR      ; Error specified in Error register?
63    jnz     SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH
64    mov     ah, RET_HD_ECC          ; Assume ECC corrected error
65    test    al, FLG_STATUS_CORR     ; ECC corrected error?
66    jnz     SHORT .ReturnBiosErrorCodeInAH
67    mov     ah, RET_HD_CONTROLLER   ; Must be Device Fault
68    jmp     SHORT .ReturnBiosErrorCodeInAH
69
70.ConvertBiosErrorToAHfromErrorRegisterInAH:
71    xor     bx, bx                  ; Clear CF
72.ErrorBitLoop:
73    rcr     ah, 1                   ; Set CF if error bit set
74    jc      SHORT .LookupErrorCode
75    inc     bx
76    test    ah, ah                  ; Clear CF
77    jnz     SHORT .ErrorBitLoop
78.LookupErrorCode:
79    mov     ah, [cs:bx+.rgbRetCodeLookup]
80.ReturnBiosErrorCodeInAH:
81    stc                             ; Set CF since error
82    ret
83
84.rgbRetCodeLookup:
85    db  RET_HD_ADDRMARK     ; Bit0=AMNF, Address Mark Not Found
86    db  RET_HD_SEEK_FAIL    ; Bit1=TK0NF, Track 0 Not Found
87    db  RET_HD_INVALID      ; Bit2=ABRT, Aborted Command
88    db  RET_HD_NOTLOCKED    ; Bit3=MCR, Media Change Requested
89    db  RET_HD_NOT_FOUND    ; Bit4=IDNF, ID Not Found
90    db  RET_HD_LOCKED       ; Bit5=MC, Media Changed
91    db  RET_HD_UNCORRECC    ; Bit6=UNC, Uncorrectable Data Error
92    db  RET_HD_BADSECTOR    ; Bit7=BBK, Bad Block Detected
93    db  RET_HD_STATUSERR    ; When Error Register is zero
94%endif
Note: See TracBrowser for help on using the repository browser.