diff --git a/ableos/.cargo/config.toml b/ableos/.cargo/config.toml index 58aed6dc..7c70298e 100644 --- a/ableos/.cargo/config.toml +++ b/ableos/.cargo/config.toml @@ -6,8 +6,10 @@ build-std-features = ["compiler-builtins-mem"] build-std = ["core", "compiler_builtins", "alloc"] + [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/Cargo.toml b/ableos/Cargo.toml index 84691a07..2db9047f 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 ae69ade5..5111e65c 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 98a22e40..0b3aa254 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 40f5a8f9..46d9ae5a 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 fb274646..fad37ed5 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/experiments/systeminfo.rs b/ableos/src/experiments/systeminfo.rs index 552ad7f2..611f5beb 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,18 @@ 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 ebe1db6c..93f679e1 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -9,10 +9,16 @@ use crate::{ driver_traits::{graphics::Graphics, serial::Serial}, relib::math::rand::{linearshift::LinearShiftRegister, prand::PRand, RAND_HANDLE, RNG}, serial_print, serial_println, + + experiments::systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, + keyboard::DecodedKey, }; use bootloader::{entry_point, BootInfo}; use lazy_static::lazy_static; + + use x86_64::{VirtAddr, structures::paging::Page}; + #[no_mangle] #[allow(unconditional_recursion)] pub extern "C" fn stack_overflow() -> u8 { @@ -21,8 +27,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; @@ -41,10 +45,11 @@ pub fn kernel_main(boot_info: &'static BootInfo) -> ! { /* If AES is present then AES init rng as well // Maybe via a cfg 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 2b08f55f..5728cc86 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -1,48 +1,39 @@ +//! 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; -#[cfg(not(target_arch = "mips"))] -// pub mod allocator; -mod kmain; -#[cfg(not(target_arch = "mips"))] -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; -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"; -extern crate alloc; + +use experiments::server; + diff --git a/ableos/src/print.rs b/ableos/src/print.rs index f47c61ad..9d3a4e11 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/relib/math/rand/mod.rs b/ableos/src/relib/math/rand/mod.rs index 78c66abc..fe50604b 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(), + }); } diff --git a/ableos/src/serial.rs b/ableos/src/serial.rs new file mode 100644 index 00000000..e69de29b diff --git a/ableos/src/wasm/mod.rs b/ableos/src/wasm/mod.rs new file mode 100644 index 00000000..e69de29b diff --git a/repbuild/src/main.rs b/repbuild/src/main.rs index a7b35076..a16ed57b 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(())