source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc@ 460

Last change on this file since 460 was 445, checked in by krille_n_@…, 12 years ago

Changes:

  • A speed optimization to the eSHL_IM macro for 386 and higher. This change breaks emulation in the sense that the macro will fail when given a memory operand as the first parameter.
  • Memory_SumCXbytesFromESSItoAL now returns with the zero flag set/cleared according to the result.
  • Unrolled all the 8 bit READ transfer loops to do 16 bytes per iteration. Added a new macro (UNROLL_SECTORS_IN_CX_TO_OWORDS) as part of it. Size wise this is expensive but I think it should be worth the ROM space. The WRITE transfer loops were left as is since writes are rare anyway (<10% of all disk I/O IIRC).
  • Minor optimizations and fixes here and there.
File size: 4.8 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : Macros for accessing data port(s) on 8-bit
3; IDE controllers.
4
5;
6; XTIDE Universal BIOS and Associated Tools
7; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 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%ifndef IDE_8BIT_INC
22%define IDE_8BIT_INC
23
24;--------------------------------------------------------------------
25; UNROLL_SECTORS_IN_CX_TO_DWORDS
26; UNROLL_SECTORS_IN_CX_TO_QWORDS
27; UNROLL_SECTORS_IN_CX_TO_OWORDS
28; Parameters:
29; CX: Number of sectors in block
30; Returns:
31; CX: Number of DWORDs, QWORDs or OWORDs in block
32; Corrupts registers:
33; Nothing
34;--------------------------------------------------------------------
35%macro UNROLL_SECTORS_IN_CX_TO_DWORDS 0
36%ifdef USE_186
37 shl cx, 7
38%else
39 xchg cl, ch ; Sectors to WORDs (SHL CX, 8)
40 shr cx, 1
41%endif
42%endmacro
43
44%macro UNROLL_SECTORS_IN_CX_TO_QWORDS 0
45%ifdef USE_186
46 shl cx, 6
47%else
48 UNROLL_SECTORS_IN_CX_TO_DWORDS
49 shr cx, 1
50%endif
51%endmacro
52
53%macro UNROLL_SECTORS_IN_CX_TO_OWORDS 0
54%ifdef USE_186
55 shl cx, 5
56%else
57 UNROLL_SECTORS_IN_CX_TO_QWORDS
58 shr cx, 1
59%endif
60%endmacro
61
62
63;--------------------------------------------------------------------
64; Emulates INSW for XTIDE.
65;
66; XTIDE_INSW
67; Parameters:
68; BL: Bit mask for toggling XTIDE data low/high reg
69; DX: XTIDE Data Low Register address
70; ES:DI: Ptr to destination buffer
71; Returns:
72; ES:DI: Incremented/decremented for next word
73; Corrupts registers:
74; AL, FLAGS
75;--------------------------------------------------------------------
76%macro XTIDE_INSW 0
77%ifdef USE_186 ; INS instruction available
78 insb ; Load low byte from port DX to [ES:DI]
79 xor dl, bl ; IDE Data Reg to XTIDE Data High Reg
80 insb ; Load high byte from port DX to [ES:DI]
81 xor dl, bl ; Restore to IDE Data Register
82%else ; If 8088/8086
83 in al, dx ; Load low byte from port
84 xor dl, bl ; IDE Data Reg to XTIDE Data High Reg
85 stosb ; Store byte to [ES:DI]
86 in al, dx ; Load high byte from port
87 xor dl, bl ; Restore to IDE Data Register
88 stosb ; Store byte to [ES:DI]
89%endif
90%endmacro
91
92
93;--------------------------------------------------------------------
94; Emulates OUTSW for XTIDE.
95;
96; XTIDE_OUTSW
97; Parameters:
98; BL: Bit mask for toggling XTIDE data low/high reg
99; DX: XTIDE Data Low Register address
100; DS:SI: Ptr to source buffer
101; Returns:
102; SI: Incremented/decremented for next word
103; Corrupts registers:
104; AX, FLAGS
105;--------------------------------------------------------------------
106%macro XTIDE_OUTSW 0
107%ifdef USE_186 ; OUTS instruction available
108 lodsb ; Load low byte from [DS:SI] to AL
109 xor dl, bl ; IDE Data Reg to XTIDE Data High Reg
110 outsb ; Output high byte from [DS:SI]
111 xor dl, bl ; XTIDE Data High Reg to Data Low Reg
112 out dx, al ; Output low byte from AL
113%else ; If 8088/8086
114 lodsw ; Load word from [DS:SI]
115 xor dl, bl ; IDE Data Reg to XTIDE Data High Reg
116 xchg al, ah ; => AL=high byte, AH=low byte
117 out dx, al ; Output high byte
118 xor dl, bl ; XTIDE Data High Reg to Data Low Reg
119 mov al, ah ; Copy low byte to AL
120 out dx, al ; Output low byte
121%endif
122%endmacro
123
124
125;--------------------------------------------------------------------
126; Emulates OUTSW for modified XTIDE.
127;
128; XTIDE_MOD_OUTSW
129; Parameters:
130; DX: XTIDE Data Low Register address
131; DS:SI: Ptr to source buffer
132; Returns:
133; SI: Incremented/decremented for next word
134; Corrupts registers:
135; AX, FLAGS
136;--------------------------------------------------------------------
137%macro XTIDE_MOD_OUTSW 0
138%ifdef USE_186 ; OUTS instruction available
139 lodsb ; Load low byte from [DS:SI] to AL
140 inc dx ; IDE Data Reg to XTIDE MOD Data High Reg
141 outsb ; Output high byte from [DS:SI]
142 dec dx ; XTIDE Data High Reg to Data Low Reg
143 out dx, al ; Output low byte from AL
144%else ; If 8088/8086
145 lodsw ; Load word from [DS:SI]
146 inc dx ; IDE Data Reg to XTIDE MOD Data High Reg
147 xchg al, ah ; => AL=high byte, AH=low byte
148 out dx, al ; Output high byte
149 dec dx ; XTIDE Data High Reg to Data Low Reg
150 mov al, ah ; Copy low byte to AL
151 out dx, al ; Output low byte
152%endif
153%endmacro
154
155
156%endif ; IDE_8BIT_INC
Note: See TracBrowser for help on using the repository browser.