diff options
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Devices/SerialDevice.cpp | 28 | ||||
-rw-r--r-- | Kernel/Devices/SerialDevice.h | 5 | ||||
-rw-r--r-- | Kernel/init.cpp | 8 |
3 files changed, 21 insertions, 20 deletions
diff --git a/Kernel/Devices/SerialDevice.cpp b/Kernel/Devices/SerialDevice.cpp index 7daec69cd7..d3bb36e166 100644 --- a/Kernel/Devices/SerialDevice.cpp +++ b/Kernel/Devices/SerialDevice.cpp @@ -10,7 +10,7 @@ namespace Kernel { -UNMAP_AFTER_INIT SerialDevice::SerialDevice(u32 base_addr, unsigned minor) +UNMAP_AFTER_INIT SerialDevice::SerialDevice(IOAddress base_addr, unsigned minor) : CharacterDevice(4, minor) , m_base_addr(base_addr) { @@ -36,7 +36,7 @@ KResultOr<size_t> SerialDevice::read(FileDescription&, u64, UserOrKernelBuffer& return buffer.write_buffered<128>(size, [&](u8* data, size_t data_size) { for (size_t i = 0; i < data_size; i++) - data[i] = IO::in8(m_base_addr); + data[i] = m_base_addr.in<u8>(); return data_size; }); } @@ -67,9 +67,9 @@ void SerialDevice::put_char(char ch) ; if (ch == '\n' && !m_last_put_char_was_carriage_return) - IO::out8(m_base_addr, '\r'); + m_base_addr.out<u8>('\r'); - IO::out8(m_base_addr, ch); + m_base_addr.out<u8>(ch); m_last_put_char_was_carriage_return = (ch == '\r'); } @@ -92,24 +92,24 @@ UNMAP_AFTER_INIT void SerialDevice::set_interrupts(bool interrupt_enable) { m_interrupt_enable = interrupt_enable; - IO::out8(m_base_addr + 1, interrupt_enable); + m_base_addr.offset(1).out<u8>(interrupt_enable); } void SerialDevice::set_baud(Baud baud) { m_baud = baud; - IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) | 0x80); // turn on DLAB - IO::out8(m_base_addr + 0, ((u8)(baud)) & 0xff); // lower half of divisor - IO::out8(m_base_addr + 1, ((u8)(baud)) >> 2); // upper half of divisor - IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) & 0x7f); // turn off DLAB + m_base_addr.offset(3).out<u8>(m_base_addr.offset(3).in<u8>() | 0x80); // turn on DLAB + m_base_addr.out<u8>(((u8)(baud)) & 0xff); // lower half of divisor + m_base_addr.offset(1).out<u8>(((u8)(baud)) >> 2); // upper half of divisor + m_base_addr.offset(3).out<u8>(m_base_addr.offset(3).in<u8>() & 0x7f); // turn off DLAB } void SerialDevice::set_fifo_control(u8 fifo_control) { m_fifo_control = fifo_control; - IO::out8(m_base_addr + 2, fifo_control); + m_base_addr.offset(2).out<u8>(fifo_control); } void SerialDevice::set_line_control(ParitySelect parity_select, StopBits stop_bits, WordLength word_length) @@ -118,26 +118,26 @@ void SerialDevice::set_line_control(ParitySelect parity_select, StopBits stop_bi m_stop_bits = stop_bits; m_word_length = word_length; - IO::out8(m_base_addr + 3, (IO::in8(m_base_addr + 3) & ~0x3f) | parity_select | stop_bits | word_length); + m_base_addr.offset(3).out<u8>((m_base_addr.offset(3).in<u8>() & ~0x3f) | parity_select | stop_bits | word_length); } void SerialDevice::set_break_enable(bool break_enable) { m_break_enable = break_enable; - IO::out8(m_base_addr + 3, IO::in8(m_base_addr + 3) & (break_enable ? 0xff : 0xbf)); + m_base_addr.offset(3).out<u8>(m_base_addr.offset(3).in<u8>() & (break_enable ? 0xff : 0xbf)); } void SerialDevice::set_modem_control(u8 modem_control) { m_modem_control = modem_control; - IO::out8(m_base_addr + 4, modem_control); + m_base_addr.offset(4).out<u8>(modem_control); } u8 SerialDevice::get_line_status() const { - return IO::in8(m_base_addr + 5); + return m_base_addr.offset(5).in<u8>(); } } diff --git a/Kernel/Devices/SerialDevice.h b/Kernel/Devices/SerialDevice.h index 1bd05c944b..5a7182d972 100644 --- a/Kernel/Devices/SerialDevice.h +++ b/Kernel/Devices/SerialDevice.h @@ -7,6 +7,7 @@ #pragma once #include <Kernel/Devices/CharacterDevice.h> +#include <Kernel/IO.h> namespace Kernel { @@ -18,7 +19,7 @@ namespace Kernel { class SerialDevice final : public CharacterDevice { AK_MAKE_ETERNAL public: - SerialDevice(u32 base_addr, unsigned minor); + SerialDevice(IOAddress base_addr, unsigned minor); virtual ~SerialDevice() override; // ^CharacterDevice @@ -122,7 +123,7 @@ private: void set_modem_control(u8 modem_control); u8 get_line_status() const; - u32 m_base_addr { 0 }; + IOAddress m_base_addr; bool m_interrupt_enable { false }; u8 m_fifo_control { 0 }; Baud m_baud { Baud38400 }; diff --git a/Kernel/init.cpp b/Kernel/init.cpp index 56b4f394d8..207242df66 100644 --- a/Kernel/init.cpp +++ b/Kernel/init.cpp @@ -157,10 +157,10 @@ extern "C" UNMAP_AFTER_INIT [[noreturn]] void init() NullDevice::initialize(); if (!get_serial_debug()) - new SerialDevice(SERIAL_COM1_ADDR, 64); - new SerialDevice(SERIAL_COM2_ADDR, 65); - new SerialDevice(SERIAL_COM3_ADDR, 66); - new SerialDevice(SERIAL_COM4_ADDR, 67); + new SerialDevice(IOAddress(SERIAL_COM1_ADDR), 64); + new SerialDevice(IOAddress(SERIAL_COM2_ADDR), 65); + new SerialDevice(IOAddress(SERIAL_COM3_ADDR), 66); + new SerialDevice(IOAddress(SERIAL_COM4_ADDR), 67); VMWareBackdoor::the(); // don't wait until first mouse packet HIDManagement::initialize(); |