rustubs/machine/
serial.rs

1//! serial output through port 3f8 (qemu), stateless, non-blocking, non-locking,
2//! not thread safe.
3
4use crate::machine::device_io::IOPort;
5use core::{fmt, str};
6pub struct SerialWritter {
7	port: IOPort,
8}
9
10impl SerialWritter {
11	pub const fn new(port: u16) -> Self { Self { port: IOPort::new(port) } }
12
13	pub fn putchar(&self, ch: char) { self.port.outb(ch as u8); }
14
15	pub fn print(&self, s: &str) {
16		for c in s.bytes() {
17			self.putchar(c as char);
18		}
19	}
20}
21
22impl fmt::Write for SerialWritter {
23	fn write_str(&mut self, s: &str) -> fmt::Result {
24		self.print(s);
25		Ok(())
26	}
27}