IgrOS-Kernel 0.1.34.545
Simple C++20 Kernel for i386/x86_64
Loading...
Searching...
No Matches
io.hpp
Go to the documentation of this file.
1
11
12
13#pragma once
14
15
16// IgrOS-Kernel arch
17#include <arch/types.hpp>
18
19
20// x86 architecture namespace
21namespace igros::x86 {
22
23
26
27
28} // namespace igros::x86
29
30
31#ifdef __cplusplus
32
33extern "C" {
34
35#endif // __cplusplus
36
37
41 [[nodiscard]]
42 auto portRead8(const igros::x86::port_t addr) noexcept -> igros::igros_byte_t;
46 [[nodiscard]]
51 [[nodiscard]]
53
57 void portWrite8(const igros::x86::port_t addr, const igros::igros_byte_t value) noexcept;
61 void portWrite16(const igros::x86::port_t addr, const igros::igros_word_t value) noexcept;
65 void portWrite32(const igros::x86::port_t addr, const igros::igros_dword_t value) noexcept;
66
67
68#ifdef __cplusplus
69
70} // extern "C"
71
72#endif // __cplusplus
73
74
75// x86 architecture namespace
76namespace igros::x86 {
77
78
80 class io final {
81
82 public:
83
85 io() noexcept = default;
87 ~io() noexcept = default;
88
90 io(const io &other) = delete;
92 auto operator=(const io &other) -> io & = delete;
94 io(io &&other) = delete;
96 auto operator=(io &&other) -> io & = delete;
97
101 [[nodiscard]]
102 static auto readPort8(const port_t addr) noexcept -> igros_byte_t;
106 [[nodiscard]]
107 static auto readPort16(const port_t addr) noexcept -> igros_word_t;
111 [[nodiscard]]
112 static auto readPort32(const port_t addr) noexcept -> igros_dword_t;
113
117 static void writePort8(const port_t addr, const igros_byte_t value) noexcept;
121 static void writePort16(const port_t addr, const igros_word_t value) noexcept;
125 static void writePort32(const port_t addr, const igros_dword_t value) noexcept;
126
130 [[nodiscard]]
131 static auto readMemory8(const igros_byte_t* const addr) noexcept -> igros_byte_t;
135 [[nodiscard]]
136 static auto readMemory16(const igros_word_t* const addr) noexcept -> igros_word_t;
140 [[nodiscard]]
141 static auto readMemory32(const igros_dword_t* const addr) noexcept -> igros_dword_t;
142
146 static void writeMemory8(igros_byte_t* const addr, const igros_byte_t value) noexcept;
150 static void writeMemory16(igros_word_t* const addr, const igros_word_t value) noexcept;
154 static void writeMemory32(igros_dword_t* const addr, const igros_dword_t value) noexcept;
155 };
156
157
159 [[nodiscard]]
160 inline auto io::readPort8(const port_t addr) noexcept -> igros_byte_t {
161 return ::portRead8(addr);
162 }
163
165 [[nodiscard]]
166 inline auto io::readPort16(const port_t addr) noexcept -> igros_word_t {
167 return ::portRead16(addr);
168 }
169
171 [[nodiscard]]
172 inline auto io::readPort32(const port_t addr) noexcept -> igros_dword_t {
173 return ::portRead32(addr);
174 }
175
176
178 inline void io::writePort8(const port_t addr, const igros_byte_t value) noexcept {
179 ::portWrite8(addr, value);
180 }
181
183 inline void io::writePort16(const port_t addr, const igros_word_t value) noexcept {
184 ::portWrite16(addr, value);
185 }
186
188 inline void io::writePort32(const port_t addr, const igros_dword_t value) noexcept {
189 ::portWrite32(addr, value);
190 }
191
192
194 [[nodiscard]]
195 inline auto io::readMemory8(const igros_byte_t* const addr) noexcept -> igros_byte_t {
196 return *addr;
197 }
198
200 [[nodiscard]]
201 inline auto io::readMemory16(const igros_word_t* const addr) noexcept -> igros_word_t {
202 return *addr;
203 }
204
206 [[nodiscard]]
207 inline auto io::readMemory32(const igros_dword_t* const addr) noexcept -> igros_dword_t {
208 return *addr;
209 }
210
211
213 inline void io::writeMemory8(igros_byte_t* const addr, const igros_byte_t value) noexcept {
214 *addr = value;
215 }
216
218 inline void io::writeMemory16(igros_word_t* const addr, const igros_word_t value) noexcept {
219 *addr = value;
220 }
221
223 inline void io::writeMemory32(igros_dword_t* const addr, const igros_dword_t value) noexcept {
224 *addr = value;
225 }
226
227
228} // namespace igros::x86
229
io() noexcept=default
Default c-tor.
static void writeMemory8(igros_byte_t *const addr, const igros_byte_t value) noexcept
Write byte to memory.
Definition io.hpp:213
static void writePort32(const port_t addr, const igros_dword_t value) noexcept
Write long to port.
Definition io.hpp:188
static void writeMemory32(igros_dword_t *const addr, const igros_dword_t value) noexcept
Write long to memory.
Definition io.hpp:223
static auto readPort16(const port_t addr) noexcept -> igros_word_t
Read word from port.
Definition io.hpp:166
io() noexcept=default
Default c-tor.
static auto readMemory8(const igros_byte_t *const addr) noexcept -> igros_byte_t
Read byte from memory.
Definition io.hpp:195
static auto readPort32(const port_t addr) noexcept -> igros_dword_t
Read long from port.
Definition io.hpp:172
static auto readMemory16(const igros_word_t *const addr) noexcept -> igros_word_t
Read word from memory.
Definition io.hpp:201
static auto readMemory32(const igros_dword_t *const addr) noexcept -> igros_dword_t
Read long from memory.
Definition io.hpp:207
static void writePort16(const port_t addr, const igros_word_t value) noexcept
Write word to port.
Definition io.hpp:183
static auto readPort8(const port_t addr) noexcept -> igros_byte_t
Read byte from port.
Definition io.hpp:160
static void writeMemory16(igros_word_t *const addr, const igros_word_t value) noexcept
Write word to memory.
Definition io.hpp:218
static void writePort8(const port_t addr, const igros_byte_t value) noexcept
Write byte to port.
Definition io.hpp:178
std::uint16_t igros_word_t
16-bit unsigned integer
Definition types.hpp:42
std::uint8_t igros_byte_t
8-bit unsigned integer
Definition types.hpp:41
std::uint32_t igros_dword_t
32-bit unsigned integer
Definition types.hpp:43
Code shared by i386 and x86_64: ports, interrupts, exceptions, paging.
igros_word_t port_t
Define port data type which is 16bit word.
Definition io.hpp:25
Common C++ types redefinition.
auto portRead8(const igros::x86::port_t addr) noexcept -> igros::igros_byte_t
Read byte from port.
auto portRead16(const igros::x86::port_t addr) noexcept -> igros::igros_word_t
Read word from port.
auto portRead32(const igros::x86::port_t addr) noexcept -> igros::igros_dword_t
Read long from port.
void portWrite32(const igros::x86::port_t addr, const igros::igros_dword_t value) noexcept
Write long to port.
void portWrite16(const igros::x86::port_t addr, const igros::igros_word_t value) noexcept
Write word to port.
void portWrite8(const igros::x86::port_t addr, const igros::igros_byte_t value) noexcept
Write byte to port.