forked from AbleOS/ableos
107 lines
2.8 KiB
Rust
107 lines
2.8 KiB
Rust
#![allow(clippy::empty_loop)]
|
|
|
|
pub extern crate externc_libm as libm;
|
|
|
|
use {
|
|
crate::{
|
|
arch::{drivers::graphics::GraphicsBuffer, init, sloop},
|
|
driver_traits::graphics::Graphics,
|
|
experiments::systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
|
keyboard::DecodedKey,
|
|
relib::math::rand::RAND_HANDLE,
|
|
scheduler::{test_fn, Thread, ThreadList},
|
|
},
|
|
alloc::{boxed::Box, rc::Rc, vec, vec::Vec},
|
|
lazy_static::lazy_static,
|
|
};
|
|
|
|
#[no_mangle]
|
|
#[allow(unconditional_recursion)]
|
|
pub extern "C" fn stack_overflow() -> u8 {
|
|
stack_overflow();
|
|
// meme number
|
|
69 // NOTE: Any specific reason for this number asside from memes?
|
|
}
|
|
|
|
lazy_static! {
|
|
pub static ref KEY_BUFFER: [DecodedKey; 256] = [DecodedKey::RawKey(123); 256];
|
|
pub static ref KEY_BUFFER_POINTER: u8 = 0;
|
|
pub static ref THREAD_LIST: spin::Mutex<ThreadList> = spin::Mutex::new(vec![]);
|
|
pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0);
|
|
}
|
|
use alloc::format;
|
|
|
|
use crate::log::{self, Log};
|
|
#[no_mangle]
|
|
pub fn kernel_main() -> ! {
|
|
init::init();
|
|
let mut a_thread = Thread::new();
|
|
|
|
a_thread.new_task(test_fn);
|
|
a_thread.new_task(test_fn);
|
|
|
|
THREAD_LIST.lock().push(a_thread);
|
|
|
|
GraphicsBuffer::draw();
|
|
GraphicsBuffer::hide_cursor();
|
|
GraphicsBuffer::show_cursor();
|
|
if false {
|
|
test_alloc();
|
|
}
|
|
// crate::wasm::evaluate();
|
|
|
|
println!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
|
log::ANSISerialLogger::debug(&format!("{} v{}", RELEASE_TYPE, KERNEL_VERSION));
|
|
|
|
{
|
|
use crate::experiments::mail::MailBoxes;
|
|
let mut x = MailBoxes::new();
|
|
x.set_flag(1);
|
|
x.set_flag(2);
|
|
// x.dump_flags();
|
|
}
|
|
|
|
// stack_overflow();
|
|
// crate::arch::shutdown();
|
|
sloop()
|
|
}
|
|
|
|
/// called by arch specific timers to tick up all kernel related functions
|
|
pub fn tick() {
|
|
let mut data = TICK.lock();
|
|
*data += 1;
|
|
RAND_HANDLE.lock().seed_entropy_timer(*data);
|
|
}
|
|
|
|
pub fn key_entropy(key: u8) {
|
|
RAND_HANDLE.lock().seed_entropy_keyboard(key);
|
|
}
|
|
|
|
fn test_alloc() {
|
|
let x: Vec<u8> = vec![1];
|
|
println!("{:?}", x);
|
|
|
|
let heap_value = Box::new(41);
|
|
println!("heap_value at {:p}", heap_value);
|
|
|
|
// create a dynamically sized vector
|
|
let mut vec = Vec::new();
|
|
for i in 0..500 {
|
|
vec.push(i);
|
|
}
|
|
println!("vec at {:p}", vec.as_slice());
|
|
|
|
// create a reference counted vector -> will be freed when count reaches 0
|
|
let reference_counted = Rc::new(vec![1, 2, 3]);
|
|
let cloned_reference = reference_counted.clone();
|
|
println!(
|
|
"current reference count is {}",
|
|
Rc::strong_count(&cloned_reference)
|
|
);
|
|
core::mem::drop(reference_counted);
|
|
println!(
|
|
"reference count is {} now",
|
|
Rc::strong_count(&cloned_reference)
|
|
);
|
|
}
|