Basic serial support

This commit is contained in:
Baptiste Wicht 2016-07-02 15:04:00 +02:00
parent cda223cc11
commit 9efd6430c2
3 changed files with 54 additions and 1 deletions

20
kernel/include/serial.hpp Normal file
View File

@ -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

View File

@ -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();

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

@ -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);
}