1
0
Fork 0
forked from koniifer/ableos
ableos-framebuffer/ableos/src/scratchpad.rs

179 lines
4.6 KiB
Rust
Raw Normal View History

2022-04-19 02:15:45 -05:00
use core::alloc::Layout;
2022-04-25 04:56:01 -05:00
use crate::encoding::bin;
2022-04-19 02:15:45 -05:00
use crate::rhai_shell::shell;
2022-04-25 04:56:01 -05:00
use crate::wasm_jumploader::run_program;
2022-04-19 02:15:45 -05:00
use acpi::{AcpiTables, PlatformInfo};
2022-04-25 04:56:01 -05:00
use genfs::Fs;
2022-02-08 03:01:29 -06:00
/// Experimental scratchpad for testing.
pub fn scratchpad() {
2022-04-09 17:26:43 -05:00
let axel_raw = "kernel{
2022-03-26 06:35:33 -05:00
vals=
time: 123
fn|
print: (None) -> (None);
foo: (None) -> (Num);
2022-04-09 17:26:43 -05:00
}";
2022-03-26 06:35:33 -05:00
let axel = axel::parse(axel_raw.to_string());
for node in axel {
info!("{:?}", node);
}
2022-04-19 02:15:45 -05:00
// acpi();
2022-04-25 04:56:01 -05:00
real_shell();
2022-02-08 04:13:53 -06:00
}
2022-02-12 03:25:02 -06:00
pub fn pci_fun() {}
2022-02-12 03:25:02 -06:00
pub fn acpi() {
let acpi_handler = AcpiStruct {};
let _table;
unsafe {
_table = AcpiTables::search_for_rsdp_bios(acpi_handler);
2022-02-12 03:25:02 -06:00
}
2022-04-19 02:15:45 -05:00
match _table.unwrap().platform_info().unwrap() {
PlatformInfo {
power_profile,
interrupt_model,
processor_info,
pm_timer,
} => {
info!("{:?}", power_profile);
info!("{:?}", interrupt_model);
// info!("{:?}", processor_info.unwrap());
// info!("{:?}", pm_timer.unwrap());
}
_ => todo!(),
}
}
// TODO: move to a better place
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AcpiStruct {}
impl acpi::AcpiHandler for AcpiStruct {
unsafe fn map_physical_region<T>(
&self,
physical_address: usize,
size: usize,
) -> acpi::PhysicalMapping<Self, T> {
info!("PHYS ADDR: {:?}", physical_address);
info!("Size: {:?}", size);
todo!("map_physical_region");
}
fn unmap_physical_region<T>(_region: &acpi::PhysicalMapping<Self, T>) {
todo!("unmap_physical_region");
}
2022-02-12 03:25:02 -06:00
}
2022-04-25 04:56:01 -05:00
pub fn real_shell() {
let _current_dir = "/".to_string();
let current_user = "able".to_string();
let mut buf = String::new();
print!("> ");
loop {
match x86_64::instructions::interrupts::without_interrupts(|| KEYBUFF.lock().pop()) {
Some('\n') => {
// match engine.eval_with_scope::<rhai::Dynamic>(&mut scope, &buf) {
// Ok(o) => println!("{o}"),
// Err(e) => println!("Eval error: {e}"),
// };
if !buf.is_empty() {
command_parser(current_user.clone(), buf.clone());
}
buf.clear();
print!("> ");
}
Some('\u{0008}') => {
buf.pop();
}
Some('\u{0009}') => {
buf.push(' ');
buf.push(' ');
buf.push(' ');
buf.push(' ');
}
Some(chr) => buf.push(chr),
None => (),
}
}
}
use crate::rhai_shell::KEYBUFF;
pub fn command_parser(user: String, command: String) {
let fs = &*FILE_SYSTEM.lock();
let mut iter = command.split_whitespace();
let bin_name = iter.next().unwrap();
if bin_name == "rhai" {
drop(fs);
shell();
return;
}
let home_exec_path = format!("/home/{}/bins/{}.wasm", user, bin_name);
let shared_exec_path = format!("/shared/bins/{}.wasm", bin_name);
let system_exec_path = format!("/system/bins/{}.wasm", bin_name);
let home_exec_file = fs.open(&home_exec_path.as_bytes(), OpenOptions::new().read(true));
let shared_exec_file = fs.open(&shared_exec_path.as_bytes(), OpenOptions::new().read(true));
let system_exec_file = fs.open(&system_exec_path.as_bytes(), OpenOptions::new().read(true));
let mut in_home = false;
let mut in_shared = false;
let mut in_system = false;
let mut binary_prog: Vec<u8> = vec![];
match home_exec_file {
Ok(file) => {
let ret = file.read_to_end(&mut binary_prog).unwrap();
in_home = true;
}
Err(error) => {
trace!("{:?}", error);
in_home = false;
}
}
match shared_exec_file {
Ok(file) => {
let ret = file.read_to_end(&mut binary_prog).unwrap();
in_shared = true;
}
Err(error) => {
trace!("{:?}", error);
in_shared = false;
}
}
match system_exec_file {
Ok(file) => {
let ret = file.read_to_end(&mut binary_prog).unwrap();
in_system = true;
}
Err(error) => {
trace!("{:?}", error);
in_system = false;
}
}
let args = iter.collect::<Vec<&str>>();
println!("{:?}", args);
if in_home || in_shared || in_system {
run_program(binary_prog);
} else {
println!("No such binary: {}", bin_name);
error!("No such binary: {}", bin_name);
}
}
use crate::filesystem::FILE_SYSTEM;
use genfs::OpenOptions;