Remove interrupt setup from asm bootloader, add io module, memcpy functions, and serial driver
This commit is contained in:
parent
799b77d11a
commit
42c9ba12dc
1 changed files with 422 additions and 264 deletions
39
src/arch/x86_64/serial.rs
Normal file
39
src/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