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