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

Last change on this file since 114 was 88, checked in by Tomi Tilli, 14 years ago

Changes to XTIDE Universal BIOS:

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