Serial stdio

master
WangRunji 7 years ago
parent fc910d4b9d
commit 7f872901ce

@ -10,7 +10,7 @@ grub_cfg := $(boot_src)/grub.cfg
assembly_source_files := $(wildcard $(boot_src)/*.asm)
assembly_object_files := $(patsubst $(boot_src)/%.asm, \
build/arch/$(arch)/boot/%.o, $(assembly_source_files))
qemu_opts := -cdrom $(iso) -smp 2
qemu_opts := -cdrom $(iso) -smp 2 -serial stdio
ifdef travis
test := 1

@ -1,4 +1,5 @@
pub mod vga;
pub mod acpi;
pub mod ioapic;
pub mod mp;
pub mod mp;
pub mod serial;

@ -0,0 +1,49 @@
/*
* Rust BareBones OS
* - By John Hodge (Mutabah/thePowersGang)
*
* arch/x86/debug.rs
* - Debug output channel
*
* Writes debug to the standard PC serial port (0x3F8 .. 0x3FF)
*
* == LICENCE ==
* This code has been put into the public domain, there are no restrictions on
* its use, and the author takes no liability.
*/
use core::fmt;
use spin::Mutex;
use x86_64::instructions::port::{inb, outb};
pub static SERIAL: Mutex<Serial> = Mutex::new(Serial{});
pub struct Serial;
impl Serial {
/// Write a single byte to the output channel
pub fn write(&mut self, byte: u8) {
unsafe {
self.wait();
// Send the byte out the serial port
outb(0x3F8, byte);
// Also send to the bochs 0xe9 hack
outb(0xE9, byte);
}
}
/// Wait for the serial port's fifo to not be empty
unsafe fn wait(&self) {
while (inb(0x3F8+5) & 0x20) == 0 {}
}
}
impl fmt::Write for Serial {
fn write_str(&mut self, s: &str) -> fmt::Result {
for byte in s.bytes() {
self.write(byte)
}
Ok(())
}
}

@ -1,4 +1,5 @@
use core::fmt;
use arch::driver::serial::SERIAL;
mod vga_writer;
@ -32,6 +33,7 @@ fn print_in_color(args: fmt::Arguments, color: Color) {
let mut writer = vga_writer::VGA_WRITER.lock();
writer.set_color(color);
writer.write_fmt(args).unwrap();
SERIAL.lock().write_fmt(args).unwrap();
}
pub fn print(args: fmt::Arguments) {

Loading…
Cancel
Save