io.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1996,2000,2002,2007 Free Software Foundation, Inc.
  4. *
  5. * GRUB 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. * GRUB 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 GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* Based on sys/io.h from GNU libc. */
  19. #ifndef GRUB_IO_H
  20. #define GRUB_IO_H 1
  21. typedef unsigned short int grub_port_t;
  22. static __inline unsigned char
  23. grub_inb (unsigned short int port)
  24. {
  25. unsigned char _v;
  26. asm volatile ("inb %w1,%0":"=a" (_v):"Nd" (port));
  27. return _v;
  28. }
  29. static __inline unsigned short int
  30. grub_inw (unsigned short int port)
  31. {
  32. unsigned short _v;
  33. asm volatile ("inw %w1,%0":"=a" (_v):"Nd" (port));
  34. return _v;
  35. }
  36. static __inline unsigned int
  37. grub_inl (unsigned short int port)
  38. {
  39. unsigned int _v;
  40. asm volatile ("inl %w1,%0":"=a" (_v):"Nd" (port));
  41. return _v;
  42. }
  43. static __inline void
  44. grub_outb (unsigned char value, unsigned short int port)
  45. {
  46. asm volatile ("outb %b0,%w1": :"a" (value), "Nd" (port));
  47. }
  48. static __inline void
  49. grub_outw (unsigned short int value, unsigned short int port)
  50. {
  51. asm volatile ("outw %w0,%w1": :"a" (value), "Nd" (port));
  52. }
  53. static __inline void
  54. grub_outl (unsigned int value, unsigned short int port)
  55. {
  56. asm volatile ("outl %0,%w1": :"a" (value), "Nd" (port));
  57. }
  58. #endif /* _SYS_IO_H */