diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-08 14:55:18 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-08 14:55:18 +0200 |
| commit | 2ed34cc51a534171f0fe08808634834bc22cf84d (patch) | |
| tree | 5b0bdbbf7b7377586935261aa141b3202cb8a431 /arch/x86_64/src | |
| parent | 296742bfa509524dc8effc3dcae4b6231d37705f (diff) | |
| download | teachos-2ed34cc51a534171f0fe08808634834bc22cf84d.tar.xz teachos-2ed34cc51a534171f0fe08808634834bc22cf84d.zip | |
x86_64: only initialize BSP LAPIC
Diffstat (limited to 'arch/x86_64/src')
| -rw-r--r-- | arch/x86_64/src/devices/local_apic.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/arch/x86_64/src/devices/local_apic.cpp b/arch/x86_64/src/devices/local_apic.cpp index 91e907a..e24e1d4 100644 --- a/arch/x86_64/src/devices/local_apic.cpp +++ b/arch/x86_64/src/devices/local_apic.cpp @@ -20,24 +20,40 @@ namespace arch::devices } // namespace local_apic::local_apic(std::size_t major, std::size_t minor, std::uint64_t hardware_id, - kapi::memory::physical_address base) + kapi::memory::physical_address base, bool is_bsp) : kapi::devices::device{major, minor, "lapic"} , m_hardware_id{hardware_id} , m_base{base} + , m_is_bsp{is_bsp} {} auto local_apic::init() -> bool { - m_virtual_base = kapi::memory::allocate_mmio_region(1); - if (!kapi::memory::map_mmio_region(m_virtual_base, m_base, kapi::memory::page_mapper::flags::writable)) + auto static shared_virtual_base = kapi::memory::allocate_mmio_region(1); + auto static is_mapped = false; + + if (!is_mapped) { - kstd::println("[x86_64:DEV] LAPIC {} MMIO mapping failed!", m_hardware_id); - return false; + if (!kapi::memory::map_mmio_region(shared_virtual_base, m_base, kapi::memory::page_mapper::flags::writable)) + { + kstd::println("[x86_64:DEV] LAPIC {} MMIO mapping failed!", m_hardware_id); + return false; + } + is_mapped = true; } - write_register(lapic_sivr_register, lapic_enable_bit | spurious_interrupt_vector); + m_virtual_base = shared_virtual_base; + + if (m_is_bsp) + { + write_register(lapic_sivr_register, lapic_enable_bit | spurious_interrupt_vector); - kstd::println("[x86_64:DEV] LAPIC {} initialized. {:#018x}@{:#018x}", m_hardware_id, m_base, m_virtual_base); + kstd::println("[x86_64:DEV] LAPIC {} initialized. {:#018x}@{:#018x}", m_hardware_id, m_base, m_virtual_base); + } + else + { + kstd::println("[x86_64:DEV] LAPIC {} is not on the BSP, deferring intialization.", m_hardware_id); + } return true; } |
