diff --git a/kernel/include/serial.hpp b/kernel/include/serial.hpp new file mode 100644 index 00000000..78b1dc3b --- /dev/null +++ b/kernel/include/serial.hpp @@ -0,0 +1,20 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#ifndef SERIAL_H +#define SERIAL_H + +namespace serial { + +void init(); + +bool is_transmit_buffer_empty(); +void transmit(char a); + +} //end of serial namespace + +#endif diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index d4893b57..9cc92c7a 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -12,6 +12,7 @@ #include "kalloc.hpp" #include "timer.hpp" #include "keyboard.hpp" +#include "serial.hpp" #include "disks.hpp" #include "acpi.hpp" #include "interrupts.hpp" @@ -85,6 +86,7 @@ void kernel_main(){ kalloc::finalize(); //Install drivers + serial::init(); timer::install(); //acpi::init(); keyboard::install_driver(); @@ -94,7 +96,7 @@ void kernel_main(){ vfs::init(); //Starting from here, the logging system can output logs to file - logging::to_file(); + //TODO logging::to_file(); //Only install system calls when everything else is ready install_system_calls(); diff --git a/kernel/src/serial.cpp b/kernel/src/serial.cpp new file mode 100644 index 00000000..b15b1300 --- /dev/null +++ b/kernel/src/serial.cpp @@ -0,0 +1,31 @@ +//======================================================================= +// Copyright Baptiste Wicht 2013-2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +//======================================================================= + +#include "serial.hpp" +#include "kernel_utils.hpp" + +#define COM1_PORT 0x3f8 + +void serial::init() { + out_byte(COM1_PORT + 1, 0x00); // Disable all interrupts + out_byte(COM1_PORT + 3, 0x80); // Enable DLAB + out_byte(COM1_PORT + 0, 0x03); // 38400 baud + out_byte(COM1_PORT + 1, 0x00); + out_byte(COM1_PORT + 3, 0x03); // 8 bits, no parity, one stop bit + out_byte(COM1_PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold + out_byte(COM1_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set +} + +bool serial::is_transmit_buffer_empty() { + return in_byte(COM1_PORT + 5) & 0x20; +} + +void serial::transmit(char a) { + while (is_transmit_buffer_empty() == 0){} + + out_byte(COM1_PORT,a); +}