work being done on simplification

This commit is contained in:
Able 2021-11-27 09:19:08 -06:00
parent ee431b65ef
commit bcc6a10763
18 changed files with 104 additions and 24 deletions

7
ableos/Cargo.lock generated
View file

@ -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"

View file

@ -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"]

View file

@ -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")
}
}

View file

@ -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;

View file

@ -1,3 +1,4 @@
pub mod allocator;
pub mod graphics;
pub mod nrf52;
pub mod serial;

View file

@ -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")
}
}

View file

@ -1,2 +1,3 @@
pub mod allocator;
pub mod graphics;
pub mod serial;

View file

@ -30,6 +30,7 @@ impl Serial123 {
use spin::Mutex;
use lazy_static::lazy_static;
lazy_static! {
pub static ref SERIAL: Mutex<Serial123> = {
let serial_port = Serial123 {

View file

@ -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()
}

View file

@ -45,9 +45,12 @@ pub fn sloop() -> ! {
hlt();
}
}
/*
#[cfg(test)]
pub fn test_runner(tests: &[&dyn Fn()]) {
for test in tests {
test();
}
}
*/

View file

@ -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<u64> = 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);
}

View file

@ -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;

38
ableos/src/log.rs Normal file
View file

@ -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!();
}
}

View file

@ -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 {

View file

@ -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;

View file