ableos/ableos/src/arch/x86_64/mod.rs

64 lines
1.6 KiB
Rust
Raw Normal View History

2022-08-06 11:48:40 +00:00
/*
2022-08-12 13:40:23 +00:00
* Copyright (c) 2022, able <abl3theabove@gmail.com>
*
* SPDX-License-Identifier: MPL-2.0
*/
2022-08-06 11:48:40 +00:00
2021-11-16 06:09:27 +00:00
pub mod drivers;
pub mod gdt;
pub mod init;
pub mod interrupts;
pub mod memory;
2021-11-23 12:01:42 +00:00
2022-04-11 22:23:11 +00:00
use crate::arch::drivers::allocator;
use bootloader::{entry_point, BootInfo};
use x86_64::{instructions::hlt, VirtAddr};
2022-08-06 11:48:40 +00:00
#[cfg(not(test))]
2021-11-23 12:01:42 +00:00
entry_point![start];
2022-08-06 11:48:40 +00:00
#[cfg(not(test))]
2021-11-23 12:01:42 +00:00
#[no_mangle]
pub fn start(boot_info: &'static BootInfo) -> ! {
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
let mut mapper = unsafe { memory::init(phys_mem_offset) };
let mut frame_allocator =
unsafe { memory::BootInfoFrameAllocator::init(&boot_info.memory_map) };
2022-04-11 22:23:11 +00:00
// let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000));
// memory::create_example_mapping(page, &mut mapper, &mut frame_allocator);
//
// let page_ptr: *mut u64 = page.start_address().as_mut_ptr();
// unsafe { page_ptr.offset(400).write_volatile(0xf021_f077_f065_804e) };
2021-11-23 12:01:42 +00:00
2021-11-28 20:50:14 +00:00
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
2022-01-18 12:15:51 +00:00
2022-08-08 19:55:28 +00:00
crate::kmain::kernel_main(mapper, frame_allocator);
2021-11-23 12:01:42 +00:00
}
2021-11-16 06:09:27 +00:00
#[allow(unused)]
pub fn shutdown() -> ! {
2022-01-13 14:54:33 +00:00
info!("Shutting down");
unsafe {
cpuio::outw(0x2000, 0x604);
}
2021-11-16 06:09:27 +00:00
sloop();
}
pub fn sloop() -> ! {
loop {
hlt();
}
}
// TODO: Split up into the randomness and the password generation
pub fn generate_process_pass() -> u128 {
// TODO: Move this into entropy_pool module
use rdrand::RdRand;
let gen = RdRand::new().unwrap();
(gen.try_next_u64().unwrap() as u128) << 64 | (gen.try_next_u64().unwrap() as u128)
}