Clean (void) casts from usr.sbin
[dragonfly.git] / usr.sbin / pcvt / set2061 / compiler.h
1 /* $XFree86: mit/server/ddx/x386/common/compiler.h,v 2.3 1993/10/03 14:55:28 dawes Exp $ */
2 /*
3  * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
4  *
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.
14  *
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.
22  *
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 $
25  */
26
27
28 #ifndef _COMPILER_H
29 #define _COMPILER_H
30
31 #ifndef __STDC__
32 # ifdef signed
33 #  undef signed
34 # endif
35 # ifdef volatile
36 #  undef volatile
37 # endif
38 # ifdef const
39 #  undef const
40 # endif
41 # define signed /**/
42 # ifdef __GNUC__
43 #  define volatile __volatile__
44 #  define const __const__
45 # else
46 #  define const /**/
47 # endif /* __GNUC__ */
48 #endif /* !__STDC__ */
49
50 #ifdef NO_INLINE
51
52 extern void outb();
53 extern void outw();
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();
65 extern void wrinx();
66 extern void modinx();
67 extern int testrg();
68 extern int textinx2();
69 extern int textinx();
70 #endif /* NeedFunctionProtoypes */
71
72 #else /* NO_INLINE */
73
74 #ifdef __GNUC__
75
76 #ifndef FAKEIT
77 #ifdef GCCUSESGAS
78
79 /*
80  * If gcc uses gas rather than the native assembler, the syntax of these
81  * inlines has to be different.         DHD
82  */
83
84 static __inline__ void
85 outb(port, val)
86 short port;
87 char val;
88 {
89    __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
90 }
91
92
93 static __inline__ void
94 outw(port, val)
95 short port;
96 short val;
97 {
98    __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
99 }
100
101 static __inline__ unsigned int
102 inb(port)
103 short port;
104 {
105    unsigned char ret;
106    __asm__ __volatile__("inb %1,%0" :
107        "=a" (ret) :
108        "d" (port));
109    return ret;
110 }
111
112 static __inline__ unsigned int
113 inw(port)
114 short port;
115 {
116    unsigned short ret;
117    __asm__ __volatile__("inw %1,%0" :
118        "=a" (ret) :
119        "d" (port));
120    return ret;
121 }
122
123 #else   /* GCCUSESGAS */
124
125 static __inline__ void
126 outb(port, val)
127      short port;
128      char val;
129 {
130   __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
131 }
132
133 static __inline__ void
134 outw(port, val)
135      short port;
136      short val;
137 {
138   __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
139 }
140
141 static __inline__ unsigned int
142 inb(port)
143      short port;
144 {
145   unsigned char ret;
146   __asm__ __volatile__("in%B0 (%1)" :
147                    "=a" (ret) :
148                    "d" (port));
149   return ret;
150 }
151
152 static __inline__ unsigned int
153 inw(port)
154      short port;
155 {
156   unsigned short ret;
157   __asm__ __volatile__("in%W0 (%1)" :
158                    "=a" (ret) :
159                    "d" (port));
160   return ret;
161 }
162
163 #endif /* GCCUSESGAS */
164
165 #else /* FAKEIT */
166
167 static __inline__ void
168 outb(port, val)
169      short port;
170      char val;
171 {
172 }
173
174 static __inline__ void
175 outw(port, val)
176      short port;
177      short val;
178 {
179 }
180
181 static __inline__ unsigned int
182 inb(port)
183      short port;
184 {
185   return 0;
186 }
187
188 static __inline__ unsigned int
189 inw(port)
190      short port;
191 {
192   return 0;
193 }
194
195 #endif /* FAKEIT */
196
197 #else /* __GNUC__ */
198 #if !defined(AMOEBA) && !defined(_MINIX)
199 # if defined(__STDC__) && (__STDC__ == 1)
200 #  define asm __asm
201 # endif
202 # ifdef SVR4
203 #  include <sys/types.h>
204 #  ifndef __USLC__
205 #   define __USLC__
206 #  endif
207 # endif
208 # include <sys/inline.h>
209 #endif
210 #endif
211
212 /*
213  *-----------------------------------------------------------------------
214  * Port manipulation convenience functions
215  *-----------------------------------------------------------------------
216  */
217
218 #ifndef __GNUC__
219 #define __inline__ /**/
220 #endif
221
222 /*
223  * rdinx - read the indexed byte port 'port', index 'ind', and return its value
224  */
225 static __inline__ unsigned char
226 #ifdef __STDC__
227 rdinx(unsigned short port, unsigned char ind)
228 #else
229 rdinx(port, ind)
230 unsigned short port;
231 unsigned char ind;
232 #endif
233 {
234         if (port == 0x3C0)              /* reset attribute flip-flop */
235                 inb(0x3DA);
236         outb(port, ind);
237         return(inb(port+1));
238 }
239
240 /*
241  * wrinx - write 'val' to port 'port', index 'ind'
242  */
243 static __inline__ void
244 #ifdef __STDC__
245 wrinx(unsigned short port, unsigned char ind, unsigned char val)
246 #else
247 wrinx(port, ind, val)
248 unsigned short port;
249 unsigned char ind, val;
250 #endif
251 {
252         outb(port, ind);
253         outb(port+1, val);
254 }
255
256 /*
257  * modinx - in register 'port', index 'ind', set the bits in 'mask' as in 'new';
258  *          the other bits are unchanged.
259  */
260 static __inline__ void
261 #ifdef __STDC__
262 modinx(unsigned short port, unsigned char ind,
263        unsigned char mask, unsigned char new)
264 #else
265 modinx(port, ind, mask, new)
266 unsigned short port;
267 unsigned char ind, mask, new;
268 #endif
269 {
270         unsigned char tmp;
271
272         tmp = (rdinx(port, ind) & ~mask) | (new & mask);
273         wrinx(port, ind, tmp);
274 }
275
276 /*
277  * tstrg - returns true iff the bits in 'mask' of register 'port' are
278  *         readable & writable.
279  */
280
281 static __inline__ int
282 #ifdef __STDC__
283 testrg(unsigned short port, unsigned char mask)
284 #else
285 tstrg(port, mask)
286 unsigned short port;
287 unsigned char mask;
288 #endif
289 {
290         unsigned char old, new1, new2;
291
292         old = inb(port);
293         outb(port, old & ~mask);
294         new1 = inb(port) & mask;
295         outb(port, old | mask);
296         new2 = inb(port) & mask;
297         outb(port, old);
298         return((new1 == 0) && (new2 == mask));
299 }
300
301 /*
302  * testinx2 - returns true iff the bits in 'mask' of register 'port', index
303  *            'ind' are readable & writable.
304  */
305 static __inline__ int
306 #ifdef __STDC__
307 testinx2(unsigned short port, unsigned char ind, unsigned char mask)
308 #else
309 testinx2(port, ind, mask)
310 unsigned short port;
311 unsigned char ind, mask;
312 #endif
313 {
314         unsigned char old, new1, new2;
315
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));
323 }
324
325 /*
326  * testinx - returns true iff all bits of register 'port', index 'ind' are
327  *           readable & writable.
328  */
329 static __inline__ int
330 #ifdef __STDC__
331 testinx(unsigned short port, unsigned char ind)
332 #else
333 testinx(port, ind, mask)
334 unsigned short port;
335 unsigned char ind;
336 #endif
337 {
338         return(testinx2(port, ind, 0xFF));
339 }
340
341 #endif /* NO_INLINE */
342 #endif /* _COMPILER_H */