Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List processors at boot #692

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading