1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/ableos/src/kmain.rs

121 lines
2.9 KiB
Rust
Raw Normal View History

2021-11-16 00:09:27 -06:00
#![allow(clippy::empty_loop)]
2021-11-28 14:50:14 -06:00
use alloc::format;
use crate::relib::network::socket::Socket;
2021-12-24 03:30:27 -06:00
use {
crate::{
arch::{drivers::graphics::GraphicsBuffer, init, sloop},
driver_traits::graphics::Graphics,
experiments::{
info::master,
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
},
log::LOG_STATE,
2021-12-24 03:30:27 -06:00
relib::math::rand::RAND_HANDLE,
scheduler::{test_fn, Thread, ThreadList},
vga_e,
},
alloc::{
string::{String, ToString},
vec,
2021-12-24 03:30:27 -06:00
},
lazy_static::lazy_static,
2021-11-16 00:09:27 -06:00
};
2022-01-13 08:54:33 -06:00
2021-11-16 00:09:27 -06:00
#[no_mangle]
#[allow(unconditional_recursion)]
pub extern "C" fn stack_overflow() -> u8 {
stack_overflow();
// meme number
2022-01-07 10:31:47 -06:00
69 // NOTE: Any specific reason for this number aside from memes?
2021-11-16 00:09:27 -06:00
}
lazy_static! {
2022-01-07 10:31:47 -06:00
pub static ref KEY_BUFFER: spin::Mutex<String> = spin::Mutex::new("".to_string());
2021-12-24 03:30:27 -06:00
pub static ref THREAD_LIST: spin::Mutex<ThreadList> = spin::Mutex::new(vec![]);
pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0);
2021-11-16 00:09:27 -06:00
}
2021-11-23 06:01:42 -06:00
2021-11-16 00:09:27 -06:00
#[no_mangle]
2021-11-23 06:01:42 -06:00
pub fn kernel_main() -> ! {
2022-01-13 08:54:33 -06:00
if false {
LOG_STATE.lock().info = false;
LOG_STATE.lock().trace = false;
LOG_STATE.lock().debug = false;
}
2021-11-16 00:09:27 -06:00
init::init();
2022-01-07 10:31:47 -06:00
2022-01-13 08:54:33 -06:00
{
let mut a_thread = Thread::new();
2021-12-24 13:00:20 -06:00
2022-01-13 08:54:33 -06:00
a_thread.new_task(test_fn);
a_thread.new_task(test_fn);
THREAD_LIST.lock().push(a_thread);
GraphicsBuffer::draw();
GraphicsBuffer::hide_cursor();
}
2021-12-24 03:30:27 -06:00
2021-12-24 08:04:07 -06:00
crate::wasm::evaluate();
2021-11-28 14:50:14 -06:00
2022-01-02 04:04:36 -06:00
{
2022-01-13 08:54:33 -06:00
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
info!(
"Brand String: {:?}",
master().unwrap().brand_string().unwrap()
);
if false {
println!("$PINK$Hi$RED$ from$GREEN$ able!$RESET$");
println!("$RED$hi$RESET$");
}
2022-01-02 04:04:36 -06:00
}
{
use crate::relib::network::socket::SimpleSock;
use crate::utils::type_of;
let mut xyz = SimpleSock::new();
xyz.write(vec![0, 0, 1, 0]);
xyz.close();
println!("type of socket: {:?}", type_of(&xyz));
println!("contents: {:?}", &xyz.read());
println!("length: {:?}", xyz.read().len());
drop(xyz);
}
{
use pretty_hex::*;
let v = vec![222, 173, 190, 239, 202, 254, 32, 24];
assert_eq!(simple_hex(&v), format!("{}", v.hex_dump()));
println!("{}", v.hex_dump());
}
//
info!("新着情報");
2022-01-07 10:31:47 -06:00
print!("$GREEN$able$RESET$@$LIGHTBLUE$stAble$ $RED$->$RESET$");
vga_e::draw_q();
2021-11-16 00:09:27 -06:00
// stack_overflow();
2022-01-13 08:54:33 -06:00
sloop()
2021-11-16 00:09:27 -06:00
}
2021-11-23 08:49:41 -06:00
2021-11-16 00:09:27 -06:00
/// 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);
2022-01-13 08:54:33 -06:00
// println!("{}", *data);
crate::kernel_state::KERNEL_STATE.lock().update_state();
2021-11-16 00:09:27 -06:00
}
2021-11-23 08:49:41 -06:00
2021-11-16 00:09:27 -06:00
pub fn key_entropy(key: u8) {
RAND_HANDLE.lock().seed_entropy_keyboard(key);
}