io.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 outb(value, port) \
  39. __asm__ volatile ("outb %%al, %%dx" :: "a" (value), "d" (port));
  40. #define outw(value, port) \
  41. __asm__ volatile ("outw %%ax, %%dx" :: "a" (value), "d" (port));
  42. #define outl(value, port) \
  43. __asm__ volatile ("outl %%eax, %%dx" :: "a" (value), "d" (port));
  44. #endif