io.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX 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. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _IO_H
  20. #define _IO_H
  21. #include <kernel/types.h>
  22. typedef __uint16_t port_t;
  23. #define inb(port) ({ \
  24. __uint8_t _r; \
  25. __asm__ volatile ("inb %%dx, %%al" : "=a" (_r) : "d" (port)); \
  26. _r; \
  27. })
  28. #define inw(port) ({ \
  29. __uint16_t _r; \
  30. __asm__ volatile ("inw %%dx, %%ax" : "=a" (_r) : "d" (port)); \
  31. _r; \
  32. })
  33. #define inl(port) ({ \
  34. __uint32_t _r; \
  35. __asm__ volatile ("inl %%dx, %%eax" : "=a" (_r) : "d" (port)); \
  36. _r; \
  37. })
  38. #define insw(port, buf, c) __asm__ volatile ("cld;rep;insw;"::"d" (port), "D" (buf), "c" (c))
  39. #define outb(value, port) \
  40. __asm__ volatile ("outb %%al, %%dx" :: "a" (value), "d" (port));
  41. #define outw(value, port) \
  42. __asm__ volatile ("outw %%ax, %%dx" :: "a" (value), "d" (port));
  43. #define outl(value, port) \
  44. __asm__ volatile ("outl %%eax, %%dx" :: "a" (value), "d" (port));
  45. #endif