apic broken pushing to debug

This commit is contained in:
2025-02-27 16:19:43 +00:00
parent ac0b47a45c
commit 821759ec63
8 changed files with 124 additions and 73 deletions
-49
View File
@@ -1,49 +0,0 @@
use core::arch::x86_64::__cpuid;
use x86_64::{PhysAddr, instructions::port::Port, registers::model_specific::Msr};
use super::cpu::model_specific_registers::*;
const IA32_APIC_BASE_MSR: u32 = 0x1b;
const IA32_APIC_BASE_MSR_BSP: u64 = 0x100;
const IA32_APIC_BASE_MSR_ENABLE: u64 = 0x800;
const CPUID_FEAT_EDX_APIC: u64 = 1 << 9; // the cpuid instruction will return this flag if it supports APIC
fn set_apic_base(apic: PhysAddr) {
let rax = (apic.as_u64() & 0xfffff0000) | IA32_APIC_BASE_MSR_ENABLE;
cpu_set_msr(IA32_APIC_BASE_MSR, rax);
}
fn get_apic_base() -> PhysAddr {
let mut value: u64 = 0;
cpu_get_msr(IA32_APIC_BASE_MSR, &mut value);
PhysAddr::new(value & 0xfffff0000)
}
fn write_apic_register(reg: u8, value: u32) {
let apic_base = get_apic_base().as_u64();
let reg_addr = (apic_base & 0xFFFFF0000) + reg as u64;
unsafe { *(reg_addr as *mut u32) = value };
}
fn read_apic_register(reg: u8) -> u32 {
let apic_base = get_apic_base().as_u64();
let reg_addr = (apic_base & 0xFFFFF0000) + reg as u64;
unsafe { *(reg_addr as *const u32) }
}
pub fn check_apic() -> bool {
let res = unsafe { __cpuid(1) };
res.edx as u64 & CPUID_FEAT_EDX_APIC != 0
}
pub fn enable_apic() {
set_apic_base(get_apic_base());
write_apic_register(0xF0, read_apic_register(0xF0) | 0x100);
}
pub struct Apic {}
pub enum ApicVector {}
-26
View File
@@ -1,26 +0,0 @@
pub mod model_specific_registers {
use core::arch::x86_64::__cpuid;
use spin::Lazy;
use x86_64::registers::model_specific::Msr;
const CPUID_FLAG_MSR: u32 = 1 << 5;
static EDX: Lazy<u32> = Lazy::new(|| unsafe { __cpuid(1).edx });
pub fn cpu_has_msr() -> bool {
*EDX & CPUID_FLAG_MSR != 0
}
pub fn cpu_get_msr(msr: u32, value: &mut u64) {
let msr = Msr::new(msr);
unsafe {
*value = msr.read();
}
}
pub fn cpu_set_msr(msr: u32, value: u64) {
let mut msr = Msr::new(msr);
unsafe {
msr.write(value);
}
}
}
-2
View File
@@ -1,7 +1,5 @@
pub mod io;
pub mod kalloc;
pub mod apic;
pub mod async_io;
pub mod cpu;
pub mod pic;