Changes to allow for detection and init of ASPs

This commit is contained in:
Jeremy Soller 2016-08-16 18:04:15 -06:00
commit 08900d56c8

View file

@ -4,18 +4,74 @@
use memory::{Frame, FrameAllocator};
use paging::{entry, ActivePageTable, Page, PhysicalAddress, VirtualAddress};
use self::rsdt::RSDT;
use self::sdt::SDT;
use self::xsdt::XSDT;
use self::local_apic::{LocalApic, LocalApicIcr};
use self::madt::{Madt, MadtEntry};
use self::rsdt::Rsdt;
use self::sdt::Sdt;
use self::xsdt::Xsdt;
pub mod local_apic;
pub mod madt;
pub mod rsdt;
pub mod sdt;
pub mod xsdt;
pub fn init_sdt(sdt: &'static Sdt) {
print!(" ");
for &c in sdt.signature.iter() {
print!("{}", c as char);
}
println!(":");
if let Some(madt) = Madt::new(sdt) {
println!(" {:>016X}: {}", madt.local_address, madt.flags);
let mut local_apic = LocalApic::new();
let me = local_apic.id() as u8;
for madt_entry in madt.iter() {
println!(" {:?}", madt_entry);
match madt_entry {
MadtEntry::LocalApic(asp_local_apic) => if asp_local_apic.id == me {
println!(" This is my local APIC");
} else {
if asp_local_apic.flags & 1 == 1 {
{
let icr = 0x00004500 | (asp_local_apic.id as u64) << 32;
println!(" Sending IPI to {}: {:>016X} {:?}", asp_local_apic.id, icr, LocalApicIcr::from_bits(icr));
local_apic.set_icr(icr);
}
{
let icr = 0x00004600 | (asp_local_apic.id as u64) << 32;
println!(" Sending SIPI to {}: {:>016X} {:?}", asp_local_apic.id, icr, LocalApicIcr::from_bits(icr));
local_apic.set_icr(icr);
}
} else {
println!(" CPU Disabled");
}
},
_ => ()
}
}
}else {
println!(" {:?}", sdt);
}
}
/// Parse the ACPI tables to gather CPU, interrupt, and timer information
pub unsafe fn init<A>(allocator: &mut A, active_table: &mut ActivePageTable) -> Option<Acpi>
where A: FrameAllocator
{
// Stupidity of enormous proportion. Write the halt opcode to the 0'th physical address
// so that START IPI's can halt the processor
{
if active_table.translate_page(Page::containing_address(VirtualAddress::new(0))).is_none() {
active_table.identity_map(Frame::containing_address(PhysicalAddress::new(0)), entry::PRESENT | entry::WRITABLE, allocator);
}
unsafe { *(0 as *mut u8) = 0xF4 };
}
let start_addr = 0xE0000;
let end_addr = 0xFFFFF;
@ -34,12 +90,12 @@ pub unsafe fn init<A>(allocator: &mut A, active_table: &mut ActivePageTable) ->
if let Some(rsdp) = RSDP::search(start_addr, end_addr) {
println!("{:?}", rsdp);
let mut get_sdt = |sdt_address: usize| -> &'static SDT {
let mut get_sdt = |sdt_address: usize| -> &'static Sdt {
if active_table.translate_page(Page::containing_address(VirtualAddress::new(sdt_address))).is_none() {
let sdt_frame = Frame::containing_address(PhysicalAddress::new(sdt_address));
active_table.identity_map(sdt_frame, entry::PRESENT | entry::NO_EXECUTE, allocator);
}
unsafe { &*(sdt_address as *const SDT) }
&*(sdt_address as *const Sdt)
};
let rxsdt = get_sdt(rsdp.sdt_address());
@ -48,25 +104,13 @@ pub unsafe fn init<A>(allocator: &mut A, active_table: &mut ActivePageTable) ->
print!("{}", c as char);
}
println!(":");
if let Some(rsdt) = RSDT::new(rxsdt) {
println!("{:?}", rsdt);
if let Some(rsdt) = Rsdt::new(rxsdt) {
for sdt_address in rsdt.iter() {
let sdt = get_sdt(sdt_address);
for &c in sdt.signature.iter() {
print!("{}", c as char);
}
println!(":");
println!("{:?}", sdt);
init_sdt(get_sdt(sdt_address));
}
} else if let Some(xsdt) = XSDT::new(rxsdt) {
println!("{:?}", xsdt);
} else if let Some(xsdt) = Xsdt::new(rxsdt) {
for sdt_address in xsdt.iter() {
let sdt = get_sdt(sdt_address);
for &c in sdt.signature.iter() {
print!("{}", c as char);
}
println!(":");
println!("{:?}", sdt);
init_sdt(get_sdt(sdt_address));
}
} else {
println!("UNKNOWN RSDT OR XSDT SIGNATURE");
@ -99,7 +143,7 @@ impl RSDP {
/// Search for the RSDP
pub fn search(start_addr: usize, end_addr: usize) -> Option<RSDP> {
for i in 0 .. (end_addr + 1 - start_addr)/16 {
let mut rsdp = unsafe { &*((start_addr + i * 16) as *const RSDP) };
let rsdp = unsafe { &*((start_addr + i * 16) as *const RSDP) };
if &rsdp.signature == b"RSD PTR " {
return Some(*rsdp);
}