Skip to content

Commit

Permalink
Implement core::fmt::Write for VirtIOConsole.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Aug 6, 2024
1 parent 0319e11 commit 8371d5d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/device/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use crate::volatile::{volread, ReadOnly, WriteOnly};
use crate::{Result, PAGE_SIZE};
use alloc::boxed::Box;
use bitflags::bitflags;
use core::ptr::NonNull;
use core::{
fmt::{self, Write},
ptr::NonNull,
};
use log::error;

const QUEUE_RECEIVEQ_PORT_0: u16 = 0;
const QUEUE_TRANSMITQ_PORT_0: u16 = 1;
Expand Down Expand Up @@ -230,6 +234,15 @@ impl<H: Hal, T: Transport> VirtIOConsole<H, T> {
}
}

impl<H: Hal, T: Transport> Write for VirtIOConsole<H, T> {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.send_bytes(s.as_bytes()).map_err(|e| {
error!("Error writing to conosel: {}", e);
fmt::Error
})
}
}

impl<H: Hal, T: Transport> Drop for VirtIOConsole<H, T> {
fn drop(&mut self) {
// Clear any pointers pointing to DMA regions, so the device doesn't try to access them
Expand Down

0 comments on commit 8371d5d

Please sign in to comment.