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

Last change on this file since 148 was 148, checked in by aitotat, 13 years ago

Changes to XTIDE Universal BIOS:

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