diff options
| author | Tianhao Wang <shrik3@mailbox.org> | 2024-06-06 00:02:53 +0200 |
|---|---|---|
| committer | Tianhao Wang <shrik3@mailbox.org> | 2024-06-11 15:17:14 +0200 |
| commit | a86f59b32eb86a1ccb94bf1e627c1115c3b6b217 (patch) | |
| tree | a3b1c10ad4fa76be79aed1f7e8eebbd2cfa146aa | |
| parent | ca8bc76fd5319842954508484542f4beb6b591d0 (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...).
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | src/lib.rs | 4 | ||||
| -rw-r--r-- | src/machine/device_io.rs | 2 | ||||
| -rw-r--r-- | src/machine/mod.rs | 1 | ||||
| -rw-r--r-- | src/machine/serial.rs | 16 |
5 files changed, 23 insertions, 4 deletions
@@ -93,14 +93,14 @@ clean: rm -f build/* qemu: bootdisk.iso - qemu-system-x86_64 -drive file=./bootdisk.iso,format=raw -k en-us + qemu-system-x86_64 -drive file=./bootdisk.iso,format=raw -k en-us -serial mon:stdio gdb: gdb -x /tmp/gdbcommands.$(shell id -u) build/kernel qemu-gdb: bootdisk.iso @echo "target remote localhost:$(shell echo $$(( $$(id -u) % (65536 - 1024) + 1024 )))" > /tmp/gdbcommands.$(shell id -u) - @qemu-system-x86_64 -drive file=bootdisk.iso,format=raw -k en-us -S -gdb tcp::$(shell echo $$(( $$(id -u) % (65536 - 1024) + 1024 ))) + @qemu-system-x86_64 -drive file=bootdisk.iso,format=raw -k en-us -S -gdb tcp::$(shell echo $$(( $$(id -u) % (65536 - 1024) + 1024 ))) -serial mon:stdio test: @echo "---BUILD DIR---" @@ -9,7 +9,6 @@ mod ds; mod io; mod machine; mod mm; -use crate::machine::key::Modifiers; mod proc; extern crate alloc; use alloc::vec::Vec; @@ -19,7 +18,9 @@ use arch::x86_64::interrupt::pic_8259::PicDeviceInt; use core::panic::PanicInfo; use defs::*; use machine::cgascr::CGAScreen; +use machine::key::Modifiers; use machine::multiboot; +use machine::serial::Serial; #[cfg(not(test))] #[panic_handler] @@ -61,6 +62,7 @@ pub extern "C" fn _entry() -> ! { for s in test_vec.iter() { println!("{s}"); } + Serial::print("hello from serial"); loop { io::KBCTL_GLOBAL.lock().fetch_key(); if let Some(k) = io::KBCTL_GLOBAL.lock().consume_key() { diff --git a/src/machine/device_io.rs b/src/machine/device_io.rs index 2a0c907..9a530f1 100644 --- a/src/machine/device_io.rs +++ b/src/machine/device_io.rs @@ -4,7 +4,7 @@ pub use crate::arch::x86_64::io_port::*; // either use the io functions directly, or via a IOPort instance. pub struct IOPort(u16); impl IOPort { - pub fn new(port: u16) -> Self { + pub const fn new(port: u16) -> Self { Self(port) } pub fn inw(&self) -> u16 { diff --git a/src/machine/mod.rs b/src/machine/mod.rs index a2cf730..b2b026f 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -5,5 +5,6 @@ pub mod key; pub mod keyctrl; pub mod mem; pub mod multiboot; +pub mod serial; // TODO: this module *should* be arch independent. 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); + } + } +} |
