use crate::arch::generate_process_pass; use crate::arch::interrupts::{reset_pit_for_cpu, set_pit_2}; use crate::devices::pci; use crate::filesystem::FILE_SYSTEM; use crate::rhai_shell::shell; use crate::rhai_shell::KEYBUFF; use crate::wasm_jumploader::run_program; use crate::{SCREEN_BUFFER, bogomips}; use acpi::{AcpiTables, PlatformInfo}; use cpuio::inb; use cpuio::outb; use genfs::Fs; use genfs::OpenOptions; use vga::writers::GraphicsWriter; // 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( &self, physical_address: usize, size: usize, ) -> acpi::PhysicalMapping { info!("PHYS ADDR: {:?}", physical_address); info!("Size: {:?}", size); todo!("map_physical_region"); } fn unmap_physical_region(_region: &acpi::PhysicalMapping) { todo!("unmap_physical_region"); } } pub struct Path { pub path: Vec, } impl Path { pub fn new(path: String) -> Self { let mut path_vec_string = vec![]; for part in path.split(&['\\', '/'][..]) { path_vec_string.push(part.to_string()); } Path { path: path_vec_string, } } } /// Experimental scratchpad for testing. pub fn scratchpad() { let axel_raw = "kernel{ vals= time: 123 fn| print: (None) -> (None); foo: (None) -> (Num); }"; let axel = axel::parse(axel_raw.to_string()); let xyz = pci::brute_force_scan(); for dev in xyz { trace!("{:?}", dev); dev.bars.iter().for_each(|bar| { trace!("{:?}", bar); }); } for node in axel { info!("{:?}", node); } /* use crate::devices::pci::brute_force_scan; let infos = brute_force_scan(); for device in infos { match device.vendor_id { 0x1af4 => { info!("Found virtio device"); use crate::virtio::device_handler; device_handler(device); } _ => { info!("Found unknown device"); } } } */ let abc = Path::new("/home/able".to_string()); for _ in 0..10 { debug!("{}", generate_process_pass()); } debug!("start the graphics"); let mut abcde = SCREEN_BUFFER.lock(); abcde.force_redraw(); abcde.draw_filled_circle(100, 100, 300, 0x0000ff00); abcde.draw_unfilled_rect(100, 100, 400, 200, 0xff000000); abcde.draw_filled_rect(300, 300, 400, 400, 0xff000000); abcde.draw_line(100, 100, 400, 200, 0xff000000); abcde.copy_to_buffer(); debug!("end the graphics"); // */ use crate::bogomips::bogomips; // bogomips(); real_shell(); } use crate::graphics::VgaBuffer; pub fn acpi() { let acpi_handler = AcpiStruct {}; let _table; unsafe { _table = AcpiTables::search_for_rsdp_bios(acpi_handler); } match _table.unwrap().platform_info().unwrap() { PlatformInfo { power_profile, interrupt_model, .. } => { info!("{:?}", power_profile); info!("{:?}", interrupt_model); // info!("{:?}", processor_info.unwrap()); // info!("{:?}", pm_timer.unwrap()); } } } 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::(&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 => (), } } } 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 = 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::>(); 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); } } pub fn sound(n_frequency: u32) { let div: u32; let tmp: u8; div = 1193180 / n_frequency; unsafe { outb(0xb6, 0x43); set_pit_2(div); //And play the sound using the PC speaker tmp = inb(0x61); if tmp != (tmp | 3) { outb(tmp | 3, 0x61); } } } pub fn sound_off() { unsafe { let tmp = inb(0x61) & 0xFC; outb(tmp, 0x61) }; reset_pit_for_cpu(); }