portio_x64.h
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #ifndef PORTIO_X64_H
23 #define PORTIO_X64_H
24 
25 #include <gsl/gsl>
26 
27 extern "C" uint8_t __inb(uint16_t port) noexcept;
28 extern "C" uint16_t __inw(uint16_t port) noexcept;
29 extern "C" uint32_t __ind(uint16_t port) noexcept;
30 
31 extern "C" void __insb(uint16_t port, uint64_t m8) noexcept;
32 extern "C" void __insw(uint16_t port, uint64_t m16) noexcept;
33 extern "C" void __insd(uint16_t port, uint64_t m32) noexcept;
34 
35 extern "C" void __insbrep(uint16_t port, uint64_t m8, uint32_t count) noexcept;
36 extern "C" void __inswrep(uint16_t port, uint64_t m16, uint32_t count) noexcept;
37 extern "C" void __insdrep(uint16_t port, uint64_t m32, uint32_t count) noexcept;
38 
39 extern "C" void __outb(uint16_t port, uint8_t val) noexcept;
40 extern "C" void __outw(uint16_t port, uint16_t val) noexcept;
41 extern "C" void __outd(uint16_t port, uint32_t val) noexcept;
42 
43 extern "C" void __outsb(uint16_t port, uint64_t m8) noexcept;
44 extern "C" void __outsw(uint16_t port, uint64_t m16) noexcept;
45 extern "C" void __outsd(uint16_t port, uint64_t m32) noexcept;
46 
47 extern "C" void __outsbrep(uint16_t port, uint64_t m8, uint32_t count) noexcept;
48 extern "C" void __outswrep(uint16_t port, uint64_t m16, uint32_t count) noexcept;
49 extern "C" void __outsdrep(uint16_t port, uint64_t m32, uint32_t count) noexcept;
50 
51 // *INDENT-OFF*
52 
53 namespace x64
54 {
55 namespace portio
56 {
57  using port_addr_type = uint16_t;
58  using port_8bit_type = uint8_t;
59  using port_16bit_type = uint16_t;
60  using port_32bit_type = uint32_t;
61  using integer_pointer = uintptr_t;
62  using size_type = uint32_t;
63 
64  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
65  auto inb(P port) noexcept { return __inb(gsl::narrow_cast<port_addr_type>(port)); }
66 
67  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
68  auto inw(P port) noexcept { return __inw(gsl::narrow_cast<port_addr_type>(port)); }
69 
70  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
71  auto ind(P port) noexcept { return __ind(gsl::narrow_cast<port_addr_type>(port)); }
72 
73  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
74  auto insb(P port, integer_pointer m8) noexcept { return __insb(gsl::narrow_cast<port_addr_type>(port), m8); }
75 
76  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
77  auto insw(P port, integer_pointer m16) noexcept { return __insw(gsl::narrow_cast<port_addr_type>(port), m16); }
78 
79  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
80  auto insd(P port, integer_pointer m32) noexcept { return __insd(gsl::narrow_cast<port_addr_type>(port), m32); }
81 
82  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
83  auto insb(P port, void *m8) noexcept { return __insb(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m8)); }
84 
85  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
86  auto insw(P port, void *m16) noexcept { return __insw(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m16)); }
87 
88  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
89  auto insd(P port, void *m32) noexcept { return __insd(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m32)); }
90 
91  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
92  auto insbrep(P port, integer_pointer m8, size_type count) noexcept { return __insbrep(gsl::narrow_cast<port_addr_type>(port), m8, count); }
93 
94  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
95  auto inswrep(P port, integer_pointer m16, size_type count) noexcept { return __inswrep(gsl::narrow_cast<port_addr_type>(port), m16, count); }
96 
97  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
98  auto insdrep(P port, integer_pointer m32, size_type count) noexcept { return __insdrep(gsl::narrow_cast<port_addr_type>(port), m32, count); }
99 
100  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
101  auto insbrep(P port, void *m8, size_type count) noexcept { return __insbrep(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m8), count); }
102 
103  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
104  auto inswrep(P port, void *m16, size_type count) noexcept { return __inswrep(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m16), count); }
105 
106  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
107  auto insdrep(P port, void *m32, size_type count) noexcept { return __insdrep(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m32), count); }
108 
109  template<class P, class T,
110  class = typename std::enable_if<std::is_integral<P>::value>::type,
111  class = typename std::enable_if<std::is_integral<T>::value>::type>
112  void outb(P port, T val) noexcept { __outb(gsl::narrow_cast<port_addr_type>(port), gsl::narrow_cast<port_8bit_type>(val)); }
113 
114  template<class P, class T,
115  class = typename std::enable_if<std::is_integral<P>::value>::type,
116  class = typename std::enable_if<std::is_integral<T>::value>::type>
117  void outw(P port, T val) noexcept { __outw(gsl::narrow_cast<port_addr_type>(port), gsl::narrow_cast<port_16bit_type>(val)); }
118 
119  template<class P, class T,
120  class = typename std::enable_if<std::is_integral<P>::value>::type,
121  class = typename std::enable_if<std::is_integral<T>::value>::type>
122  void outd(P port, T val) noexcept { __outd(gsl::narrow_cast<port_addr_type>(port), gsl::narrow_cast<port_32bit_type>(val)); }
123 
124  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
125  void outsb(P port, integer_pointer m8) noexcept { __outsb(gsl::narrow_cast<port_addr_type>(port), m8); }
126 
127  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
128  void outsw(P port, integer_pointer m16) noexcept { __outsw(gsl::narrow_cast<port_addr_type>(port), m16); }
129 
130  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
131  void outsd(P port, integer_pointer m32) noexcept { __outsd(gsl::narrow_cast<port_addr_type>(port), m32); }
132 
133  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
134  void outsb(P port, void *m8) noexcept { __outsb(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m8)); }
135 
136  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
137  void outsw(P port, void *m16) noexcept { __outsw(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m16)); }
138 
139  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
140  void outsd(P port, void *m32) noexcept { __outsd(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m32)); }
141 
142  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
143  void outsbrep(P port, integer_pointer m8, size_type count) noexcept { __outsbrep(gsl::narrow_cast<port_addr_type>(port), m8, count); }
144 
145  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
146  void outswrep(P port, integer_pointer m16, size_type count) noexcept { __outswrep(gsl::narrow_cast<port_addr_type>(port), m16, count); }
147 
148  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
149  void outsdrep(P port, integer_pointer m32, size_type count) noexcept { __outsdrep(gsl::narrow_cast<port_addr_type>(port), m32, count); }
150 
151  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
152  void outsbrep(P port, void *m8, size_type count) noexcept { __outsbrep(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m8), count); }
153 
154  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
155  void outswrep(P port, void *m16, size_type count) noexcept { __outswrep(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m16), count); }
156 
157  template<class P, class = typename std::enable_if<std::is_integral<P>::value>::type>
158  void outsdrep(P port, void *m32, size_type count) noexcept { __outsdrep(gsl::narrow_cast<port_addr_type>(port), reinterpret_cast<integer_pointer>(m32), count); }
159 }
160 }
161 
162 // *INDENT-ON*
163 
164 #endif
auto inb(P port) noexcept
Definition: portio_x64.h:65
void __outsb(uint16_t port, uint64_t m8) noexcept
uint32_t __ind(uint16_t port) noexcept
void outsb(P port, integer_pointer m8) noexcept
Definition: portio_x64.h:125
void __inswrep(uint16_t port, uint64_t m16, uint32_t count) noexcept
auto insbrep(P port, integer_pointer m8, size_type count) noexcept
Definition: portio_x64.h:92
void outw(P port, T val) noexcept
Definition: portio_x64.h:117
void outswrep(P port, integer_pointer m16, size_type count) noexcept
Definition: portio_x64.h:146
void outsbrep(P port, integer_pointer m8, size_type count) noexcept
Definition: portio_x64.h:143
void __insw(uint16_t port, uint64_t m16) noexcept
void __insdrep(uint16_t port, uint64_t m32, uint32_t count) noexcept
void outb(P port, T val) noexcept
Definition: portio_x64.h:112
auto insb(P port, integer_pointer m8) noexcept
Definition: portio_x64.h:74
void outd(P port, T val) noexcept
Definition: portio_x64.h:122
uint16_t port_16bit_type
Definition: portio_x64.h:59
auto insw(P port, integer_pointer m16) noexcept
Definition: portio_x64.h:77
void __outsdrep(uint16_t port, uint64_t m32, uint32_t count) noexcept
void outsw(P port, integer_pointer m16) noexcept
Definition: portio_x64.h:128
void __outsbrep(uint16_t port, uint64_t m8, uint32_t count) noexcept
uint16_t __inw(uint16_t port) noexcept
void uint64_t uint64_t uint64_t *rdx noexcept
auto inswrep(P port, integer_pointer m16, size_type count) noexcept
Definition: portio_x64.h:95
void __outd(uint16_t port, uint32_t val) noexcept
void __outsw(uint16_t port, uint64_t m16) noexcept
uint16_t port_addr_type
Definition: portio_x64.h:57
uint32_t size_type
Definition: portio_x64.h:62
void __insb(uint16_t port, uint64_t m8) noexcept
void outsdrep(P port, integer_pointer m32, size_type count) noexcept
Definition: portio_x64.h:149
void __insbrep(uint16_t port, uint64_t m8, uint32_t count) noexcept
uint8_t __inb(uint16_t port) noexcept
void __outw(uint16_t port, uint16_t val) noexcept
auto insdrep(P port, integer_pointer m32, size_type count) noexcept
Definition: portio_x64.h:98
uintptr_t integer_pointer
Definition: portio_x64.h:61
void outsd(P port, integer_pointer m32) noexcept
Definition: portio_x64.h:131
void __outsd(uint16_t port, uint64_t m32) noexcept
auto insd(P port, integer_pointer m32) noexcept
Definition: portio_x64.h:80
uint8_t port_8bit_type
Definition: portio_x64.h:58
void __outswrep(uint16_t port, uint64_t m16, uint32_t count) noexcept
Definition: cache_x64.h:31
auto inw(P port) noexcept
Definition: portio_x64.h:68
void __insd(uint16_t port, uint64_t m32) noexcept
auto ind(P port) noexcept
Definition: portio_x64.h:71
uint32_t port_32bit_type
Definition: portio_x64.h:60
void __outb(uint16_t port, uint8_t val) noexcept