diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-02-12 17:55:31 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-02-12 17:55:31 +0200 |
commit | 46a5f1ee4db70a037af5038deaa1d64ad0f7862c (patch) | |
tree | 0250b88f2eb69a7a0987a78d23a06e2125df74a2 /drivers/serial.h | |
parent | Add comments to explain CGA ports better (diff) | |
download | kernel.cpp-46a5f1ee4db70a037af5038deaa1d64ad0f7862c.tar.xz |
Add serial0 console output
Diffstat (limited to 'drivers/serial.h')
-rw-r--r-- | drivers/serial.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/serial.h b/drivers/serial.h new file mode 100644 index 0000000..0579dd4 --- /dev/null +++ b/drivers/serial.h @@ -0,0 +1,47 @@ +#pragma once + +#include <stdlib.h> +#include "ports.h" + +/* + * Serial Port + * + * useful links: + * https://wiki.osdev.org/Serial_Ports + * https://www.lowlevel.eu/wiki/Serielle_Schnittstelle + */ + +class SerialPort : public Console { +public: + SerialPort(); + ~SerialPort() = default; + + bool ready_read(); + uint8_t read(); + + bool ready_write(); + void write(char c) override; + void write(ViewIterator& iter) override { + while (iter) { + write(iter.next()); + } + } + + void update_cursor() override {} + +private: + enum PortOffset : uint16_t { + BaudDiv_l = 0, // if dlab is set + BaudDiv_h = 1, // if dlab is set + Data = 0, // read from receive buffer / write to transmit buffer + InterruptControl = 1, // interrupt enable + FifoControl = 2, // interrupt ID and FIFO control + LineControl = 3, // most significant bit is the DLAB + ModemControl = 4, + LineStatus = 5, + ModemStatus = 6, + Scratch = 7, + }; + + com1_port_t port; +}; |