From 9584f8a3ed12bd6510c6ce7bbdf3c99d5e22c6bf Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Mon, 21 Oct 2024 16:50:45 +0200 Subject: [PATCH] List processors at boot (#692) --- Makefile | 3 ++- src/lib.rs | 2 +- src/sys/acpi.rs | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c7e731cd8..0a076f7ae 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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) diff --git a/src/lib.rs b/src/lib.rs index b76c3a648..62b48321d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 diff --git a/src/sys/acpi.rs b/src/sys/acpi.rs index cdf948884..d8f599e4d 100644 --- a/src/sys/acpi.rs +++ b/src/sys/acpi.rs @@ -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}; @@ -16,6 +17,14 @@ 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::() { if let Ok(block) = fadt.pm1a_control_block() { unsafe { @@ -23,7 +32,7 @@ pub fn init() { } } } - 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(); @@ -157,3 +166,13 @@ fn read_addr(addr: usize) -> T where T: Copy { let virtual_address = sys::mem::phys_to_virt(PhysAddr::new(addr as u64)); unsafe { *virtual_address.as_ptr::() } } + +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); +}