1 /* $Id: portio.c,v 1.1 2001/11/28 10:26:52 bpalmer Exp $
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)
12 //#include <ddk/ntddk.h>
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
55 READ_PORT_BUFFER_UCHAR (PUCHAR Port
,
59 __asm__
__volatile__ ("cld ; rep ; insb\n\t"
60 : "=D" (Buffer
), "=c" (Count
)
61 : "d" (Port
),"0" (Buffer
),"1" (Count
));
65 READ_PORT_BUFFER_USHORT (PUSHORT Port
,
69 __asm__
__volatile__ ("cld ; rep ; insw"
70 : "=D" (Buffer
), "=c" (Count
)
71 : "d" (Port
),"0" (Buffer
),"1" (Count
));
75 READ_PORT_BUFFER_ULONG (PULONG Port
,
79 __asm__
__volatile__ ("cld ; rep ; insl"
80 : "=D" (Buffer
), "=c" (Count
)
81 : "d" (Port
),"0" (Buffer
),"1" (Count
));
85 READ_PORT_UCHAR (PUCHAR Port
)
89 __asm__("inb %w1, %0\n\t"
97 READ_PORT_USHORT (PUSHORT Port
)
101 __asm__("inw %w1, %0\n\t"
109 READ_PORT_ULONG (PULONG Port
)
113 __asm__("inl %w1, %0\n\t"
121 WRITE_PORT_BUFFER_UCHAR (PUCHAR Port
,
125 __asm__
__volatile__ ("cld ; rep ; outsb"
126 : "=S" (Buffer
), "=c" (Count
)
127 : "d" (Port
),"0" (Buffer
),"1" (Count
));
131 WRITE_PORT_BUFFER_USHORT (PUSHORT Port
,
135 __asm__
__volatile__ ("cld ; rep ; outsw"
136 : "=S" (Buffer
), "=c" (Count
)
137 : "d" (Port
),"0" (Buffer
),"1" (Count
));
141 WRITE_PORT_BUFFER_ULONG (PULONG Port
,
145 __asm__
__volatile__ ("cld ; rep ; outsl"
146 : "=S" (Buffer
), "=c" (Count
)
147 : "d" (Port
),"0" (Buffer
),"1" (Count
));
151 WRITE_PORT_UCHAR (PUCHAR Port
,
154 __asm__("outb %0, %w1\n\t"
162 WRITE_PORT_USHORT (PUSHORT Port
,
165 __asm__("outw %0, %w1\n\t"
173 WRITE_PORT_ULONG (PULONG Port
,
176 __asm__("outl %0, %w1\n\t"