From 51c841e2de87150aef1a89ab37c8bc3cc585cc66 Mon Sep 17 00:00:00 2001 From: Able Date: Tue, 12 Apr 2022 13:26:52 -0500 Subject: [PATCH] upgrades people upgrades destroying erins clean code --- Cargo.lock | 1 + ableos/Cargo.toml | 7 +- ableos/src/arch/riscv/drivers/sysinfo.rs | 1 + ableos/src/arch/riscv/mod.rs | 19 ++++ ableos/src/arch/x86_64/drivers/mod.rs | 1 + .../x86_64/drivers/sysinfo.rs} | 1 + ableos/src/arch/x86_64/drivers/virtio/mod.rs | 0 ableos/src/experiments/kinfo.rs | 86 ++++++++++++++----- ableos/src/experiments/mod.rs | 1 - ableos/src/experiments/systeminfo.rs | 4 +- ableos/src/kmain.rs | 2 +- ableos/src/lib.rs | 3 + ableos/src/rhai_shell/mod.rs | 6 +- ableos/src/wasm_jumploader/host_functions.rs | 1 + 14 files changed, 101 insertions(+), 32 deletions(-) create mode 100644 ableos/src/arch/riscv/drivers/sysinfo.rs rename ableos/src/{experiments/info.rs => arch/x86_64/drivers/sysinfo.rs} (99%) create mode 100644 ableos/src/arch/x86_64/drivers/virtio/mod.rs diff --git a/Cargo.lock b/Cargo.lock index b912d591..850b6b4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,7 @@ dependencies = [ "toml", "uart_16550", "unicode-width", + "versioning", "vga", "volatile 0.2.7", "wasmi", diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index 6f5926d8..54805f9c 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -18,7 +18,7 @@ run-args = [ "-smp", "cores=2", - "-device", #"ati-vga", + "-device", "cirrus-vga", # "-device", @@ -27,8 +27,8 @@ run-args = [ # "-drive", # "file=disk.qcow2,if=none,id=drive0", - # "-device", - # "virtio-rng", + "-device", + "virtio-rng", "-qmp", "unix:../qmp-sock,server,nowait" @@ -56,6 +56,7 @@ rhai = "1.6.0" libwasm = {git="https://git.ablecorp.us:443/able/libwasm.git"} acpi = "4.1.0" axel = { git = "https://git.ablecorp.us/able/aos_userland" } +versioning = { git = "https://git.ablecorp.us/able/aos_userland" } [dependencies.logos] version = "0.12" diff --git a/ableos/src/arch/riscv/drivers/sysinfo.rs b/ableos/src/arch/riscv/drivers/sysinfo.rs new file mode 100644 index 00000000..73efc452 --- /dev/null +++ b/ableos/src/arch/riscv/drivers/sysinfo.rs @@ -0,0 +1 @@ +pub fn sysinfo() {} diff --git a/ableos/src/arch/riscv/mod.rs b/ableos/src/arch/riscv/mod.rs index 445b13bb..d5416341 100644 --- a/ableos/src/arch/riscv/mod.rs +++ b/ableos/src/arch/riscv/mod.rs @@ -51,6 +51,25 @@ extern "C" fn _start() -> ! { uart.put('\r' as u8); } + 91 => { + if let Some(ch) = uart.get() { + match ch as char { + 'A' => { + serial_println!("That's the up arrow!"); + } + 'B' => { + serial_println!("That's the down arrow!"); + } + 'C' => { + serial_println!("That's the right arrow!"); + } + 'D' => { + serial_println!("That's the left arrow!"); + } + } + } + } + _ => { uart.put(c); } diff --git a/ableos/src/arch/x86_64/drivers/mod.rs b/ableos/src/arch/x86_64/drivers/mod.rs index 75821e2c..89f292e3 100644 --- a/ableos/src/arch/x86_64/drivers/mod.rs +++ b/ableos/src/arch/x86_64/drivers/mod.rs @@ -1,6 +1,7 @@ pub mod allocator; pub mod graphics; pub mod serial; +pub mod sysinfo; pub mod timer; #[deprecated(note = "The use of hardware specific drivers for VGA is discouraged")] diff --git a/ableos/src/experiments/info.rs b/ableos/src/arch/x86_64/drivers/sysinfo.rs similarity index 99% rename from ableos/src/experiments/info.rs rename to ableos/src/arch/x86_64/drivers/sysinfo.rs index b5b8ff24..05ca9da6 100644 --- a/ableos/src/experiments/info.rs +++ b/ableos/src/arch/x86_64/drivers/sysinfo.rs @@ -16,6 +16,7 @@ not(any(target_arch = "x86_64", target_arch = "x86")), allow(dead_code) )] +pub fn sysinfo() {} use core::arch::asm; use core::ops::Deref; diff --git a/ableos/src/arch/x86_64/drivers/virtio/mod.rs b/ableos/src/arch/x86_64/drivers/virtio/mod.rs new file mode 100644 index 00000000..e69de29b diff --git a/ableos/src/experiments/kinfo.rs b/ableos/src/experiments/kinfo.rs index fd31a804..c292f99c 100644 --- a/ableos/src/experiments/kinfo.rs +++ b/ableos/src/experiments/kinfo.rs @@ -1,26 +1,25 @@ +use core::fmt::Display; + +use crate::{arch::drivers::sysinfo::master, ALLOCATOR}; + use super::systeminfo::SystemMemory; +use versioning::Version; +use x86_64::instructions::interrupts::{disable, enable}; -// NOTE: Move to somewhere else -pub static KINFO: KernelInfo = KernelInfo { - kernel_version: SemanticVersion { - major: 0, - minor: 0, - patch: 0, - }, - memory: SystemMemory { used: 0, total: 0 }, -}; - -// Can be standardized -// NOTE: Move this to relib -pub struct SemanticVersion { - pub major: u8, - pub minor: u8, - pub patch: u8, +pub enum CpuType { + RiscV(String), + X86_64(String), } - -impl core::fmt::Display for SemanticVersion { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - write!(f, "v{}.{}.{}", self.major, self.minor, self.patch) +impl Display for CpuType { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!( + f, + "{}", + match self { + CpuType::RiscV(s) => s, + CpuType::X86_64(s) => s, + } + ) } } @@ -28,8 +27,51 @@ impl core::fmt::Display for SemanticVersion { pub struct KernelInfo { // os: String, // host: String, - pub kernel_version: SemanticVersion, - // cpu: String, + pub kernel_version: Version, + pub cpu: CpuType, // gpu: String, pub memory: SystemMemory, } + +impl KernelInfo { + pub fn get() -> KernelInfo { + disable(); + let allocator = ALLOCATOR.lock(); + let total = allocator.size(); + let used = allocator.used(); + enable(); + + let cpu = CpuType::X86_64(master().unwrap().brand_string().unwrap().to_string()); + + KernelInfo { + kernel_version: Version { + major: 0, + minor: 0, + patch: 0, + }, + cpu, + memory: SystemMemory { total, used }, + } + } +} + +impl Display for KernelInfo { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!( + f, + " + OS: AbleOS + Host: {{}} + Kernel: {}.{}.{} + CPU: {} + Memory: {}/{} + ", + self.kernel_version.major, + self.kernel_version.minor, + self.kernel_version.patch, + self.cpu, + self.memory.used, + self.memory.total + ) + } +} diff --git a/ableos/src/experiments/mod.rs b/ableos/src/experiments/mod.rs index f1c8bf54..134b35d8 100644 --- a/ableos/src/experiments/mod.rs +++ b/ableos/src/experiments/mod.rs @@ -3,7 +3,6 @@ pub mod absi; pub mod clip; pub mod futex; -pub mod info; pub mod kinfo; pub mod mail; pub mod server; diff --git a/ableos/src/experiments/systeminfo.rs b/ableos/src/experiments/systeminfo.rs index 1e815d42..06fda4e3 100644 --- a/ableos/src/experiments/systeminfo.rs +++ b/ableos/src/experiments/systeminfo.rs @@ -10,8 +10,8 @@ pub const RELEASE_TYPE: &str = "debug"; pub const RELEASE_TYPE: &str = "release"; pub struct SystemMemory { - pub used: u64, - pub total: u64, + pub used: usize, + pub total: usize, } impl core::fmt::Display for SystemMemory { diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 5f2850a9..f0f1fb2b 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -1,6 +1,6 @@ #![allow(clippy::empty_loop)] -use crate::info::master; +use crate::arch::drivers::sysinfo::master; use crate::scheduler::SCHEDULER; use crate::{ arch::{init, sloop}, diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index f8985a3b..36add599 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -7,6 +7,9 @@ #![feature(abi_x86_interrupt)] #![feature(alloc_error_handler)] #![feature(prelude_import)] +// Needed for riscv +#![feature(asm_sym)] +#![feature(naked_functions)] #[macro_use] pub extern crate log; diff --git a/ableos/src/rhai_shell/mod.rs b/ableos/src/rhai_shell/mod.rs index 31ddc85d..2528e363 100644 --- a/ableos/src/rhai_shell/mod.rs +++ b/ableos/src/rhai_shell/mod.rs @@ -1,5 +1,6 @@ +use crate::arch::drivers::sysinfo::{master, sysinfo}; + use crate::filesystem::FILE_SYSTEM; -use crate::info::master; use crate::time::fetch_time; use crate::wasm_jumploader::interp; use crate::ALLOCATOR; @@ -90,14 +91,13 @@ pub fn set_hostname(name: String) { /// Examine a memory pointer pub fn peek_memory(ptr: i64) -> i64 { - println!(">:("); unsafe { *(ptr as *const u8) as _ } } pub fn poke_memory(ptr: i64, val: i64) { match val.try_into() { Ok(val) => unsafe { *(ptr as *mut u8) = val }, - Err(_) => println!("Error: {val} cannot be converted into u8"), + Err(_) => error!("{val} cannot be converted into u8"), } } diff --git a/ableos/src/wasm_jumploader/host_functions.rs b/ableos/src/wasm_jumploader/host_functions.rs index a0c3c43e..9d0a51cf 100644 --- a/ableos/src/wasm_jumploader/host_functions.rs +++ b/ableos/src/wasm_jumploader/host_functions.rs @@ -147,6 +147,7 @@ impl Externals for HostExternals { GET_TIME_INDEX => { use core::sync::atomic::Ordering::*; trace!("SYSCALL: get time"); + x86_64::instructions::interrupts::disable(); let tick_time = kernel::TICK.load(Relaxed); x86_64::instructions::interrupts::enable();