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 $
24 * $DragonFly: src/usr.sbin/pcvt/set2061/Attic/compiler.h,v 1.3 2004/12/18 22:48:04 swildner Exp $
43 # define volatile __volatile__
44 # define const __const__
47 # endif /* __GNUC__ */
48 #endif /* !__STDC__ */
54 extern unsigned int inb();
55 extern unsigned int inw();
56 #if NeedFunctionPrototypes
57 extern unsigned char rdinx(unsigned short, unsigned char);
58 extern void wrinx(unsigned short, unsigned char, unsigned char);
59 extern void modinx(unsigned short, unsigned char, unsigned char, unsigned char);
60 extern int testrg(unsigned short, unsigned char);
61 extern int textinx2(unsigned short, unsigned char, unsigned char);
62 extern int textinx(unsigned short, unsigned char);
63 #else /* NeedFunctionProtoypes */
64 extern unsigned char rdinx();
68 extern int textinx2();
70 #endif /* NeedFunctionProtoypes */
80 * If gcc uses gas rather than the native assembler, the syntax of these
81 * inlines has to be different. DHD
84 static __inline__ void
89 __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
93 static __inline__ void
98 __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
101 static __inline__ unsigned int
106 __asm__ __volatile__("inb %1,%0" :
112 static __inline__ unsigned int
117 __asm__ __volatile__("inw %1,%0" :
123 #else /* GCCUSESGAS */
125 static __inline__ void
130 __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
133 static __inline__ void
138 __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
141 static __inline__ unsigned int
146 __asm__ __volatile__("in%B0 (%1)" :
152 static __inline__ unsigned int
157 __asm__ __volatile__("in%W0 (%1)" :
163 #endif /* GCCUSESGAS */
167 static __inline__ void
174 static __inline__ void
181 static __inline__ unsigned int
188 static __inline__ unsigned int
198 #if !defined(AMOEBA) && !defined(_MINIX)
199 # if defined(__STDC__) && (__STDC__ == 1)
203 # include <sys/types.h>
208 # include <sys/inline.h>
213 *-----------------------------------------------------------------------
214 * Port manipulation convenience functions
215 *-----------------------------------------------------------------------
219 #define __inline__ /**/
223 * rdinx - read the indexed byte port 'port', index 'ind', and return its value
225 static __inline__ unsigned char
227 rdinx(unsigned short port, unsigned char ind)
234 if (port == 0x3C0) /* reset attribute flip-flop */
241 * wrinx - write 'val' to port 'port', index 'ind'
243 static __inline__ void
245 wrinx(unsigned short port, unsigned char ind, unsigned char val)
247 wrinx(port, ind, val)
249 unsigned char ind, val;
257 * modinx - in register 'port', index 'ind', set the bits in 'mask' as in 'new';
258 * the other bits are unchanged.
260 static __inline__ void
262 modinx(unsigned short port, unsigned char ind,
263 unsigned char mask, unsigned char new)
265 modinx(port, ind, mask, new)
267 unsigned char ind, mask, new;
272 tmp = (rdinx(port, ind) & ~mask) | (new & mask);
273 wrinx(port, ind, tmp);
277 * tstrg - returns true iff the bits in 'mask' of register 'port' are
278 * readable & writable.
281 static __inline__ int
283 testrg(unsigned short port, unsigned char mask)
290 unsigned char old, new1, new2;
293 outb(port, old & ~mask);
294 new1 = inb(port) & mask;
295 outb(port, old | mask);
296 new2 = inb(port) & mask;
298 return((new1 == 0) && (new2 == mask));
302 * testinx2 - returns true iff the bits in 'mask' of register 'port', index
303 * 'ind' are readable & writable.
305 static __inline__ int
307 testinx2(unsigned short port, unsigned char ind, unsigned char mask)
309 testinx2(port, ind, mask)
311 unsigned char ind, mask;
314 unsigned char old, new1, new2;
316 old = rdinx(port, ind);
317 wrinx(port, ind, old & ~mask);
318 new1 = rdinx(port, ind) & mask;
319 wrinx(port, ind, old | mask);
320 new2 = rdinx(port, ind) & mask;
321 wrinx(port, ind, old);
322 return((new1 == 0) && (new2 == mask));
326 * testinx - returns true iff all bits of register 'port', index 'ind' are
327 * readable & writable.
329 static __inline__ int
331 testinx(unsigned short port, unsigned char ind)
333 testinx(port, ind, mask)
338 return(testinx2(port, ind, 0xFF));
341 #endif /* NO_INLINE */
342 #endif /* _COMPILER_H */