From d45bf363f110fa9a94b87908c0634c8f6b56db17 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 28 Sep 2023 12:30:27 +0300 Subject: [PATCH] Kernel: Enter ACPI mode with lai --- kernel/include/kernel/InterruptController.h | 5 +++++ kernel/include/kernel/Thread.h | 2 +- kernel/kernel/InterruptController.cpp | 23 ++++++++++++++++++--- kernel/kernel/kernel.cpp | 2 ++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/kernel/include/kernel/InterruptController.h b/kernel/include/kernel/InterruptController.h index 40514f0db2..b2a160ec68 100644 --- a/kernel/include/kernel/InterruptController.h +++ b/kernel/include/kernel/InterruptController.h @@ -16,6 +16,11 @@ public: static void initialize(bool force_pic); static InterruptController& get(); + + void enter_acpi_mode(); + +private: + bool m_using_apic { false }; }; bool interrupts_enabled(); \ No newline at end of file diff --git a/kernel/include/kernel/Thread.h b/kernel/include/kernel/Thread.h index c4115098e3..c6a0b5b440 100644 --- a/kernel/include/kernel/Thread.h +++ b/kernel/include/kernel/Thread.h @@ -94,7 +94,7 @@ namespace Kernel void validate_stack() const; private: - static constexpr size_t m_kernel_stack_size = PAGE_SIZE * 1; + static constexpr size_t m_kernel_stack_size = PAGE_SIZE * 4; static constexpr size_t m_userspace_stack_size = PAGE_SIZE * 2; static constexpr size_t m_interrupt_stack_size = PAGE_SIZE * 2; BAN::UniqPtr m_interrupt_stack; diff --git a/kernel/kernel/InterruptController.cpp b/kernel/kernel/InterruptController.cpp index 7dc1206a95..45fd79a4b9 100644 --- a/kernel/kernel/InterruptController.cpp +++ b/kernel/kernel/InterruptController.cpp @@ -3,6 +3,8 @@ #include #include +#include + static InterruptController* s_instance = nullptr; InterruptController& InterruptController::get() @@ -19,11 +21,26 @@ void InterruptController::initialize(bool force_pic) PIC::remap(); if (!force_pic) + { s_instance = APIC::create(); - if (s_instance) - return; + if (s_instance) + { + s_instance->m_using_apic = true; + return; + } + } + dprintln("Using PIC instead of APIC"); s_instance = PIC::create(); + ASSERT(s_instance); + + s_instance->m_using_apic = false; +} + +void InterruptController::enter_acpi_mode() +{ + if (lai_enable_acpi(m_using_apic ? 1 : 0) != 0) + dwarnln("could not enter acpi mode"); } bool interrupts_enabled() @@ -31,4 +48,4 @@ bool interrupts_enabled() uintptr_t flags; asm volatile("pushf; pop %0" : "=r"(flags) :: "memory"); return flags & (1 << 9); -} \ No newline at end of file +} diff --git a/kernel/kernel/kernel.cpp b/kernel/kernel/kernel.cpp index da9e39650b..633d0ecc50 100644 --- a/kernel/kernel/kernel.cpp +++ b/kernel/kernel/kernel.cpp @@ -161,6 +161,8 @@ static void init2(void*) dprintln("Scheduler started"); + InterruptController::get().enter_acpi_mode(); + auto console = MUST(DevFileSystem::get().root_inode()->find_inode(cmdline.console)); ASSERT(console->is_tty()); ((TTY*)console.ptr())->set_as_current();