]> git.ipfire.org Git - ipfire-2.x.git/blame - src/hwinfo/src/int10/AsmMacros.h
Kleiner netter neuer Versuch.
[ipfire-2.x.git] / src / hwinfo / src / int10 / AsmMacros.h
CommitLineData
a6316ce4
MT
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
76static __inline__ unsigned int inb(unsigned long int p) { return _inb(p); };
77static __inline__ unsigned int inw(unsigned long int p) { return _inw(p); };
78static __inline__ unsigned int inl(unsigned long int p) { return _inl(p); };
79static __inline__ void outb(unsigned long int p, unsigned char v) { _outb(v,p); };
80static __inline__ void outw(unsigned long int p, unsigned short v) { _outw(v,p); };
81static __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
90static __inline__ void
91outb(port, val)
92unsigned long port;
93char val;
94{
95 __asm__ __volatile__("stba %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
96}
97
98static __inline__ void
99outw(port, val)
100unsigned long port;
101char val;
102{
103 __asm__ __volatile__("stha %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
104}
105
106static __inline__ void
107outl(port, val)
108unsigned long port;
109char val;
110{
111 __asm__ __volatile__("sta %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
112}
113
114static __inline__ unsigned int
115inb(port)
116unsigned 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
123static __inline__ unsigned int
124inw(port)
125unsigned 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
132static __inline__ unsigned int
133inl(port)
134unsigned 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__
142unsigned int IOPortBase; /* Memory mapped I/O port area */
143
144static __inline__ void
145outb(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
154static __inline__ void
155outw(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
164static __inline__ void
165outl(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
174static __inline__ unsigned int
175inb(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
183static __inline__ unsigned int
184inw(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
192static __inline__ unsigned int
193inl(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__)
202extern unsigned char *ioBase;
203
204static volatile void
205eieio()
206{
207 __asm__ __volatile__ ("eieio");
208}
209
210static void
211outb(port, value)
212short port;
213unsigned char value;
214{
215 *(uchar *)(ioBase + port) = value; eieio();
216}
217
218static void
219outw(port, value)
220short port;
221unsigned short value;
222{
223 *(unsigned short *)(ioBase + port) = value; eieio();
224}
225
226static void
227outl(port, value)
228short port;
229unsigned long value;
230{
231 *(unsigned long *)(ioBase + port) = value; eieio();
232}
233
234static unsigned char
235inb(port)
236short port;
237{
238 unsigned char val;
239
240 val = *((unsigned char *)(ioBase + port)); eieio();
241 return(val);
242}
243
244static unsigned short
245inw(port)
246short port;
247{
248 unsigned short val;
249
250 val = *((unsigned short *)(ioBase + port)); eieio();
251 return(val);
252}
253
254static unsigned long
255inl(port)
256short 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
269extern void outb(u_int32_t port, u_int8_t val);
270extern void outw(u_int32_t port, u_int16_t val);
271extern void outl(u_int32_t port, u_int32_t val);
272extern u_int8_t inb(u_int32_t port);
273extern u_int16_t inw(u_int32_t port);
274extern u_int32_t inl(u_int32_t port);
275
276#else
277#ifdef GCCUSESGAS
278static __inline__ void
279outb(port, val)
280short port;
281char val;
282{
283 __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
284}
285
286static __inline__ void
287outw(port, val)
288short port;
289short val;
290{
291 __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
292}
293
294static __inline__ void
295outl(port, val)
296short port;
297unsigned int val;
298{
299 __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
300}
301
302static __inline__ unsigned int
303inb(port)
304short port;
305{
306 unsigned char ret;
307 __asm__ __volatile__("inb %1,%0" :
308 "=a" (ret) :
309 "d" (port));
310 return ret;
311}
312
313static __inline__ unsigned int
314inw(port)
315short port;
316{
317 unsigned short ret;
318 __asm__ __volatile__("inw %1,%0" :
319 "=a" (ret) :
320 "d" (port));
321 return ret;
322}
323
324static __inline__ unsigned int
325inl(port)
326short 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
337static __inline__ void
338outb(port, val)
339 short port;
340 char val;
341{
342 __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
343}
344
345static __inline__ void
346outw(port, val)
347 short port;
348 short val;
349{
350 __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
351}
352
353static __inline__ void
354outl(port, val)
355 short port;
356 unsigned int val;
357{
358 __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
359}
360
361static __inline__ unsigned int
362inb(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
372static __inline__ unsigned int
373inw(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
383static __inline__ unsigned int
384inl(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
408static __inline__ void
409intr_disable()
410{
411 __asm__ __volatile__("cli");
412}
413
414static __inline__ void
415intr_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
429u8_t inb(U16_t);
430void outb(U16_t, U8_t);
431u16_t inw(U16_t);
432void outw(U16_t, U16_t);
433u32_t inl(U16_t);
434void 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__ */