A couple of header fixes to get all the FreeLDR-loaded boot drivers to compile and...
[reactos.git] / reactos / include / ddk / ioaccess.h
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
22 #if __GNUC__ >= 3
23 #pragma GCC system_header
24 #endif
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #define H2I(p) PtrToUshort(p)
31
32 #ifndef NO_PORT_MACROS
33
34 #if defined(_X86_)
35 #define READ_REGISTER_UCHAR(r) (*(volatile UCHAR *)(r))
36 #define READ_REGISTER_USHORT(r) (*(volatile USHORT *)(r))
37 #define READ_REGISTER_ULONG(r) (*(volatile ULONG *)(r))
38 #define WRITE_REGISTER_UCHAR(r, v) (*(volatile UCHAR *)(r) = (v))
39 #define WRITE_REGISTER_USHORT(r, v) (*(volatile USHORT *)(r) = (v))
40 #define WRITE_REGISTER_ULONG(r, v) (*(volatile ULONG *)(r) = (v))
41 #define READ_PORT_UCHAR(p) (UCHAR)(__inbyte H2I(p))
42 #define READ_PORT_USHORT(p) (USHORT)(__inword H2I(p))
43 #define READ_PORT_ULONG(p) (ULONG)(__indword H2I(p))
44 #define WRITE_PORT_UCHAR(p, v) __outbyte (H2I(p), (v))
45 #define WRITE_PORT_USHORT(p, v) __outword (H2I(p), (v))
46 #define WRITE_PORT_ULONG(p, v) __outdword (H2I(p), (v))
47
48 #elif defined(_PPC_) || defined(_MIPS_) || defined(_ARM_)
49
50 #define READ_REGISTER_UCHAR(r) (*(volatile UCHAR * const)(r))
51 #define READ_REGISTER_USHORT(r) (*(volatile USHORT * const)(r))
52 #define READ_REGISTER_ULONG(r) (*(volatile ULONG * const)(r))
53 #define WRITE_REGISTER_UCHAR(r, v) (*(volatile UCHAR * const)(r) = (v))
54 #define WRITE_REGISTER_USHORT(r, v) (*(volatile USHORT * const)(r) = (v))
55 #define WRITE_REGISTER_ULONG(r, v) (*(volatile ULONG * const)(r) = (v))
56 #define READ_PORT_UCHAR(r) READ_REGISTER_UCHAR(r)
57 #define READ_PORT_USHORT(r) READ_REGISTER_USHORT(r)
58 #define READ_PORT_ULONG(r) READ_REGISTER_ULONG(r)
59 #define WRITE_PORT_UCHAR(p, v) WRITE_REGISTER_UCHAR(p, (UCHAR) (v))
60 #define WRITE_PORT_USHORT(p, v) WRITE_REGISTER_USHORT(p, (USHORT) (v))
61 #define WRITE_PORT_ULONG(p, v) WRITE_REGISTER_ULONG(p, (ULONG) (v))
62
63 #else
64
65 #error Unsupported architecture
66
67 #endif
68
69 #endif /* NO_PORT_MACROS */
70 #endif /* __IOACCESS_H */