CPUID support

pull/11/head
able 2023-09-20 12:01:12 -05:00
parent 0d101ed865
commit b233347ca4
2 changed files with 55 additions and 10 deletions

View File

@ -0,0 +1,49 @@
use {
crate::{alloc::string::ToString, device_tree::DeviceTree, kmain::DEVICE_TREE},
alloc::string::String,
core::arch::asm,
xml::XMLElement,
};
pub fn collect_device_info() {
log::trace!("Collecting devices on aarch64");
// Lock device tree
unsafe {
DEVICE_TREE.force_unlock();
}
let device_tree = &mut DEVICE_TREE.lock();
collect_cpu_info(device_tree);
// let dt = DEVICE_TREE.lock();
}
fn collect_cpu_info(device_tree: &mut DeviceTree) {
let mut cpu = XMLElement::new("cpu");
let cpu_id = cpu_id();
cpu.set_attribute("CPU Name", cpu_id.0);
cpu.set_attribute("CPU Id", cpu_id.1);
let cpus = device_tree.devices.get_mut("CPUs").unwrap();
cpus.push(cpu);
}
fn cpu_id() -> (String, u64) {
let mut cpu_id: u64 = 0;
unsafe {
asm!("mrs {cpu_id}, MIDR_EL1",
cpu_id = out(reg) cpu_id,
)
}
let cpu_name = match cpu_id {
// the source of these two was a stackoverflow question
// https://raspberrypi.stackexchange.com/questions/117175/how-do-i-read-the-cpuid-in-aarch64-asm
0x410FD034 => "Cortex-A53".to_string(),
0x410FD083 => "Cortex-A72".to_string(),
_ => "Unknown".to_string(),
};
log::trace!("CPU Name: {cpu_name} - CPU ID: 0x{:X}", cpu_id);
(cpu_name, cpu_id)
}

View File

@ -4,6 +4,9 @@ use {
core::arch::asm,
limine::FramebufferRequest,
};
mod device_info_collector;
use device_info_collector::collect_device_info;
pub mod logging;
use limine::HhdmRequest;
extern "C" {
@ -14,22 +17,13 @@ const INITIAL_KERNEL_HEAP_START: *mut u8 = _initial_kernel_heap_start as _;
const INITIAL_KERNEL_HEAP_SIZE: *const () = _initial_kernel_heap_size as _;
pub const PAGE_SIZE: usize = 4096;
static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
#[no_mangle]
unsafe extern "C" fn _kernel_start() -> ! {
crate::logger::init().expect("failed to set logger");
log::info!("Initialising AKern {}", crate::VERSION);
static FB_REQ: FramebufferRequest = FramebufferRequest::new(0);
let fb1 = &FB_REQ.get_response().get().unwrap().framebuffers()[0];
for i in 0..100_usize {
let offset = i * fb1.pitch as usize + i * 4;
unsafe {
*(fb1.address.as_ptr().unwrap().offset(offset as isize) as *mut u32) = 0xFFFFFFFF;
}
}
static HDHM_REQ: HhdmRequest = HhdmRequest::new(0);
// memory::init_pt(VirtAddr::new(
// HDHM_REQ
@ -40,6 +34,8 @@ unsafe extern "C" fn _kernel_start() -> ! {
// ));
allocator::init(INITIAL_KERNEL_HEAP_START, INITIAL_KERNEL_HEAP_SIZE as _);
collect_device_info();
let bm = MOD_REQ.get_response().get();
use limine::{KernelFileRequest, ModuleRequest};
static KFILE_REQ: KernelFileRequest = KernelFileRequest::new(0);