Rename the src directory to kernel.
This commit is contained in:
parent
7b8ba1a118
commit
f8bd171efd
1 changed files with 0 additions and 0 deletions
39
kernel/arch/x86_64/serial.rs
Normal file
39
kernel/arch/x86_64/serial.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
use core::fmt;
|
||||
use super::io::{Io, Pio};
|
||||
|
||||
pub struct SerialConsole {
|
||||
status: Pio<u8>,
|
||||
data: Pio<u8>
|
||||
}
|
||||
|
||||
impl SerialConsole {
|
||||
pub fn new() -> SerialConsole {
|
||||
SerialConsole {
|
||||
status: Pio::new(0x3F8 + 5),
|
||||
data: Pio::new(0x3F8)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write(&mut self, bytes: &[u8]) {
|
||||
for byte in bytes.iter() {
|
||||
while !self.status.readf(0x20) {}
|
||||
self.data.write(*byte);
|
||||
|
||||
if *byte == 8 {
|
||||
while !self.status.readf(0x20) {}
|
||||
self.data.write(0x20);
|
||||
|
||||
while !self.status.readf(0x20) {}
|
||||
self.data.write(8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Write for SerialConsole {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
|
||||
self.write(s.as_bytes());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue