serial_port_intel_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 SERIAL_PORT_INTEL_X64_H
23 #define SERIAL_PORT_INTEL_X64_H
24 
25 #include <string>
26 #include <memory>
27 
28 #include <constants.h>
29 #include <intrinsics/portio_x64.h>
30 
32 {
33 constexpr const x64::portio::port_8bit_type dlab = 1U << 7;
34 
41 
46 
55 
59 }
60 
75 {
76 public:
77 
80 
82  {
83  baud_rate_50 = 0x0900,
84  baud_rate_75 = 0x0600,
85  baud_rate_110 = 0x0417,
86  baud_rate_150 = 0x0300,
87  baud_rate_300 = 0x0180,
88  baud_rate_600 = 0x00C0,
89  baud_rate_1200 = 0x0060,
90  baud_rate_1800 = 0x0040,
91  baud_rate_2000 = 0x003A,
92  baud_rate_2400 = 0x0030,
93  baud_rate_3600 = 0x0020,
94  baud_rate_4800 = 0x0018,
95  baud_rate_7200 = 0x0010,
96  baud_rate_9600 = 0x000C,
97  baud_rate_19200 = 0x0006,
98  baud_rate_38400 = 0x0003,
99  baud_rate_57600 = 0x0002,
101  };
102 
104  {
109  };
110 
112  {
113  stop_bits_1 = 0x00,
114  stop_bits_2 = 0x04
115  };
116 
118  {
119  parity_none = 0x00,
120  parity_odd = 0x08,
121  parity_even = 0x18,
122  parity_mark = 0x28,
124  };
125 
126 public:
127 
134 
140  ~serial_port_intel_x64() = default;
141 
150 
164 
176  baud_rate_t baud_rate() const noexcept;
177 
188  void set_data_bits(data_bits_t bits) noexcept;
189 
197  data_bits_t data_bits() const noexcept;
198 
209  void set_stop_bits(stop_bits_t bits) noexcept;
210 
218  stop_bits_t stop_bits() const noexcept;
219 
230  void set_parity_bits(parity_bits_t bits) noexcept;
231 
239  parity_bits_t parity_bits() const noexcept;
240 
248  port_type port() const noexcept
249  { return m_port; }
250 
260  void write(char c) noexcept;
261 
271  void write(const std::string &str) noexcept
272  {
273  for (auto c : str)
274  write(c);
275  }
276 
277 private:
278 
279  void enable_dlab() const noexcept;
280  void disable_dlab() const noexcept;
281 
282  bool get_line_status_empty_transmitter() const noexcept;
283 
284 private:
285 
286  port_type m_port;
287 
288 public:
289 
290  serial_port_intel_x64(serial_port_intel_x64 &&) noexcept = default;
291  serial_port_intel_x64 &operator=(serial_port_intel_x64 &&) noexcept = default;
293  serial_port_intel_x64 &operator=(const serial_port_intel_x64 &) = delete;
294 };
295 
296 #endif
constexpr const x64::portio::port_8bit_type line_status_overrun_error
constexpr const x64::portio::port_8bit_type line_status_empty_data
constexpr const x64::portio::port_8bit_type dlab
parity_bits_t parity_bits() const noexcept
void set_parity_bits(parity_bits_t bits) noexcept
baud_rate_t baud_rate() const noexcept
constexpr const x64::portio::port_8bit_type line_status_break_interrupt
constexpr const x64::portio::port_8bit_type line_control_parity_mask
x64::portio::port_8bit_type value_type
constexpr const x64::portio::port_8bit_type line_control_stop_mask
serial_port_intel_x64(port_type port=DEFAULT_COM_PORT) noexcept
#define DEFAULT_COM_PORT
Definition: constants.h:289
data_bits_t data_bits() const noexcept
void write(char c) noexcept
constexpr const x64::portio::port_8bit_type line_status_empty_transmitter
constexpr const x64::portio::port_8bit_type fifo_control_clear_transmit_fifo
constexpr const x64::portio::port_addr_type line_status_reg
constexpr const x64::portio::port_8bit_type line_control_data_mask
constexpr const x64::portio::port_8bit_type line_status_recieved_fifo_error
constexpr const x64::portio::port_8bit_type fifo_control_dma_mode_select
void uint64_t uint64_t uint64_t *rdx noexcept
~serial_port_intel_x64()=default
constexpr const x64::portio::port_8bit_type line_status_framing_error
uint16_t port_addr_type
Definition: portio_x64.h:57
void set_stop_bits(stop_bits_t bits) noexcept
constexpr const x64::portio::port_addr_type baud_rate_lo_reg
x64::portio::port_addr_type port_type
constexpr const x64::portio::port_8bit_type line_status_parity_error
port_type port() const noexcept
void set_baud_rate(baud_rate_t rate) noexcept
void write(const std::string &str) noexcept
static serial_port_intel_x64 * instance() noexcept
constexpr const x64::portio::port_addr_type line_control_reg
constexpr const x64::portio::port_addr_type baud_rate_hi_reg
uint8_t port_8bit_type
Definition: portio_x64.h:58
void set_data_bits(data_bits_t bits) noexcept
stop_bits_t stop_bits() const noexcept
constexpr const x64::portio::port_8bit_type fifo_control_enable_fifos
constexpr const x64::portio::port_8bit_type line_status_data_ready
constexpr const x64::portio::port_addr_type fifo_control_reg
constexpr const x64::portio::port_8bit_type fifo_control_clear_recieve_fifo
constexpr const x64::portio::port_addr_type interrupt_en_reg