AsmMacros.h 10.0 KB

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