1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : IDE Read/Write functions for transferring block using PIO modes.
|
---|
3 | ; These functions should only be called from IdeTransfer.asm.
|
---|
4 |
|
---|
5 | ;
|
---|
6 | ; XTIDE Universal BIOS and Associated Tools
|
---|
7 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
8 | ;
|
---|
9 | ; This program is free software; you can redistribute it and/or modify
|
---|
10 | ; it under the terms of the GNU General Public License as published by
|
---|
11 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
12 | ; (at your option) any later version.
|
---|
13 | ;
|
---|
14 | ; This program is distributed in the hope that it will be useful,
|
---|
15 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | ; GNU General Public License for more details.
|
---|
18 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
19 | ;
|
---|
20 |
|
---|
21 | ; Section containing code
|
---|
22 | SECTION .text
|
---|
23 |
|
---|
24 |
|
---|
25 | ; --------------------------------------------------------------------------------------------------
|
---|
26 | ;
|
---|
27 | ; READ routines follow
|
---|
28 | ;
|
---|
29 | ; --------------------------------------------------------------------------------------------------
|
---|
30 |
|
---|
31 |
|
---|
32 | %ifdef MODULE_8BIT_IDE
|
---|
33 |
|
---|
34 | ;--------------------------------------------------------------------
|
---|
35 | ; IdePioBlock_ReadFromXtideRev1
|
---|
36 | ; Parameters:
|
---|
37 | ; CX: Block size in 512 byte sectors
|
---|
38 | ; DX: IDE Data port address
|
---|
39 | ; ES:DI: Normalized ptr to buffer to receive data
|
---|
40 | ; Returns:
|
---|
41 | ; Nothing
|
---|
42 | ; Corrupts registers:
|
---|
43 | ; AX, BX, CX
|
---|
44 | ;--------------------------------------------------------------------
|
---|
45 | ALIGN JUMP_ALIGN
|
---|
46 | IdePioBlock_ReadFromXtideRev1:
|
---|
47 | UNROLL_SECTORS_IN_CX_TO_OWORDS
|
---|
48 | mov bl, 8 ; Bit mask for toggling data low/high reg
|
---|
49 | ALIGN JUMP_ALIGN
|
---|
50 | .InswLoop:
|
---|
51 | %rep 8 ; WORDs
|
---|
52 | XTIDE_INSW
|
---|
53 | %endrep
|
---|
54 | loop .InswLoop
|
---|
55 | ret
|
---|
56 |
|
---|
57 |
|
---|
58 | ;--------------------------------------------------------------------
|
---|
59 | ; IdePioBlock_ReadFrom8bitDataPort
|
---|
60 | ;
|
---|
61 | ; 8-bit PIO from a single data port.
|
---|
62 | ;
|
---|
63 | ; Parameters:
|
---|
64 | ; CX: Block size in 512 byte sectors
|
---|
65 | ; DX: IDE Data port address
|
---|
66 | ; ES:DI: Normalized ptr to buffer to receive data
|
---|
67 | ; Returns:
|
---|
68 | ; Nothing
|
---|
69 | ; Corrupts registers:
|
---|
70 | ; AX, BX, CX
|
---|
71 | ;--------------------------------------------------------------------
|
---|
72 | ALIGN JUMP_ALIGN
|
---|
73 | IdePioBlock_ReadFrom8bitDataPort:
|
---|
74 | %ifdef USE_186
|
---|
75 | shl cx, 9 ; Sectors to BYTEs
|
---|
76 | rep insb
|
---|
77 | ret
|
---|
78 | %else ; 808x
|
---|
79 | UNROLL_SECTORS_IN_CX_TO_OWORDS
|
---|
80 | ALIGN JUMP_ALIGN
|
---|
81 | .ReadNextOword:
|
---|
82 | %rep 16 ; BYTEs
|
---|
83 | in al, dx ; Read BYTE
|
---|
84 | stosb ; Store BYTE to [ES:DI]
|
---|
85 | %endrep
|
---|
86 | loop .ReadNextOword
|
---|
87 | ret
|
---|
88 | %endif
|
---|
89 |
|
---|
90 | %endif ; MODULE_8BIT_IDE
|
---|
91 |
|
---|
92 |
|
---|
93 | ;--------------------------------------------------------------------
|
---|
94 | ; IdePioBlock_ReadFrom16bitDataPort
|
---|
95 | ;
|
---|
96 | ; 16-bit PIO from a single data port.
|
---|
97 | ;
|
---|
98 | ; Parameters:
|
---|
99 | ; CX: Block size in 512 byte sectors
|
---|
100 | ; DX: IDE Data port address
|
---|
101 | ; ES:DI: Normalized ptr to buffer to receive data
|
---|
102 | ; Returns:
|
---|
103 | ; Nothing
|
---|
104 | ; Corrupts registers:
|
---|
105 | ; AX, BX, CX
|
---|
106 | ;--------------------------------------------------------------------
|
---|
107 | ALIGN JUMP_ALIGN
|
---|
108 | IdePioBlock_ReadFrom16bitDataPort:
|
---|
109 | %ifdef USE_186
|
---|
110 | xchg cl, ch ; Sectors to WORDs
|
---|
111 | rep insw
|
---|
112 | ret
|
---|
113 |
|
---|
114 | %else ; 808x
|
---|
115 | UNROLL_SECTORS_IN_CX_TO_OWORDS
|
---|
116 | ALIGN JUMP_ALIGN
|
---|
117 | .ReadNextOword:
|
---|
118 | %rep 8 ; WORDs
|
---|
119 | in ax, dx ; Read WORD
|
---|
120 | stosw ; Store WORD to [ES:DI]
|
---|
121 | %endrep
|
---|
122 | loop .ReadNextOword
|
---|
123 | ret
|
---|
124 | %endif
|
---|
125 |
|
---|
126 |
|
---|
127 | ;--------------------------------------------------------------------
|
---|
128 | ALIGN JUMP_ALIGN
|
---|
129 | IdePioBlock_ReadFrom32bitDataPort:
|
---|
130 | db 0C1h ; SHL
|
---|
131 | db 0E1h ; CX
|
---|
132 | db 7 ; 7 (Sectors to DWORDs)
|
---|
133 | rep
|
---|
134 | db 66h ; Override operand size to 32-bit
|
---|
135 | db 6Dh ; INSW/INSD
|
---|
136 | ret
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 | ; --------------------------------------------------------------------------------------------------
|
---|
141 | ;
|
---|
142 | ; WRITE routines follow
|
---|
143 | ;
|
---|
144 | ; --------------------------------------------------------------------------------------------------
|
---|
145 |
|
---|
146 | %ifdef MODULE_8BIT_IDE
|
---|
147 |
|
---|
148 | ;--------------------------------------------------------------------
|
---|
149 | ; IdePioBlock_WriteToXtideRev1
|
---|
150 | ; Parameters:
|
---|
151 | ; CX: Block size in 512-byte sectors
|
---|
152 | ; DX: IDE Data port address
|
---|
153 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
154 | ; Returns:
|
---|
155 | ; Nothing
|
---|
156 | ; Corrupts registers:
|
---|
157 | ; AX, BX, CX
|
---|
158 | ;--------------------------------------------------------------------
|
---|
159 | ALIGN JUMP_ALIGN
|
---|
160 | IdePioBlock_WriteToXtideRev1:
|
---|
161 | push ds
|
---|
162 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
163 | mov bl, 8 ; Bit mask for toggling data low/high reg
|
---|
164 | push es
|
---|
165 | pop ds
|
---|
166 | ALIGN JUMP_ALIGN
|
---|
167 | .OutswLoop:
|
---|
168 | %rep 4 ; WORDs
|
---|
169 | XTIDE_OUTSW
|
---|
170 | %endrep
|
---|
171 | loop .OutswLoop
|
---|
172 | pop ds
|
---|
173 | ret
|
---|
174 |
|
---|
175 |
|
---|
176 | ;--------------------------------------------------------------------
|
---|
177 | ; IdePioBlock_WriteToXtideRev2 or rev 1 with swapped A0 and A3 (chuck-mod)
|
---|
178 | ; Parameters:
|
---|
179 | ; CX: Block size in 512-byte sectors
|
---|
180 | ; DX: IDE Data port address
|
---|
181 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
182 | ; Returns:
|
---|
183 | ; Nothing
|
---|
184 | ; Corrupts registers:
|
---|
185 | ; AX, BX, CX
|
---|
186 | ;--------------------------------------------------------------------
|
---|
187 | ALIGN JUMP_ALIGN
|
---|
188 | IdePioBlock_WriteToXtideRev2:
|
---|
189 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
190 | push ds
|
---|
191 | push es
|
---|
192 | pop ds
|
---|
193 | ALIGN JUMP_ALIGN
|
---|
194 | .WriteNextQword:
|
---|
195 | %rep 4 ; WORDs
|
---|
196 | XTIDE_MOD_OUTSW
|
---|
197 | %endrep
|
---|
198 | loop .WriteNextQword
|
---|
199 | pop ds
|
---|
200 | ret
|
---|
201 |
|
---|
202 |
|
---|
203 | ;--------------------------------------------------------------------
|
---|
204 | ; IdePioBlock_WriteTo8bitDataPort
|
---|
205 | ; Parameters:
|
---|
206 | ; CX: Block size in 512-byte sectors
|
---|
207 | ; DX: IDE Data port address
|
---|
208 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
209 | ; Returns:
|
---|
210 | ; Nothing
|
---|
211 | ; Corrupts registers:
|
---|
212 | ; AX, BX, CX
|
---|
213 | ;--------------------------------------------------------------------
|
---|
214 | ALIGN JUMP_ALIGN
|
---|
215 | IdePioBlock_WriteTo8bitDataPort:
|
---|
216 | %ifdef USE_186
|
---|
217 | shl cx, 9 ; Sectors to BYTEs
|
---|
218 | es ; Source is ES segment
|
---|
219 | rep outsb
|
---|
220 | ret
|
---|
221 |
|
---|
222 | %else ; 808x
|
---|
223 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
224 | push ds
|
---|
225 | push es
|
---|
226 | pop ds
|
---|
227 | ALIGN JUMP_ALIGN
|
---|
228 | .WriteNextQword:
|
---|
229 | %rep 8 ; BYTEs
|
---|
230 | lodsb ; Load BYTE from [DS:SI]
|
---|
231 | out dx, al ; Write BYTE
|
---|
232 | %endrep
|
---|
233 | loop .WriteNextQword
|
---|
234 | pop ds
|
---|
235 | ret
|
---|
236 | %endif
|
---|
237 |
|
---|
238 | %endif ; MODULE_8BIT_IDE
|
---|
239 |
|
---|
240 |
|
---|
241 | ;--------------------------------------------------------------------
|
---|
242 | ; IdePioBlock_WriteTo16bitDataPort Normal 16-bit IDE, XT-CFv3 in BIU Mode
|
---|
243 | ; IdePioBlock_WriteTo32bitDataPort VLB/PCI 32-bit IDE
|
---|
244 | ; Parameters:
|
---|
245 | ; CX: Block size in 512-byte sectors
|
---|
246 | ; DX: IDE Data port address
|
---|
247 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
248 | ; Returns:
|
---|
249 | ; Nothing
|
---|
250 | ; Corrupts registers:
|
---|
251 | ; AX, BX, CX
|
---|
252 | ;--------------------------------------------------------------------
|
---|
253 | ALIGN JUMP_ALIGN
|
---|
254 | IdePioBlock_WriteTo16bitDataPort:
|
---|
255 | %ifdef USE_186
|
---|
256 | xchg cl, ch ; Sectors to WORDs
|
---|
257 | es ; Source is ES segment
|
---|
258 | rep outsw
|
---|
259 | ret
|
---|
260 |
|
---|
261 | %else ; 808x
|
---|
262 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
263 | push ds
|
---|
264 | push es
|
---|
265 | pop ds
|
---|
266 | ALIGN JUMP_ALIGN
|
---|
267 | .WriteNextQword:
|
---|
268 | %rep 4 ; WORDs
|
---|
269 | lodsw ; Load WORD from [DS:SI]
|
---|
270 | out dx, ax ; Write WORD
|
---|
271 | %endrep
|
---|
272 | loop .WriteNextQword
|
---|
273 | pop ds
|
---|
274 | ret
|
---|
275 | %endif
|
---|
276 |
|
---|
277 | ;--------------------------------------------------------------------
|
---|
278 | ALIGN JUMP_ALIGN
|
---|
279 | IdePioBlock_WriteTo32bitDataPort:
|
---|
280 | db 0C1h ; SHL
|
---|
281 | db 0E1h ; CX
|
---|
282 | db 7 ; 7 (Sectors to DWORDs)
|
---|
283 | es ; Source is ES segment
|
---|
284 | rep
|
---|
285 | db 66h ; Override operand size to 32-bit
|
---|
286 | db 6Fh ; OUTSW/OUTSD
|
---|
287 | ret
|
---|