aboutsummaryrefslogtreecommitdiff
path: root/src/machine/serial.rs
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@mailbox.org>2024-06-06 00:02:53 +0200
committerTianhao Wang <shrik3@mailbox.org>2024-06-11 15:17:14 +0200
commita86f59b32eb86a1ccb94bf1e627c1115c3b6b217 (patch)
treea3b1c10ad4fa76be79aed1f7e8eebbd2cfa146aa /src/machine/serial.rs
parentca8bc76fd5319842954508484542f4beb6b591d0 (diff)
io: add serial output through port 0x3f8 (qemu)
not yet wrapped with fmt macros because I want some thing stateless. (i.e. I don't want to pass `&mut self` to write_str...).
Diffstat (limited to 'src/machine/serial.rs')
-rw-r--r--src/machine/serial.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/machine/serial.rs b/src/machine/serial.rs
new file mode 100644
index 0000000..edb18c0
--- /dev/null
+++ b/src/machine/serial.rs
@@ -0,0 +1,16 @@
+use crate::machine::device_io::IOPort;
+use core::{fmt, str};
+/// serial output through port 3f8 (qemu), stateless, not thread safe.
+pub struct Serial {}
+impl Serial {
+ const PORT: IOPort = IOPort::new(0x3f8);
+ pub fn putchar(ch: char) {
+ Self::PORT.outb(ch as u8);
+ }
+
+ pub fn print(s: &str) {
+ for c in s.bytes() {
+ Self::putchar(c as char);
+ }
+ }
+}