2022-08-04 09:03:44 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2022, Umut İnan Erdoğan <umutinanerdogan@pm.me>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2021-11-16 00:09:27 -06:00
|
|
|
#![allow(clippy::empty_loop)]
|
2022-11-23 06:00:38 -06:00
|
|
|
|
2022-08-01 06:09:05 -05:00
|
|
|
use core::sync::atomic::AtomicU64;
|
2022-07-28 20:15:02 -05:00
|
|
|
|
2022-08-09 03:11:15 -05:00
|
|
|
use crate::arch::memory::BootInfoFrameAllocator;
|
2022-08-01 06:09:05 -05:00
|
|
|
use crate::arch::{drivers::sysinfo::master, init, sloop};
|
2022-08-12 08:40:23 -05:00
|
|
|
use crate::devices::pci;
|
2022-08-01 06:09:05 -05:00
|
|
|
use crate::relib::network::socket::{SimpleSock, Socket};
|
2022-11-23 04:02:02 -06:00
|
|
|
use crate::{boot_conf::KernelConfig, scratchpad, systeminfo::RELEASE_TYPE};
|
|
|
|
// use crate::{boot_conf::KernelConfig, scratchpad, systeminfo::RELEASE_TYPE, TERM};
|
2022-08-04 09:03:44 -05:00
|
|
|
use crate::{filesystem, hardware};
|
2022-07-31 01:54:01 -05:00
|
|
|
use kernel::KERNEL_VERSION;
|
2022-04-11 15:51:54 -05:00
|
|
|
use spin::Lazy;
|
2022-01-13 08:54:33 -06:00
|
|
|
|
2022-08-08 14:55:28 -05:00
|
|
|
// FIXME: platform agnostic paging stuff
|
2022-08-09 03:11:15 -05:00
|
|
|
use x86_64::structures::paging::{Mapper, Size4KiB};
|
2022-08-08 14:55:28 -05:00
|
|
|
|
2022-04-11 15:51:54 -05:00
|
|
|
// TODO: Change this structure to allow for multiple cores loaded
|
|
|
|
pub static KERNEL_CONF: Lazy<KernelConfig> = Lazy::new(KernelConfig::new);
|
2021-11-23 06:01:42 -06:00
|
|
|
|
2022-01-26 19:43:03 -06:00
|
|
|
/// The main entry point of the kernel
|
2022-08-08 14:55:28 -05:00
|
|
|
pub fn kernel_main(
|
|
|
|
mut mapper: impl Mapper<Size4KiB>,
|
2022-08-09 03:11:15 -05:00
|
|
|
mut frame_allocator: BootInfoFrameAllocator,
|
2022-08-08 14:55:28 -05:00
|
|
|
) -> ! {
|
2021-11-16 00:09:27 -06:00
|
|
|
init::init();
|
2022-03-11 13:51:47 -06:00
|
|
|
|
2022-07-31 05:22:39 -05:00
|
|
|
// /*
|
2022-03-11 13:51:47 -06:00
|
|
|
if KERNEL_CONF.logging.enabled {
|
|
|
|
log::set_max_level(KERNEL_CONF.log_level());
|
2022-07-31 06:21:50 -05:00
|
|
|
// println!("{:#?}", *KERNEL_CONF);
|
2022-03-11 13:51:47 -06:00
|
|
|
} else {
|
|
|
|
log::set_max_level(log::LevelFilter::Off);
|
|
|
|
}
|
2022-07-31 05:22:39 -05:00
|
|
|
// */
|
|
|
|
// let mut term = TERM.lock();
|
|
|
|
// term.initialize();
|
|
|
|
// term.set_dirty(true);
|
|
|
|
// term.draw_term();
|
|
|
|
// drop(term);
|
2022-02-03 13:47:58 -06:00
|
|
|
|
2022-08-12 08:48:22 -05:00
|
|
|
pci::init(&mut mapper, &mut frame_allocator);
|
2022-08-12 08:40:23 -05:00
|
|
|
|
2022-07-31 01:54:01 -05:00
|
|
|
x86_64::instructions::interrupts::without_interrupts(|| {
|
|
|
|
hardware::init_mouse();
|
|
|
|
});
|
2022-08-04 09:03:44 -05:00
|
|
|
|
|
|
|
filesystem::init().unwrap();
|
|
|
|
|
2022-08-01 21:56:01 -05:00
|
|
|
/*
|
2022-07-31 01:54:01 -05:00
|
|
|
|
|
|
|
// println!("abc");
|
2022-07-28 20:15:02 -05:00
|
|
|
let mut ipc_service = IPC.lock();
|
|
|
|
// create some channels or whatever here then drop it
|
2022-07-29 06:13:26 -05:00
|
|
|
let log_handle = ipc_service.create_channel("LOG", true);
|
2022-07-29 09:46:09 -05:00
|
|
|
let log_sock_handle = ipc_service.create_socket("LOG", true);
|
|
|
|
|
|
|
|
for handle in ipc_service.examine_board() {
|
2022-07-31 01:54:01 -05:00
|
|
|
// println!("Discovered: {}", handle);
|
2022-07-29 09:46:09 -05:00
|
|
|
}
|
2022-07-28 20:15:02 -05:00
|
|
|
|
|
|
|
drop(ipc_service);
|
|
|
|
|
2022-07-31 01:54:01 -05:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// use x86_ata::{init, ATA_BLOCK_SIZE};
|
2022-07-29 13:29:54 -05:00
|
|
|
// 1. Initialise ATA Subsystem. (Perform Once, on boot)
|
2022-07-31 01:54:01 -05:00
|
|
|
// init().expect("Failed To Start ATA...");
|
|
|
|
// let mut buffer: [u8; ATA_BLOCK_SIZE] = [0; ATA_BLOCK_SIZE];
|
2022-07-29 13:29:54 -05:00
|
|
|
// FIXME: Calls to read panic the kernel
|
|
|
|
// read(0, 0, 0, &mut buffer);
|
|
|
|
|
|
|
|
// for abc in list() {
|
|
|
|
// trace!("{:?}", abc);
|
|
|
|
// }
|
2022-07-31 05:22:39 -05:00
|
|
|
/*
|
2022-07-31 01:54:01 -05:00
|
|
|
log_version_data();
|
2022-08-01 04:06:04 -05:00
|
|
|
// */
|
2022-08-07 16:42:23 -05:00
|
|
|
scratchpad();
|
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
|
|
|
|
2022-07-29 06:13:26 -05:00
|
|
|
pub fn traceloop() {
|
2022-07-29 11:51:54 -05:00
|
|
|
// TODO: Having an empty function double faults
|
2022-07-29 09:46:09 -05:00
|
|
|
|
|
|
|
// let mut last_time = 0.0;
|
|
|
|
/*
|
2022-07-29 06:13:26 -05:00
|
|
|
loop {
|
2022-07-29 09:46:09 -05:00
|
|
|
// FIXME: the following double faults
|
|
|
|
/*
|
|
|
|
let time = fetch_time();
|
|
|
|
if time > last_time {
|
|
|
|
last_time = time;
|
|
|
|
trace!("Timer");
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO: This also double faults
|
|
|
|
let fs = &*crate::filesystem::FILE_SYSTEM.lock();
|
|
|
|
let path = format!("/home/able/bins/aos_test.wasm");
|
|
|
|
|
|
|
|
let home_exec_file = fs.open(&path.as_bytes(), OpenOptions::new().read(true));
|
|
|
|
|
|
|
|
drop(fs);
|
|
|
|
let mut binary_prog: Vec<u8> = vec![];
|
|
|
|
|
|
|
|
match home_exec_file {
|
|
|
|
Ok(file) => {
|
|
|
|
let ret = file.read_to_end(&mut binary_prog).unwrap();
|
|
|
|
}
|
|
|
|
_ => {}
|
2022-07-29 06:13:26 -05:00
|
|
|
}
|
2022-07-29 09:46:09 -05:00
|
|
|
|
|
|
|
wasm_jumploader::run_program(&binary_prog);
|
|
|
|
*/
|
2022-07-29 06:13:26 -05: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() {
|
2022-07-31 01:54:01 -05:00
|
|
|
info!("{} v{}", RELEASE_TYPE, KERNEL_VERSION);
|
2022-01-18 06:15:51 -06:00
|
|
|
info!(
|
2022-03-16 05:39:01 -05:00
|
|
|
"Brand String: {}",
|
|
|
|
master().unwrap().brand_string().unwrap()
|
2022-01-18 06:15:51 -06:00
|
|
|
);
|
|
|
|
}
|
2022-07-31 01:54:01 -05:00
|
|
|
|
|
|
|
pub static TICK: AtomicU64 = AtomicU64::new(0);
|
|
|
|
|
|
|
|
pub fn tick() {
|
|
|
|
x86_64::instructions::interrupts::without_interrupts(|| {
|
2022-11-23 04:02:02 -06:00
|
|
|
// let mut term = TERM.lock();
|
2022-07-31 01:54:01 -05:00
|
|
|
|
2022-11-23 04:02:02 -06:00
|
|
|
// term.draw_term();
|
2022-07-31 01:54:01 -05:00
|
|
|
use core::sync::atomic::Ordering::Relaxed;
|
|
|
|
|
|
|
|
let mut data = TICK.load(Relaxed);
|
|
|
|
data = data.wrapping_add(1);
|
|
|
|
|
|
|
|
TICK.store(data, Relaxed);
|
|
|
|
});
|
|
|
|
}
|