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