Add stupid first serial output

This commit is contained in:
Justin C. Miller
2018-04-23 10:22:02 -07:00
parent 1113164505
commit ef24894211
3 changed files with 50 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
#include "console.h" #include "console.h"
#include "io.h"
const char digits[] = "0123456789abcdef"; const char digits[] = "0123456789abcdef";
@@ -80,6 +81,18 @@ console::console(const font &f, const screen &s, void *scratch, size_t len) :
default_console = this; 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 * char *
console::line_pointer(unsigned line) console::line_pointer(unsigned line)
{ {
@@ -171,6 +184,7 @@ console::puts(const char *message)
break; break;
case '\n': case '\n':
serial_write('\r');
m_pos.x = 0; m_pos.x = 0;
m_pos.y++; m_pos.y++;
break; break;
@@ -191,6 +205,7 @@ console::puts(const char *message)
scroll(1); scroll(1);
line = line_pointer(m_pos.y); line = line_pointer(m_pos.y);
} }
serial_write(c);
} }
return count; return count;

16
src/kernel/io.cpp Normal file
View File

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

19
src/kernel/io.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include <stdint.h>
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;