io.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* arch/x86/include64/arch/io.h
  2. *
  3. * This file is part of evx.
  4. *
  5. * evx is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * evx is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with evx. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #ifndef __ARCH_IO_H
  19. #define __ARCH_IO_H
  20. #ifndef __ASSEMBLER__
  21. #include <sys/types.h>
  22. /* we can use assembly here! yeah! */
  23. #define inb(port) ({ \
  24. __uint8_t _r; \
  25. __asm__ volatile ("inb %%dx, %%al" : "=a" (_r) : "d" ((port))); \
  26. _r; \
  27. })
  28. #define outb(val, port) __asm__ volatile ("outb %%al, %%dx" :: "a" ((val)), "d" ((port)))
  29. #define inw(port) ({ \
  30. __uint16_t _r; \
  31. __asm__ volatile ("inw %%dx, %%ax" : "=a" (_r) : "d" ((port))); \
  32. _r; \
  33. })
  34. #define outw(val, port) __asm__ volatile ("outw %%ax, %%dx" :: "a" ((val)), "d" ((port)))
  35. #define inl(port) ({ \
  36. __uint32_t _r; \
  37. __asm__ volatile ("inl %%dx, %%eax" : "=a" (_r) : "d" ((port))); \
  38. _r; \
  39. })
  40. #define outl(val, port) __asm__ volatile ("outl %%eax, %%dx" :: "a" ((val)), "d" ((port)))
  41. #endif
  42. #endif