io_i386.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Copyright (C) 1996, 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. /*
  16. * June 16, 2001 hacked for uClibc inclusion by Manuel Novoa III
  17. *
  18. * This was originally sys/io.h from glibc-2.2.2. However, uClibc
  19. * currently shares the same sys/io.h for all archs. So, I placed
  20. * moved and renamed it to bits/io_i386.h and modified sys/io.h to
  21. * conditionally include this if __i386__ was defined.
  22. */
  23. #if !defined _SYS_IO_H || defined _BITS_IO_I386_H
  24. #error Never include <bits/io_i386.h> directly; use <sys/io.h> instead.
  25. #endif
  26. #define _BITS_IO_I386_H 1
  27. #if defined __GNUC__ && __GNUC__ >= 2
  28. static __inline unsigned char
  29. inb (unsigned short int port)
  30. {
  31. unsigned char _v;
  32. __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
  33. return _v;
  34. }
  35. static __inline unsigned char
  36. inb_p (unsigned short int port)
  37. {
  38. unsigned char _v;
  39. __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  40. return _v;
  41. }
  42. static __inline unsigned short int
  43. inw (unsigned short int port)
  44. {
  45. unsigned short _v;
  46. __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
  47. return _v;
  48. }
  49. static __inline unsigned short int
  50. inw_p (unsigned short int port)
  51. {
  52. unsigned short int _v;
  53. __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  54. return _v;
  55. }
  56. static __inline unsigned int
  57. inl (unsigned short int port)
  58. {
  59. unsigned int _v;
  60. __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
  61. return _v;
  62. }
  63. static __inline unsigned int
  64. inl_p (unsigned short int port)
  65. {
  66. unsigned int _v;
  67. __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  68. return _v;
  69. }
  70. static __inline void
  71. outb (unsigned char value, unsigned short int port)
  72. {
  73. __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
  74. }
  75. static __inline void
  76. outb_p (unsigned char value, unsigned short int port)
  77. {
  78. __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
  79. "Nd" (port));
  80. }
  81. static __inline void
  82. outw (unsigned short int value, unsigned short int port)
  83. {
  84. __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
  85. }
  86. static __inline void
  87. outw_p (unsigned short int value, unsigned short int port)
  88. {
  89. __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
  90. "Nd" (port));
  91. }
  92. static __inline void
  93. outl (unsigned int value, unsigned short int port)
  94. {
  95. __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
  96. }
  97. static __inline void
  98. outl_p (unsigned int value, unsigned short int port)
  99. {
  100. __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
  101. "Nd" (port));
  102. }
  103. static __inline void
  104. insb (unsigned short int port, void *addr, unsigned long int count)
  105. {
  106. __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
  107. "=c" (count):"d" (port), "0" (addr), "1" (count));
  108. }
  109. static __inline void
  110. insw (unsigned short int port, void *addr, unsigned long int count)
  111. {
  112. __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
  113. "=c" (count):"d" (port), "0" (addr), "1" (count));
  114. }
  115. static __inline void
  116. insl (unsigned short int port, void *addr, unsigned long int count)
  117. {
  118. __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
  119. "=c" (count):"d" (port), "0" (addr), "1" (count));
  120. }
  121. static __inline void
  122. outsb (unsigned short int port, const void *addr, unsigned long int count)
  123. {
  124. __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
  125. "=c" (count):"d" (port), "0" (addr), "1" (count));
  126. }
  127. static __inline void
  128. outsw (unsigned short int port, const void *addr, unsigned long int count)
  129. {
  130. __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
  131. "=c" (count):"d" (port), "0" (addr), "1" (count));
  132. }
  133. static __inline void
  134. outsl (unsigned short int port, const void *addr, unsigned long int count)
  135. {
  136. __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
  137. "=c" (count):"d" (port), "0" (addr), "1" (count));
  138. }
  139. #endif /* GNU C */