home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / include / mondello / compiler.h < prev    next >
C/C++ Source or Header  |  1996-05-27  |  7KB  |  372 lines

  1. #ifndef _COMPILER_H
  2. #define _COMPILER_H
  3.  
  4. #ifndef __STDC__
  5. # ifdef signed
  6. #  undef signed
  7. # endif
  8. # ifdef volatile
  9. #  undef volatile
  10. # endif
  11. # ifdef const
  12. #  undef const
  13. # endif
  14. # define signed /**/
  15. # ifdef __GNUC__
  16. #  define volatile __volatile__
  17. #  define const __const__
  18. # else
  19. #  define const /**/
  20. # endif /* __GNUC__ */
  21. #endif /* !__STDC__ */
  22.  
  23. #ifdef NO_INLINE
  24.  
  25. extern void outb();
  26. extern void outw();
  27. extern void outl();
  28. extern unsigned int inb();
  29. extern unsigned int inw();
  30. extern unsigned int inl();
  31. #if NeedFunctionPrototypes
  32. extern unsigned char rdinx(unsigned short, unsigned char);
  33. extern void wrinx(unsigned short, unsigned char, unsigned char);
  34. extern void modinx(unsigned short, unsigned char, unsigned char, unsigned char);
  35. extern int testrg(unsigned short, unsigned char);
  36. extern int textinx2(unsigned short, unsigned char, unsigned char);
  37. extern int textinx(unsigned short, unsigned char);
  38. #else /* NeedFunctionProtoypes */
  39. extern unsigned char rdinx();
  40. extern void wrinx();
  41. extern void modinx();
  42. extern int testrg();
  43. extern int textinx2();
  44. extern int textinx();
  45. #endif /* NeedFunctionProtoypes */
  46.  
  47. #else /* NO_INLINE */
  48.  
  49. #ifdef __GNUC__
  50.  
  51. #ifndef FAKEIT
  52. #ifdef GCCUSESGAS
  53.  
  54. /*
  55.  * If gcc uses gas rather than the native assembler, the syntax of these
  56.  * inlines has to be different.        DHD
  57.  */
  58.  
  59. static __inline__ void
  60. outb(port, val)
  61. short port;
  62. char val;
  63. {
  64.    __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
  65. }
  66.  
  67.  
  68. static __inline__ void
  69. outw(port, val)
  70. short port;
  71. short val;
  72. {
  73.    __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
  74. }
  75.  
  76. static __inline__ void
  77. outl(port, val)
  78. short port;
  79. int val;
  80. {
  81.    __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
  82. }
  83.  
  84. static __inline__ unsigned int
  85. inb(port)
  86. short port;
  87. {
  88.    unsigned char ret;
  89.    __asm__ __volatile__("inb %1,%0" :
  90.        "=a" (ret) :
  91.        "d" (port));
  92.    return ret;
  93. }
  94.  
  95. static __inline__ unsigned int
  96. inw(port)
  97. short port;
  98. {
  99.    unsigned short ret;
  100.    __asm__ __volatile__("inw %1,%0" :
  101.        "=a" (ret) :
  102.        "d" (port));
  103.    return ret;
  104. }
  105.  
  106. static __inline__ unsigned int
  107. inl(port)
  108. short port;
  109. {
  110.    unsigned int ret;
  111.    __asm__ __volatile__("inl %1,%0" :
  112.        "=a" (ret) :
  113.        "d" (port));
  114.    return ret;
  115. }
  116.  
  117. #else    /* GCCUSESGAS */
  118.  
  119. static __inline__ void
  120. outb(port, val)
  121.      short port;
  122.      char val;
  123. {
  124.   __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
  125. }
  126.  
  127. static __inline__ void
  128. outw(port, val)
  129.      short port;
  130.      short val;
  131. {
  132.   __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
  133. }
  134.  
  135. static __inline__ void
  136. outl(port, val)
  137.      short port;
  138.      unsigned int val;
  139. {
  140.   __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
  141. }
  142.  
  143. static __inline__ unsigned int
  144. inb(port)
  145.      short port;
  146. {
  147.   unsigned char ret;
  148.   __asm__ __volatile__("in%B0 (%1)" :
  149.            "=a" (ret) :
  150.            "d" (port));
  151.   return ret;
  152. }
  153.  
  154. static __inline__ unsigned int
  155. inw(port)
  156.      short port;
  157. {
  158.   unsigned short ret;
  159.   __asm__ __volatile__("in%W0 (%1)" :
  160.            "=a" (ret) :
  161.            "d" (port));
  162.   return ret;
  163. }
  164.  
  165. static __inline__ unsigned int
  166. inl(port)
  167.      short port;
  168. {
  169.   unsigned int ret;
  170.   __asm__ __volatile__("in%L0 (%1)" :
  171.                    "=a" (ret) :
  172.                    "d" (port));
  173.   return ret;
  174. }
  175.  
  176. #endif /* GCCUSESGAS */
  177.  
  178. #else /* FAKEIT */
  179.  
  180. static __inline__ void
  181. outb(port, val)
  182.      short port;
  183.      char val;
  184. {
  185. }
  186.  
  187. static __inline__ void
  188. outw(port, val)
  189.      short port;
  190.      short val;
  191. {
  192. }
  193.  
  194. static __inline__ void
  195. outl(port, val)
  196.      short port;
  197.      int val;
  198. {
  199. }
  200.  
  201. static __inline__ unsigned int
  202. inb(port)
  203.      short port;
  204. {
  205.   return 0;
  206. }
  207.  
  208. static __inline__ unsigned int
  209. inw(port)
  210.      short port;
  211. {
  212.   return 0;
  213. }
  214.  
  215. static __inline__ unsigned int
  216. inl(port)
  217.      short port;
  218. {
  219.   return 0;
  220. }
  221.  
  222. #endif /* FAKEIT */
  223.  
  224. #else /* __GNUC__ */
  225. #if !defined(AMOEBA) && !defined(MINIX)
  226. # if defined(__STDC__) && (__STDC__ == 1)
  227. #  ifndef asm
  228. #   define asm __asm
  229. #  endif
  230. # endif
  231. # ifdef SVR4
  232. #  include <sys/types.h>
  233. #  ifndef __USLC__
  234. #   define __USLC__
  235. #  endif
  236. # endif
  237. # include <sys/inline.h>
  238. #endif
  239. #endif
  240.  
  241. /*
  242.  *-----------------------------------------------------------------------
  243.  * Port manipulation convenience functions
  244.  *-----------------------------------------------------------------------
  245.  */
  246.  
  247. #ifndef __GNUC__
  248. #define __inline__ /**/
  249. #endif
  250.  
  251. /*
  252.  * rdinx - read the indexed byte port 'port', index 'ind', and return its value
  253.  */
  254. static __inline__ unsigned char 
  255. #ifdef __STDC__
  256. rdinx(unsigned short port, unsigned char ind)
  257. #else
  258. rdinx(port, ind)
  259. unsigned short port;
  260. unsigned char ind;
  261. #endif
  262. {
  263.     if (port == 0x3C0)        /* reset attribute flip-flop */
  264.         (void) inb(0x3DA);
  265.     outb(port, ind);
  266.     return(inb(port+1));
  267. }
  268.  
  269. /*
  270.  * wrinx - write 'val' to port 'port', index 'ind'
  271.  */
  272. static __inline__ void 
  273. #ifdef __STDC__
  274. wrinx(unsigned short port, unsigned char ind, unsigned char val)
  275. #else
  276. wrinx(port, ind, val)
  277. unsigned short port;
  278. unsigned char ind, val;
  279. #endif
  280. {
  281.     outb(port, ind);
  282.     outb(port+1, val);
  283. }
  284.  
  285. /*
  286.  * modinx - in register 'port', index 'ind', set the bits in 'mask' as in 'new';
  287.  *        the other bits are unchanged.
  288.  */
  289. static __inline__ void
  290. #ifdef __STDC__
  291. modinx(unsigned short port, unsigned char ind, 
  292.        unsigned char mask, unsigned char new)
  293. #else
  294. modinx(port, ind, mask, new)
  295. unsigned short port;
  296. unsigned char ind, mask, new;
  297. #endif
  298. {
  299.     unsigned char tmp;
  300.  
  301.     tmp = (rdinx(port, ind) & ~mask) | (new & mask);
  302.     wrinx(port, ind, tmp);
  303. }
  304.  
  305. /*
  306.  * tstrg - returns true iff the bits in 'mask' of register 'port' are
  307.  *       readable & writable.
  308.  */
  309.  
  310. static __inline__ int
  311. #ifdef __STDC__
  312. testrg(unsigned short port, unsigned char mask)
  313. #else
  314. tstrg(port, mask)
  315. unsigned short port;
  316. unsigned char mask;
  317. #endif
  318. {
  319.     unsigned char old, new1, new2;
  320.  
  321.     old = inb(port);
  322.     outb(port, old & ~mask);
  323.     new1 = inb(port) & mask;
  324.     outb(port, old | mask);
  325.     new2 = inb(port) & mask;
  326.     outb(port, old);
  327.     return((new1 == 0) && (new2 == mask));
  328. }
  329.  
  330. /*
  331.  * testinx2 - returns true iff the bits in 'mask' of register 'port', index
  332.  *          'ind' are readable & writable.
  333.  */
  334. static __inline__ int
  335. #ifdef __STDC__
  336. testinx2(unsigned short port, unsigned char ind, unsigned char mask)
  337. #else
  338. testinx2(port, ind, mask)
  339. unsigned short port;
  340. unsigned char ind, mask;
  341. #endif
  342. {
  343.     unsigned char old, new1, new2;
  344.  
  345.     old = rdinx(port, ind);
  346.     wrinx(port, ind, old & ~mask);
  347.     new1 = rdinx(port, ind) & mask;
  348.     wrinx(port, ind, old | mask);
  349.     new2 = rdinx(port, ind) & mask;
  350.     wrinx(port, ind, old);
  351.     return((new1 == 0) && (new2 == mask));
  352. }
  353.  
  354. /*
  355.  * testinx - returns true iff all bits of register 'port', index 'ind' are 
  356.  *              readable & writable.
  357.  */
  358. static __inline__ int
  359. #ifdef __STDC__
  360. testinx(unsigned short port, unsigned char ind)
  361. #else
  362. testinx(port, ind, mask)
  363. unsigned short port;
  364. unsigned char ind;
  365. #endif
  366. {
  367.     return(testinx2(port, ind, 0xFF));
  368. }
  369.  
  370. #endif /* NO_INLINE */
  371. #endif /* _COMPILER_H */
  372.