Parse MADT

This commit is contained in:
Mathieu Strypsteen 2024-07-13 22:51:14 +02:00
parent 4a39f6fa9c
commit d42972f9ec
4 changed files with 52 additions and 3 deletions

View file

@ -16,7 +16,7 @@ use kernel_common::{
use linked_list_allocator::LockedHeap;
use log::{error, info};
use spin::Once;
use sys::{acpica::AcpiInitializeTables, pic::disable_pic};
use sys::{acpica::AcpiInitializeTables, acpica_osl::AE_OK, madt::parse_madt, pic::disable_pic};
mod cpu;
mod misc;
@ -47,8 +47,12 @@ extern "C" fn main(temp_loader_struct: *const LoaderStruct) -> ! {
disable_pic();
RSDP_ADDRESS.call_once(|| loader_struct.rsdp_address);
unsafe {
AcpiInitializeTables(null_mut(), 16, 0);
let status = AcpiInitializeTables(null_mut(), 16, 0);
if status != AE_OK {
panic!("Failed to initialize ACPI tables");
}
}
parse_madt();
loop {
hlt();
}

1
kernel/src/sys/lapic.rs Normal file
View file

@ -0,0 +1 @@
pub fn setup_lapic(_address: u64) {}

42
kernel/src/sys/madt.rs Normal file
View file

@ -0,0 +1,42 @@
use core::mem::size_of;
use crate::sys::acpica_osl::AE_OK;
use super::{
acpica::{acpi_madt_local_apic_override, acpi_subtable_header, acpi_table_header, acpi_table_madt, AcpiGetTable},
lapic::setup_lapic,
};
pub fn parse_madt() {
let madt: &acpi_table_madt;
let signature = b"APIC" as *const u8;
let mut address: u64 = 0;
unsafe {
let status = AcpiGetTable(signature as *mut i8, 1, &mut address as *mut u64 as *mut *mut acpi_table_header);
if status != AE_OK {
panic!("Failed to get APIC table");
}
madt = &*(address as *const acpi_table_madt);
}
let mut lapic_address: u64 = madt.Address as u64;
let mut subtable_address = madt as *const acpi_table_madt as u64 + size_of::<acpi_table_madt>() as u64;
let end_address = madt as *const acpi_table_madt as u64 + madt.Header.Length as u64;
while subtable_address < end_address {
let subtable_header;
unsafe {
subtable_header = &*(subtable_address as *const acpi_subtable_header);
}
match subtable_header.Type {
5 => {
let subtable;
unsafe {
subtable = &*(subtable_address as *const acpi_madt_local_apic_override);
}
lapic_address = subtable.Address;
}
_ => {}
}
subtable_address += subtable_header.Length as u64;
}
setup_lapic(lapic_address);
}

View file

@ -1,3 +1,5 @@
pub mod acpica;
mod acpica_osl;
pub mod acpica_osl;
mod lapic;
pub mod madt;
pub mod pic;