1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * 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 arch::cpu;
use libc::c_char;
use mutex::{StaticMutex,STATIC_MUTEX_INIT};

static MUTEX: StaticMutex = STATIC_MUTEX_INIT;

unsafe fn putb(b: u8) {
    // Wait for the serial port's fifo to not be empty
    while (cpu::inb(0x3F8+5) & 0x20) == 0 {
        // Do nothing
    }

    // Send the byte out the serial port
    cpu::outb(0x3F8, b);
    
    // Also send to the bochs 0xe9 hack
    cpu::outb(0xe9, b);
}

pub fn puts(s: &str) {
    let _x = lock!(MUTEX);
	for b in s.bytes() {
		unsafe { putb(b) };
	}
}

pub unsafe fn put_cstr(s: *const c_char) {
    let _x = lock!(MUTEX);
    let mut s = s;
    while *s != 0 {
        putb(*s as u8);
        s = s.offset(1);
    }
}