From bcc6a107638039fa853938079008634d5d787a8a Mon Sep 17 00:00:00 2001 From: Able Date: Sat, 27 Nov 2021 09:19:08 -0600 Subject: [PATCH] work being done on simplification --- {ableos/.vscode => .vscode}/settings.json | 0 ableos/Cargo.lock | 7 ++++ ableos/Cargo.toml | 1 + ableos/src/allocator/aalloc.rs | 18 +++++++++ ableos/src/allocator/mod.rs | 4 +- .../aarch64/drivers/allocator.rs} | 0 ableos/src/arch/aarch64/drivers/mod.rs | 1 + ableos/src/arch/riscv/drivers/allocator.rs | 14 +++++++ ableos/src/arch/riscv/drivers/mod.rs | 1 + ableos/src/arch/riscv/drivers/serial.rs | 1 + ableos/src/arch/riscv/mod.rs | 8 ++-- ableos/src/arch/x86_64/mod.rs | 3 ++ ableos/src/kmain.rs | 14 ++----- ableos/src/lib.rs | 9 ++--- ableos/src/log.rs | 38 +++++++++++++++++++ ableos/src/print.rs | 8 ++++ ableos/src/relib/math/rand/mod.rs | 1 - ableos/src/serial.rs | 0 18 files changed, 104 insertions(+), 24 deletions(-) rename {ableos/.vscode => .vscode}/settings.json (100%) create mode 100644 ableos/src/allocator/aalloc.rs rename ableos/src/{allocator/dummy.rs => arch/aarch64/drivers/allocator.rs} (100%) create mode 100644 ableos/src/arch/riscv/drivers/allocator.rs create mode 100644 ableos/src/log.rs delete mode 100644 ableos/src/serial.rs diff --git a/ableos/.vscode/settings.json b/.vscode/settings.json similarity index 100% rename from ableos/.vscode/settings.json rename to .vscode/settings.json diff --git a/ableos/Cargo.lock b/ableos/Cargo.lock index 9d9bb0f8..25e01df7 100644 --- a/ableos/Cargo.lock +++ b/ableos/Cargo.lock @@ -10,6 +10,7 @@ dependencies = [ "cpuio", "lazy_static", "linked_list_allocator", + "lliw", "pic8259", "psp", "spin", @@ -70,6 +71,12 @@ dependencies = [ "spinning_top", ] +[[package]] +name = "lliw" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d502c8bcc35a4f7ca9a7ffb7ac27b15ba30b1b92c2d69a1e4437e2635d73af7" + [[package]] name = "lock_api" version = "0.4.5" diff --git a/ableos/Cargo.toml b/ableos/Cargo.toml index 3c8038a6..5996595d 100644 --- a/ableos/Cargo.toml +++ b/ableos/Cargo.toml @@ -16,6 +16,7 @@ run-args=["-serial", "stdio"] [dependencies] spin = "0.5.2" linked_list_allocator = "0.9.0" +lliw = "0.2.0" [dependencies.lazy_static] features = ["spin_no_std"] diff --git a/ableos/src/allocator/aalloc.rs b/ableos/src/allocator/aalloc.rs new file mode 100644 index 00000000..652c74a8 --- /dev/null +++ b/ableos/src/allocator/aalloc.rs @@ -0,0 +1,18 @@ +/*! +The allocator to be implemented by ableOS +*/ + +use alloc::alloc::{GlobalAlloc, Layout}; +use core::ptr::null_mut; + +pub struct AAloc; + +unsafe impl GlobalAlloc for AAloc { + unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { + null_mut() + } + + unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) { + panic!("dealloc should be never called") + } +} diff --git a/ableos/src/allocator/mod.rs b/ableos/src/allocator/mod.rs index 8b2d79ac..22f96619 100644 --- a/ableos/src/allocator/mod.rs +++ b/ableos/src/allocator/mod.rs @@ -1,8 +1,6 @@ use alloc::alloc::{GlobalAlloc, Layout}; -// use core::alloc::{GlobalAlloc, Layout}; -use core::ptr::null_mut; -// mod dummy; +mod aalloc; // use dummy::Dummy; pub const HEAP_START: usize = 0x_4444_4444_0000; diff --git a/ableos/src/allocator/dummy.rs b/ableos/src/arch/aarch64/drivers/allocator.rs similarity index 100% rename from ableos/src/allocator/dummy.rs rename to ableos/src/arch/aarch64/drivers/allocator.rs diff --git a/ableos/src/arch/aarch64/drivers/mod.rs b/ableos/src/arch/aarch64/drivers/mod.rs index 5111e65c..e2e6ab66 100644 --- a/ableos/src/arch/aarch64/drivers/mod.rs +++ b/ableos/src/arch/aarch64/drivers/mod.rs @@ -1,3 +1,4 @@ +pub mod allocator; pub mod graphics; pub mod nrf52; pub mod serial; diff --git a/ableos/src/arch/riscv/drivers/allocator.rs b/ableos/src/arch/riscv/drivers/allocator.rs new file mode 100644 index 00000000..7b5f9d55 --- /dev/null +++ b/ableos/src/arch/riscv/drivers/allocator.rs @@ -0,0 +1,14 @@ +use alloc::alloc::{GlobalAlloc, Layout}; +use core::ptr::null_mut; + +pub struct Dummy; + +unsafe impl GlobalAlloc for Dummy { + unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { + null_mut() + } + + unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) { + panic!("dealloc should be never called") + } +} diff --git a/ableos/src/arch/riscv/drivers/mod.rs b/ableos/src/arch/riscv/drivers/mod.rs index b832ebf9..00605972 100644 --- a/ableos/src/arch/riscv/drivers/mod.rs +++ b/ableos/src/arch/riscv/drivers/mod.rs @@ -1,2 +1,3 @@ +pub mod allocator; pub mod graphics; pub mod serial; diff --git a/ableos/src/arch/riscv/drivers/serial.rs b/ableos/src/arch/riscv/drivers/serial.rs index fad37ed5..42ae31de 100644 --- a/ableos/src/arch/riscv/drivers/serial.rs +++ b/ableos/src/arch/riscv/drivers/serial.rs @@ -30,6 +30,7 @@ impl Serial123 { use spin::Mutex; use lazy_static::lazy_static; + lazy_static! { pub static ref SERIAL: Mutex = { let serial_port = Serial123 { diff --git a/ableos/src/arch/riscv/mod.rs b/ableos/src/arch/riscv/mod.rs index 7d850fdf..919f759f 100644 --- a/ableos/src/arch/riscv/mod.rs +++ b/ableos/src/arch/riscv/mod.rs @@ -30,10 +30,12 @@ unsafe extern "C" fn _boot() -> ! { sym _start, options(noreturn)); } -use crate::serial::SERIAL; - extern "C" fn _start() -> ! { - SERIAL.lock().out(format_args!("Hi")); + let uart_data = 0x10000000 as *mut u8; + for c in b"Hardcoded serial output\n" { + unsafe { uart_data.write_volatile(*c) }; + } + sloop() } diff --git a/ableos/src/arch/x86_64/mod.rs b/ableos/src/arch/x86_64/mod.rs index 79a63a44..c5059c2b 100644 --- a/ableos/src/arch/x86_64/mod.rs +++ b/ableos/src/arch/x86_64/mod.rs @@ -45,9 +45,12 @@ pub fn sloop() -> ! { hlt(); } } + +/* #[cfg(test)] pub fn test_runner(tests: &[&dyn Fn()]) { for test in tests { test(); } } +*/ diff --git a/ableos/src/kmain.rs b/ableos/src/kmain.rs index 3bed61f9..3cd0504e 100644 --- a/ableos/src/kmain.rs +++ b/ableos/src/kmain.rs @@ -1,16 +1,10 @@ #![allow(clippy::empty_loop)] use crate::{ - arch::{ - drivers::graphics::GraphicsBuffer, - init, - memory::{self, translate_addr}, - sloop, - }, - driver_traits::{graphics::Graphics, serial::Serial}, + arch::{drivers::graphics::GraphicsBuffer, init, sloop}, + driver_traits::graphics::Graphics, experiments::systeminfo::{KERNEL_VERSION, RELEASE_TYPE}, keyboard::DecodedKey, - relib::math::rand::{linearshift::LinearShiftRegister, prand::PRand, RAND_HANDLE, RNG}, - serial_print, serial_println, + relib::math::rand::{RAND_HANDLE, RNG}, }; use lazy_static::lazy_static; @@ -65,14 +59,12 @@ pub fn kernel_main() -> ! { } lazy_static! { - // TODO: should have a sin wave influence contribution to entropy pub static ref TICK: spin::Mutex = spin::Mutex::new(0); } /// called by arch specific timers to tick up all kernel related functions pub fn tick() { let mut data = TICK.lock(); *data += 1; - // serial_println!("{}", *data); RAND_HANDLE.lock().seed_entropy_timer(*data); } diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index fcd7c4f0..08b62f0a 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -4,6 +4,7 @@ #![feature( abi_x86_interrupt, asm, + asm_sym, alloc_error_handler, core_intrinsics, global_asm, @@ -27,16 +28,12 @@ pub mod arch; #[macro_use] pub mod print; -use arch::drivers::serial; +pub mod allocator; pub mod driver_traits; pub mod experiments; pub mod keyboard; pub mod kmain; +pub mod log; pub mod panic; pub mod relib; - -use experiments::server; - extern crate alloc; - -pub mod allocator; diff --git a/ableos/src/log.rs b/ableos/src/log.rs new file mode 100644 index 00000000..74222666 --- /dev/null +++ b/ableos/src/log.rs @@ -0,0 +1,38 @@ +pub trait Log { + fn debug(); + fn error(); + fn log(); + fn trace(); +} + +use crate::serial_print; +use lliw::{Bg, Fg, Reset, Style}; +pub struct ANSISerialLogger; +impl Log for ANSISerialLogger { + fn debug() { + // serial_print!("[{}Debug{}]",); + + serial_print!( + "{}{}Attention!{}{} You have {}{}1{}{} new message", + Style::Underline, + Fg::Yellow, + Style::NoUnderline, + Fg::Reset, + Bg::White, + Fg::Black, + Bg::Reset, + Fg::Reset, + ); + + todo!(); + } + fn error() { + todo!(); + } + fn log() { + todo!(); + } + fn trace() { + todo!(); + } +} diff --git a/ableos/src/print.rs b/ableos/src/print.rs index 26545b2f..76a2013e 100644 --- a/ableos/src/print.rs +++ b/ableos/src/print.rs @@ -25,6 +25,14 @@ impl core::fmt::Write for Stdout { fn write_str(&mut self, s: &str) -> Result<(), Error> { Ok(()) } + + 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! print { diff --git a/ableos/src/relib/math/rand/mod.rs b/ableos/src/relib/math/rand/mod.rs index fe50604b..4617a4f6 100644 --- a/ableos/src/relib/math/rand/mod.rs +++ b/ableos/src/relib/math/rand/mod.rs @@ -54,7 +54,6 @@ impl RandomHandeler { self.linearshift .seed(self.entropy.pool[self.entropy.pool_index as usize]); } - // FIXME: Likely to panic pub fn seed_entropy_keyboard(&mut self, key: u8) { self.entropy.pool_index += key; diff --git a/ableos/src/serial.rs b/ableos/src/serial.rs deleted file mode 100644 index e69de29b..00000000