From b84c4c9d8c90f3d3fd5a60de282278912fad2f04 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 2 Apr 2026 13:59:27 +0200 Subject: x86_64/devices: implement ISA bus stub --- arch/x86_64/include/arch/bus/isa.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 arch/x86_64/include/arch/bus/isa.hpp (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/bus/isa.hpp b/arch/x86_64/include/arch/bus/isa.hpp new file mode 100644 index 0000000..41dda93 --- /dev/null +++ b/arch/x86_64/include/arch/bus/isa.hpp @@ -0,0 +1,31 @@ +#ifndef TEACHOS_X86_64_BUS_ISA_HPP +#define TEACHOS_X86_64_BUS_ISA_HPP + +#include "kapi/devices/bus.hpp" +#include "kapi/devices/device.hpp" + +#include +#include + +namespace arch::bus +{ + + struct isa final : public kapi::devices::bus + { + isa(); + + auto add_child(kstd::unique_ptr child) -> void override; + + [[nodiscard]] auto children() const -> kstd::vector> const & override; + + auto init() -> bool override; + + private: + kstd::vector> m_devices{}; + kstd::vector> m_observers{}; + bool m_initialized{}; + }; + +} // namespace arch::bus + +#endif // TEACHOS_X86_64_BUS_ISA_HPP -- cgit v1.2.3 From 66ffd2ad8c793c4eea1527848fe4772e42595718 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 2 Apr 2026 14:24:52 +0200 Subject: kapi: extract common bus code --- arch/x86_64/include/arch/bus/isa.hpp | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/bus/isa.hpp b/arch/x86_64/include/arch/bus/isa.hpp index 41dda93..bd92b2e 100644 --- a/arch/x86_64/include/arch/bus/isa.hpp +++ b/arch/x86_64/include/arch/bus/isa.hpp @@ -2,10 +2,6 @@ #define TEACHOS_X86_64_BUS_ISA_HPP #include "kapi/devices/bus.hpp" -#include "kapi/devices/device.hpp" - -#include -#include namespace arch::bus { @@ -13,17 +9,6 @@ namespace arch::bus struct isa final : public kapi::devices::bus { isa(); - - auto add_child(kstd::unique_ptr child) -> void override; - - [[nodiscard]] auto children() const -> kstd::vector> const & override; - - auto init() -> bool override; - - private: - kstd::vector> m_devices{}; - kstd::vector> m_observers{}; - bool m_initialized{}; }; } // namespace arch::bus -- cgit v1.2.3 From ab4c59912c526d515e6e72188c08a7f92e5573e8 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 2 Apr 2026 15:07:54 +0200 Subject: x86_64: implement legacy PIT driver --- arch/x86_64/include/arch/devices/legacy_pit.hpp | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 arch/x86_64/include/arch/devices/legacy_pit.hpp (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/devices/legacy_pit.hpp b/arch/x86_64/include/arch/devices/legacy_pit.hpp new file mode 100644 index 0000000..d28e4d6 --- /dev/null +++ b/arch/x86_64/include/arch/devices/legacy_pit.hpp @@ -0,0 +1,28 @@ +#ifndef TEACHOS_ARCH_X86_64_DEVICES_LEGACY_PIT_HPP +#define TEACHOS_ARCH_X86_64_DEVICES_LEGACY_PIT_HPP + +#include "kapi/devices/device.hpp" +#include "kapi/interrupts.hpp" + +#include + +namespace arch::devices +{ + + struct legacy_pit : kapi::devices::device, kapi::interrupts::handler + { + explicit legacy_pit(std::uint32_t frequency_in_hz); + + auto init() -> bool override; + + auto handle_interrupt(std::uint32_t irq_number) -> kapi::interrupts::status override; + + private: + std::uint32_t m_irq_number{}; + std::uint32_t m_frequency_in_hz{}; + std::uint64_t m_ticks{}; + }; + +} // namespace arch::devices + +#endif \ No newline at end of file -- cgit v1.2.3 From 21489576381d827871e7cdf060929c5d7f3d4e9f Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 2 Apr 2026 15:49:14 +0200 Subject: devices: don't automatically allocate major numbers in ctors --- arch/x86_64/include/arch/bus/isa.hpp | 4 +++- arch/x86_64/include/arch/devices/legacy_pit.hpp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/bus/isa.hpp b/arch/x86_64/include/arch/bus/isa.hpp index bd92b2e..5deed25 100644 --- a/arch/x86_64/include/arch/bus/isa.hpp +++ b/arch/x86_64/include/arch/bus/isa.hpp @@ -3,12 +3,14 @@ #include "kapi/devices/bus.hpp" +#include + namespace arch::bus { struct isa final : public kapi::devices::bus { - isa(); + isa(std::size_t major); }; } // namespace arch::bus diff --git a/arch/x86_64/include/arch/devices/legacy_pit.hpp b/arch/x86_64/include/arch/devices/legacy_pit.hpp index d28e4d6..de742ae 100644 --- a/arch/x86_64/include/arch/devices/legacy_pit.hpp +++ b/arch/x86_64/include/arch/devices/legacy_pit.hpp @@ -4,6 +4,7 @@ #include "kapi/devices/device.hpp" #include "kapi/interrupts.hpp" +#include #include namespace arch::devices @@ -11,7 +12,7 @@ namespace arch::devices struct legacy_pit : kapi::devices::device, kapi::interrupts::handler { - explicit legacy_pit(std::uint32_t frequency_in_hz); + legacy_pit(std::size_t major, std::uint32_t frequency_in_hz); auto init() -> bool override; -- cgit v1.2.3 From c5afb5c1ce1c084c840dbb58d73af6fe2b235ec7 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 2 Apr 2026 15:55:47 +0200 Subject: x86_64: ensure PIT is not overwhelmed on config --- arch/x86_64/include/arch/device_io/port_io.hpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/device_io/port_io.hpp b/arch/x86_64/include/arch/device_io/port_io.hpp index 70773dd..4c8d66a 100644 --- a/arch/x86_64/include/arch/device_io/port_io.hpp +++ b/arch/x86_64/include/arch/device_io/port_io.hpp @@ -102,6 +102,11 @@ namespace arch::io : std::string_view{"eax"}; }; + auto inline wait() -> void + { + port<0x80, std::uint8_t, port_write>::write(0); + } + } // namespace arch::io #endif \ No newline at end of file -- cgit v1.2.3