3973
|
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
|
|
61
|
|
62
|
|
63 /* $XFree86: xc/programs/Xserver/hw/xfree86/SuperProbe/AsmMacros.h,v 3.13 1999/03/28 15:32:21 dawes Exp $ */
|
|
64
|
|
65 #if defined(__GNUC__)
|
|
66 #if defined(linux) && defined(__alpha__)
|
|
67 #define inb _inb
|
|
68 #define inw _inw
|
|
69 #define inl _inl
|
|
70 #define outb(p,v) _outb((v),(p))
|
|
71 #define outw(p,v) _outw((v),(p))
|
|
72 #define outl(p,v) _outl((v),(p))
|
|
73 #else
|
|
74 #if defined(__sparc__)
|
|
75 #ifndef ASI_PL
|
|
76 #define ASI_PL 0x88
|
|
77 #endif
|
|
78
|
|
79 static __inline__ void
|
|
80 outb(port, val)
|
|
81 unsigned long port;
|
|
82 char val;
|
|
83 {
|
|
84 __asm__ __volatile__("stba %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
|
|
85 }
|
|
86
|
|
87 static __inline__ void
|
|
88 outw(port, val)
|
|
89 unsigned long port;
|
|
90 char val;
|
|
91 {
|
|
92 __asm__ __volatile__("stha %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
|
|
93 }
|
|
94
|
|
95 static __inline__ void
|
|
96 outl(port, val)
|
|
97 unsigned long port;
|
|
98 char val;
|
|
99 {
|
|
100 __asm__ __volatile__("sta %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL));
|
|
101 }
|
|
102
|
|
103 static __inline__ unsigned int
|
|
104 inb(port)
|
|
105 unsigned long port;
|
|
106 {
|
|
107 unsigned char ret;
|
|
108 __asm__ __volatile__("lduba [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
|
|
109 return ret;
|
|
110 }
|
|
111
|
|
112 static __inline__ unsigned int
|
|
113 inw(port)
|
|
114 unsigned long port;
|
|
115 {
|
|
116 unsigned char ret;
|
|
117 __asm__ __volatile__("lduha [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
|
|
118 return ret;
|
|
119 }
|
|
120
|
|
121 static __inline__ unsigned int
|
|
122 inl(port)
|
|
123 unsigned long port;
|
|
124 {
|
|
125 unsigned char ret;
|
|
126 __asm__ __volatile__("lda [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL));
|
|
127 return ret;
|
|
128 }
|
|
129 #else
|
|
130 #ifdef __arm32__
|
|
131 unsigned int IOPortBase; /* Memory mapped I/O port area */
|
|
132
|
|
133 static __inline__ void
|
|
134 outb(port, val)
|
|
135 short port;
|
|
136 char val;
|
|
137 {
|
|
138 if ((unsigned short)port >= 0x400) return;
|
|
139
|
|
140 *(volatile unsigned char*)(((unsigned short)(port))+IOPortBase) = val;
|
|
141 }
|
|
142
|
|
143 static __inline__ void
|
|
144 outw(port, val)
|
|
145 short port;
|
|
146 short val;
|
|
147 {
|
|
148 if ((unsigned short)port >= 0x400) return;
|
|
149
|
|
150 *(volatile unsigned short*)(((unsigned short)(port))+IOPortBase) = val;
|
|
151 }
|
|
152
|
|
153 static __inline__ void
|
|
154 outl(port, val)
|
|
155 short port;
|
|
156 int val;
|
|
157 {
|
|
158 if ((unsigned short)port >= 0x400) return;
|
|
159
|
|
160 *(volatile unsigned long*)(((unsigned short)(port))+IOPortBase) = val;
|
|
161 }
|
|
162
|
|
163 static __inline__ unsigned int
|
|
164 inb(port)
|
|
165 short port;
|
|
166 {
|
|
167 if ((unsigned short)port >= 0x400) return((unsigned int)-1);
|
|
168
|
|
169 return(*(volatile unsigned char*)(((unsigned short)(port))+IOPortBase));
|
|
170 }
|
|
171
|
|
172 static __inline__ unsigned int
|
|
173 inw(port)
|
|
174 short port;
|
|
175 {
|
|
176 if ((unsigned short)port >= 0x400) return((unsigned int)-1);
|
|
177
|
|
178 return(*(volatile unsigned short*)(((unsigned short)(port))+IOPortBase));
|
|
179 }
|
|
180
|
|
181 static __inline__ unsigned int
|
|
182 inl(port)
|
|
183 short port;
|
|
184 {
|
|
185 if ((unsigned short)port >= 0x400) return((unsigned int)-1);
|
|
186
|
|
187 return(*(volatile unsigned long*)(((unsigned short)(port))+IOPortBase));
|
|
188 }
|
|
189 #else /* __arm32__ */
|
|
190 #if defined(Lynx) && defined(__powerpc__)
|
|
191 extern unsigned char *ioBase;
|
|
192
|
|
193 static volatile void
|
|
194 eieio()
|
|
195 {
|
|
196 __asm__ __volatile__ ("eieio");
|
|
197 }
|
|
198
|
|
199 static void
|
|
200 outb(port, value)
|
|
201 short port;
|
|
202 unsigned char value;
|
|
203 {
|
|
204 *(uchar *)(ioBase + port) = value; eieio();
|
|
205 }
|
|
206
|
|
207 static void
|
|
208 outw(port, value)
|
|
209 short port;
|
|
210 unsigned short value;
|
|
211 {
|
|
212 *(unsigned short *)(ioBase + port) = value; eieio();
|
|
213 }
|
|
214
|
|
215 static void
|
|
216 outl(port, value)
|
|
217 short port;
|
|
218 unsigned long value;
|
|
219 {
|
|
220 *(unsigned long *)(ioBase + port) = value; eieio();
|
|
221 }
|
|
222
|
|
223 static unsigned char
|
|
224 inb(port)
|
|
225 short port;
|
|
226 {
|
|
227 unsigned char val;
|
|
228
|
|
229 val = *((unsigned char *)(ioBase + port)); eieio();
|
|
230 return(val);
|
|
231 }
|
|
232
|
|
233 static unsigned short
|
|
234 inw(port)
|
|
235 short port;
|
|
236 {
|
|
237 unsigned short val;
|
|
238
|
|
239 val = *((unsigned short *)(ioBase + port)); eieio();
|
|
240 return(val);
|
|
241 }
|
|
242
|
|
243 static unsigned long
|
|
244 inl(port)
|
|
245 short port;
|
|
246 {
|
|
247 unsigned long val;
|
|
248
|
|
249 val = *((unsigned long *)(ioBase + port)); eieio();
|
|
250 return(val);
|
|
251 }
|
|
252
|
|
253 #else
|
|
254 #ifdef GCCUSESGAS
|
|
255 static __inline__ void
|
|
256 outb(port, val)
|
|
257 short port;
|
|
258 char val;
|
|
259 {
|
|
260 __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
|
|
261 }
|
|
262
|
|
263 static __inline__ void
|
|
264 outw(port, val)
|
|
265 short port;
|
|
266 short val;
|
|
267 {
|
|
268 __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
|
|
269 }
|
|
270
|
|
271 static __inline__ void
|
|
272 outl(port, val)
|
|
273 short port;
|
|
274 unsigned int val;
|
|
275 {
|
|
276 __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
|
|
277 }
|
|
278
|
|
279 static __inline__ unsigned int
|
|
280 inb(port)
|
|
281 short port;
|
|
282 {
|
|
283 unsigned char ret;
|
|
284 __asm__ __volatile__("inb %1,%0" :
|
|
285 "=a" (ret) :
|
|
286 "d" (port));
|
|
287 return ret;
|
|
288 }
|
|
289
|
|
290 static __inline__ unsigned int
|
|
291 inw(port)
|
|
292 short port;
|
|
293 {
|
|
294 unsigned short ret;
|
|
295 __asm__ __volatile__("inw %1,%0" :
|
|
296 "=a" (ret) :
|
|
297 "d" (port));
|
|
298 return ret;
|
|
299 }
|
|
300
|
|
301 static __inline__ unsigned int
|
|
302 inl(port)
|
|
303 short port;
|
|
304 {
|
|
305 unsigned int ret;
|
|
306 __asm__ __volatile__("inl %1,%0" :
|
|
307 "=a" (ret) :
|
|
308 "d" (port));
|
|
309 return ret;
|
|
310 }
|
|
311
|
|
312 #else /* GCCUSESGAS */
|
|
313
|
|
314 static __inline__ void
|
|
315 outb(port, val)
|
|
316 short port;
|
|
317 char val;
|
|
318 {
|
|
319 __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
|
|
320 }
|
|
321
|
|
322 static __inline__ void
|
|
323 outw(port, val)
|
|
324 short port;
|
|
325 short val;
|
|
326 {
|
|
327 __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
|
|
328 }
|
|
329
|
|
330 static __inline__ void
|
|
331 outl(port, val)
|
|
332 short port;
|
|
333 unsigned int val;
|
|
334 {
|
|
335 __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
|
|
336 }
|
|
337
|
|
338 static __inline__ unsigned int
|
|
339 inb(port)
|
|
340 short port;
|
|
341 {
|
|
342 unsigned int ret;
|
|
343 __asm__ __volatile__("in%B0 (%1)" :
|
|
344 "=a" (ret) :
|
|
345 "d" (port));
|
|
346 return ret;
|
|
347 }
|
|
348
|
|
349 static __inline__ unsigned int
|
|
350 inw(port)
|
|
351 short port;
|
|
352 {
|
|
353 unsigned int ret;
|
|
354 __asm__ __volatile__("in%W0 (%1)" :
|
|
355 "=a" (ret) :
|
|
356 "d" (port));
|
|
357 return ret;
|
|
358 }
|
|
359
|
|
360 static __inline__ unsigned int
|
|
361 inl(port)
|
|
362 short port;
|
|
363 {
|
|
364 unsigned int ret;
|
|
365 __asm__ __volatile__("in%L0 (%1)" :
|
|
366 "=a" (ret) :
|
|
367 "d" (port));
|
|
368 return ret;
|
|
369 }
|
|
370
|
|
371 #endif /* GCCUSESGAS */
|
|
372 #endif /* Lynx && __powerpc__ */
|
|
373 #endif /* arm32 */
|
|
374 #endif /* linux && __sparc__ */
|
|
375 #endif /* linux && __alpha__ */
|
|
376
|
|
377 #if defined(linux) || defined(__arm32__) || (defined(Lynx) && defined(__powerpc__))
|
|
378
|
|
379 #define intr_disable()
|
|
380 #define intr_enable()
|
|
381
|
|
382 #else
|
|
383
|
|
384 static __inline__ void
|
|
385 intr_disable()
|
|
386 {
|
|
387 __asm__ __volatile__("cli");
|
|
388 }
|
|
389
|
|
390 static __inline__ void
|
|
391 intr_enable()
|
|
392 {
|
|
393 __asm__ __volatile__("sti");
|
|
394 }
|
|
395
|
|
396 #endif /* else !linux && !__arm32__ */
|
|
397
|
|
398 #else /* __GNUC__ */
|
|
399
|
|
400 #if defined(_MINIX) && defined(_ACK)
|
|
401
|
|
402 /* inb, outb, inw and outw are defined in the library */
|
|
403 /* ... but I've no idea if the same is true for inl & outl */
|
|
404
|
|
405 u8_t inb(U16_t);
|
|
406 void outb(U16_t, U8_t);
|
|
407 u16_t inw(U16_t);
|
|
408 void outw(U16_t, U16_t);
|
|
409 u32_t inl(U16_t);
|
|
410 void outl(U16_t, U32_t);
|
|
411
|
|
412 #else /* not _MINIX and _ACK */
|
|
413
|
|
414 # if defined(__STDC__) && (__STDC__ == 1)
|
|
415 # ifndef NCR
|
|
416 # define asm __asm
|
|
417 # endif
|
|
418 # endif
|
|
419 # ifdef SVR4
|
|
420 # include <sys/types.h>
|
|
421 # ifndef __USLC__
|
|
422 # define __USLC__
|
|
423 # endif
|
|
424 # endif
|
|
425 #ifndef SCO325
|
|
426 # include <sys/inline.h>
|
|
427 #else
|
|
428 # include "../common/scoasm.h"
|
|
429 #endif
|
|
430 #define intr_disable() asm("cli")
|
|
431 #define intr_enable() asm("sti")
|
|
432
|
|
433 #endif /* _MINIX and _ACK */
|
|
434 #endif /* __GNUC__ */
|