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 | ; Modified by JJP for XT-CFv3 support, Mar-13
|
---|
22 |
|
---|
23 | ; Section containing code
|
---|
24 | SECTION .text
|
---|
25 |
|
---|
26 |
|
---|
27 | ; --------------------------------------------------------------------------------------------------
|
---|
28 | ;
|
---|
29 | ; READ routines follow
|
---|
30 | ;
|
---|
31 | ; --------------------------------------------------------------------------------------------------
|
---|
32 |
|
---|
33 |
|
---|
34 | %ifdef MODULE_8BIT_IDE
|
---|
35 |
|
---|
36 | ;--------------------------------------------------------------------
|
---|
37 | ; IdePioBlock_ReadFromXtideRev1
|
---|
38 | ; Parameters:
|
---|
39 | ; CX: Block size in 512 byte sectors
|
---|
40 | ; DX: IDE Data port address
|
---|
41 | ; ES:DI: Normalized ptr to buffer to receive data
|
---|
42 | ; Returns:
|
---|
43 | ; Nothing
|
---|
44 | ; Corrupts registers:
|
---|
45 | ; AX, BX, CX
|
---|
46 | ;--------------------------------------------------------------------
|
---|
47 | ALIGN JUMP_ALIGN
|
---|
48 | IdePioBlock_ReadFromXtideRev1:
|
---|
49 | UNROLL_SECTORS_IN_CX_TO_OWORDS
|
---|
50 | mov bl, 8 ; Bit mask for toggling data low/high reg
|
---|
51 | ALIGN JUMP_ALIGN
|
---|
52 | .InswLoop:
|
---|
53 | %rep 8 ; WORDs
|
---|
54 | XTIDE_INSW
|
---|
55 | %endrep
|
---|
56 | loop .InswLoop
|
---|
57 | ret
|
---|
58 |
|
---|
59 |
|
---|
60 | ;--------------------------------------------------------------------
|
---|
61 | ; IdePioBlock_ReadFrom8bitDataPort
|
---|
62 | ;
|
---|
63 | ; 8-bit PIO from a single data port.
|
---|
64 | ;
|
---|
65 | ; Parameters:
|
---|
66 | ; CX: Block size in 512 byte sectors
|
---|
67 | ; DX: IDE Data port address
|
---|
68 | ; ES:DI: Normalized ptr to buffer to receive data
|
---|
69 | ; Returns:
|
---|
70 | ; Nothing
|
---|
71 | ; Corrupts registers:
|
---|
72 | ; AX, BX, CX
|
---|
73 | ;--------------------------------------------------------------------
|
---|
74 | ALIGN JUMP_ALIGN
|
---|
75 | IdePioBlock_ReadFrom8bitDataPort:
|
---|
76 | %ifdef USE_186
|
---|
77 | shl cx, 9 ; Sectors to BYTEs
|
---|
78 | rep insb
|
---|
79 | ret
|
---|
80 | %else ; If 8088/8086
|
---|
81 | UNROLL_SECTORS_IN_CX_TO_OWORDS
|
---|
82 | ALIGN JUMP_ALIGN
|
---|
83 | .ReadNextOword:
|
---|
84 | %rep 16 ; BYTEs
|
---|
85 | in al, dx ; Read BYTE
|
---|
86 | stosb ; Store BYTE to [ES:DI]
|
---|
87 | %endrep
|
---|
88 | loop .ReadNextOword
|
---|
89 | ret
|
---|
90 | %endif
|
---|
91 |
|
---|
92 | %endif ; MODULE_8BIT_IDE
|
---|
93 |
|
---|
94 |
|
---|
95 | ;--------------------------------------------------------------------
|
---|
96 | ; IdePioBlock_ReadFrom16bitDataPort
|
---|
97 | ;
|
---|
98 | ; 16-bit PIO from a single data port.
|
---|
99 | ;
|
---|
100 | ; Parameters:
|
---|
101 | ; CX: Block size in 512 byte sectors
|
---|
102 | ; DX: IDE Data port address
|
---|
103 | ; ES:DI: Normalized ptr to buffer to receive data
|
---|
104 | ; Returns:
|
---|
105 | ; Nothing
|
---|
106 | ; Corrupts registers:
|
---|
107 | ; AX, BX, CX
|
---|
108 | ;--------------------------------------------------------------------
|
---|
109 | ALIGN JUMP_ALIGN
|
---|
110 | IdePioBlock_ReadFrom16bitDataPort:
|
---|
111 | %ifdef USE_186
|
---|
112 | xchg cl, ch ; Sectors to WORDs
|
---|
113 | rep insw
|
---|
114 | ret
|
---|
115 |
|
---|
116 | %else ; If 8088/8086
|
---|
117 | UNROLL_SECTORS_IN_CX_TO_OWORDS
|
---|
118 | ALIGN JUMP_ALIGN
|
---|
119 | .ReadNextOword:
|
---|
120 | %rep 8 ; WORDs
|
---|
121 | in ax, dx ; Read WORD
|
---|
122 | stosw ; Store WORD to [ES:DI]
|
---|
123 | %endrep
|
---|
124 | loop .ReadNextOword
|
---|
125 | ret
|
---|
126 | %endif
|
---|
127 |
|
---|
128 |
|
---|
129 | ;--------------------------------------------------------------------
|
---|
130 | ALIGN JUMP_ALIGN
|
---|
131 | IdePioBlock_ReadFrom32bitDataPort:
|
---|
132 | db 0C1h ; SHL
|
---|
133 | db 0E1h ; CX
|
---|
134 | db 7 ; 7 (Sectors to DWORDs)
|
---|
135 | rep
|
---|
136 | db 66h ; Override operand size to 32-bit
|
---|
137 | db 6Dh ; INSW/INSD
|
---|
138 | ret
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 | ; --------------------------------------------------------------------------------------------------
|
---|
143 | ;
|
---|
144 | ; WRITE routines follow
|
---|
145 | ;
|
---|
146 | ; --------------------------------------------------------------------------------------------------
|
---|
147 |
|
---|
148 | %ifdef MODULE_8BIT_IDE
|
---|
149 |
|
---|
150 | ;--------------------------------------------------------------------
|
---|
151 | ; IdePioBlock_WriteToXtideRev1
|
---|
152 | ; Parameters:
|
---|
153 | ; CX: Block size in 512-byte sectors
|
---|
154 | ; DX: IDE Data port address
|
---|
155 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
156 | ; Returns:
|
---|
157 | ; Nothing
|
---|
158 | ; Corrupts registers:
|
---|
159 | ; AX, BX, CX, DX
|
---|
160 | ;--------------------------------------------------------------------
|
---|
161 | ALIGN JUMP_ALIGN
|
---|
162 | IdePioBlock_WriteToXtideRev1:
|
---|
163 | push ds
|
---|
164 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
165 | mov bl, 8 ; Bit mask for toggling data low/high reg
|
---|
166 | push es ; Copy ES...
|
---|
167 | pop ds ; ...to DS
|
---|
168 | ALIGN JUMP_ALIGN
|
---|
169 | .OutswLoop:
|
---|
170 | %rep 4 ; WORDs
|
---|
171 | XTIDE_OUTSW
|
---|
172 | %endrep
|
---|
173 | loop .OutswLoop
|
---|
174 | pop ds
|
---|
175 | ret
|
---|
176 |
|
---|
177 |
|
---|
178 | ;--------------------------------------------------------------------
|
---|
179 | ; IdePioBlock_WriteToXtideRev2 or rev 1 with swapped A0 and A3 (chuck-mod)
|
---|
180 | ; Parameters:
|
---|
181 | ; CX: Block size in 512-byte sectors
|
---|
182 | ; DX: IDE Data port address
|
---|
183 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
184 | ; Returns:
|
---|
185 | ; Nothing
|
---|
186 | ; Corrupts registers:
|
---|
187 | ; AX, BX, CX, DX
|
---|
188 | ;--------------------------------------------------------------------
|
---|
189 | ALIGN JUMP_ALIGN
|
---|
190 | IdePioBlock_WriteToXtideRev2:
|
---|
191 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
192 | push ds
|
---|
193 | push es ; Copy ES...
|
---|
194 | pop ds ; ...to DS
|
---|
195 | ALIGN JUMP_ALIGN
|
---|
196 | .WriteNextQword:
|
---|
197 | %rep 4 ; WORDs
|
---|
198 | XTIDE_MOD_OUTSW ; special macro
|
---|
199 | %endrep
|
---|
200 | loop .WriteNextQword
|
---|
201 | pop ds
|
---|
202 | ret
|
---|
203 |
|
---|
204 |
|
---|
205 | ;--------------------------------------------------------------------
|
---|
206 | ; IdePioBlock_WriteTo8bitDataPort
|
---|
207 | ; Parameters:
|
---|
208 | ; CX: Block size in 512-byte sectors
|
---|
209 | ; DX: IDE Data port address
|
---|
210 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
211 | ; Returns:
|
---|
212 | ; Nothing
|
---|
213 | ; Corrupts registers:
|
---|
214 | ; AX, BX, CX, DX
|
---|
215 | ;--------------------------------------------------------------------
|
---|
216 | ALIGN JUMP_ALIGN
|
---|
217 | IdePioBlock_WriteTo8bitDataPort:
|
---|
218 | %ifdef USE_186
|
---|
219 | shl cx, 9 ; Sectors to BYTEs
|
---|
220 | es ; Source is ES segment
|
---|
221 | rep outsb
|
---|
222 | ret
|
---|
223 |
|
---|
224 | %else ; If 8088/8086
|
---|
225 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
226 | push ds
|
---|
227 | ;mov ax, es
|
---|
228 | ;mov ds, ax ; move es to ds via ax (does this run faster on 8088?)
|
---|
229 | push es
|
---|
230 | pop ds
|
---|
231 | ALIGN JUMP_ALIGN
|
---|
232 | .WriteNextQword:
|
---|
233 | %rep 8 ; BYTEs
|
---|
234 | lodsb ; Load BYTE from [DS:SI]
|
---|
235 | out dx, al ; Write BYTE
|
---|
236 | %endrep
|
---|
237 | loop .WriteNextQword
|
---|
238 | pop ds
|
---|
239 | ret
|
---|
240 | %endif
|
---|
241 |
|
---|
242 | %endif ; MODULE_8BIT_IDE
|
---|
243 |
|
---|
244 |
|
---|
245 | ;--------------------------------------------------------------------
|
---|
246 | ; IdePioBlock_WriteTo16bitDataPort Normal 16-bit IDE, XT-CFv3 in BIU Mode
|
---|
247 | ; IdePioBlock_WriteTo32bitDataPort VLB/PCI 32-bit IDE
|
---|
248 | ; Parameters:
|
---|
249 | ; CX: Block size in 512-byte sectors
|
---|
250 | ; DX: IDE Data port address
|
---|
251 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
252 | ; Returns:
|
---|
253 | ; Nothing
|
---|
254 | ; Corrupts registers:
|
---|
255 | ; AX, BX, CX, DX
|
---|
256 | ;--------------------------------------------------------------------
|
---|
257 | ALIGN JUMP_ALIGN
|
---|
258 | IdePioBlock_WriteTo16bitDataPort:
|
---|
259 | %ifdef USE_186
|
---|
260 | xchg cl, ch ; Sectors to WORDs
|
---|
261 | es ; Source is ES segment
|
---|
262 | rep outsw
|
---|
263 | ret
|
---|
264 |
|
---|
265 | %else ; If 8088/8086
|
---|
266 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
267 | push ds
|
---|
268 | ;mov ax, es
|
---|
269 | ;mov ds, ax ; move es to ds via ax (does this run faster on 8088?)
|
---|
270 | push es
|
---|
271 | pop ds
|
---|
272 | ALIGN JUMP_ALIGN
|
---|
273 | .WriteNextQword:
|
---|
274 | %rep 4 ; WORDs
|
---|
275 | lodsw ; Load WORD from [DS:SI]
|
---|
276 | out dx, ax ; Write WORD
|
---|
277 | %endrep
|
---|
278 | loop .WriteNextQword
|
---|
279 | pop ds
|
---|
280 | ret
|
---|
281 | %endif ; if/else USE_186
|
---|
282 |
|
---|
283 | ;--------------------------------------------------------------------
|
---|
284 | ALIGN JUMP_ALIGN
|
---|
285 | IdePioBlock_WriteTo32bitDataPort:
|
---|
286 | db 0C1h ; SHL
|
---|
287 | db 0E1h ; CX
|
---|
288 | db 7 ; 7 (Sectors to DWORDs)
|
---|
289 | es ; Source is ES segment
|
---|
290 | rep
|
---|
291 | db 66h ; Override operand size to 32-bit
|
---|
292 | db 6Fh ; OUTSW/OUTSD
|
---|
293 | ret
|
---|