diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-15 15:56:43 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-15 15:56:43 +0200 |
| commit | 014e52494a73ce80d9e4c47e4eab676213c25a03 (patch) | |
| tree | 4a1633c7d6308276db650602a0266582e2247de0 | |
| parent | 3130556cdab078de5db6fabdf6f2d57c05ced08a (diff) | |
| download | kernel-014e52494a73ce80d9e4c47e4eab676213c25a03.tar.xz kernel-014e52494a73ce80d9e4c47e4eab676213c25a03.zip | |
kernel/cpu: introduce core index number
| -rw-r--r-- | arch/x86_64/arch/devices/local_apic.cpp | 8 | ||||
| -rw-r--r-- | arch/x86_64/arch/devices/local_apic.hpp | 7 | ||||
| -rw-r--r-- | arch/x86_64/kapi/cpu.cpp | 7 | ||||
| -rw-r--r-- | kapi/kapi/devices/cpu.hpp | 5 | ||||
| -rw-r--r-- | kernel/kapi/devices/cpu.cpp | 9 |
5 files changed, 28 insertions, 8 deletions
diff --git a/arch/x86_64/arch/devices/local_apic.cpp b/arch/x86_64/arch/devices/local_apic.cpp index b481a667..f3ab8d32 100644 --- a/arch/x86_64/arch/devices/local_apic.cpp +++ b/arch/x86_64/arch/devices/local_apic.cpp @@ -74,9 +74,10 @@ namespace arch::devices divide_configuration = 0x3e0, }; - local_apic::local_apic(std::size_t major, std::size_t minor, std::uint64_t hardware_id, + local_apic::local_apic(std::size_t major, std::size_t minor, std::uint64_t core_index, std::uint64_t hardware_id, kapi::memory::physical_address base, bool is_bsp) : kapi::devices::device{major, minor, "lapic"} + , m_core_index{core_index} , m_hardware_id{hardware_id} , m_base{base} , m_is_bsp{is_bsp} @@ -119,6 +120,11 @@ namespace arch::devices return true; } + auto local_apic::core_index() const noexcept -> std::uint64_t + { + return m_core_index; + } + auto local_apic::read_register(registers id) const -> std::uint32_t { auto reg = static_cast<std::uint32_t volatile *>(m_mapped_region.first + std::to_underlying(id)); diff --git a/arch/x86_64/arch/devices/local_apic.hpp b/arch/x86_64/arch/devices/local_apic.hpp index f8f080dc..3a2d5417 100644 --- a/arch/x86_64/arch/devices/local_apic.hpp +++ b/arch/x86_64/arch/devices/local_apic.hpp @@ -12,17 +12,20 @@ namespace arch::devices struct local_apic : kapi::devices::device { - local_apic(std::size_t major, std::size_t minor, std::uint64_t hardware_id, kapi::memory::physical_address base, - bool is_bsp); + local_apic(std::size_t major, std::size_t minor, std::uint64_t core_index, std::uint64_t hardware_id, + kapi::memory::physical_address base, bool is_bsp); auto init() -> bool override; + [[nodiscard]] auto core_index() const noexcept -> std::uint64_t; + private: enum struct registers : std::ptrdiff_t; [[nodiscard]] auto read_register(registers id) const -> std::uint32_t; auto write_register(registers id, std::uint32_t value) -> void; + std::uint64_t m_core_index{}; std::uint64_t m_hardware_id{}; kapi::memory::physical_address m_base{}; kapi::memory::mmio_region m_mapped_region{}; diff --git a/arch/x86_64/kapi/cpu.cpp b/arch/x86_64/kapi/cpu.cpp index 70cd3635..c51e08b3 100644 --- a/arch/x86_64/kapi/cpu.cpp +++ b/arch/x86_64/kapi/cpu.cpp @@ -74,9 +74,10 @@ namespace kapi::cpu { auto is_bsp = !bsp_found; bsp_found = true; - 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.id(), - local_apic_address, is_bsp)); + auto core = + kstd::make_unique<devices::cpu::core>(core_major, core_count, core_count, apic.processor_id(), is_bsp); + core->add_child(kstd::make_unique<arch::devices::local_apic>(interrupt_controller_major, core_count, core_count, + apic.id(), local_apic_address, is_bsp)); cpu_bus->add_child(std::move(core)); ++core_count; } diff --git a/kapi/kapi/devices/cpu.hpp b/kapi/kapi/devices/cpu.hpp index f8ff60c6..a39580b4 100644 --- a/kapi/kapi/devices/cpu.hpp +++ b/kapi/kapi/devices/cpu.hpp @@ -15,12 +15,15 @@ namespace kapi::devices //! A virtual CPU Core to host all core local devices. struct core final : kapi::devices::bus { - explicit core(std::size_t major_number, std::size_t minor_number, std::uint64_t hardware_id, bool is_bsp); + explicit core(std::size_t major_number, std::size_t minor_number, std::uint64_t index, std::uint64_t hardware_id, + bool is_bsp); [[nodiscard]] auto hardware_id() const -> std::uint64_t; [[nodiscard]] auto is_bsp() const -> bool; + [[nodiscard]] auto index() const noexcept -> std::uint64_t; private: + std::uint64_t m_index; std::uint64_t m_hardware_id; bool m_is_bsp; }; diff --git a/kernel/kapi/devices/cpu.cpp b/kernel/kapi/devices/cpu.cpp index f0e1d725..da55cf2c 100644 --- a/kernel/kapi/devices/cpu.cpp +++ b/kernel/kapi/devices/cpu.cpp @@ -8,12 +8,19 @@ namespace kapi::devices { - cpu::core::core(std::size_t major_number, std::size_t minor_number, std::uint64_t hardware_id, bool is_bsp) + cpu::core::core(std::size_t major_number, std::size_t minor_number, std::uint64_t index, std::uint64_t hardware_id, + bool is_bsp) : kapi::devices::bus{major_number, minor_number, "cpu_core"} + , m_index{index} , m_hardware_id{hardware_id} , m_is_bsp{is_bsp} {} + auto cpu::core::index() const noexcept -> std::uint64_t + { + return m_index; + } + auto cpu::core::hardware_id() const -> std::uint64_t { return m_hardware_id; |
