diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-10 10:30:32 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-10 10:33:13 +0200 |
| commit | dd8dfa3e674d05927e9ed4b7efcb634a634bfdcc (patch) | |
| tree | ca3cf623e077837763182b699585b004ab06bd49 /arch/x86_64 | |
| parent | ed663488a66383e136534a5c43c66ef5868cb2d3 (diff) | |
| download | teachos-dd8dfa3e674d05927e9ed4b7efcb634a634bfdcc.tar.xz teachos-dd8dfa3e674d05927e9ed4b7efcb634a634bfdcc.zip | |
kapi: move CPU to kapi
Diffstat (limited to 'arch/x86_64')
| -rw-r--r-- | arch/x86_64/include/arch/cpu/initialization.hpp | 5 | ||||
| -rw-r--r-- | arch/x86_64/kapi/cpu.cpp | 26 |
2 files changed, 19 insertions, 12 deletions
diff --git a/arch/x86_64/include/arch/cpu/initialization.hpp b/arch/x86_64/include/arch/cpu/initialization.hpp index 71186d4..564c544 100644 --- a/arch/x86_64/include/arch/cpu/initialization.hpp +++ b/arch/x86_64/include/arch/cpu/initialization.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef TEACHOS_ARCH_X86_64_CPU_INITIALIZATION_HPP +#define TEACHOS_ARCH_X86_64_CPU_INITIALIZATION_HPP namespace arch::cpu { @@ -7,3 +8,5 @@ namespace arch::cpu auto initialize_legacy_interrupts() -> void; } // namespace arch::cpu + +#endif diff --git a/arch/x86_64/kapi/cpu.cpp b/arch/x86_64/kapi/cpu.cpp index 1382e08..726ec6a 100644 --- a/arch/x86_64/kapi/cpu.cpp +++ b/arch/x86_64/kapi/cpu.cpp @@ -2,6 +2,7 @@ #include "kapi/acpi.hpp" #include "kapi/devices.hpp" +#include "kapi/devices/cpu.hpp" #include "kapi/system.hpp" #include "arch/cpu/initialization.hpp" @@ -42,8 +43,9 @@ namespace kapi::cpu __builtin_unreachable(); } - auto discover_topology(kapi::devices::bus & bus) -> bool + auto discover_topology() -> bool { + auto static const cpu_major = kapi::devices::allocate_major_number(); auto static const core_major = kapi::devices::allocate_major_number(); auto static const interrupt_controller_major = kapi::devices::allocate_major_number(); @@ -54,10 +56,6 @@ namespace kapi::cpu return false; } - auto bsp_found = false; - auto core_count = 0uz; - auto local_apic_address = madt->local_interrupt_controller_address(); - auto lapic_entries = *madt | std::views::filter([](auto const & entry) { return entry.type() == acpi::multiple_apic_description_table_entry::types::processor_local_apic; }) | std::views::transform([](auto const & entry) { @@ -66,18 +64,24 @@ namespace kapi::cpu return static_cast<bool>(entry.active_flags() & candidate_flags); }); + auto bsp_found = false; + auto core_count = 0uz; + auto local_apic_address = madt->local_interrupt_controller_address(); + auto cpu_bus = kstd::make_unique<devices::cpu>(cpu_major, 0); + for (auto const & apic : lapic_entries) { auto is_bsp = !bsp_found; bsp_found = true; - auto instance = kstd::make_unique<arch::devices::local_apic>(interrupt_controller_major, core_count, - apic.apic_id(), local_apic_address, is_bsp); - if (core_detected(bus, core_major, core_count, apic.processor_id(), is_bsp, std::move(instance))) - { - ++core_count; - } + auto core = kstd::make_unique<devices::cpu::core>(core_major, core_count, apic.processor_id(), is_bsp); + core->add_child(kstd::make_unique<arch::devices::local_apic>(interrupt_controller_major, core_count, + apic.apic_id(), local_apic_address, is_bsp)); + cpu_bus->add_child(std::move(core)); + ++core_count; } + devices::get_root_bus().add_child(std::move(cpu_bus)); + kstd::println("[x86_64:PLT] Found {} CPU cores", core_count); return core_count > 0; } |
