home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / include / asm / io.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  3.6 KB  |  151 lines

  1. #ifndef _ASM_IO_H
  2. #define _ASM_IO_H
  3.  
  4. /*
  5.  * Thanks to James van Artsdalen for a better timing-fix than
  6.  * the two short jumps: using outb's to a nonexistent port seems
  7.  * to guarantee better timings even on fast machines.
  8.  *
  9.  * On the other hand, I'd like to be sure of a non-existent port:
  10.  * I feel a bit unsafe about using 0x80.
  11.  *
  12.  *        Linus
  13.  */
  14.  
  15. #ifdef SLOW_IO_BY_JUMPING
  16. #define __SLOW_DOWN_IO __asm__ __volatile__("jmp 1f\n1:\tjmp 1f\n1:")
  17. #else
  18. #define __SLOW_DOWN_IO __asm__ __volatile__("outb %al,$0x80")
  19. #endif
  20.  
  21. #ifdef REALLY_SLOW_IO
  22. #define SLOW_DOWN_IO { __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; __SLOW_DOWN_IO; }
  23. #else
  24. #define SLOW_DOWN_IO __SLOW_DOWN_IO
  25. #endif
  26.  
  27. #ifdef __i386__
  28. /* This is the more general version of outb.. */
  29. extern inline void __outb(unsigned char value, unsigned short port)
  30. {
  31. __asm__ __volatile__ ("outb %b0,%w1"
  32.         : /* no outputs */
  33.         :"a" (value),"d" (port));
  34. }
  35. #endif /* architecture */
  36.  
  37. /* this is used for constant port numbers < 256.. */
  38. extern inline void __outbc(unsigned char value, unsigned short port)
  39. {
  40. __asm__ __volatile__ ("outb %b0,%1"
  41.         : /* no outputs */
  42.         :"a" (value),"i" (port));
  43. }
  44.  
  45. #ifdef __i386__
  46. /* general version of inb */
  47. extern inline unsigned int __inb(unsigned short port)
  48. {
  49.     unsigned int _v;
  50. __asm__ __volatile__ ("inb %w1,%b0"
  51.         :"=a" (_v):"d" (port),"0" (0));
  52.     return _v;
  53. }
  54. #endif /* architecture */
  55.  
  56. /* inb with constant port nr 0-255 */
  57. extern inline unsigned int __inbc(unsigned short port)
  58. {
  59.     unsigned int _v;
  60. __asm__ __volatile__ ("inb %1,%b0"
  61.         :"=a" (_v):"i" (port),"0" (0));
  62.     return _v;
  63. }
  64.  
  65. #if defined(__i386__)
  66. extern inline void __outb_p(unsigned char value, unsigned short port)
  67. {
  68. __asm__ __volatile__ ("outb %b0,%w1"
  69.         : /* no outputs */
  70.         :"a" (value),"d" (port));
  71.     SLOW_DOWN_IO;
  72. }
  73. #elif defined(__mc68000__)
  74. static inline void put_user_byte_io(char val,char *addr)
  75. {
  76.     __asm__ __volatile__ ("moveb %0,%1"
  77.                   : /* no outputs */
  78.                   :"r" (val),"m" (*addr)
  79.                   : "memory");
  80. }
  81. #define outb_p(x,addr) put_user_byte_io((x),(char *)(addr))
  82. #define outb(x,addr) put_user_byte_io((x),(char *)(addr))
  83. #endif /* architecture */
  84.  
  85. extern inline void __outbc_p(unsigned char value, unsigned short port)
  86. {
  87. __asm__ __volatile__ ("outb %b0,%1"
  88.         : /* no outputs */
  89.         :"a" (value),"i" (port));
  90.     SLOW_DOWN_IO;
  91. }
  92.  
  93. #if defined(__i386__)
  94. extern inline unsigned int __inb_p(unsigned short port)
  95. {
  96.     unsigned int _v;
  97. __asm__ __volatile__ ("inb %w1,%b0"
  98.         :"=a" (_v):"d" (port),"0" (0));
  99.     SLOW_DOWN_IO;
  100.     return _v;
  101. }
  102. #elif defined(__mc68000__)
  103. static inline unsigned char get_user_byte_io(const char * addr)
  104. {
  105.     register unsigned char _v;
  106.  
  107.     __asm__ __volatile__ ("moveb %1,%0":"=r" (_v):"m" (*addr));
  108.     return _v;
  109. }
  110. #define inb_p(addr) get_user_byte_io((char *)(addr))
  111. #define inb(addr) get_user_byte_io((char *)(addr))
  112. #endif /* architecture */
  113.  
  114. extern inline unsigned int __inbc_p(unsigned short port)
  115. {
  116.     unsigned int _v;
  117. __asm__ __volatile__ ("inb %1,%b0"
  118.         :"=a" (_v):"i" (port),"0" (0));
  119.     SLOW_DOWN_IO;
  120.     return _v;
  121. }
  122.  
  123. #ifdef __i386__
  124. /*
  125.  * Note that due to the way __builtin_constant_p() works, you
  126.  *  - can't use it inside a inline function (it will never be true)
  127.  *  - you don't have to worry about side effects within the __builtin..
  128.  */
  129. #define outb(val,port) \
  130. ((__builtin_constant_p((port)) && (port) < 256) ? \
  131.     __outbc((val),(port)) : \
  132.     __outb((val),(port)))
  133.  
  134. #define inb(port) \
  135. ((__builtin_constant_p((port)) && (port) < 256) ? \
  136.     __inbc(port) : \
  137.     __inb(port))
  138.  
  139. #define outb_p(val,port) \
  140. ((__builtin_constant_p((port)) && (port) < 256) ? \
  141.     __outbc_p((val),(port)) : \
  142.     __outb_p((val),(port)))
  143.  
  144. #define inb_p(port) \
  145. ((__builtin_constant_p((port)) && (port) < 256) ? \
  146.     __inbc_p(port) : \
  147.     __inb_p(port))
  148. #endif /* i386 */
  149.  
  150. #endif
  151.