1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : IDE Device wait 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
|
---|
21 | SECTION .text
|
---|
22 |
|
---|
23 | ;--------------------------------------------------------------------
|
---|
24 | ; IdeWait_IRQorDRQ
|
---|
25 | ; Parameters:
|
---|
26 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
27 | ; SS:BP: Ptr to IDEPACK, PIOVARS or MEMPIOVARS
|
---|
28 | ; Returns:
|
---|
29 | ; AH: INT 13h Error Code
|
---|
30 | ; CF: Cleared if success, Set if error
|
---|
31 | ; Corrupts registers:
|
---|
32 | ; AL, BX, CX, DX
|
---|
33 | ;--------------------------------------------------------------------
|
---|
34 | IdeWait_IRQorDRQ:
|
---|
35 | mov bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
|
---|
36 |
|
---|
37 | %ifdef MODULE_IRQ
|
---|
38 | test BYTE [bp+IDEPACK.bDeviceControl], FLG_DEVCONTROL_nIEN
|
---|
39 | jnz SHORT IdeWait_PollStatusFlagInBLwithTimeoutInBH ; Interrupt disabled
|
---|
40 | %endif
|
---|
41 | ; Fall to IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
|
---|
42 |
|
---|
43 |
|
---|
44 | ;--------------------------------------------------------------------
|
---|
45 | ; IdeWait_IRQorStatusFlagInBLwithTimeoutInBH
|
---|
46 | ; Parameters:
|
---|
47 | ; BH: Timeout ticks
|
---|
48 | ; BL: IDE Status Register bit to wait
|
---|
49 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
50 | ; Returns:
|
---|
51 | ; AH: INT 13h Error Code
|
---|
52 | ; CF: Cleared if success, Set if error
|
---|
53 | ; Corrupts registers:
|
---|
54 | ; AL, BX, CX, DX
|
---|
55 | ;--------------------------------------------------------------------
|
---|
56 | IdeWait_IRQorStatusFlagInBLwithTimeoutInBH:
|
---|
57 | %ifdef MODULE_IRQ
|
---|
58 | call IdeIrq_WaitForIRQ
|
---|
59 | %endif
|
---|
60 | ; Always fall to IdeWait_PollStatusFlagInBLwithTimeoutInBH for error processing
|
---|
61 |
|
---|
62 |
|
---|
63 | ;--------------------------------------------------------------------
|
---|
64 | ; IdeWait_PollStatusFlagInBLwithTimeoutInBH
|
---|
65 | ; Parameters:
|
---|
66 | ; BH: Timeout ticks
|
---|
67 | ; BL: IDE Status Register bit to poll
|
---|
68 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
69 | ; Returns:
|
---|
70 | ; AH: INT 13h Error Code
|
---|
71 | ; CF: Cleared if success, Set if error
|
---|
72 | ; Corrupts registers:
|
---|
73 | ; AL, BX, CX, DX
|
---|
74 | ;--------------------------------------------------------------------
|
---|
75 | IdeWait_PollStatusFlagInBLwithTimeoutInBH:
|
---|
76 | mov ah, bl
|
---|
77 | mov cl, bh
|
---|
78 | call Timer_InitializeTimeoutWithTicksInCL
|
---|
79 | and ah, ~FLG_STATUS_BSY
|
---|
80 | jz SHORT PollBsyOnly
|
---|
81 | ; Fall to PollBsyAndFlgInAH
|
---|
82 |
|
---|
83 | ;--------------------------------------------------------------------
|
---|
84 | ; PollBsyAndFlgInAH
|
---|
85 | ; Parameters:
|
---|
86 | ; AH: Status Register Flag to poll (until set) when device not busy
|
---|
87 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
88 | ; Returns:
|
---|
89 | ; AH: BIOS Error code
|
---|
90 | ; CF: Clear if wait completed successfully (no errors)
|
---|
91 | ; Set if any error
|
---|
92 | ; Corrupts registers:
|
---|
93 | ; AL, BX, CX, DX
|
---|
94 | ;--------------------------------------------------------------------
|
---|
95 | PollBsyAndFlgInAH:
|
---|
96 | call IdeIO_InputStatusRegisterToAL ; Discard contents of first read
|
---|
97 |
|
---|
98 | .PollLoop:
|
---|
99 | call IdeIO_InputStatusRegisterToAL
|
---|
100 | test al, FLG_STATUS_BSY ; Controller busy?
|
---|
101 | jnz SHORT .UpdateTimeout ; If so, jump to timeout update
|
---|
102 | test al, ah ; Test secondary flag
|
---|
103 | jnz SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
104 | .UpdateTimeout:
|
---|
105 | call Timer_SetCFifTimeout
|
---|
106 | jnc SHORT .PollLoop ; Loop if time left
|
---|
107 | call IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
108 | jc SHORT .ReturnErrorCodeInAH
|
---|
109 | mov ah, RET_HD_TIMEOUT ; Expected bit never got set
|
---|
110 | stc
|
---|
111 | .ReturnErrorCodeInAH:
|
---|
112 | ret
|
---|
113 |
|
---|
114 |
|
---|
115 | ;--------------------------------------------------------------------
|
---|
116 | ; PollBsyOnly
|
---|
117 | ; Parameters:
|
---|
118 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
119 | ; Returns:
|
---|
120 | ; AH: BIOS Error code
|
---|
121 | ; CF: Clear if wait completed successfully (no errors)
|
---|
122 | ; Set if any error
|
---|
123 | ; Corrupts registers:
|
---|
124 | ; AL, BX, CX, DX
|
---|
125 | ;--------------------------------------------------------------------
|
---|
126 | PollBsyOnly:
|
---|
127 | call IdeIO_InputStatusRegisterToAL ; Discard contents of first read
|
---|
128 |
|
---|
129 | .PollLoop:
|
---|
130 | call IdeIO_InputStatusRegisterToAL
|
---|
131 | test al, FLG_STATUS_BSY ; Controller busy?
|
---|
132 | jz SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|
133 | call Timer_SetCFifTimeout ; Update timeout counter
|
---|
134 | jnc SHORT .PollLoop ; Loop if time left (sets CF on timeout)
|
---|
135 | jmp SHORT IdeError_GetBiosErrorCodeToAHfromPolledStatusRegisterInAL
|
---|