libhd  5.0
AsmMacros.h
Go to the documentation of this file.
1 /* $XConsortium: AsmMacros.h /main/13 1996/10/25 11:33:12 kaleb $ */
2 /*
3  * (c) Copyright 1993,1994 by David Wexelblat <dwex@xfree86.org>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * DAVID WEXELBLAT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Except as contained in this notice, the name of David Wexelblat shall not be
24  * used in advertising or otherwise to promote the sale, use or other dealings
25  * in this Software without prior written authorization from David Wexelblat.
26  *
27  */
28 /*
29  * Copyright 1997
30  * Digital Equipment Corporation. All rights reserved.
31  * This software is furnished under license and may be used and copied only in
32  * accordance with the following terms and conditions. Subject to these
33  * conditions, you may download, copy, install, use, modify and distribute
34  * this software in source and/or binary form. No title or ownership is
35  * transferred hereby.
36  *
37  * 1) Any source code used, modified or distributed must reproduce and retain
38  * this copyright notice and list of conditions as they appear in the source
39  * file.
40  *
41  * 2) No right is granted to use any trade name, trademark, or logo of Digital
42  * Equipment Corporation. Neither the "Digital Equipment Corporation" name
43  * nor any trademark or logo of Digital Equipment Corporation may be used
44  * to endorse or promote products derived from this software without the
45  * prior written permission of Digital Equipment Corporation.
46  *
47  * 3) This software is provided "AS-IS" and any express or implied warranties,
48  * including but not limited to, any implied warranties of merchantability,
49  * fitness for a particular purpose, or non-infringement are disclaimed. In
50  * no event shall DIGITAL be liable for any damages whatsoever, and in
51  * particular, DIGITAL shall not be liable for special, indirect,
52  * consequential, or incidental damages or damages for
53  * lost profits, loss of revenue or loss of use, whether such damages arise
54  * in contract,
55  * negligence, tort, under statute, in equity, at law or otherwise, even if
56  * advised of the possibility of such damage.
57  *
58  */
59 
60 /* $XFree86: xc/programs/Xserver/hw/xfree86/SuperProbe/AsmMacros.h,v 3.14 1999/09/25 14:36:58 dawes Exp $ */
61 
62 
63 #if defined(__GNUC__)
64 
65 #if defined(linux) && (defined(__alpha__) || defined(__ia64__))
66 
67 #include <sys/io.h>
68 
69 #undef inb
70 #undef inw
71 #undef inl
72 #undef outb
73 #undef outw
74 #undef outl
75 
76 static __inline__ unsigned int inb(unsigned long int p) { return _inb(p); };
77 static __inline__ unsigned int inw(unsigned long int p) { return _inw(p); };
78 static __inline__ unsigned int inl(unsigned long int p) { return _inl(p); };
79 static __inline__ void outb(unsigned long int p, unsigned char v) { _outb(v,p); };
80 static __inline__ void outw(unsigned long int p, unsigned short v) { _outw(v,p); };
81 static __inline__ void outl(unsigned long int p, unsigned int v) { _outl(v,p); };
82 
83 #else
84 
85 #if defined(__sparc__)
86 #ifndef ASI_PL
87 #define ASI_PL 0x88
88 #endif
89 
90 static __inline__ void
91 outb(port, val)
92 unsigned long port;
93 char val;
94 {
95  __asm__ __volatile__("stba %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
96 }
97 
98 static __inline__ void
99 outw(port, val)
100 unsigned long port;
101 char val;
102 {
103  __asm__ __volatile__("stha %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
104 }
105 
106 static __inline__ void
107 outl(port, val)
108 unsigned long port;
109 char val;
110 {
111  __asm__ __volatile__("sta %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
112 }
113 
114 static __inline__ unsigned int
115 inb(port)
116 unsigned long port;
117 {
118  unsigned char ret;
119  __asm__ __volatile__("lduba [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
120  return ret;
121 }
122 
123 static __inline__ unsigned int
124 inw(port)
125 unsigned long port;
126 {
127  unsigned char ret;
128  __asm__ __volatile__("lduha [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
129  return ret;
130 }
131 
132 static __inline__ unsigned int
133 inl(port)
134 unsigned long port;
135 {
136  unsigned char ret;
137  __asm__ __volatile__("lda [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
138  return ret;
139 }
140 #else
141 #ifdef __arm32__
142 unsigned int IOPortBase; /* Memory mapped I/O port area */
143 
144 static __inline__ void
145 outb(port, val)
146  short port;
147  char val;
148 {
149  if ((unsigned short)port >= 0x400) return;
150 
151  *(volatile unsigned char*)(((unsigned short)(port))+IOPortBase) = val;
152 }
153 
154 static __inline__ void
155 outw(port, val)
156  short port;
157  short val;
158 {
159  if ((unsigned short)port >= 0x400) return;
160 
161  *(volatile unsigned short*)(((unsigned short)(port))+IOPortBase) = val;
162 }
163 
164 static __inline__ void
165 outl(port, val)
166  short port;
167  int val;
168 {
169  if ((unsigned short)port >= 0x400) return;
170 
171  *(volatile unsigned long*)(((unsigned short)(port))+IOPortBase) = val;
172 }
173 
174 static __inline__ unsigned int
175 inb(port)
176  short port;
177 {
178  if ((unsigned short)port >= 0x400) return((unsigned int)-1);
179 
180  return(*(volatile unsigned char*)(((unsigned short)(port))+IOPortBase));
181 }
182 
183 static __inline__ unsigned int
184 inw(port)
185  short port;
186 {
187  if ((unsigned short)port >= 0x400) return((unsigned int)-1);
188 
189  return(*(volatile unsigned short*)(((unsigned short)(port))+IOPortBase));
190 }
191 
192 static __inline__ unsigned int
193 inl(port)
194  short port;
195 {
196  if ((unsigned short)port >= 0x400) return((unsigned int)-1);
197 
198  return(*(volatile unsigned long*)(((unsigned short)(port))+IOPortBase));
199 }
200 #else /* __arm32__ */
201 #if defined(Lynx) && defined(__powerpc__)
202 extern unsigned char *ioBase;
203 
204 static volatile void
205 eieio()
206 {
207  __asm__ __volatile__ ("eieio");
208 }
209 
210 static void
211 outb(port, value)
212 short port;
213 unsigned char value;
214 {
215  *(uchar *)(ioBase + port) = value; eieio();
216 }
217 
218 static void
219 outw(port, value)
220 short port;
221 unsigned short value;
222 {
223  *(unsigned short *)(ioBase + port) = value; eieio();
224 }
225 
226 static void
227 outl(port, value)
228 short port;
229 unsigned long value;
230 {
231  *(unsigned long *)(ioBase + port) = value; eieio();
232 }
233 
234 static unsigned char
235 inb(port)
236 short port;
237 {
238  unsigned char val;
239 
240  val = *((unsigned char *)(ioBase + port)); eieio();
241  return(val);
242 }
243 
244 static unsigned short
245 inw(port)
246 short port;
247 {
248  unsigned short val;
249 
250  val = *((unsigned short *)(ioBase + port)); eieio();
251  return(val);
252 }
253 
254 static unsigned long
255 inl(port)
256 short port;
257 {
258  unsigned long val;
259 
260  val = *((unsigned long *)(ioBase + port)); eieio();
261  return(val);
262 }
263 
264 #else
265 #if defined(__FreeBSD__) && defined(__alpha__)
266 
267 #include <sys/types.h>
268 
269 extern void outb(u_int32_t port, u_int8_t val);
270 extern void outw(u_int32_t port, u_int16_t val);
271 extern void outl(u_int32_t port, u_int32_t val);
272 extern u_int8_t inb(u_int32_t port);
273 extern u_int16_t inw(u_int32_t port);
274 extern u_int32_t inl(u_int32_t port);
275 
276 #else
277 #ifdef GCCUSESGAS
278 static __inline__ void
279 outb(port, val)
280 short port;
281 char val;
282 {
283  __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
284 }
285 
286 static __inline__ void
287 outw(port, val)
288 short port;
289 short val;
290 {
291  __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
292 }
293 
294 static __inline__ void
295 outl(port, val)
296 short port;
297 unsigned int val;
298 {
299  __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
300 }
301 
302 static __inline__ unsigned int
303 inb(port)
304 short port;
305 {
306  unsigned char ret;
307  __asm__ __volatile__("inb %1,%0" :
308  "=a" (ret) :
309  "d" (port));
310  return ret;
311 }
312 
313 static __inline__ unsigned int
314 inw(port)
315 short port;
316 {
317  unsigned short ret;
318  __asm__ __volatile__("inw %1,%0" :
319  "=a" (ret) :
320  "d" (port));
321  return ret;
322 }
323 
324 static __inline__ unsigned int
325 inl(port)
326 short port;
327 {
328  unsigned int ret;
329  __asm__ __volatile__("inl %1,%0" :
330  "=a" (ret) :
331  "d" (port));
332  return ret;
333 }
334 
335 #else /* GCCUSESGAS */
336 
337 static __inline__ void
338 outb(port, val)
339  short port;
340  char val;
341 {
342  __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
343 }
344 
345 static __inline__ void
346 outw(port, val)
347  short port;
348  short val;
349 {
350  __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
351 }
352 
353 static __inline__ void
354 outl(port, val)
355  short port;
356  unsigned int val;
357 {
358  __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
359 }
360 
361 static __inline__ unsigned int
362 inb(port)
363  short port;
364 {
365  unsigned int ret;
366  __asm__ __volatile__("in%B0 (%1)" :
367  "=a" (ret) :
368  "d" (port));
369  return ret;
370 }
371 
372 static __inline__ unsigned int
373 inw(port)
374  short port;
375 {
376  unsigned int ret;
377  __asm__ __volatile__("in%W0 (%1)" :
378  "=a" (ret) :
379  "d" (port));
380  return ret;
381 }
382 
383 static __inline__ unsigned int
384 inl(port)
385  short port;
386 {
387  unsigned int ret;
388  __asm__ __volatile__("in%L0 (%1)" :
389  "=a" (ret) :
390  "d" (port));
391  return ret;
392 }
393 
394 #endif /* GCCUSESGAS */
395 #endif /* Lynx && __powerpc__ */
396 #endif /* arm32 */
397 #endif /* linux && __sparc__ */
398 #endif /* linux && __alpha__ */
399 #endif /* __FreeBSD__ && __alpha__ */
400 
401 #if defined(linux) || defined(__arm32__) || (defined(Lynx) && defined(__powerpc__))
402 
403 #define intr_disable()
404 #define intr_enable()
405 
406 #else
407 
408 static __inline__ void
409 intr_disable()
410 {
411  __asm__ __volatile__("cli");
412 }
413 
414 static __inline__ void
415 intr_enable()
416 {
417  __asm__ __volatile__("sti");
418 }
419 
420 #endif /* else !linux && !__arm32__ */
421 
422 #else /* __GNUC__ */
423 
424 #if defined(_MINIX) && defined(_ACK)
425 
426 /* inb, outb, inw and outw are defined in the library */
427 /* ... but I've no idea if the same is true for inl & outl */
428 
429 u8_t inb(U16_t);
430 void outb(U16_t, U8_t);
431 u16_t inw(U16_t);
432 void outw(U16_t, U16_t);
433 u32_t inl(U16_t);
434 void outl(U16_t, U32_t);
435 
436 #else /* not _MINIX and _ACK */
437 
438 # if defined(__STDC__) && (__STDC__ == 1)
439 # ifndef NCR
440 # define asm __asm
441 # endif
442 # endif
443 # ifdef SVR4
444 # include <sys/types.h>
445 # ifndef __USLC__
446 # define __USLC__
447 # endif
448 # endif
449 #ifndef SCO325
450 # include <sys/inline.h>
451 #else
452 # include "../common/scoasm.h"
453 #endif
454 #define intr_disable() asm("cli")
455 #define intr_enable() asm("sti")
456 
457 #endif /* _MINIX and _ACK */
458 #endif /* __GNUC__ */