2021-11-16 00:09:27 -06:00
|
|
|
#![allow(clippy::empty_loop)]
|
2021-11-28 14:50:14 -06:00
|
|
|
|
2022-01-25 19:02:22 -06:00
|
|
|
use alloc::{format, vec::Vec};
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
boot_conf::BootConfig,
|
2022-01-26 19:43:03 -06:00
|
|
|
capabilities::FileAccess,
|
|
|
|
file::{File, PathRep},
|
|
|
|
scheduler::SCHEDULER,
|
2022-01-27 01:37:12 -06:00
|
|
|
ALIAS_TABLE,
|
2022-01-25 19:02:22 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
// use crate::scheduler;
|
|
|
|
|
2021-12-24 03:30:27 -06:00
|
|
|
use {
|
|
|
|
crate::{
|
2022-01-22 00:01:16 -06:00
|
|
|
arch::{init, sloop},
|
|
|
|
boot_conf,
|
2022-01-16 09:23:19 -06:00
|
|
|
experiments::{
|
|
|
|
info::master,
|
|
|
|
systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
|
|
|
|
},
|
2022-01-22 00:01:16 -06:00
|
|
|
graphics::{VgaBuffer, SCREEN_BUFFER},
|
2022-01-16 19:42:11 -06:00
|
|
|
relib::network::socket::Socket,
|
2022-01-22 00:01:16 -06:00
|
|
|
relib::network::socket::{SimpleSock, SocketReturns},
|
|
|
|
vga_e::{self, num_to_vga16},
|
2022-01-16 09:23:19 -06:00
|
|
|
},
|
|
|
|
alloc::{
|
|
|
|
string::{String, ToString},
|
|
|
|
vec,
|
2021-12-24 03:30:27 -06:00
|
|
|
},
|
2022-01-22 00:01:16 -06:00
|
|
|
core::sync::atomic::{AtomicU64, Ordering::*},
|
2021-12-24 03:30:27 -06:00
|
|
|
lazy_static::lazy_static,
|
2022-01-22 00:01:16 -06:00
|
|
|
log::*,
|
|
|
|
picorand::PicoRandGenerate,
|
|
|
|
rkyv::{ser::serializers::AllocSerializer, Deserialize},
|
|
|
|
shadeable::pixel_format::from_vga_16,
|
|
|
|
y_compositor_protocol::Version,
|
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();
|
2021-11-23 05:54:57 -06:00
|
|
|
// 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());
|
2022-01-22 00:01:16 -06:00
|
|
|
pub static ref TICK: AtomicU64 = AtomicU64::new(0);
|
2022-01-25 19:02:22 -06:00
|
|
|
pub static ref BOOT_CONF: BootConfig = boot_conf::BootConfig::new();
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2021-11-23 06:01:42 -06:00
|
|
|
|
2022-01-26 19:43:03 -06:00
|
|
|
/// The main entry point of the kernel
|
2021-11-16 00:09:27 -06:00
|
|
|
#[no_mangle]
|
2021-11-23 06:01:42 -06:00
|
|
|
pub fn kernel_main() -> ! {
|
2021-11-16 00:09:27 -06:00
|
|
|
init::init();
|
2022-01-25 19:02:22 -06:00
|
|
|
log::set_max_level(BOOT_CONF.log_level());
|
2022-01-16 14:55:58 -06:00
|
|
|
|
2022-01-25 19:02:22 -06:00
|
|
|
use crate::scheduler::Priority;
|
|
|
|
let mut scheduler = SCHEDULER.lock();
|
|
|
|
|
|
|
|
use Priority::*;
|
|
|
|
|
2022-01-27 01:37:12 -06:00
|
|
|
let mut process_1 = scheduler.new_process(High);
|
|
|
|
process_1.capabilities.files = FileAccess::Some(vec![PathRep {
|
2022-01-26 19:43:03 -06:00
|
|
|
location: FileLocations::Home,
|
|
|
|
file_name: "test".to_string(),
|
|
|
|
}]);
|
2022-01-27 01:37:12 -06:00
|
|
|
scheduler.add_process(process_1);
|
|
|
|
for ref_process in &scheduler.list {
|
|
|
|
trace!("{:?}", ref_process);
|
2022-01-25 19:02:22 -06:00
|
|
|
}
|
|
|
|
drop(scheduler);
|
2022-01-16 09:23:19 -06:00
|
|
|
|
2022-01-26 19:43:03 -06:00
|
|
|
use crate::proto_filetable::contain::FILE_TABLE;
|
|
|
|
use crate::proto_filetable::file::FileLocations;
|
|
|
|
|
|
|
|
let mut file_table = FILE_TABLE.lock();
|
|
|
|
let mut new_file = File::new(FileLocations::Bin, "test".to_string(), "txt".to_string());
|
|
|
|
|
2022-01-27 01:37:12 -06:00
|
|
|
new_file.write_bytes(b"Hello, world!");
|
2022-01-26 19:43:03 -06:00
|
|
|
file_table.add_file("test", new_file);
|
|
|
|
|
|
|
|
let file = file_table.get_file("test");
|
|
|
|
|
|
|
|
match file {
|
|
|
|
Some(file) => {
|
|
|
|
let file_bytes = &file.data_pointer;
|
|
|
|
let file_string = String::from_utf8(file_bytes.to_vec()).unwrap();
|
|
|
|
info!("{}", file_string);
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
info!("File not found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 01:37:12 -06:00
|
|
|
crate::tests::screen_writer_test();
|
|
|
|
|
2022-01-25 19:02:22 -06:00
|
|
|
use crate::wasm::WasmProgram;
|
|
|
|
let ret = WasmProgram::new_from_bytes(&[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);
|
|
|
|
trace!("Binary Valid: {:?}", ret.validate_header());
|
2022-01-16 09:23:19 -06:00
|
|
|
|
2021-11-23 05:54:57 -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() {
|
2022-01-22 00:01:16 -06:00
|
|
|
let mut data = TICK.load(Relaxed);
|
|
|
|
data += 1;
|
|
|
|
|
2022-01-13 08:54:33 -06:00
|
|
|
crate::kernel_state::KERNEL_STATE.lock().update_state();
|
2022-01-25 19:02:22 -06:00
|
|
|
|
|
|
|
let mut scheduler = SCHEDULER.lock();
|
|
|
|
scheduler.bump_exec();
|
|
|
|
|
2022-01-22 00:01:16 -06:00
|
|
|
TICK.store(data, Relaxed)
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2022-01-26 19:43:03 -06:00
|
|
|
/// called every time a key is pressed to add it to the randomness pool
|
|
|
|
pub fn key_entropy(key: u8) {}
|
2022-01-18 06:15:51 -06:00
|
|
|
|
2022-01-22 00:01:16 -06:00
|
|
|
pub fn cpu_socket_startup() {
|
|
|
|
let mut cpu_info_socket = SimpleSock::new();
|
|
|
|
cpu_info_socket.register_protocol("CPU_INFO".to_string());
|
2022-01-18 06:15:51 -06:00
|
|
|
|
2022-01-22 00:01:16 -06:00
|
|
|
let x = master().unwrap();
|
2022-01-22 01:26:25 -06:00
|
|
|
let _xyz = x.brand_string().unwrap();
|
2022-01-18 06:15:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn log_version_data() {
|
|
|
|
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
|
|
|
info!(
|
|
|
|
"Brand String: {:?}",
|
|
|
|
master().unwrap().brand_string().unwrap()
|
|
|
|
);
|
|
|
|
}
|