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

190 lines
4.6 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
2022-02-18 10:04:10 -06:00
// use acpi::AcpiTables;
// use x86_64::instructions::interrupts::{disable, enable};
2022-02-07 03:42:57 -06:00
2022-02-18 10:04:10 -06:00
// use crate::{scratchpad, SCHEDULER, SCREEN_BUFFER};
2022-02-08 03:01:29 -06:00
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-28 07:40:47 -06:00
boot_conf::BootConfig,
2022-02-18 10:04:10 -06:00
// capabilities::FileAccess,
experiments::systeminfo::{KERNEL_VERSION, RELEASE_TYPE},
// file::PathRep,
2022-02-04 00:16:06 -06:00
relib::network::socket::{SimpleSock, Socket},
2022-02-18 10:04:10 -06:00
// scheduler::SCHEDULER,
// VgaBuffer,
// SCREEN_BUFFER,
scratchpad,
// SCHEDULER,
SCREEN_BUFFER,
2022-02-04 00:16:06 -06:00
},
alloc::{
format,
string::{String, ToString},
vec,
},
2022-01-22 00:01:16 -06:00
core::sync::atomic::{AtomicU64, Ordering::*},
2022-02-04 00:16:06 -06:00
facepalm::start_facepalm,
2021-12-24 03:30:27 -06:00
lazy_static::lazy_static,
2022-01-22 00:01:16 -06:00
log::*,
2022-02-18 10:04:10 -06:00
// shadeable::pixel_format::from_vga_16,
// vga::colors::Color16,
2021-11-16 00:09:27 -06:00
};
2022-01-13 08:54:33 -06:00
2021-11-16 00:09:27 -06:00
lazy_static! {
2022-02-07 21:14:47 -06:00
// TODO: Change this structure to allow for multiple cores loaded
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
/// 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-02-18 10:04:10 -06:00
// log::set_max_level(BOOT_CONF.log_level());
2022-01-16 14:55:58 -06:00
2022-02-18 10:04:10 -06:00
/*
2022-02-07 07:33:40 -06:00
let mut scheduler = SCHEDULER.lock();
2022-02-18 10:04:10 -06:00
2022-02-07 07:33:40 -06:00
use crate::scheduler::Priority::*;
let mut process_1 = scheduler.new_process(High);
process_1.capabilities.files = FileAccess::Some(vec![PathRep {
location: FileLocations::Home,
file_name: "test".to_string(),
}]);
scheduler.add_process(process_1);
for ref_process in &scheduler.list {
trace!("{:?}", ref_process);
2022-02-07 06:38:18 -06:00
}
2022-02-07 07:33:40 -06:00
drop(scheduler);
2022-02-03 13:47:58 -06:00
2022-02-18 10:04:10 -06:00
*/
// use crate::proto_filetable::file::FileLocations;
2022-02-03 13:47:58 -06:00
2022-02-18 10:04:10 -06:00
/*
if false {
let mut sock_print_id = SimpleSock::new();
sock_print_id.register_protocol("Screen Printer".to_string());
sock_print_id.write(format!("🐑").into());
let mut mode = SCREEN_BUFFER.lock();
2022-02-07 06:38:18 -06:00
2022-02-18 10:04:10 -06:00
mode.force_redraw();
for current in (*String::from_utf8_lossy(&sock_print_id.peek().unwrap())).chars() {
// mode.draw_char(0, 0, current, from_vga_16(Color16::Red));
}
// mode.copy_to_buffer();
}
*/
/*
2022-02-07 07:33:40 -06:00
// TODO: create a scratchpad module
2022-02-07 03:42:57 -06:00
if false {
// Currently not implemented
2022-02-07 06:38:18 -06:00
let acpi_handler = AcpiStruct {};
let mut table;
2022-02-07 03:42:57 -06:00
unsafe {
2022-02-07 06:38:18 -06:00
table = AcpiTables::search_for_rsdp_bios(acpi_handler);
2022-02-07 03:42:57 -06:00
}
}
2022-02-03 13:47:58 -06:00
2022-02-12 23:17:17 -06:00
2022-02-18 10:04:10 -06:00
*/
// start_facepalm();
// scratchpad();
/*
2022-02-17 04:05:56 -06:00
if false {
2022-02-18 10:04:10 -06:00
// disable();
2022-02-12 23:17:17 -06:00
let mut mode = SCREEN_BUFFER.lock();
mode.force_redraw();
2022-02-18 10:04:10 -06:00
// mode.copy_to_buffer();
2022-02-12 23:17:17 -06:00
mode.clear();
mode.draw_char(0, 0, 'v', 0xff00ffff);
2022-02-18 10:04:10 -06:00
// mode.copy_to_buffer();
2022-02-12 23:17:17 -06:00
drop(mode);
2022-02-18 10:04:10 -06:00
// enable()
2022-02-12 23:17:17 -06:00
// sloop::halt();
}
2022-02-18 10:04:10 -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();
// let mut scheduler = SCHEDULER.lock();
// scheduler.bump_exec();
2022-02-07 06:38:18 -06:00
// drop(scheduler);
2022-01-25 19:02:22 -06:00
2022-01-22 00:01:16 -06:00
TICK.store(data, Relaxed)
2021-11-16 00:09:27 -06:00
}
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-02-18 10:04:10 -06:00
// let x = master().unwrap();
// 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!(
2022-02-18 10:04:10 -06:00
"Brand String: ",
// master().unwrap().brand_string().unwrap()
2022-01-18 06:15:51 -06:00
);
}
2022-02-18 10:04:10 -06:00
2022-02-07 07:33:40 -06:00
// TODO: Split up into the randomness and the password generation
2022-02-07 03:01:50 -06:00
pub fn generate_process_pass() -> u128 {
2022-02-07 07:33:40 -06:00
// TODO: Move this into entropy_pool module
2022-02-18 10:04:10 -06:00
// use rdrand::RdRand;
// let gen = RdRand::new().unwrap();
2022-02-07 07:33:40 -06:00
// TODO: Split off into process module
2022-02-18 10:04:10 -06:00
// let ret = (gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128);
// ret
123
2022-02-07 03:01:50 -06:00
}
2022-02-18 10:04:10 -06:00
/*
2022-02-07 03:42:57 -06:00
// TODO: move to a better place
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
2022-02-07 06:38:18 -06:00
pub struct AcpiStruct {}
2022-02-07 03:42:57 -06:00
2022-02-07 06:38:18 -06:00
impl acpi::AcpiHandler for AcpiStruct {
2022-02-07 03:42:57 -06:00
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-18 10:04:10 -06:00
*/