ioaccess.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * ioaccess.h
  3. *
  4. * Windows Device Driver Kit
  5. *
  6. * This file is part of the w32api package.
  7. *
  8. * THIS SOFTWARE IS NOT COPYRIGHTED
  9. *
  10. * This source code is offered for use in the public domain. You may
  11. * use, modify or distribute it freely.
  12. *
  13. * This code is distributed in the hope that it will be useful but
  14. * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  15. * DISCLAIMED. This includes but is not limited to warranties of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. *
  18. */
  19. #ifndef __IOACCESS_H
  20. #define __IOACCESS_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #define H2I(p) PtrToUshort(p)
  25. #ifndef NO_PORT_MACROS
  26. #if defined(_X86_) || defined(_M_AMD64)
  27. #define READ_REGISTER_UCHAR(r) (*(volatile UCHAR *)(r))
  28. #define READ_REGISTER_USHORT(r) (*(volatile USHORT *)(r))
  29. #define READ_REGISTER_ULONG(r) (*(volatile ULONG *)(r))
  30. #define WRITE_REGISTER_UCHAR(r, v) (*(volatile UCHAR *)(r) = (v))
  31. #define WRITE_REGISTER_USHORT(r, v) (*(volatile USHORT *)(r) = (v))
  32. #define WRITE_REGISTER_ULONG(r, v) (*(volatile ULONG *)(r) = (v))
  33. #define READ_PORT_UCHAR(p) (UCHAR)(__inbyte (H2I(p)))
  34. #define READ_PORT_USHORT(p) (USHORT)(__inword (H2I(p)))
  35. #define READ_PORT_ULONG(p) (ULONG)(__indword (H2I(p)))
  36. #define WRITE_PORT_UCHAR(p, v) __outbyte (H2I(p), (v))
  37. #define WRITE_PORT_USHORT(p, v) __outword (H2I(p), (v))
  38. #define WRITE_PORT_ULONG(p, v) __outdword (H2I(p), (v))
  39. #define MEMORY_BARRIER()
  40. #elif defined(_PPC_) || defined(_MIPS_) || defined(_ARM_)
  41. #define READ_REGISTER_UCHAR(r) (*(volatile UCHAR * const)(r))
  42. #define READ_REGISTER_USHORT(r) (*(volatile USHORT * const)(r))
  43. #define READ_REGISTER_ULONG(r) (*(volatile ULONG * const)(r))
  44. #define WRITE_REGISTER_UCHAR(r, v) (*(volatile UCHAR * const)(r) = (v))
  45. #define WRITE_REGISTER_USHORT(r, v) (*(volatile USHORT * const)(r) = (v))
  46. #define WRITE_REGISTER_ULONG(r, v) (*(volatile ULONG * const)(r) = (v))
  47. #define READ_PORT_UCHAR(r) READ_REGISTER_UCHAR(r)
  48. #define READ_PORT_USHORT(r) READ_REGISTER_USHORT(r)
  49. #define READ_PORT_ULONG(r) READ_REGISTER_ULONG(r)
  50. #define WRITE_PORT_UCHAR(p, v) WRITE_REGISTER_UCHAR(p, (UCHAR) (v))
  51. #define WRITE_PORT_USHORT(p, v) WRITE_REGISTER_USHORT(p, (USHORT) (v))
  52. #define WRITE_PORT_ULONG(p, v) WRITE_REGISTER_ULONG(p, (ULONG) (v))
  53. #else
  54. #error Unsupported architecture
  55. #endif
  56. #endif /* NO_PORT_MACROS */
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif /* __IOACCESS_H */