mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
Add stupid first serial output
This commit is contained in:
@@ -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;
|
||||
|
||||
16
src/kernel/io.cpp
Normal file
16
src/kernel/io.cpp
Normal 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
19
src/kernel/io.h
Normal 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;
|
||||
Reference in New Issue
Block a user