Patch| Serial out agnostic

This commit is contained in:
Able 2022-03-11 17:13:41 -06:00
parent d2638b1fb4
commit c18035feb4
12 changed files with 92 additions and 96 deletions

View file

@ -10,8 +10,6 @@ panic = "abort"
[package.metadata.bootimage] [package.metadata.bootimage]
run-args = [ run-args = [
"--nodefaults", "--nodefaults",
"-cpu", "-cpu",
"Broadwell-v3", "Broadwell-v3",
@ -20,13 +18,9 @@ run-args = [
"-smp", "-smp",
"cores=2", "cores=2",
"-device", #"ati-vga", "-device", #"ati-vga",
"cirrus-vga", "cirrus-vga",
# "-device", # "-device",
# "virtio-blk-pci,drive=drive0,id=virtblk0,num-queues=4", # "virtio-blk-pci,drive=drive0,id=virtblk0,num-queues=4",
# A simple example of a boot image # A simple example of a boot image
@ -48,27 +42,16 @@ test-args = [
] ]
[dependencies] [dependencies]
linked_list_allocator = "0.9.0" linked_list_allocator = "0.9.0"
lliw = "0.2.0" lliw = "0.2.0"
# qoi_rs = "*"
spin = "0.5.2" spin = "0.5.2"
# vga = "*"
log = "*" log = "*"
pretty-hex = "0.2.1" pretty-hex = "0.2.1"
unicode-width = "0.1.7" unicode-width = "0.1.7"
picorand = "*" picorand = "*"
watson = "0.4" watson = "0.4"
genfs = "0.1.0" genfs = "0.1.0"
# pc-beeper = "0.1.0"
rhai = "1.5" rhai = "1.5"
# pci = {git="https://gitlab.com/robigalia/pci"}
libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"} libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"}
acpi = "4.1.0" acpi = "4.1.0"
@ -77,12 +60,10 @@ version = "0.12.0"
default-features = false default-features = false
features = ["export_derive"] features = ["export_derive"]
[dependencies.rdrand] [dependencies.rdrand]
version = "0.8.1" version = "0.8.1"
default-features = false default-features = false
[dependencies.kernel] [dependencies.kernel]
path = "../kernel" path = "../kernel"
@ -91,10 +72,6 @@ version = "*"
default-features = false default-features = false
features = ["derive", "alloc"] features = ["derive", "alloc"]
[dependencies.hashbrown] [dependencies.hashbrown]
version = "0.7.2" version = "0.7.2"
default-features = false default-features = false

View file

@ -128,27 +128,3 @@ impl Write for Uart {
Ok(()) Ok(())
} }
} }
// ///////////////////////////////////
// / RUST MACROS
// ///////////////////////////////////
#[macro_export]
macro_rules! sprint
{
($($args:tt)+) => ({
use core::fmt::Write;
let _ = write!(crate::arch::drivers::uart::Uart::new(0x1000_0000), $($args)+);
});
}
#[macro_export]
macro_rules! sprintln
{
() => ({
sprint!("\r\n")
});
($fmt:expr) => (sprint!(concat!($fmt, "\r\n")));
($fmt:expr, $($args:tt)+) => ({
sprint!(concat!($fmt, "\r\n"), $($args)+)
});
}

View file

@ -33,8 +33,8 @@ unsafe extern "C" fn _boot() -> ! {
extern "C" fn _start() -> ! { extern "C" fn _start() -> ! {
let uart = crate::arch::drivers::uart::Uart::new(0x1000_0000); let uart = crate::arch::drivers::uart::Uart::new(0x1000_0000);
uart.init(); uart.init();
use crate::serial_println;
println!("Hello, world!"); serial_println!("Hello, world!\r");
loop { loop {
if let Some(c) = uart.get() { if let Some(c) = uart.get() {
@ -52,7 +52,7 @@ extern "C" fn _start() -> ! {
} }
} }
println!("Serial connection closed."); serial_println!("Serial connection closed.\r");
sloop() sloop()
} }

View file

@ -18,16 +18,16 @@ pub fn _print(args: ::core::fmt::Arguments) {
} }
/// Prints to the host through the serial interface. /// Prints to the host through the serial interface.
#[macro_export] #[macro_export]
macro_rules! serial_print { macro_rules! sprint {
($($arg:tt)*) => { ($($arg:tt)*) => {
$crate::arch::drivers::serial::_print(format_args!($($arg)*)); $crate::arch::drivers::serial::_print(format_args!($($arg)*));
}; };
} }
/// Prints to the host through the serial interface, appending a newline. /// Prints to the host through the serial interface, appending a newline.
#[macro_export] #[macro_export]
macro_rules! serial_println { macro_rules! sprintln {
() => ($crate::serial_print!("\n")); () => ($crate::sprint!("\n"));
($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n"))); ($fmt:expr) => ($crate::sprint!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => ($crate::serial_print!( ($fmt:expr, $($arg:tt)*) => ($crate::sprint!(
concat!($fmt, "\n"), $($arg)*)); concat!($fmt, "\n"), $($arg)*));
} }

View file

@ -11,7 +11,6 @@ use {
relib::network::socket::{SimpleSock, Socket}, relib::network::socket::{SimpleSock, Socket},
scratchpad, scratchpad,
}, },
facepalm::start_facepalm,
lazy_static::lazy_static, lazy_static::lazy_static,
}; };
@ -73,36 +72,11 @@ pub fn generate_process_pass() -> u128 {
// ret // ret
123 123
} }
/*
// TODO: move to a better place
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AcpiStruct {}
impl acpi::AcpiHandler for AcpiStruct {
unsafe fn map_physical_region<T>(
&self,
physical_address: usize,
size: usize,
) -> acpi::PhysicalMapping<Self, T> {
info!("PHYS ADDR: {:?}", physical_address);
info!("Size: {:?}", size);
todo!("map_physical_region");
}
fn unmap_physical_region<T>(_region: &acpi::PhysicalMapping<Self, T>) {
todo!("unmap_physical_region");
}
}
*/
use kernel::KERNEL_VERSION; use kernel::KERNEL_VERSION;
use crate::{ use crate::{
boot_conf::KernelConfig, boot_conf::KernelConfig,
kprint,
scheduler::{capabilities::FileAccess, SCHEDULER}, scheduler::{capabilities::FileAccess, SCHEDULER},
serial_print, serial_println,
systeminfo::RELEASE_TYPE, systeminfo::RELEASE_TYPE,
}; };

View file

@ -40,6 +40,10 @@ pub mod wasm_jumploader;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub mod port_io; pub mod port_io;
#[macro_use]
pub mod serial_print;
pub mod time;
#[macro_use] #[macro_use]
pub extern crate log; pub extern crate log;

View file

@ -1,7 +1,7 @@
use core::sync::atomic::Ordering; use core::sync::atomic::Ordering;
use crate::network::socket::{SimpleSock, Socket}; use crate::network::socket::{SimpleSock, Socket};
use crate::{kprint, serial_println}; use crate::time::fetch_time;
use kernel::TICK; use kernel::TICK;
use lliw::{Fg, Reset}; use lliw::{Fg, Reset};
@ -19,10 +19,8 @@ impl log::Log for SimpleLogger {
fn log(&self, record: &Record) { fn log(&self, record: &Record) {
if self.enabled(record.metadata()) { if self.enabled(record.metadata()) {
let color; let color;
disable();
let time = TICK.load(Ordering::Relaxed) as f64; let time_float = fetch_time();
enable();
let time_float = time;
match record.level() { match record.level() {
log::Level::Error => color = (Fg::Red, "$RED$"), log::Level::Error => color = (Fg::Red, "$RED$"),
@ -66,7 +64,6 @@ impl log::Log for SimpleLogger {
} }
use log::{LevelFilter, SetLoggerError}; use log::{LevelFilter, SetLoggerError};
use x86_64::instructions::interrupts::{disable, enable};
static LOGGER: SimpleLogger = SimpleLogger; static LOGGER: SimpleLogger = SimpleLogger;

View file

@ -3,6 +3,8 @@ pub use core::prelude::rust_2021::*;
pub use core::prelude::v1::*; pub use core::prelude::v1::*;
pub use crate::print::*; pub use crate::print::*;
pub use crate::serial_print::*;
pub use log::{debug, info, trace, warn}; pub use log::{debug, info, trace, warn};
pub use alloc::{boxed::Box, format, string::*, vec, vec::*}; pub use alloc::{boxed::Box, format, string::*, vec, vec::*};

View file

@ -1,4 +1,8 @@
pub fn rhai_shell() { #[cfg(target_arch = "riscv64")]
pub fn shell() {}
#[cfg(target_arch = "x86_64")]
pub fn shell() {
let engine = engine_construction(); let engine = engine_construction();
let mut scope = rhai::Scope::new(); let mut scope = rhai::Scope::new();
@ -31,22 +35,19 @@ lazy_static::lazy_static!(
); );
use rhai::Engine; use rhai::Engine;
use x86_64::instructions::interrupts::{disable, enable};
use crate::time::fetch_time;
use crate::wasm_jumploader::interp; use crate::wasm_jumploader::interp;
use crate::{ use crate::{
arch::{shutdown, sloop}, arch::{shutdown, sloop},
systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
KERNEL_STATE, KERNEL_STATE,
}; };
use kernel::TICK;
pub fn afetch() { pub fn afetch() {
let kstate = KERNEL_STATE.lock(); let kstate = KERNEL_STATE.lock();
use core::sync::atomic::Ordering::*;
disable(); let tick_time = fetch_time();
let tick_time = TICK.load(Relaxed);
println!( println!(
"OS: AbleOS "OS: AbleOS
@ -55,7 +56,7 @@ Kernel: AKern-{}-v{}
Uptime: {}", Uptime: {}",
kstate.hostname, RELEASE_TYPE, KERNEL_VERSION, tick_time kstate.hostname, RELEASE_TYPE, KERNEL_VERSION, tick_time
); );
enable();
drop(kstate); drop(kstate);
} }
pub fn set_hostname(name: String) { pub fn set_hostname(name: String) {

View file

@ -1,12 +1,12 @@
use acpi::AcpiTables; use acpi::AcpiTables;
use crate::{kprintln, rhai_shell::rhai_shell, serial_println}; use crate::rhai_shell::shell;
/// Experimental scratchpad for testing. /// Experimental scratchpad for testing.
pub fn scratchpad() { pub fn scratchpad() {
// pci_fun(); // pci_fun();
rhai_shell(); shell();
} }
pub fn pci_fun() {} pub fn pci_fun() {}

View file

@ -0,0 +1,48 @@
pub struct Serialout;
use core::fmt::{Arguments, Error};
impl Serialout {
pub fn write_fmt(&mut self, arg: Arguments<'_>) /*-> Result<(), Error> */
{
let _ = core::fmt::Write::write_fmt(self, arg);
// Ok(())
}
}
impl core::fmt::Write for Serialout {
#[cfg(target_arch = "aarch64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
// Don't actually print anything yet lmao
Ok(())
}
#[cfg(target_arch = "x86_64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
crate::arch::drivers::serial::_print(format_args!("{}", s));
Ok(())
}
#[cfg(target_arch = "riscv64")]
fn write_str(&mut self, s: &str) -> Result<(), Error> {
write!(crate::arch::drivers::uart::Uart::new(0x1000_0000), "{}", s)
}
fn write_char(&mut self, c: char) -> core::fmt::Result {
self.write_str(c.encode_utf8(&mut [0; 4]))
}
fn write_fmt(mut self: &mut Self, args: Arguments<'_>) -> core::fmt::Result {
core::fmt::write(&mut self, args)
}
}
#[macro_export]
macro_rules! serial_print {
() => {
::core::write!($crate::serial_print::Serialout, "")
};
($($tt:tt)*) => {
::core::write!($crate::serial_print::Serialout, $($tt)*)
};
}
#[macro_export]
macro_rules! serial_println {
($($tt:tt)*) => {
::core::writeln!($crate::serial_print::Serialout, $($tt)*)
// panic![];
};
}

17
ableos/src/time.rs Normal file
View file

@ -0,0 +1,17 @@
#[cfg(target_arch = "x86_64")]
pub fn fetch_time() -> f64 {
use x86_64::instructions::interrupts::{disable, enable};
disable();
let time = TICK.load(Ordering::Relaxed) as f64;
enable();
time
}
use core::sync::atomic::Ordering;
use kernel::TICK;
#[cfg(target_arch = "riscv64")]
pub fn fetch_time() -> f64 {
let time = TICK.load(Ordering::Relaxed) as f64;
time
}