diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-16 10:29:30 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-29 09:05:04 +0200 |
| commit | 1b964278762dde86b0b737bd9a34fec569339f54 (patch) | |
| tree | 7fe0f4707e05f46461f03744d178f413b7bbca28 /arch/x86_64/src/devices | |
| parent | d906d70c94c2a40d5fc6fd26056c7bc57d540002 (diff) | |
| download | teachos-1b964278762dde86b0b737bd9a34fec569339f54.tar.xz teachos-1b964278762dde86b0b737bd9a34fec569339f54.zip | |
x86_64: use p1204 project layout
Diffstat (limited to 'arch/x86_64/src/devices')
| -rw-r--r-- | arch/x86_64/src/devices/init.cpp | 76 | ||||
| -rw-r--r-- | arch/x86_64/src/devices/legacy_pit.cpp | 60 | ||||
| -rw-r--r-- | arch/x86_64/src/devices/local_apic.cpp | 134 |
3 files changed, 0 insertions, 270 deletions
diff --git a/arch/x86_64/src/devices/init.cpp b/arch/x86_64/src/devices/init.cpp deleted file mode 100644 index c30e8cf..0000000 --- a/arch/x86_64/src/devices/init.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include <arch/devices/init.hpp> - -#include <arch/boot/boot.hpp> -#include <arch/bus/isa.hpp> -#include <arch/devices/legacy_pit.hpp> - -#include <kapi/acpi.hpp> -#include <kapi/cpu.hpp> -#include <kapi/devices.hpp> - -#include <acpi/acpi.hpp> - -#include <kstd/memory> -#include <kstd/print> - -#include <cstdint> -#include <utility> - -namespace arch::devices -{ - - namespace - { - constexpr auto pit_frequency_in_hz = std::uint32_t{100u}; - - auto get_acpi_root_pointer() -> kstd::observer_ptr<::acpi::rsdp const> - { - auto const & mbi = kapi::boot::bootstrap_information.mbi; - auto system_description_pointer = static_cast<::acpi::rsdp const *>(nullptr); - - if (auto const & xsdp = mbi->maybe_acpi_xsdp()) - { - auto data = xsdp->pointer().data(); - - system_description_pointer = reinterpret_cast<::acpi::xsdp const *>(data); - } - else if (auto const & rsdp = mbi->maybe_acpi_rsdp()) - { - auto data = rsdp->pointer().data(); - system_description_pointer = reinterpret_cast<::acpi::rsdp const *>(data); - } - - return kstd::make_observer(system_description_pointer); - } - } // namespace - - auto init_acpi_devices() -> void - { - auto acpi_root_pointer = get_acpi_root_pointer(); - if (acpi_root_pointer && acpi_root_pointer->validate()) - { - if (kapi::acpi::init(*acpi_root_pointer)) - { - kstd::println("[x86_64:DEV] ACPI subsystem initialized."); - } - } - - kapi::cpu::discover_topology(); - } - - auto init_legacy_devices() -> void - { - kstd::println("[x86_64:DEV] Initializing ISA bus..."); - - auto isa_major_number = kapi::devices::allocate_major_number(); - auto isa_bus = kstd::make_unique<arch::bus::isa>(isa_major_number); - - auto pit_major_number = kapi::devices::allocate_major_number(); - auto pit = kstd::make_unique<arch::devices::legacy_pit>(pit_major_number, pit_frequency_in_hz); - isa_bus->add_child(std::move(pit)); - - auto & root_bus = kapi::devices::get_root_bus(); - root_bus.add_child(std::move(isa_bus)); - } - -} // namespace arch::devices diff --git a/arch/x86_64/src/devices/legacy_pit.cpp b/arch/x86_64/src/devices/legacy_pit.cpp deleted file mode 100644 index d542d47..0000000 --- a/arch/x86_64/src/devices/legacy_pit.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include <arch/devices/legacy_pit.hpp> - -#include <arch/device_io/port_io.hpp> - -#include <kapi/devices.hpp> -#include <kapi/devices/device.hpp> -#include <kapi/interrupts.hpp> - -#include <cstddef> -#include <cstdint> - -namespace arch::devices -{ - - namespace - { - using command_port = io::port<0x43, std::uint8_t, io::port_write>; - using channel_0_port = io::port<0x40, std::uint8_t, io::port_write>; - using channel_1_port = io::port<0x41, std::uint8_t, io::port_write>; - using channel_2_port = io::port<0x42, std::uint8_t, io::port_write>; - - constexpr auto base_frequency = 1'193'182u; - constexpr auto square_wave_mode = 0x36; - } // namespace - - legacy_pit::legacy_pit(std::size_t major, std::uint32_t frequency_in_hz) - : kapi::devices::device{major, 0, "legacy_pit"} - , m_irq_number{0} - , m_frequency_in_hz{frequency_in_hz} - {} - - auto legacy_pit::init() -> bool - { - auto divisor = static_cast<std::uint16_t>(base_frequency / m_frequency_in_hz); - - kapi::interrupts::register_handler(m_irq_number, *this); - - command_port::write<std::uint8_t>(square_wave_mode); - io::wait(); - channel_0_port::write<std::uint8_t>(divisor & 0xff); - io::wait(); - channel_0_port::write<std::uint8_t>(divisor >> 8 & 0xff); - io::wait(); - - return true; - } - - auto legacy_pit::handle_interrupt(std::uint32_t irq_number) -> kapi::interrupts::status - { - if (irq_number != m_irq_number) - { - return kapi::interrupts::status::unhandled; - } - - ++m_ticks; - - return kapi::interrupts::status::handled; - } - -} // namespace arch::devices
\ No newline at end of file diff --git a/arch/x86_64/src/devices/local_apic.cpp b/arch/x86_64/src/devices/local_apic.cpp deleted file mode 100644 index 660921b..0000000 --- a/arch/x86_64/src/devices/local_apic.cpp +++ /dev/null @@ -1,134 +0,0 @@ -#include <arch/devices/local_apic.hpp> - -#include <kapi/devices.hpp> -#include <kapi/memory.hpp> - -#include <kstd/print> - -#include <cstddef> -#include <cstdint> -#include <utility> - -namespace arch::devices -{ - - namespace - { - constexpr auto lapic_enable_bit = 0x100u; - constexpr auto spurious_interrupt_vector = 0xFFu; - - constexpr auto offset_of_version = 0u; - constexpr auto offset_of_max_lvt_entry = 16u; - constexpr auto offset_of_eoi_suppression = 24u; - - } // namespace - - enum struct local_apic::registers : std::ptrdiff_t - { - id = 0x020, - version = 0x030, - task_priority = 0x080, - arbitration_priority = 0x090, - processor_priority = 0x0a0, - eoi = 0x0b0, - remote_read = 0x0c0, - logical_destination = 0x0d0, - destination_format = 0x0e0, - spurious_interrupt_vector = 0x0f0, - in_service_0 = 0x100, - in_service_1 = 0x110, - in_service_2 = 0x120, - in_service_3 = 0x130, - in_service_4 = 0x140, - in_service_5 = 0x150, - in_service_6 = 0x160, - in_service_7 = 0x170, - trigger_mode_0 = 0x180, - trigger_mode_1 = 0x190, - trigger_mode_2 = 0x1a0, - trigger_mode_3 = 0x1b0, - trigger_mode_4 = 0x1c0, - trigger_mode_5 = 0x1d0, - trigger_mode_6 = 0x1e0, - trigger_mode_7 = 0x1f0, - interrupt_request_0 = 0x200, - interrupt_request_1 = 0x210, - interrupt_request_2 = 0x220, - interrupt_request_3 = 0x230, - interrupt_request_4 = 0x240, - interrupt_request_5 = 0x250, - interrupt_request_6 = 0x260, - interrupt_request_7 = 0x270, - error_status = 0x280, - lvt_corrected_machine_check_interrupt = 0x2f0, - interrupt_command_0 = 0x300, - interrupt_command_1 = 0x310, - lvt_timer = 0x320, - lvt_thermal_sensors = 0x330, - lvt_performance_monitoring_counters = 0x340, - lvt_local_interrupt_0 = 0x350, - lvt_local_interrupt_1 = 0x360, - lvt_error = 0x370, - initial_count = 0x380, - current_count = 0x390, - divide_configuration = 0x3e0, - }; - - local_apic::local_apic(std::size_t major, std::size_t minor, std::uint64_t hardware_id, - 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 - { - auto static shared_virtual_base = kapi::memory::allocate_mmio_region(1); - auto static is_mapped = false; - - if (!is_mapped) - { - 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; - } - - m_mapped_region = shared_virtual_base; - - if (m_is_bsp) - { - auto raw_version = read_register(registers::version); - m_version = (raw_version >> offset_of_version) & 0xff; - m_highest_lvt_entry_index = (raw_version >> offset_of_max_lvt_entry) & 0xff; - m_supports_eoi_broadcast_suppression = (raw_version >> offset_of_eoi_suppression) & 0x1; - - write_register(registers::spurious_interrupt_vector, lapic_enable_bit | spurious_interrupt_vector); - - kstd::println("[x86_64:DEV] LAPIC initialized. version: {#x} | max_lvt_entry: {} | eoi_suppression: {:s}", - m_version, m_highest_lvt_entry_index, m_supports_eoi_broadcast_suppression); - } - else - { - kstd::println("[x86_64:DEV] LAPIC {} is not on the BSP, deferring initialization.", m_hardware_id); - } - - return true; - } - - 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)); - return *reg; - } - - auto local_apic::write_register(registers id, std::uint32_t value) -> void - { - auto reg = static_cast<std::uint32_t volatile *>(m_mapped_region.first + std::to_underlying(id)); - *reg = value; - } - -} // namespace arch::devices |
