Add beginning basic serial driver

This commit is contained in:
Justin C. Miller
2018-05-03 00:08:22 -07:00
parent 59700b07db
commit d9fe457b44
6 changed files with 128 additions and 38 deletions

31
src/kernel/serial.cpp Normal file
View File

@@ -0,0 +1,31 @@
#include "io.h"
#include "serial.h"
serial_port g_com1;
serial_port::serial_port() :
m_port(0)
{
}
serial_port::serial_port(uint16_t port) :
m_port(port)
{
}
bool serial_port::read_ready() { return (inb(m_port + 5) & 0x01) != 0; }
bool serial_port::write_ready() { return (inb(m_port + 5) & 0x20) != 0; }
char
serial_port::read() {
while (!read_ready());
return inb(m_port);
}
void
serial_port::write(char c) {
while (!write_ready());
outb(m_port, c);
}