diff --git a/src/kernel/console.cpp b/src/kernel/console.cpp index 540fae4..1a5c9eb 100644 --- a/src/kernel/console.cpp +++ b/src/kernel/console.cpp @@ -1,4 +1,5 @@ #include "console.h" +#include "io.h" const char digits[] = "0123456789abcdef"; @@ -80,6 +81,18 @@ console::console(const font &f, const screen &s, void *scratch, size_t len) : default_console = this; } +static bool +serial_ready() +{ + return (inb(COM1 + 5) & 0x20) != 0; +} + +static void +serial_write(char c) { + while (!serial_ready()); + outb(COM1, c); +} + char * console::line_pointer(unsigned line) { @@ -171,6 +184,7 @@ console::puts(const char *message) break; case '\n': + serial_write('\r'); m_pos.x = 0; m_pos.y++; break; @@ -191,6 +205,7 @@ console::puts(const char *message) scroll(1); line = line_pointer(m_pos.y); } + serial_write(c); } return count; diff --git a/src/kernel/io.cpp b/src/kernel/io.cpp new file mode 100644 index 0000000..c75949a --- /dev/null +++ b/src/kernel/io.cpp @@ -0,0 +1,16 @@ +#include "io.h" + +uint8_t +inb(uint16_t port) +{ + uint8_t val; + __asm__ __volatile__ ( "inb %1, %0" : "=a"(val) : "Nd"(port) ); + return val; +} + +void +outb(uint16_t port, uint8_t val) +{ + __asm__ __volatile__ ( "outb %0, %1" :: "a"(val), "Nd"(port) ); +} + diff --git a/src/kernel/io.h b/src/kernel/io.h new file mode 100644 index 0000000..da34a07 --- /dev/null +++ b/src/kernel/io.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +extern "C" { + +/// Read a byte from an IO port. +/// \arg port The address of the IO port +/// \returns One byte read from the port +uint8_t inb(uint16_t port); + +/// Write a byte to an IO port. +/// \arg port The addres of the IO port +/// \arg val The byte to write +void outb(uint16_t port, uint8_t val); + +} + +const uint16_t COM1 = 0x03f8;