Skip to content

Commit

Permalink
List processors at boot (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc authored Oct 21, 2024
1 parent 4d7e2b0 commit 9584f8a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ keyboard = qwerty# qwerty, azerty, dvorak
mode = release

# Emulation options
smp = 2
nic = rtl8139# rtl8139, pcnet, e1000
audio = sdl# sdl, coreaudio
signal = off# on
Expand Down Expand Up @@ -73,7 +74,7 @@ image: $(img)
cargo bootimage $(cargo-opts)
dd conv=notrunc if=$(bin) of=$(img)

qemu-opts = -m $(memory) -drive file=$(img),format=raw \
qemu-opts = -m $(memory) -smp $(smp) -drive file=$(img),format=raw \
-audiodev $(audio),id=a0 -machine pcspk-audiodev=a0 \
-netdev user,id=e0,hostfwd=tcp::8080-:80 -device $(nic),netdev=e0
ifeq ($(kvm),true)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub fn init(boot_info: &'static BootInfo) {
log!("SYS MOROS v{}", v);

sys::mem::init(boot_info);
sys::acpi::init(); // Require MEM
sys::cpu::init();
sys::acpi::init(); // Require MEM
sys::rng::init();
sys::pci::init(); // Require MEM
sys::net::init(); // Require PCI
Expand Down
21 changes: 20 additions & 1 deletion src/sys/acpi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::sys;

use acpi::{AcpiHandler, AcpiTables, PhysicalMapping};
use acpi::platform::{Processor, ProcessorState};
use alloc::boxed::Box;
use aml::value::AmlValue;
use aml::{AmlContext, AmlName, DebugVerbosity, Handler};
Expand All @@ -16,14 +17,22 @@ pub fn init() {
let res = unsafe { AcpiTables::search_for_rsdp_bios(MorosAcpiHandler) };
match res {
Ok(acpi) => {
if let Ok(info) = acpi.platform_info() {
if let Some(info) = info.processor_info {
log_cpu(&info.boot_processor);
for processor in info.application_processors.iter() {
log_cpu(&processor);
}
}
}
if let Ok(fadt) = acpi.find_table::<acpi::fadt::Fadt>() {
if let Ok(block) = fadt.pm1a_control_block() {
unsafe {
PM1A_CNT_BLK = block.address as u32;
}
}
}
if let Ok(dsdt) = &acpi.dsdt() {
if let Ok(dsdt) = acpi.dsdt() {
let phys_addr = PhysAddr::new(dsdt.address as u64);
let virt_addr = sys::mem::phys_to_virt(phys_addr);
let ptr = virt_addr.as_ptr();
Expand Down Expand Up @@ -157,3 +166,13 @@ fn read_addr<T>(addr: usize) -> T where T: Copy {
let virtual_address = sys::mem::phys_to_virt(PhysAddr::new(addr as u64));
unsafe { *virtual_address.as_ptr::<T>() }
}

fn log_cpu(processor: &Processor) {
let kind = if processor.is_ap { "AP" } else { "BP" };
let state = match processor.state {
ProcessorState::Disabled => "disabled",
ProcessorState::Running => "running",
ProcessorState::WaitingForSipi => "waiting",
};
log!("CPU {}:{} {}", kind, processor.processor_uid, state);
}

0 comments on commit 9584f8a

Please sign in to comment.