1 /* $XFree86: mit/server/ddx/x386/common/compiler.h,v 2.3 1993/10/03 14:55:28 dawes Exp $ */
3 * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of Thomas Roell not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission. Thomas Roell makes no representations
12 * about the suitability of this software for any purpose. It is provided
13 * "as is" without express or implied warranty.
15 * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
23 * $FreeBSD: src/usr.sbin/pcvt/set2061/compiler.h,v 1.5 1999/08/28 05:11:28 peter Exp $
42 # define volatile __volatile__
43 # define const __const__
46 # endif /* __GNUC__ */
47 #endif /* !__STDC__ */
53 extern unsigned int inb();
54 extern unsigned int inw();
55 #if NeedFunctionPrototypes
56 extern unsigned char rdinx(unsigned short, unsigned char);
57 extern void wrinx(unsigned short, unsigned char, unsigned char);
58 extern void modinx(unsigned short, unsigned char, unsigned char, unsigned char);
59 extern int testrg(unsigned short, unsigned char);
60 extern int textinx2(unsigned short, unsigned char, unsigned char);
61 extern int textinx(unsigned short, unsigned char);
62 #else /* NeedFunctionProtoypes */
63 extern unsigned char rdinx();
67 extern int textinx2();
69 #endif /* NeedFunctionProtoypes */
79 * If gcc uses gas rather than the native assembler, the syntax of these
80 * inlines has to be different. DHD
83 static __inline__ void
88 __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
92 static __inline__ void
97 __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
100 static __inline__ unsigned int
105 __asm__ __volatile__("inb %1,%0" :
111 static __inline__ unsigned int
116 __asm__ __volatile__("inw %1,%0" :
122 #else /* GCCUSESGAS */
124 static __inline__ void
129 __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
132 static __inline__ void
137 __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
140 static __inline__ unsigned int
145 __asm__ __volatile__("in%B0 (%1)" :
151 static __inline__ unsigned int
156 __asm__ __volatile__("in%W0 (%1)" :
162 #endif /* GCCUSESGAS */
166 static __inline__ void
173 static __inline__ void
180 static __inline__ unsigned int
187 static __inline__ unsigned int
197 #if !defined(AMOEBA) && !defined(_MINIX)
198 # if defined(__STDC__) && (__STDC__ == 1)
202 # include <sys/types.h>
207 # include <sys/inline.h>
212 *-----------------------------------------------------------------------
213 * Port manipulation convenience functions
214 *-----------------------------------------------------------------------
218 #define __inline__ /**/
222 * rdinx - read the indexed byte port 'port', index 'ind', and return its value
224 static __inline__ unsigned char
226 rdinx(unsigned short port, unsigned char ind)
233 if (port == 0x3C0) /* reset attribute flip-flop */
240 * wrinx - write 'val' to port 'port', index 'ind'
242 static __inline__ void
244 wrinx(unsigned short port, unsigned char ind, unsigned char val)
246 wrinx(port, ind, val)
248 unsigned char ind, val;
256 * modinx - in register 'port', index 'ind', set the bits in 'mask' as in 'new';
257 * the other bits are unchanged.
259 static __inline__ void
261 modinx(unsigned short port, unsigned char ind,
262 unsigned char mask, unsigned char new)
264 modinx(port, ind, mask, new)
266 unsigned char ind, mask, new;
271 tmp = (rdinx(port, ind) & ~mask) | (new & mask);
272 wrinx(port, ind, tmp);
276 * tstrg - returns true iff the bits in 'mask' of register 'port' are
277 * readable & writable.
280 static __inline__ int
282 testrg(unsigned short port, unsigned char mask)
289 unsigned char old, new1, new2;
292 outb(port, old & ~mask);
293 new1 = inb(port) & mask;
294 outb(port, old | mask);
295 new2 = inb(port) & mask;
297 return((new1 == 0) && (new2 == mask));
301 * testinx2 - returns true iff the bits in 'mask' of register 'port', index
302 * 'ind' are readable & writable.
304 static __inline__ int
306 testinx2(unsigned short port, unsigned char ind, unsigned char mask)
308 testinx2(port, ind, mask)
310 unsigned char ind, mask;
313 unsigned char old, new1, new2;
315 old = rdinx(port, ind);
316 wrinx(port, ind, old & ~mask);
317 new1 = rdinx(port, ind) & mask;
318 wrinx(port, ind, old | mask);
319 new2 = rdinx(port, ind) & mask;
320 wrinx(port, ind, old);
321 return((new1 == 0) && (new2 == mask));
325 * testinx - returns true iff all bits of register 'port', index 'ind' are
326 * readable & writable.
328 static __inline__ int
330 testinx(unsigned short port, unsigned char ind)
332 testinx(port, ind, mask)
337 return(testinx2(port, ind, 0xFF));
340 #endif /* NO_INLINE */
341 #endif /* _COMPILER_H */