source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HStatus.asm @ 3

Last change on this file since 3 was 3, checked in by aitotat, 14 years ago
File size: 8.2 KB
Line 
1; File name     :   HStatus.asm
2; Project name  :   IDE BIOS
3; Created date  :   15.12.2009
4; Last update   :   13.4.2010
5; Author        :   Tomi Tilli
6; Description   :   IDE Status Register polling functions.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Waits Hard Disk IRQ when not transferring data.
13; If interrupts are disabled, RDY flag is polled.
14;
15; HStatus_WaitIrqOrRdy
16;   Parameters:
17;       DS:BX:  Ptr to DPT
18;   Returns:
19;       AH:     BIOS Error code
20;       CF:     0 if wait succesfull
21;               1 if any error
22;   Corrupts registers:
23;       AL, CX, DX
24;--------------------------------------------------------------------
25ALIGN JUMP_ALIGN
26HStatus_WaitIrqOrRdy:
27    test    BYTE [di+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
28    jz      HIRQ_WaitIRQ                    ; Wait for IRQ if enabled
29    call    HStatus_ReadAndIgnoreAlternateStatus
30    mov     cl, B_TIMEOUT_DRQ               ; Load DRQ (not RDY) timeout
31    jmp     SHORT HStatus_WaitRdy           ; Jump to poll RDY
32
33
34;--------------------------------------------------------------------
35; Reads Alternate Status Register and ignores result.
36; Alternate Status Register is read to prevent polling host from
37; reading status before it is valid.
38;
39; HStatus_ReadAndIgnoreAlternateStatus
40;   Parameters:
41;       DS:BX:  Ptr to DPT
42;   Returns:
43;       Nothing
44;   Corrupts registers:
45;       AL, CX, DX
46;--------------------------------------------------------------------
47ALIGN JUMP_ALIGN
48HStatus_ReadAndIgnoreAlternateStatus:
49    mov     cx, bx                          ; Backup BX
50    eMOVZX  bx, BYTE [bx+DPT.bIdeOff]       ; CS:BX now points to IDEVARS
51    mov     dx, [cs:bx+IDEVARS.wPortCtrl]   ; DX = Control Block base port
52    add     dx, BYTE REGR_IDEC_AST          ; DX = Alternate Status Register address
53    in      al, dx                          ; Read Alternate Status Register
54    mov     bx, cx                          ; Restore BX
55    ret
56
57
58;--------------------------------------------------------------------
59; Waits until Hard Disk is ready to transfer data.
60;
61; HStatus_WaitIrqOrDrq
62;   Parameters:
63;       DS:BX:  Ptr to DPT (in RAMVARS segment)
64;   Returns:
65;       AH:     BIOS Error code
66;       CF:     0 if wait succesfull
67;               1 if any error
68;   Corrupts registers:
69;       AL
70;--------------------------------------------------------------------
71ALIGN JUMP_ALIGN
72HStatus_WaitIrqOrDrq:
73    push    dx
74    push    cx
75
76    ; Check if interrupts are enabled
77    test    BYTE [bx+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN
78    jnz     SHORT .PollDRQ                  ; Poll DRQ if IRQ disabled
79    call    HIRQ_WaitIRQ                    ; Wait for IRQ
80    jmp     SHORT .Return
81
82ALIGN JUMP_ALIGN
83.PollDRQ:
84    call    HStatus_ReadAndIgnoreAlternateStatus
85    call    HStatus_WaitDrqDefTime
86ALIGN JUMP_ALIGN
87.Return:
88    pop     cx
89    pop     dx
90    ret
91
92
93;--------------------------------------------------------------------
94; Waits until busy flag is cleared from selected Hard Disk drive.
95;
96; HStatus_WaitBsyDefTime    Uses default timeout
97; HStatus_WaitBsy           Uses user defined timeout
98; HStatus_WaitBsyBase       Uses user base port address and timeout
99;   Parameters:
100;       CL:     Timeout value in system timer ticks (not HStatus_WaitBsyDefTime)
101;       DX:     IDE Base port address (HUtil_WaitBsyBase only)
102;       DS:     Segment to RAMVARS
103;   Returns:
104;       AH:     BIOS Error code
105;       DX:     IDE Status Register Address
106;       CF:     0 if wait succesfull
107;               1 if any error
108;   Corrupts registers:
109;       AL, CX
110;--------------------------------------------------------------------
111ALIGN JUMP_ALIGN
112HStatus_WaitBsyDefTime:
113    mov     cl, B_TIMEOUT_BSY           ; Load timeout value
114ALIGN JUMP_ALIGN
115HStatus_WaitBsy:
116    mov     dx, [RAMVARS.wIdeBase]      ; Load offset to base port
117ALIGN JUMP_ALIGN
118HStatus_WaitBsyBase:
119    add     dx, BYTE REGR_IDE_ST        ; Add offset to status reg
120    jmp     SHORT HStatus_PollBsy       ; Wait until not busy
121
122
123;--------------------------------------------------------------------
124; Waits until Hard Disk is ready to accept commands.
125;
126; HStatus_WaitRdyDefTime    Uses default timeout
127; HStatus_WaitRdy           Uses user defined timeout
128; HStatus_WaitRdyBase       Uses user base port address and timeout
129;   Parameters:
130;       CL:     Timeout value in system timer ticks (not HStatus_WaitRdyDefTime)
131;       DX:     IDE Base port address (HStatus_WaitRdyBase only)
132;       DS:     Segment to RAMVARS
133;   Returns:
134;       AH:     BIOS Error code
135;       DX:     IDE Status Register Address
136;       CF:     0 if wait succesfull
137;               1 if any error
138;   Corrupts registers:
139;       AL, CX
140;--------------------------------------------------------------------
141ALIGN JUMP_ALIGN
142HStatus_WaitRdyDefTime:
143    mov     cl, B_TIMEOUT_RDY           ; Load timeout value
144ALIGN JUMP_ALIGN
145HStatus_WaitRdy:
146    mov     dx, [RAMVARS.wIdeBase]      ; Load offset to base port
147ALIGN JUMP_ALIGN
148HStatus_WaitRdyBase:
149    add     dx, BYTE REGR_IDE_ST        ; Add offset to status reg
150    mov     ah, FLG_IDE_ST_DRDY         ; Flag to poll
151    jmp     SHORT HStatus_PollBsyAndFlg ; Wait until flag set
152
153
154;--------------------------------------------------------------------
155; Waits until Hard Disk is ready to transfer data.
156; Note! This function polls DRQ even if interrupts are enabled!
157;
158; HStatus_WaitDrqDefTime    Uses default timeout
159; HStatus_WaitDrq           Uses user defined timeout
160; HStatus_WaitDrqBase       Uses user base port address and timeout
161;   Parameters:
162;       CL:     Timeout value in system timer ticks (not HStatus_WaitDrqDefTime)
163;       DX:     IDE Base port address (HStatus_WaitDrqBase only)
164;       DS:     Segment to RAMVARS
165;   Returns:
166;       AH:     BIOS Error code
167;       DX:     IDE Status Register Address
168;       CF:     0 if wait succesfull
169;               1 if any error
170;   Corrupts registers:
171;       AL, CX
172;--------------------------------------------------------------------
173ALIGN JUMP_ALIGN
174HStatus_WaitDrqDefTime:
175    mov     cl, B_TIMEOUT_DRQ           ; Load timeout value
176ALIGN JUMP_ALIGN
177HStatus_WaitDrq:
178    mov     dx, [RAMVARS.wIdeBase]      ; Load offset to base port
179ALIGN JUMP_ALIGN
180HStatus_WaitDrqBase:
181    add     dx, BYTE REGR_IDE_ST        ; Add offset to status reg
182    mov     ah, FLG_IDE_ST_DRQ          ; Flag to poll
183    ; Fall to HStatus_PollBsyAndFlg
184
185;--------------------------------------------------------------------
186; IDE Status register polling.
187; This function first waits until controller is not busy.
188; When not busy, IDE Status Register is polled until wanted
189; flag (HBIT_ST_DRDY or HBIT_ST_DRQ) is set.
190;
191; HStatus_PollBusyAndFlg
192;   Parameters:
193;       AH:     Status Register Flag to poll (until set) when not busy
194;       CL:     Timeout value in system timer ticks
195;       DX:     IDE Status Register Address
196;       DS:     Segment to RAMVARS
197;   Returns:
198;       AH:     BIOS Error code
199;       CF:     Clear if wait completed successfully (no errors)
200;               Set if any error
201;   Corrupts registers:
202;       AL, CX
203;--------------------------------------------------------------------
204ALIGN JUMP_ALIGN
205HStatus_PollBsyAndFlg:
206    call    SoftDelay_InitTimeout       ; Initialize timeout counter
207ALIGN JUMP_ALIGN
208.PollLoop:
209    in      al, dx                      ; Load IDE Status Register
210    test    al, FLG_IDE_ST_BSY          ; Controller busy?
211    jnz     SHORT .UpdateTimeout        ;  If so, jump to timeout update
212    test    al, ah                      ; Test secondary flag
213    jnz     SHORT HStatus_PollCompleted ; If set, break loop
214ALIGN JUMP_ALIGN
215.UpdateTimeout:
216    call    SoftDelay_UpdTimeout        ; Update timeout counter
217    jnc     SHORT .PollLoop             ; Loop if time left (sets CF on timeout)
218    mov     ah, RET_HD_TIMEOUT          ; Load error code for timeout
219    ret
220
221
222;--------------------------------------------------------------------
223; IDE Status register polling.
224; This function waits until controller is not busy.
225;
226; HStatus_PollBsy
227;   Parameters:
228;       CL:     Timeout value in system timer ticks
229;       DX:     IDE Status Register Address
230;       DS:     Segment to RAMVARS
231;   Returns:
232;       AH:     BIOS Error code
233;       CF:     Clear if wait completed successfully (no errors)
234;               Set if any error
235;   Corrupts registers:
236;       AL, CX
237;--------------------------------------------------------------------
238ALIGN JUMP_ALIGN
239HStatus_PollBsy:
240    call    SoftDelay_InitTimeout       ; Initialize timeout counter
241ALIGN JUMP_ALIGN
242.PollLoop:
243    in      al, dx                      ; Load IDE Status Reg
244    test    al, FLG_IDE_ST_BSY          ; Controller busy? (clears CF)
245    jz      SHORT HStatus_PollCompleted ;  If not, jump to check errors
246    call    SoftDelay_UpdTimeout        ; Update timeout counter
247    jnc     SHORT .PollLoop             ; Loop if time left (sets CF on timeout)
248    mov     ah, RET_HD_TIMEOUT          ; Load error code for timeout
249    ret
250
251ALIGN JUMP_ALIGN
252HStatus_PollCompleted:
253    test    al, FLG_IDE_ST_DF | FLG_IDE_ST_ERR
254    jnz     SHORT .GetErrorCode         ;  If errors, jump to get error code
255    xor     ah, ah                      ; Zero AH and clear CF
256    ret
257.GetErrorCode:
258    jmp     HError_GetErrorCodeForStatusReg
Note: See TracBrowser for help on using the repository browser.