From b6ba831ea0cecfcd4bc5edd3530caaf32711ec6f Mon Sep 17 00:00:00 2001 From: Able Date: Thu, 18 Nov 2021 00:35:50 -0600 Subject: [PATCH] Setting up serial to be out putted to more easily --- ableos/src/arch/riscv/drivers/serial.rs | 29 +++++++++++++++++++++++++ ableos/src/arch/riscv/mod.rs | 9 +++----- repbuild/src/main.rs | 3 +-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/ableos/src/arch/riscv/drivers/serial.rs b/ableos/src/arch/riscv/drivers/serial.rs index da9bc6c..fb27464 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 7368637..5ae0349 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 3cdad2d..a7b3507 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")