From aea13d428f9c799a8f3a0c5e93ddcd15d45d047b Mon Sep 17 00:00:00 2001 From: Able Date: Sun, 21 Nov 2021 02:13:50 -0600 Subject: [PATCH 1/4] cleanup --- ableos/Cargo.toml | 5 +++- ableos/src/arch/aarch64/drivers/mod.rs | 1 + .../src/arch/aarch64/{ => drivers}/serial.rs | 1 + ableos/src/arch/aarch64/mod.rs | 1 - ableos/src/arch/riscv/drivers/serial.rs | 1 + ableos/src/lib.rs | 2 ++ ableos/src/print.rs | 14 ----------- ableos/src/serial.rs | 0 repbuild/src/main.rs | 23 ++++++++++++++++++- 9 files changed, 31 insertions(+), 17 deletions(-) rename ableos/src/arch/aarch64/{ => drivers}/serial.rs (83%) create mode 100644 ableos/src/serial.rs diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index 077645a..08c1b40 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -15,12 +15,15 @@ run-args=["-serial", "stdio"] [dependencies] spin = "0.5.2" -# linked_list_allocator = "0.9.0" [dependencies.lazy_static] features = ["spin_no_std"] version = "1.0" +# [dependencies.rhai] +# version = "*" +# features = ["no_std"] + # alloc required # [dependencies.wasmi] # version = "*" diff --git a/ableos/src/arch/aarch64/drivers/mod.rs b/ableos/src/arch/aarch64/drivers/mod.rs index ae69ade..5111e65 100644 --- a/ableos/src/arch/aarch64/drivers/mod.rs +++ b/ableos/src/arch/aarch64/drivers/mod.rs @@ -1,2 +1,3 @@ pub mod graphics; pub mod nrf52; +pub mod serial; diff --git a/ableos/src/arch/aarch64/serial.rs b/ableos/src/arch/aarch64/drivers/serial.rs similarity index 83% rename from ableos/src/arch/aarch64/serial.rs rename to ableos/src/arch/aarch64/drivers/serial.rs index 98a22e4..0b3aa25 100644 --- a/ableos/src/arch/aarch64/serial.rs +++ b/ableos/src/arch/aarch64/drivers/serial.rs @@ -1,3 +1,4 @@ +/// Prints to the host through the serial interface. #[macro_export] macro_rules! serial_print { ($($arg:tt)*) => {}; diff --git a/ableos/src/arch/aarch64/mod.rs b/ableos/src/arch/aarch64/mod.rs index 40f5a8f..46d9ae5 100644 --- a/ableos/src/arch/aarch64/mod.rs +++ b/ableos/src/arch/aarch64/mod.rs @@ -4,7 +4,6 @@ use core::ptr; pub mod drivers; pub mod init; -pub mod serial; use crate::arch::drivers::nrf52::{Level, Pins}; use core::ptr::write_volatile; global_asm!(include_str!("boot.s")); diff --git a/ableos/src/arch/riscv/drivers/serial.rs b/ableos/src/arch/riscv/drivers/serial.rs index fb27464..fad37ed 100644 --- a/ableos/src/arch/riscv/drivers/serial.rs +++ b/ableos/src/arch/riscv/drivers/serial.rs @@ -33,6 +33,7 @@ use lazy_static::lazy_static; lazy_static! { pub static ref SERIAL: Mutex = { let serial_port = Serial123 { + /// UART port for the serial bus uart_data: 0x10000000, }; Mutex::new(serial_port) diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 6ca5156..5459521 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -1,3 +1,5 @@ +//! hi + #![no_std] // #![deny(warnings)] #![feature(asm)] diff --git a/ableos/src/print.rs b/ableos/src/print.rs index f47c61a..9d3a4e1 100644 --- a/ableos/src/print.rs +++ b/ableos/src/print.rs @@ -9,20 +9,12 @@ impl Stdout { } } impl core::fmt::Write for Stdout { - #[cfg(target_arch = "arm")] - fn write_str(&mut self, s: &str) -> Result<(), Error> { - use crate::arch::write; - write(s); - Ok(()) - } - #[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> { use crate::kprint; @@ -34,12 +26,6 @@ impl core::fmt::Write for Stdout { fn write_str(&mut self, s: &str) -> Result<(), Error> { Ok(()) } - #[cfg(target_arch = "mips")] - fn write_str(&mut self, s: &str) -> Result<(), Error> { - use psp::dprint; - dprint!("{}", s); - Ok(()) - } } #[macro_export] macro_rules! print { diff --git a/ableos/src/serial.rs b/ableos/src/serial.rs new file mode 100644 index 0000000..e69de29 diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index a7b3507..a16ed57 100644 --- a/repbuild/src/main.rs +++ b/repbuild/src/main.rs @@ -11,6 +11,11 @@ enum Command { #[clap(long, short, arg_enum)] machine: Option, }, + + Doc { + #[clap(long, short, arg_enum)] + machine: Option, + }, } #[derive(clap::ArgEnum, Debug, Clone)] @@ -34,7 +39,6 @@ fn main() -> anyhow::Result<()> { }; match machine.unwrap_or(MachineType::X86) { MachineType::X86 => { - // Used for the x86-64 variant only xshell::cmd!("cargo run --release").run()?; } MachineType::ARM => { @@ -67,6 +71,23 @@ fn main() -> anyhow::Result<()> { } } } + + Command::Doc { machine } => { + let _dir = xshell::pushd("./ableos"); + + match machine.unwrap_or(MachineType::X86) { + MachineType::X86 => { + xshell::cmd!("cargo doc --open").run()?; + } + MachineType::ARM => { + xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json") + .run()?; + } + MachineType::RISCV => { + xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?; + } + } + } } Ok(()) From b3817c0bd36d6c6541f60d3faa75f4cdd21a6788 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 22 Nov 2021 04:10:07 -0600 Subject: [PATCH 2/4] slowly adding alloc features --- ableos/.cargo/config.toml | 2 +- ableos/src/experiments/systeminfo.rs | 34 ++++++++++++------- ableos/src/kmain.rs | 9 ++--- ableos/src/lib.rs | 7 ---- ableos/src/relib/math/rand/mod.rs | 51 ++++++++++++++-------------- 5 files changed, 52 insertions(+), 51 deletions(-) diff --git a/ableos/.cargo/config.toml b/ableos/.cargo/config.toml index 75f0784..e2703d6 100644 --- a/ableos/.cargo/config.toml +++ b/ableos/.cargo/config.toml @@ -3,7 +3,7 @@ target = "./json_targets/x86_64-ableos.json" [unstable] build-std-features = ["compiler-builtins-mem"] -build-std = ["core", "compiler_builtins"] +build-std = ["core","alloc", "compiler_builtins"] [target.'cfg(target_arch = "x86_64")'] diff --git a/ableos/src/experiments/systeminfo.rs b/ableos/src/experiments/systeminfo.rs index 552ad7f..b0efc23 100644 --- a/ableos/src/experiments/systeminfo.rs +++ b/ableos/src/experiments/systeminfo.rs @@ -1,18 +1,18 @@ // Can be standardized // NOTE: move the file to the src/ dir pub struct SystemMemory { - pub used: u64, - pub total: u64, + pub used: u64, + pub total: u64, } impl core::fmt::Display for SystemMemory { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - write!(f, "{} Bytes / {} Bytes", self.used, self.total) - } + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "{} Bytes / {} Bytes", self.used, self.total) + } } /* pub fn format_system_info() -> core::string::String { - let x = format!( - "{} + let x = format!( + "{} OS: AbleOS Host: ComputAble Kernel: {} @@ -23,11 +23,19 @@ Gpu: MIPS32 R4000 R4k Cpu: {} Memory: {} ", - crate::experiments::BANNER, - crate::experiments::kinfo::KINFO.kernel_version, - crate::arch::ARCH, - crate::experiments::kinfo::KINFO.memory - ); - return x; + crate::experiments::BANNER, + crate::experiments::kinfo::KINFO.kernel_version, + crate::arch::ARCH, + crate::experiments::kinfo::KINFO.memory + ); + return x; } */ + +pub const KERNEL_VERSION: &str = env!("CARGO_PKG_VERSION"); +#[cfg(debug_assertions)] +/// A constant to check if the kernel is in debug mode +pub const RELEASE_TYPE: &str = "debug"; +#[cfg(not(debug_assertions))] +/// A constant to check if the kernel is in release mode +pub const RELEASE_TYPE: &str = "release"; diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index f917606..9967d9d 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -2,10 +2,13 @@ use crate::{ arch::{drivers::graphics::GraphicsBuffer, init}, driver_traits::{graphics::Graphics, serial::Serial}, + experiments::systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, + keyboard::DecodedKey, relib::math::rand::{linearshift::LinearShiftRegister, prand::PRand, RAND_HANDLE, RNG}, serial_print, serial_println, }; use lazy_static::lazy_static; + #[no_mangle] #[allow(unconditional_recursion)] pub extern "C" fn stack_overflow() -> u8 { @@ -13,8 +16,6 @@ pub extern "C" fn stack_overflow() -> u8 { 69 // NOTE: Any specific reason for this number asside from memes? } -use crate::keyboard::DecodedKey; - lazy_static! { pub static ref KEY_BUFFER: [DecodedKey; 256] = [DecodedKey::RawKey(123); 256]; pub static ref KEY_BUFFER_POINTER: u8 = 0; @@ -33,8 +34,8 @@ pub extern "C" fn kernel_main() { AES::init_rng(); */ - #[cfg(not(target_arch = "riscv64"))] - println!("init"); + + println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION); { use crate::experiments::mail::MailBoxes; diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 5459521..476f340 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -40,10 +40,3 @@ mod panic; pub use experiments::server; pub mod keyboard; pub mod relib; -pub const KERNEL_VERSION: &str = env!("CARGO_PKG_VERSION"); -#[cfg(debug_assertions)] -/// A constant to check if the kernel is in debug mode -pub const RELEASE_TYPE: &str = "debug"; -#[cfg(not(debug_assertions))] -/// A constant to check if the kernel is in release mode -pub const RELEASE_TYPE: &str = "release"; diff --git a/ableos/src/relib/math/rand/mod.rs b/ableos/src/relib/math/rand/mod.rs index 78c66ab..fe50604 100644 --- a/ableos/src/relib/math/rand/mod.rs +++ b/ableos/src/relib/math/rand/mod.rs @@ -2,14 +2,13 @@ pub mod linearshift; pub mod prand; pub mod wichmanhillrand; // FIXEME: Reimplement -use crate::serial_println; use lazy_static::lazy_static; use linearshift::LinearShiftRegister; use prand::PRand; pub trait RNG { - fn new() -> Self; - fn rand(&mut self) -> u64; - fn seed(&mut self, seed: u64); + fn new() -> Self; + fn rand(&mut self) -> u64; + fn seed(&mut self, seed: u64); } pub type KeyEntropyHandler = u8; @@ -21,20 +20,20 @@ pub struct Entropy { pool: [u64; 255], } impl Entropy { - pub fn new() -> Self { - Self { - bytes_count: 0, - pool: [0; 255], - pool_index: 0, - } - } - pub fn poll_hardware() { - todo!(); - } - pub fn read_entropy(&mut self) -> u8 { - self.bytes_count -= 1; - 1 - } + pub fn new() -> Self { + Self { + bytes_count: 0, + pool: [0; 255], + pool_index: 0, + } + } + pub fn poll_hardware() { + todo!(); + } + pub fn read_entropy(&mut self) -> u8 { + self.bytes_count -= 1; + 1 + } } impl Default for Entropy { fn default() -> Self { @@ -42,9 +41,9 @@ impl Default for Entropy { } } pub struct RandomHandeler { - prand: prand::PRand, - linearshift: linearshift::LinearShiftRegister, - entropy: Entropy, + prand: prand::PRand, + linearshift: linearshift::LinearShiftRegister, + entropy: Entropy, } impl RandomHandeler { pub fn seed_entropy(&mut self) { @@ -79,9 +78,9 @@ impl RandomHandeler { } } lazy_static! { - pub static ref RAND_HANDLE: spin::Mutex = spin::Mutex::new(RandomHandeler { - prand: PRand::new(), - linearshift: LinearShiftRegister::new(), - entropy: Entropy::new(), - }); + pub static ref RAND_HANDLE: spin::Mutex = spin::Mutex::new(RandomHandeler { + prand: PRand::new(), + linearshift: LinearShiftRegister::new(), + entropy: Entropy::new(), + }); } From 6adc312213276dde62235e7ccf4a162be6a3fe7d Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 22 Nov 2021 07:37:41 -0600 Subject: [PATCH 3/4] miniscule work --- ableos/src/experiments/systeminfo.rs | 1 - ableos/src/lib.rs | 3 --- ableos/src/wasm/mod.rs | 0 3 files changed, 4 deletions(-) create mode 100644 ableos/src/wasm/mod.rs diff --git a/ableos/src/experiments/systeminfo.rs b/ableos/src/experiments/systeminfo.rs index b0efc23..611f5be 100644 --- a/ableos/src/experiments/systeminfo.rs +++ b/ableos/src/experiments/systeminfo.rs @@ -31,7 +31,6 @@ Memory: {} return x; } */ - pub const KERNEL_VERSION: &str = env!("CARGO_PKG_VERSION"); #[cfg(debug_assertions)] /// A constant to check if the kernel is in debug mode diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 476f340..5261538 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -32,10 +32,7 @@ use arch::drivers::serial; mod driver_traits; mod experiments; -#[cfg(not(target_arch = "mips"))] -// pub mod allocator; mod kmain; -#[cfg(not(target_arch = "mips"))] mod panic; pub use experiments::server; pub mod keyboard; diff --git a/ableos/src/wasm/mod.rs b/ableos/src/wasm/mod.rs new file mode 100644 index 0000000..e69de29 From 5ced36a91651f167918adc86ade5462bf166d54c Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 22 Nov 2021 10:30:49 -0600 Subject: [PATCH 4/4] h --- ableos/.cargo/config.toml | 1 + ableos/src/lib.rs | 41 +++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ableos/.cargo/config.toml b/ableos/.cargo/config.toml index e2703d6..3120ea5 100644 --- a/ableos/.cargo/config.toml +++ b/ableos/.cargo/config.toml @@ -9,5 +9,6 @@ build-std = ["core","alloc", "compiler_builtins"] [target.'cfg(target_arch = "x86_64")'] # --quiet suppresses warning messages from the bootimage crate runner = "bootimage runner --quiet" + [target.riscv64gc-unknown-none-elf] rustflags = "-C link-arg=-T../ableos/src/arch/riscv/virt.lds" diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 5261538..3d95faf 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -1,39 +1,38 @@ //! hi #![no_std] -// #![deny(warnings)] -#![feature(asm)] -#![feature(global_asm)] -#![feature(abi_x86_interrupt)] -#![feature(core_intrinsics, lang_items, llvm_asm)] -// #![feature(alloc_error_handler)] // at the top of the file -#![reexport_test_harness_main = "test_main"] -#![feature(custom_test_frameworks)] -#![test_runner(crate::arch::test_runner)] -#![feature(naked_functions)] -#[cfg(target_arch = "arm")] -#[path = "arch/aarch32/mod.rs"] -mod arch; +#![feature( + abi_x86_interrupt, + asm, + core_intrinsics, + global_asm, + lang_items, + llvm_asm, + naked_functions +)] #[cfg(target_arch = "aarch64")] #[path = "arch/aarch64/mod.rs"] -mod arch; +pub mod arch; #[cfg(target_arch = "x86_64")] #[path = "arch/x86_64/mod.rs"] -mod arch; +pub mod arch; + #[cfg(target_arch = "riscv64")] #[path = "arch/riscv/mod.rs"] -mod arch; +pub mod arch; + #[macro_use] pub mod print; use arch::drivers::serial; -mod driver_traits; -mod experiments; -mod kmain; -mod panic; -pub use experiments::server; +pub mod driver_traits; +pub mod experiments; pub mod keyboard; +pub mod kmain; +pub mod panic; pub mod relib; + +use experiments::server;