2021-11-16 00:09:27 -06:00
|
|
|
#![allow(clippy::empty_loop)]
|
|
|
|
use crate::{
|
2021-11-22 03:51:11 -06:00
|
|
|
arch::{
|
|
|
|
drivers::graphics::GraphicsBuffer,
|
|
|
|
init,
|
|
|
|
memory::{self, translate_addr},
|
|
|
|
sloop,
|
|
|
|
},
|
|
|
|
driver_traits::{graphics::Graphics, serial::Serial},
|
|
|
|
relib::math::rand::{linearshift::LinearShiftRegister, prand::PRand, RAND_HANDLE, RNG},
|
|
|
|
serial_print, serial_println,
|
2021-11-16 00:09:27 -06:00
|
|
|
};
|
2021-11-22 03:51:11 -06:00
|
|
|
use bootloader::{entry_point, BootInfo};
|
2021-11-16 00:09:27 -06:00
|
|
|
use lazy_static::lazy_static;
|
2021-11-22 03:51:11 -06:00
|
|
|
use x86_64::{VirtAddr, structures::paging::Page};
|
2021-11-16 00:09:27 -06:00
|
|
|
#[no_mangle]
|
|
|
|
#[allow(unconditional_recursion)]
|
|
|
|
pub extern "C" fn stack_overflow() -> u8 {
|
2021-11-22 03:51:11 -06:00
|
|
|
stack_overflow();
|
|
|
|
// meme number
|
|
|
|
69 // NOTE: Any specific reason for this number asside from memes?
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
use crate::keyboard::DecodedKey;
|
|
|
|
|
|
|
|
lazy_static! {
|
2021-11-22 03:51:11 -06:00
|
|
|
pub static ref KEY_BUFFER: [DecodedKey; 256] = [DecodedKey::RawKey(123); 256];
|
|
|
|
pub static ref KEY_BUFFER_POINTER: u8 = 0;
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2021-11-22 03:51:11 -06:00
|
|
|
// Defines the entry point
|
|
|
|
entry_point![kernel_main];
|
2021-11-16 00:09:27 -06:00
|
|
|
#[no_mangle]
|
2021-11-22 03:51:11 -06:00
|
|
|
pub fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
|
|
|
init::init();
|
2021-11-16 00:09:27 -06:00
|
|
|
|
2021-11-22 03:51:11 -06:00
|
|
|
GraphicsBuffer::draw();
|
|
|
|
GraphicsBuffer::hide_cursor();
|
|
|
|
GraphicsBuffer::show_cursor();
|
|
|
|
seed_rng();
|
2021-11-16 00:09:27 -06:00
|
|
|
|
2021-11-22 03:51:11 -06:00
|
|
|
/* If AES is present then AES init rng as well
|
|
|
|
// Maybe via a cfg
|
|
|
|
AES::init_rng();
|
2021-11-16 00:09:27 -06:00
|
|
|
|
2021-11-22 03:51:11 -06:00
|
|
|
*/
|
|
|
|
#[cfg(not(target_arch = "riscv64"))]
|
|
|
|
println!("init");
|
2021-11-17 08:42:54 -06:00
|
|
|
|
2021-11-22 03:51:11 -06:00
|
|
|
{
|
|
|
|
use crate::experiments::mail::MailBoxes;
|
|
|
|
let mut x = MailBoxes::new();
|
|
|
|
x.set_flag(1);
|
|
|
|
x.set_flag(2);
|
|
|
|
// x.dump_flags();
|
|
|
|
}
|
2021-11-16 00:09:27 -06:00
|
|
|
|
2021-11-22 03:51:11 -06:00
|
|
|
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
|
|
|
|
|
|
|
|
let mut mapper = unsafe { memory::init(phys_mem_offset) };
|
2021-11-22 08:58:35 -06:00
|
|
|
let mut frame_allocator = unsafe {
|
|
|
|
memory::BootInfoFrameAllocator::init(&boot_info.memory_map)
|
|
|
|
};
|
2021-11-22 03:51:11 -06:00
|
|
|
|
2021-11-22 08:58:35 -06:00
|
|
|
let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000));
|
2021-11-22 03:51:11 -06:00
|
|
|
memory::create_example_mapping(page, &mut mapper, &mut frame_allocator);
|
|
|
|
|
|
|
|
let page_ptr: *mut u64 = page.start_address().as_mut_ptr();
|
2021-11-22 08:58:35 -06:00
|
|
|
unsafe { page_ptr.offset(400).write_volatile(0xf021_f077_f065_804e) };
|
2021-11-22 03:51:11 -06:00
|
|
|
|
|
|
|
// stack_overflow();
|
|
|
|
// crate::arch::shutdown();
|
|
|
|
sloop()
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
// TODO: reimplement for the random handler
|
|
|
|
pub fn seed_rng() -> PRand {
|
2021-11-22 03:51:11 -06:00
|
|
|
println!("Seeding PRNG");
|
|
|
|
let data = TICK.lock();
|
|
|
|
let mut rand = PRand::new();
|
|
|
|
let seed = rand.rand();
|
|
|
|
println!("{:?}", seed);
|
|
|
|
rand.seed(*data);
|
|
|
|
println!("Seeded PRNG");
|
|
|
|
rand
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
lazy_static! {
|
2021-11-22 03:51:11 -06:00
|
|
|
// TODO: should have a sin wave influence contribution to entropy
|
|
|
|
pub static ref TICK: spin::Mutex<u64> = spin::Mutex::new(0);
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
/// called by arch specific timers to tick up all kernel related functions
|
|
|
|
pub fn tick() {
|
2021-11-22 03:51:11 -06:00
|
|
|
let mut data = TICK.lock();
|
|
|
|
*data += 1;
|
|
|
|
// serial_println!("{}", *data);
|
|
|
|
RAND_HANDLE.lock().seed_entropy_timer(*data);
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
pub fn key_entropy(key: u8) {
|
2021-11-22 03:51:11 -06:00
|
|
|
RAND_HANDLE.lock().seed_entropy_keyboard(key);
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|