1
0
Fork 0
forked from AbleOS/ableos

slowly adding alloc features

This commit is contained in:
Able 2021-11-22 04:10:07 -06:00
parent aea13d428f
commit b3817c0bd3
5 changed files with 52 additions and 51 deletions

View file

@ -3,7 +3,7 @@ target = "./json_targets/x86_64-ableos.json"
[unstable] [unstable]
build-std-features = ["compiler-builtins-mem"] build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins"] build-std = ["core","alloc", "compiler_builtins"]
[target.'cfg(target_arch = "x86_64")'] [target.'cfg(target_arch = "x86_64")']

View file

@ -1,18 +1,18 @@
// Can be standardized // Can be standardized
// NOTE: move the file to the src/ dir // NOTE: move the file to the src/ dir
pub struct SystemMemory { pub struct SystemMemory {
pub used: u64, pub used: u64,
pub total: u64, pub total: u64,
} }
impl core::fmt::Display for SystemMemory { impl core::fmt::Display for SystemMemory {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "{} Bytes / {} Bytes", self.used, self.total) write!(f, "{} Bytes / {} Bytes", self.used, self.total)
} }
} }
/* /*
pub fn format_system_info() -> core::string::String { pub fn format_system_info() -> core::string::String {
let x = format!( let x = format!(
"{} "{}
OS: AbleOS OS: AbleOS
Host: ComputAble Host: ComputAble
Kernel: {} Kernel: {}
@ -23,11 +23,19 @@ Gpu: MIPS32 R4000 R4k
Cpu: {} Cpu: {}
Memory: {} Memory: {}
", ",
crate::experiments::BANNER, crate::experiments::BANNER,
crate::experiments::kinfo::KINFO.kernel_version, crate::experiments::kinfo::KINFO.kernel_version,
crate::arch::ARCH, crate::arch::ARCH,
crate::experiments::kinfo::KINFO.memory crate::experiments::kinfo::KINFO.memory
); );
return x; 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";

View file

@ -2,10 +2,13 @@
use crate::{ use crate::{
arch::{drivers::graphics::GraphicsBuffer, init}, arch::{drivers::graphics::GraphicsBuffer, init},
driver_traits::{graphics::Graphics, serial::Serial}, driver_traits::{graphics::Graphics, serial::Serial},
experiments::systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
keyboard::DecodedKey,
relib::math::rand::{linearshift::LinearShiftRegister, prand::PRand, RAND_HANDLE, RNG}, relib::math::rand::{linearshift::LinearShiftRegister, prand::PRand, RAND_HANDLE, RNG},
serial_print, serial_println, serial_print, serial_println,
}; };
use lazy_static::lazy_static; use lazy_static::lazy_static;
#[no_mangle] #[no_mangle]
#[allow(unconditional_recursion)] #[allow(unconditional_recursion)]
pub extern "C" fn stack_overflow() -> u8 { 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? 69 // NOTE: Any specific reason for this number asside from memes?
} }
use crate::keyboard::DecodedKey;
lazy_static! { lazy_static! {
pub static ref KEY_BUFFER: [DecodedKey; 256] = [DecodedKey::RawKey(123); 256]; pub static ref KEY_BUFFER: [DecodedKey; 256] = [DecodedKey::RawKey(123); 256];
pub static ref KEY_BUFFER_POINTER: u8 = 0; pub static ref KEY_BUFFER_POINTER: u8 = 0;
@ -33,8 +34,8 @@ pub extern "C" fn kernel_main() {
AES::init_rng(); AES::init_rng();
*/ */
#[cfg(not(target_arch = "riscv64"))]
println!("init"); println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
{ {
use crate::experiments::mail::MailBoxes; use crate::experiments::mail::MailBoxes;

View file

@ -40,10 +40,3 @@ mod panic;
pub use experiments::server; pub use experiments::server;
pub mod keyboard; pub mod keyboard;
pub mod relib; 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";

View file

@ -2,14 +2,13 @@
pub mod linearshift; pub mod linearshift;
pub mod prand; pub mod prand;
pub mod wichmanhillrand; // FIXEME: Reimplement pub mod wichmanhillrand; // FIXEME: Reimplement
use crate::serial_println;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use linearshift::LinearShiftRegister; use linearshift::LinearShiftRegister;
use prand::PRand; use prand::PRand;
pub trait RNG { pub trait RNG {
fn new() -> Self; fn new() -> Self;
fn rand(&mut self) -> u64; fn rand(&mut self) -> u64;
fn seed(&mut self, seed: u64); fn seed(&mut self, seed: u64);
} }
pub type KeyEntropyHandler = u8; pub type KeyEntropyHandler = u8;
@ -21,20 +20,20 @@ pub struct Entropy {
pool: [u64; 255], pool: [u64; 255],
} }
impl Entropy { impl Entropy {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
bytes_count: 0, bytes_count: 0,
pool: [0; 255], pool: [0; 255],
pool_index: 0, pool_index: 0,
} }
} }
pub fn poll_hardware() { pub fn poll_hardware() {
todo!(); todo!();
} }
pub fn read_entropy(&mut self) -> u8 { pub fn read_entropy(&mut self) -> u8 {
self.bytes_count -= 1; self.bytes_count -= 1;
1 1
} }
} }
impl Default for Entropy { impl Default for Entropy {
fn default() -> Self { fn default() -> Self {
@ -42,9 +41,9 @@ impl Default for Entropy {
} }
} }
pub struct RandomHandeler { pub struct RandomHandeler {
prand: prand::PRand, prand: prand::PRand,
linearshift: linearshift::LinearShiftRegister, linearshift: linearshift::LinearShiftRegister,
entropy: Entropy, entropy: Entropy,
} }
impl RandomHandeler { impl RandomHandeler {
pub fn seed_entropy(&mut self) { pub fn seed_entropy(&mut self) {
@ -79,9 +78,9 @@ impl RandomHandeler {
} }
} }
lazy_static! { lazy_static! {
pub static ref RAND_HANDLE: spin::Mutex<RandomHandeler> = spin::Mutex::new(RandomHandeler { pub static ref RAND_HANDLE: spin::Mutex<RandomHandeler> = spin::Mutex::new(RandomHandeler {
prand: PRand::new(), prand: PRand::new(),
linearshift: LinearShiftRegister::new(), linearshift: LinearShiftRegister::new(),
entropy: Entropy::new(), entropy: Entropy::new(),
}); });
} }