io.h 1.6 KB

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