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