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

Last change on this file since 7 was 3, checked in by Tomi Tilli, 15 years ago
File size: 5.7 KB
RevLine 
[3]1; File name : IDE_8bit.inc
2; Project name : IDE BIOS
3; Created date : 4.4.2010
4; Last update : 13.4.2010
5; Author : Tomi Tilli
6; Description : Macros for accessing data port(s) on 8-bit
7; IDE controllers.
8%ifndef IDE_8BIT_INC
9%define IDE_8BIT_INC
10
11;--------------------------------------------------------------------
12; Emulates REP INSW for XTIDE dual (8-bit) data port.
13;
14; eREP_DUAL_BYTE_PORT_INSW
15; Parameters:
16; CX: Loop count
17; DX: Port address (must be IDE Data Register)
18; ES:DI: Ptr to destination buffer
19; Returns:
20; CX: Zero
21; DI: Incremented/decremented
22; Corrupts registers:
23; AX, FLAGS
24;--------------------------------------------------------------------
25%macro eREP_DUAL_BYTE_PORT_INSW 0
26 push bx
27 times 2 shr cx, 1 ; Loop unrolling
28 mov bx, 8 ; Bit mask for toggling data low/high reg
29ALIGN JUMP_ALIGN
30%%InswLoop:
31 eDUAL_BYTE_PORT_INSW
32 eDUAL_BYTE_PORT_INSW
33 eDUAL_BYTE_PORT_INSW
34 eDUAL_BYTE_PORT_INSW
35 loop %%InswLoop
36 pop bx
37%endmacro
38
39;--------------------------------------------------------------------
40; Emulates INSW for XTIDE dual (8-bit) data port.
41;
42; eDUAL_BYTE_PORT_INSW
43; Parameters:
44; BX: Bit mask for toggling XTIDE data low/high reg
45; DX: Port address (must be IDE Data Register)
46; ES:DI: Ptr to destination buffer
47; Returns:
48; ES:DI: Incremented/decremented for next word
49; Corrupts registers:
50; AL, FLAGS
51;--------------------------------------------------------------------
52%macro eDUAL_BYTE_PORT_INSW 0
53%ifdef USE_186 ; INS instruction available
54 insb ; Load low byte from port DX to [ES:DI]
55 xor dx, bx ; IDE Data Reg to XTIDE Data High Reg
56 insb ; Load high byte from port DX to [ES:DI]
57 xor dx, bx ; Restore to IDE Data Register
58%else ; If 8088/8086
59 in al, dx ; Load low byte from port
60 xor dx, bx ; IDE Data Reg to XTIDE Data High Reg
61 stosb ; Store byte to [ES:DI]
62 in al, dx ; Load high byte from port
63 xor dx, bx ; Restore to IDE Data Register
64 stosb ; Store byte to [ES:DI]
65%endif
66%endmacro
67
68
69;--------------------------------------------------------------------
70; Emulates REP OUTSW for XTIDE dual (8-bit) data port.
71;
72; eREP_DUAL_BYTE_PORT_OUTSW
73; Parameters:
74; CX: Loop count
75; DX: Port address (must be IDE Data Register)
76; ES:SI: Ptr to source buffer
77; Returns:
78; SI: Incremented/decremented
79; Corrupts registers:
80; AX, CX
81;--------------------------------------------------------------------
82%macro eREP_DUAL_BYTE_PORT_OUTSW 0
83 push ds
84 push bx
85 times 2 shr cx, 1 ; Loop unrolling
86 mov bx, 8 ; Bit mask for toggling data low/high reg
87 push es ; Copy ES...
88 pop ds ; ...to DS
89ALIGN JUMP_ALIGN
90%%OutswLoop:
91 eDUAL_BYTE_PORT_OUTSW
92 eDUAL_BYTE_PORT_OUTSW
93 eDUAL_BYTE_PORT_OUTSW
94 eDUAL_BYTE_PORT_OUTSW
95 loop %%OutswLoop
96 pop bx
97 pop ds
98%endmacro
99
100;--------------------------------------------------------------------
101; Emulates OUTSW for XTIDE dual (8-bit) data port.
102;
103; eDUAL_BYTE_PORT_OUTSW
104; Parameters:
105; BX: Bit mask for toggling XTIDE data low/high reg
106; DX: Port address (must be IDE Data Register)
107; DS:SI: Ptr to source buffer
108; Returns:
109; SI: Incremented/decremented for next word
110; Corrupts registers:
111; AX, FLAGS
112;--------------------------------------------------------------------
113%macro eDUAL_BYTE_PORT_OUTSW 0
114%ifdef USE_186 ; OUTS instruction available
115 lodsb ; Load low byte from [DS:SI] to AL
116 xor dx, bx ; IDE Data Reg to XTIDE Data High Reg
117 outsb ; Output high byte from [DS:SI]
118 xor dx, bx ; IDE Data Reg to XTIDE Data Low Reg
119 out dx, al ; Output low byte from AL
120%else ; If 8088/8086
121 lodsw ; Load word from [DS:SI]
122 xor dx, bx ; IDE Data Reg to XTIDE Data High Reg
123 xchg al, ah ; => AL=high byte, AH=low byte
124 out dx, al ; Output high byte
125 xor dx, bx ; XTIDE Data High Reg to IDE Data Reg
126 mov al, ah ; Copy low byte to AL
127 out dx, al ; Output low byte
128%endif
129%endmacro
130
131
132;--------------------------------------------------------------------
133; Emulates REP INSW for IDE controllers with single 8-bit Data Port.
134;
135; eREP_SINGLE_BYTE_PORT_INSW
136; Parameters:
137; CX: Number of WORDs to transfer
138; DX: IDE Data Port address
139; ES:DI: Ptr to destination buffer
140; Returns:
141; DI: Incremented/decremented
142; Corrupts registers:
143; AL, CX
144;--------------------------------------------------------------------
145%macro eREP_SINGLE_BYTE_PORT_INSW 0
146%ifdef USE_186 ; INS instruction available
147 shl cx, 1 ; WORD count to BYTE count
148 rep insb
149%else ; If 8088/8086
150 shr cx, 1 ; WORD count to DWORD count
151ALIGN JUMP_ALIGN
152%%InsdLoop:
153 in al, dx
154 stosb ; Store to [ES:DI]
155 in al, dx
156 stosb
157 in al, dx
158 stosb
159 in al, dx
160 stosb
161 loop %%InsdLoop
162%endif
163%endmacro
164
165
166;--------------------------------------------------------------------
167; Emulates REP OUTSW for IDE controllers with single 8-bit Data Port.
168;
169; eREP_SINGLE_BYTE_PORT_OUTSW
170; Parameters:
171; CX: Number of WORDs to transfer
172; DX: IDE Data Port address
173; ES:SI: Ptr to source buffer
174; Returns:
175; SI: Incremented/decremented
176; Corrupts registers:
177; AL, CX
178;--------------------------------------------------------------------
179%macro eREP_SINGLE_BYTE_PORT_OUTSW 0
180%ifdef USE_186 ; OUTS instruction available
181 shl cx, 1 ; WORD count to BYTE count
182 eSEG es ; Source is ES segment
183 rep outsb
184%else ; If 8088/8086
185 shr cx, 1 ; WORD count to DWORD count
186 push ds ; Store DS
187 push es ; Copy ES...
188 pop ds ; ...to DS
189ALIGN JUMP_ALIGN
190%%OutsdLoop:
191 lodsb ; Load from [DS:SI] to AL
192 out dx, al
193 lodsb
194 out dx, al
195 lodsb
196 out dx, al
197 lodsb
198 out dx, al
199 loop %%OutsdLoop
200 pop ds ; Restore DS
201%endif
202%endmacro
203
204
205%endif ; IDE_8BIT_INC
Note: See TracBrowser for help on using the repository browser.