diff --git a/ableos/src/arch/riscv/drivers/serial.rs b/ableos/src/arch/riscv/drivers/serial.rs index da9bc6cd..fb274646 100644 --- a/ableos/src/arch/riscv/drivers/serial.rs +++ b/ableos/src/arch/riscv/drivers/serial.rs @@ -1,3 +1,7 @@ +use core::fmt::Arguments; +use core::fmt::Error; + +/// Prints to the host through the serial interface. #[macro_export] macro_rules! serial_print { ($($arg:tt)*) => {}; @@ -9,3 +13,28 @@ macro_rules! serial_println { ($fmt:expr) => {}; ($fmt:expr, $($arg:tt)*) => {}; } + +pub struct Serial123 { + uart_data: u32, +} + +impl Serial123 { + pub fn out(&mut self, s: ::core::fmt::Arguments) { + let uart_data = 0x10000000 as *mut u8; + for c in b"Hello, world!\n" { + unsafe { uart_data.write_volatile(*c) }; + } + } +} + +use spin::Mutex; + +use lazy_static::lazy_static; +lazy_static! { + pub static ref SERIAL: Mutex = { + let serial_port = Serial123 { + uart_data: 0x10000000, + }; + Mutex::new(serial_port) + }; +} diff --git a/ableos/src/arch/riscv/mod.rs b/ableos/src/arch/riscv/mod.rs index 73686376..5ae03499 100644 --- a/ableos/src/arch/riscv/mod.rs +++ b/ableos/src/arch/riscv/mod.rs @@ -29,13 +29,10 @@ unsafe extern "C" fn _boot() -> ! { ", sym _start, options(noreturn)); } - +use crate::serial::SERIAL; extern "C" fn _start() -> ! { - let uart_data = 0x10000000 as *mut u8; - for c in b"Hello, world!\n" { - unsafe { uart_data.write_volatile(*c) }; - } - + SERIAL.lock().out(format_args!("Hi")); + // Serial123::out(); sloop() } diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index 3cdad2d4..a7b35076 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -49,8 +49,7 @@ fn main() -> anyhow::Result<()> { -kernel target/aarch64-ableos/release/ableos -device virtio-keyboard " - ) - .run()?; + ).run()?; } MachineType::RISCV => { xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf")