source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm@ 629

Last change on this file since 629 was 623, checked in by Krister Nordvall, 2 years ago

Changes:

  • Reversed the change to IdeDPT.asm in r622 as it didn't work as intended.
  • Reordered some procedures to reduce alignment padding.
  • Added two new defines (EXTRA_LOOP_UNROLLING_SMALL and EXTRA_LOOP_UNROLLING_LARGE) that should improve transfer speeds for some hardware combinations, specifically 808x CPUs with any IDE controller using port I/O and any CPU with XT-IDE controllers.
  • Added a new define (USE_086) for use with 8086 and V30 CPUs only. Unlike the other USE_x86 defines, this define will not change the instruction set used and is therefore compatible with all CPUs. However, it will apply padding to make jump destinations WORD aligned which should improve performance on 8086/V30 CPUs but on 8088/V20 CPUs there is no benefit and, in addition to wasting ROM space, it might in fact be slower on these machines. Since the vast majority of XT class machines are using 8088/V20 CPUs this define is not used in the official XT builds - it's primarily intended for custom BIOS builds.
  • XTIDECFG: The URL to the support forum has been updated.
File size: 11.2 KB
Line 
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
22SECTION .text
23
24
25; --------------------------------------------------------------------------------------------------
26;
27; READ routines follow
28;
29; --------------------------------------------------------------------------------------------------
30
31%ifdef MODULE_8BIT_IDE
32;--------------------------------------------------------------------
33; IdePioBlock_ReadFromXtideRev1
34; Parameters:
35; CX: Block size in 512 byte sectors
36; DX: IDE Data port address
37; ES:DI: Normalized ptr to buffer to receive data
38; Returns:
39; Nothing
40; Corrupts registers:
41; AX, BX, CX
42;--------------------------------------------------------------------
43ALIGN JUMP_ALIGN
44IdePioBlock_ReadFromXtideRev1:
45%ifdef EXTRA_LOOP_UNROLLING_LARGE
46 UNROLL_SECTORS_IN_CX_TO_32WORDS
47%elifdef EXTRA_LOOP_UNROLLING_SMALL
48 UNROLL_SECTORS_IN_CX_TO_16WORDS
49%else
50 UNROLL_SECTORS_IN_CX_TO_OWORDS
51%endif
52 mov bl, 8 ; Bit mask for toggling data low/high reg
53ALIGN JUMP_ALIGN
54.NextIteration:
55%ifdef EXTRA_LOOP_UNROLLING_LARGE
56 %rep 32 ; WORDs
57 XTIDE_INSW
58 %endrep
59 dec cx
60%ifdef USE_386
61 jnz .NextIteration
62%else
63 jz SHORT .BlockTransferred
64 jmp .NextIteration
65
66ALIGN JUMP_ALIGN
67.BlockTransferred:
68%endif
69%elifdef EXTRA_LOOP_UNROLLING_SMALL
70 %rep 16 ; WORDs
71 XTIDE_INSW
72 %endrep
73%ifdef USE_186
74 loop .NextIteration
75%else
76 dec cx
77 jz SHORT .BlockTransferred
78 jmp .NextIteration
79
80ALIGN JUMP_ALIGN
81.BlockTransferred:
82%endif
83%else
84 %rep 8 ; WORDs
85 XTIDE_INSW
86 %endrep
87 loop .NextIteration
88%endif
89 ret
90
91
92;--------------------------------------------------------------------
93; IdePioBlock_ReadFromXtideRev2_Olivetti
94; Parameters:
95; CX: Block size in 512 byte sectors
96; DX: IDE Data port address
97; ES:DI: Normalized ptr to buffer to receive data
98; Returns:
99; Nothing
100; Corrupts registers:
101; AX, CX
102;--------------------------------------------------------------------
103ALIGN JUMP_ALIGN
104IdePioBlock_ReadFromXtideRev2_Olivetti:
105%ifdef EXTRA_LOOP_UNROLLING_LARGE
106 UNROLL_SECTORS_IN_CX_TO_32WORDS
107%elifdef EXTRA_LOOP_UNROLLING_SMALL
108 UNROLL_SECTORS_IN_CX_TO_16WORDS
109%else
110 UNROLL_SECTORS_IN_CX_TO_OWORDS
111%endif
112ALIGN JUMP_ALIGN
113.NextIteration:
114%ifdef EXTRA_LOOP_UNROLLING_LARGE
115 %rep 32 ; WORDs
116 XTIDE_MOD_OLIVETTI_INSW
117 %endrep
118 dec cx
119%ifdef USE_386
120 jnz .NextIteration
121%else
122 jz SHORT .BlockTransferred
123 jmp .NextIteration
124
125ALIGN JUMP_ALIGN
126.BlockTransferred:
127%endif
128%elifdef EXTRA_LOOP_UNROLLING_SMALL
129 %rep 16 ; WORDs
130 XTIDE_MOD_OLIVETTI_INSW
131 %endrep
132 loop .NextIteration
133%else
134 %rep 8 ; WORDs
135 XTIDE_MOD_OLIVETTI_INSW
136 %endrep
137 loop .NextIteration
138%endif
139 ret
140
141
142;--------------------------------------------------------------------
143; 8-bit PIO from a single data port.
144;
145; IdePioBlock_ReadFrom8bitDataPort
146; Parameters:
147; CX: Block size in 512 byte sectors
148; DX: IDE Data port address
149; ES:DI: Normalized ptr to buffer to receive data
150; Returns:
151; Nothing
152; Corrupts registers:
153; AX, CX
154;--------------------------------------------------------------------
155ALIGN JUMP_ALIGN
156IdePioBlock_ReadFrom8bitDataPort:
157%ifdef USE_186
158 shl cx, 9 ; Sectors to BYTEs
159 rep insb
160 ret
161
162%else ; 808x
163%ifdef EXTRA_LOOP_UNROLLING_LARGE
164 UNROLL_SECTORS_IN_CX_TO_32WORDS
165%elifdef EXTRA_LOOP_UNROLLING_SMALL
166 UNROLL_SECTORS_IN_CX_TO_16WORDS
167%else
168 UNROLL_SECTORS_IN_CX_TO_OWORDS
169%endif
170ALIGN JUMP_ALIGN
171.NextIteration:
172%ifdef EXTRA_LOOP_UNROLLING_LARGE
173 %rep 64 ; BYTEs
174 in al, dx ; Read BYTE
175 stosb ; Store BYTE to [ES:DI]
176 %endrep
177 dec cx
178 jz SHORT .BlockTransferred
179 jmp .NextIteration
180
181ALIGN JUMP_ALIGN
182.BlockTransferred:
183%elifdef EXTRA_LOOP_UNROLLING_SMALL
184 %rep 32 ; BYTEs
185 in al, dx ; Read BYTE
186 stosb ; Store BYTE to [ES:DI]
187 %endrep
188 loop .NextIteration
189%else
190 %rep 16 ; BYTEs
191 in al, dx ; Read BYTE
192 stosb ; Store BYTE to [ES:DI]
193 %endrep
194 loop .NextIteration
195%endif
196 ret
197%endif
198%endif ; MODULE_8BIT_IDE
199
200
201;--------------------------------------------------------------------
202; 16-bit and 32-bit PIO from a single data port.
203;
204; IdePioBlock_ReadFrom16bitDataPort
205; IdePioBlock_ReadFrom32bitDataPort
206; Parameters:
207; CX: Block size in 512 byte sectors
208; DX: IDE Data port address
209; ES:DI: Normalized ptr to buffer to receive data
210; Returns:
211; Nothing
212; Corrupts registers:
213; AX, CX
214;--------------------------------------------------------------------
215ALIGN JUMP_ALIGN
216IdePioBlock_ReadFrom16bitDataPort:
217%ifdef USE_186
218 xchg cl, ch ; Sectors to WORDs
219 rep insw
220 ret
221
222%else ; 808x
223%ifdef EXTRA_LOOP_UNROLLING_LARGE
224 UNROLL_SECTORS_IN_CX_TO_32WORDS
225%elifdef EXTRA_LOOP_UNROLLING_SMALL
226 UNROLL_SECTORS_IN_CX_TO_16WORDS
227%else
228 UNROLL_SECTORS_IN_CX_TO_OWORDS
229%endif
230ALIGN JUMP_ALIGN
231.NextIteration:
232%ifdef EXTRA_LOOP_UNROLLING_LARGE
233 %rep 32 ; WORDs
234 in ax, dx ; Read WORD
235 stosw ; Store WORD to [ES:DI]
236 %endrep
237%elifdef EXTRA_LOOP_UNROLLING_SMALL
238 %rep 16 ; WORDs
239 in ax, dx ; Read WORD
240 stosw ; Store WORD to [ES:DI]
241 %endrep
242%else
243 %rep 8 ; WORDs
244 in ax, dx ; Read WORD
245 stosw ; Store WORD to [ES:DI]
246 %endrep
247%endif
248 loop .NextIteration
249 ret
250%endif
251
252
253;--------------------------------------------------------------------
254%ifdef MODULE_ADVANCED_ATA
255ALIGN JUMP_ALIGN
256IdePioBlock_ReadFrom32bitDataPort:
257 shl cx, 7 ; Sectors to DWORDs
258 rep insd
259 ret
260%endif ; MODULE_ADVANCED_ATA
261
262
263; --------------------------------------------------------------------------------------------------
264;
265; WRITE routines follow
266;
267; --------------------------------------------------------------------------------------------------
268
269%ifdef MODULE_8BIT_IDE
270;--------------------------------------------------------------------
271; IdePioBlock_WriteToXtideRev1
272; Parameters:
273; CX: Block size in 512-byte sectors
274; DX: IDE Data port address
275; DS:SI: Normalized ptr to buffer containing data
276; Returns:
277; Nothing
278; Corrupts registers:
279; AX, BX, CX
280;--------------------------------------------------------------------
281ALIGN JUMP_ALIGN
282IdePioBlock_WriteToXtideRev1:
283%ifdef EXTRA_LOOP_UNROLLING_LARGE
284 UNROLL_SECTORS_IN_CX_TO_16WORDS
285%elifdef EXTRA_LOOP_UNROLLING_SMALL
286 UNROLL_SECTORS_IN_CX_TO_OWORDS
287%else
288 UNROLL_SECTORS_IN_CX_TO_QWORDS
289%endif
290 mov bl, 8 ; Bit mask for toggling data low/high reg
291ALIGN JUMP_ALIGN
292.NextIteration:
293%ifdef EXTRA_LOOP_UNROLLING_LARGE
294 %rep 16 ; WORDs
295 XTIDE_OUTSW
296 %endrep
297%ifdef USE_186
298 loop .NextIteration
299%else
300 dec cx
301 jz SHORT .BlockTransferred
302 jmp .NextIteration
303
304ALIGN JUMP_ALIGN
305.BlockTransferred:
306%endif
307%elifdef EXTRA_LOOP_UNROLLING_SMALL
308 %rep 8 ; WORDs
309 XTIDE_OUTSW
310 %endrep
311 loop .NextIteration
312%else
313 %rep 4 ; WORDs
314 XTIDE_OUTSW
315 %endrep
316 loop .NextIteration
317%endif
318 ret
319
320
321;--------------------------------------------------------------------
322; IdePioBlock_WriteToXtideRev2 or rev 1 with swapped A0 and A3 (chuck-mod)
323; Parameters:
324; CX: Block size in 512-byte sectors
325; DX: IDE Data port address
326; DS:SI: Normalized ptr to buffer containing data
327; Returns:
328; Nothing
329; Corrupts registers:
330; AX, CX
331;--------------------------------------------------------------------
332ALIGN JUMP_ALIGN
333IdePioBlock_WriteToXtideRev2:
334%ifdef EXTRA_LOOP_UNROLLING_LARGE
335 UNROLL_SECTORS_IN_CX_TO_16WORDS
336%elifdef EXTRA_LOOP_UNROLLING_SMALL
337 UNROLL_SECTORS_IN_CX_TO_OWORDS
338%else
339 UNROLL_SECTORS_IN_CX_TO_QWORDS
340%endif
341ALIGN JUMP_ALIGN
342.NextIteration:
343%ifdef EXTRA_LOOP_UNROLLING_LARGE
344 %rep 16 ; WORDs
345 XTIDE_MOD_OUTSW
346 %endrep
347%ifdef USE_186
348 loop .NextIteration
349%else
350 dec cx
351 jz SHORT .BlockTransferred
352 jmp .NextIteration
353
354ALIGN JUMP_ALIGN
355.BlockTransferred:
356%endif
357%elifdef EXTRA_LOOP_UNROLLING_SMALL
358 %rep 8 ; WORDs
359 XTIDE_MOD_OUTSW
360 %endrep
361 loop .NextIteration
362%else
363 %rep 4 ; WORDs
364 XTIDE_MOD_OUTSW
365 %endrep
366 loop .NextIteration
367%endif
368 ret
369
370
371;--------------------------------------------------------------------
372; IdePioBlock_WriteTo8bitDataPort
373; Parameters:
374; CX: Block size in 512-byte sectors
375; DX: IDE Data port address
376; DS:SI: Normalized ptr to buffer containing data
377; Returns:
378; Nothing
379; Corrupts registers:
380; AX, CX
381;--------------------------------------------------------------------
382ALIGN JUMP_ALIGN
383IdePioBlock_WriteTo8bitDataPort:
384%ifdef USE_186
385 shl cx, 9 ; Sectors to BYTEs
386 rep outsb
387 ret
388
389%else ; 808x
390%ifdef EXTRA_LOOP_UNROLLING_LARGE
391 UNROLL_SECTORS_IN_CX_TO_16WORDS
392%elifdef EXTRA_LOOP_UNROLLING_SMALL
393 UNROLL_SECTORS_IN_CX_TO_OWORDS
394%else
395 UNROLL_SECTORS_IN_CX_TO_QWORDS
396%endif
397ALIGN JUMP_ALIGN
398.NextIteration:
399%ifdef EXTRA_LOOP_UNROLLING_LARGE
400 %rep 32 ; BYTEs
401 lodsb ; Load BYTE from [DS:SI]
402 out dx, al ; Write BYTE
403 %endrep
404%elifdef EXTRA_LOOP_UNROLLING_SMALL
405 %rep 16 ; BYTEs
406 lodsb ; Load BYTE from [DS:SI]
407 out dx, al ; Write BYTE
408 %endrep
409%else
410 %rep 8 ; BYTEs
411 lodsb ; Load BYTE from [DS:SI]
412 out dx, al ; Write BYTE
413 %endrep
414%endif
415 loop .NextIteration
416 ret
417%endif
418%endif ; MODULE_8BIT_IDE
419
420
421;--------------------------------------------------------------------
422; IdePioBlock_WriteTo16bitDataPort Normal 16-bit IDE, XT-CFv3 in BIU Mode
423; IdePioBlock_WriteTo32bitDataPort VLB/PCI 32-bit IDE
424; Parameters:
425; CX: Block size in 512-byte sectors
426; DX: IDE Data port address
427; DS:SI: Normalized ptr to buffer containing data
428; Returns:
429; Nothing
430; Corrupts registers:
431; AX, CX
432;--------------------------------------------------------------------
433ALIGN JUMP_ALIGN
434IdePioBlock_WriteTo16bitDataPort:
435%ifdef USE_186
436 xchg cl, ch ; Sectors to WORDs
437 rep outsw
438 ret
439
440%else ; 808x
441%ifdef EXTRA_LOOP_UNROLLING_LARGE
442 UNROLL_SECTORS_IN_CX_TO_16WORDS
443%elifdef EXTRA_LOOP_UNROLLING_SMALL
444 UNROLL_SECTORS_IN_CX_TO_OWORDS
445%else
446 UNROLL_SECTORS_IN_CX_TO_QWORDS
447%endif
448ALIGN JUMP_ALIGN
449.NextIteration:
450%ifdef EXTRA_LOOP_UNROLLING_LARGE
451 %rep 16 ; WORDs
452 lodsw ; Load WORD from [DS:SI]
453 out dx, ax ; Write WORD
454 %endrep
455%elifdef EXTRA_LOOP_UNROLLING_SMALL
456 %rep 8 ; WORDs
457 lodsw ; Load WORD from [DS:SI]
458 out dx, ax ; Write WORD
459 %endrep
460%else
461 %rep 4 ; WORDs
462 lodsw ; Load WORD from [DS:SI]
463 out dx, ax ; Write WORD
464 %endrep
465%endif
466 loop .NextIteration
467 ret
468%endif
469
470;--------------------------------------------------------------------
471%ifdef MODULE_ADVANCED_ATA
472ALIGN JUMP_ALIGN
473IdePioBlock_WriteTo32bitDataPort:
474 shl cx, 7 ; Sectors to DWORDs
475 rep outsd
476 ret
477%endif ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.