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

Last change on this file since 625 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
RevLine 
[473]1; Project name : XTIDE Universal BIOS
[558]2; Description : IDE Read/Write functions for transferring block using PIO modes.
[473]3; These functions should only be called from IdeTransfer.asm.
4
5;
6; XTIDE Universal BIOS and Associated Tools
[526]7; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[473]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
[545]24
25; --------------------------------------------------------------------------------------------------
26;
27; READ routines follow
28;
29; --------------------------------------------------------------------------------------------------
30
[473]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:
[623]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
[473]50 UNROLL_SECTORS_IN_CX_TO_OWORDS
[623]51%endif
[473]52 mov bl, 8 ; Bit mask for toggling data low/high reg
53ALIGN JUMP_ALIGN
[623]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
[580]84 %rep 8 ; WORDs
[473]85 XTIDE_INSW
86 %endrep
[623]87 loop .NextIteration
88%endif
[473]89 ret
90
91
92;--------------------------------------------------------------------
[601]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:
[623]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
[601]110 UNROLL_SECTORS_IN_CX_TO_OWORDS
[623]111%endif
[601]112ALIGN JUMP_ALIGN
[623]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
[601]134 %rep 8 ; WORDs
135 XTIDE_MOD_OLIVETTI_INSW
136 %endrep
[623]137 loop .NextIteration
138%endif
[601]139 ret
140
141
142;--------------------------------------------------------------------
[545]143; 8-bit PIO from a single data port.
144;
[589]145; IdePioBlock_ReadFrom8bitDataPort
[473]146; Parameters:
[558]147; CX: Block size in 512 byte sectors
148; DX: IDE Data port address
[473]149; ES:DI: Normalized ptr to buffer to receive data
150; Returns:
151; Nothing
152; Corrupts registers:
[589]153; AX, CX
[473]154;--------------------------------------------------------------------
155ALIGN JUMP_ALIGN
[545]156IdePioBlock_ReadFrom8bitDataPort:
157%ifdef USE_186
158 shl cx, 9 ; Sectors to BYTEs
159 rep insb
160 ret
[623]161
[580]162%else ; 808x
[623]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
[473]168 UNROLL_SECTORS_IN_CX_TO_OWORDS
[623]169%endif
[473]170ALIGN JUMP_ALIGN
[623]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
[545]190 %rep 16 ; BYTEs
191 in al, dx ; Read BYTE
192 stosb ; Store BYTE to [ES:DI]
[473]193 %endrep
[623]194 loop .NextIteration
195%endif
[545]196 ret
[473]197%endif
[589]198%endif ; MODULE_8BIT_IDE
[473]199
200
201;--------------------------------------------------------------------
[589]202; 16-bit and 32-bit PIO from a single data port.
203;
[545]204; IdePioBlock_ReadFrom16bitDataPort
[589]205; IdePioBlock_ReadFrom32bitDataPort
[473]206; Parameters:
[558]207; CX: Block size in 512 byte sectors
208; DX: IDE Data port address
[473]209; ES:DI: Normalized ptr to buffer to receive data
210; Returns:
211; Nothing
212; Corrupts registers:
[589]213; AX, CX
[473]214;--------------------------------------------------------------------
215ALIGN JUMP_ALIGN
[545]216IdePioBlock_ReadFrom16bitDataPort:
[473]217%ifdef USE_186
[589]218 xchg cl, ch ; Sectors to WORDs
[545]219 rep insw
[473]220 ret
221
[580]222%else ; 808x
[623]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
[473]228 UNROLL_SECTORS_IN_CX_TO_OWORDS
[623]229%endif
[473]230ALIGN JUMP_ALIGN
[623]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
[545]243 %rep 8 ; WORDs
[558]244 in ax, dx ; Read WORD
245 stosw ; Store WORD to [ES:DI]
[473]246 %endrep
[623]247%endif
248 loop .NextIteration
[473]249 ret
250%endif
251
252
253;--------------------------------------------------------------------
[589]254%ifdef MODULE_ADVANCED_ATA
[545]255ALIGN JUMP_ALIGN
256IdePioBlock_ReadFrom32bitDataPort:
[589]257 shl cx, 7 ; Sectors to DWORDs
258 rep insd
[545]259 ret
[589]260%endif ; MODULE_ADVANCED_ATA
[545]261
262
263; --------------------------------------------------------------------------------------------------
264;
265; WRITE routines follow
266;
267; --------------------------------------------------------------------------------------------------
268
269%ifdef MODULE_8BIT_IDE
270;--------------------------------------------------------------------
[473]271; IdePioBlock_WriteToXtideRev1
272; Parameters:
[558]273; CX: Block size in 512-byte sectors
274; DX: IDE Data port address
[589]275; DS:SI: Normalized ptr to buffer containing data
[473]276; Returns:
277; Nothing
278; Corrupts registers:
[580]279; AX, BX, CX
[473]280;--------------------------------------------------------------------
281ALIGN JUMP_ALIGN
282IdePioBlock_WriteToXtideRev1:
[623]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
[473]288 UNROLL_SECTORS_IN_CX_TO_QWORDS
[623]289%endif
[473]290 mov bl, 8 ; Bit mask for toggling data low/high reg
291ALIGN JUMP_ALIGN
[623]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
[473]313 %rep 4 ; WORDs
314 XTIDE_OUTSW
315 %endrep
[623]316 loop .NextIteration
317%endif
[473]318 ret
319
320
321;--------------------------------------------------------------------
322; IdePioBlock_WriteToXtideRev2 or rev 1 with swapped A0 and A3 (chuck-mod)
323; Parameters:
[558]324; CX: Block size in 512-byte sectors
325; DX: IDE Data port address
[589]326; DS:SI: Normalized ptr to buffer containing data
[473]327; Returns:
328; Nothing
329; Corrupts registers:
[589]330; AX, CX
[473]331;--------------------------------------------------------------------
332ALIGN JUMP_ALIGN
333IdePioBlock_WriteToXtideRev2:
[623]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
[473]339 UNROLL_SECTORS_IN_CX_TO_QWORDS
[623]340%endif
[473]341ALIGN JUMP_ALIGN
[623]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
[473]363 %rep 4 ; WORDs
[580]364 XTIDE_MOD_OUTSW
[473]365 %endrep
[623]366 loop .NextIteration
367%endif
[473]368 ret
369
370
371;--------------------------------------------------------------------
[545]372; IdePioBlock_WriteTo8bitDataPort
[473]373; Parameters:
[558]374; CX: Block size in 512-byte sectors
375; DX: IDE Data port address
[589]376; DS:SI: Normalized ptr to buffer containing data
[473]377; Returns:
378; Nothing
379; Corrupts registers:
[589]380; AX, CX
[473]381;--------------------------------------------------------------------
382ALIGN JUMP_ALIGN
383IdePioBlock_WriteTo8bitDataPort:
384%ifdef USE_186
385 shl cx, 9 ; Sectors to BYTEs
386 rep outsb
387 ret
388
[580]389%else ; 808x
[623]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
[545]395 UNROLL_SECTORS_IN_CX_TO_QWORDS
[623]396%endif
[473]397ALIGN JUMP_ALIGN
[623]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
[545]410 %rep 8 ; BYTEs
411 lodsb ; Load BYTE from [DS:SI]
[580]412 out dx, al ; Write BYTE
[473]413 %endrep
[623]414%endif
415 loop .NextIteration
[473]416 ret
417%endif
418%endif ; MODULE_8BIT_IDE
419
420
421;--------------------------------------------------------------------
[545]422; IdePioBlock_WriteTo16bitDataPort Normal 16-bit IDE, XT-CFv3 in BIU Mode
[473]423; IdePioBlock_WriteTo32bitDataPort VLB/PCI 32-bit IDE
424; Parameters:
[558]425; CX: Block size in 512-byte sectors
426; DX: IDE Data port address
[589]427; DS:SI: Normalized ptr to buffer containing data
[473]428; Returns:
429; Nothing
430; Corrupts registers:
[589]431; AX, CX
[473]432;--------------------------------------------------------------------
433ALIGN JUMP_ALIGN
434IdePioBlock_WriteTo16bitDataPort:
[545]435%ifdef USE_186
[473]436 xchg cl, ch ; Sectors to WORDs
[545]437 rep outsw
[473]438 ret
439
[580]440%else ; 808x
[623]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
[545]446 UNROLL_SECTORS_IN_CX_TO_QWORDS
[623]447%endif
[545]448ALIGN JUMP_ALIGN
[623]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
[545]461 %rep 4 ; WORDs
[558]462 lodsw ; Load WORD from [DS:SI]
[580]463 out dx, ax ; Write WORD
[545]464 %endrep
[623]465%endif
466 loop .NextIteration
[545]467 ret
[580]468%endif
[545]469
[473]470;--------------------------------------------------------------------
[589]471%ifdef MODULE_ADVANCED_ATA
[473]472ALIGN JUMP_ALIGN
473IdePioBlock_WriteTo32bitDataPort:
[589]474 shl cx, 7 ; Sectors to DWORDs
475 rep outsd
[473]476 ret
[589]477%endif ; MODULE_ADVANCED_ATA
Note: See TracBrowser for help on using the repository browser.