3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/hal/x86/portio.c
6 * PURPOSE: Port I/O functions
7 * PROGRAMMER: Eric Kohl (ekohl@abo.rhein-zeitung.de)
16 /* FUNCTIONS ****************************************************************/
19 * This file contains the definitions for the x86 IO instructions
20 * inb/inw/inl/outb/outw/outl and the "string versions" of the same
21 * (insb/insw/insl/outsb/outsw/outsl). You can also use "pausing"
22 * versions of the single-IO instructions (inb_p/inw_p/..).
24 * This file is not meant to be obfuscating: it's just complicated
25 * to (a) handle it all in a way that makes gcc able to optimize it
26 * as well as possible and (b) trying to avoid writing the same thing
27 * over and over again with slight variations and possibly making a
32 * Thanks to James van Artsdalen for a better timing-fix than
33 * the two short jumps: using outb's to a nonexistent port seems
34 * to guarantee better timings even on fast machines.
36 * On the other hand, I'd like to be sure of a non-existent port:
37 * I feel a bit unsafe about using 0x80 (should be safe, though)
42 #ifdef SLOW_IO_BY_JUMPING
43 #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
45 #define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
49 #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
51 #define SLOW_DOWN_IO __SLOW_DOWN_IO
54 #undef READ_PORT_BUFFER_UCHAR
58 READ_PORT_BUFFER_UCHAR (PUCHAR Port
,
62 __asm__
__volatile__ ("cld ; rep ; insb\n\t"
63 : "=D" (Buffer
), "=c" (Count
)
64 : "d" (Port
),"0" (Buffer
),"1" (Count
));
67 #undef READ_PORT_BUFFER_USHORT
71 READ_PORT_BUFFER_USHORT (USHORT
* Port
,
75 __asm__
__volatile__ ("cld ; rep ; insw"
76 : "=D" (Buffer
), "=c" (Count
)
77 : "d" (Port
),"0" (Buffer
),"1" (Count
));
80 #undef READ_PORT_BUFFER_ULONG
84 READ_PORT_BUFFER_ULONG (ULONG
* Port
,
88 __asm__
__volatile__ ("cld ; rep ; insl"
89 : "=D" (Buffer
), "=c" (Count
)
90 : "d" (Port
),"0" (Buffer
),"1" (Count
));
93 #undef READ_PORT_UCHAR
97 READ_PORT_UCHAR (PUCHAR Port
)
101 __asm__("inb %w1, %0\n\t"
108 #undef READ_PORT_USHORT
112 READ_PORT_USHORT (USHORT
* Port
)
116 __asm__("inw %w1, %0\n\t"
123 #undef READ_PORT_ULONG
127 READ_PORT_ULONG (ULONG
* Port
)
131 __asm__("inl %w1, %0\n\t"
138 #undef WRITE_PORT_BUFFER_UCHAR
142 WRITE_PORT_BUFFER_UCHAR (PUCHAR Port
,
146 __asm__
__volatile__ ("cld ; rep ; outsb"
147 : "=S" (Buffer
), "=c" (Count
)
148 : "d" (Port
),"0" (Buffer
),"1" (Count
));
151 #undef WRITE_PORT_BUFFER_USHORT
155 WRITE_PORT_BUFFER_USHORT (USHORT
* Port
,
159 __asm__
__volatile__ ("cld ; rep ; outsw"
160 : "=S" (Buffer
), "=c" (Count
)
161 : "d" (Port
),"0" (Buffer
),"1" (Count
));
164 #undef WRITE_PORT_BUFFER_ULONG
168 WRITE_PORT_BUFFER_ULONG (ULONG
* Port
,
172 __asm__
__volatile__ ("cld ; rep ; outsl"
173 : "=S" (Buffer
), "=c" (Count
)
174 : "d" (Port
),"0" (Buffer
),"1" (Count
));
177 #undef WRITE_PORT_UCHAR
181 WRITE_PORT_UCHAR (PUCHAR Port
,
184 __asm__("outb %0, %w1\n\t"
191 #undef WRITE_PORT_USHORT
195 WRITE_PORT_USHORT (USHORT
* Port
,
198 __asm__("outw %0, %w1\n\t"
205 #undef WRITE_PORT_ULONG
209 WRITE_PORT_ULONG (ULONG
* Port
,
212 __asm__("outl %0, %w1\n\t"