2023-01-23 20:13:57 +02:00
|
|
|
#include <BAN/Errors.h>
|
|
|
|
#include <kernel/InterruptController.h>
|
|
|
|
#include <kernel/APIC.h>
|
|
|
|
#include <kernel/PIC.h>
|
|
|
|
|
2023-10-05 18:53:45 +03:00
|
|
|
namespace Kernel
|
2023-01-23 20:13:57 +02:00
|
|
|
{
|
|
|
|
|
2023-10-05 18:53:45 +03:00
|
|
|
static InterruptController* s_instance = nullptr;
|
|
|
|
|
|
|
|
InterruptController& InterruptController::get()
|
|
|
|
{
|
|
|
|
ASSERT(s_instance);
|
|
|
|
return *s_instance;
|
|
|
|
}
|
2023-01-23 20:13:57 +02:00
|
|
|
|
2023-10-05 18:53:45 +03:00
|
|
|
void InterruptController::initialize(bool force_pic)
|
2023-09-28 12:30:27 +03:00
|
|
|
{
|
2023-10-05 18:53:45 +03:00
|
|
|
ASSERT(s_instance == nullptr);
|
|
|
|
|
|
|
|
PIC::mask_all();
|
|
|
|
PIC::remap();
|
|
|
|
|
|
|
|
if (!force_pic)
|
2023-09-28 12:30:27 +03:00
|
|
|
{
|
2023-10-05 18:53:45 +03:00
|
|
|
s_instance = APIC::create();
|
|
|
|
if (s_instance)
|
|
|
|
{
|
|
|
|
s_instance->m_using_apic = true;
|
|
|
|
return;
|
|
|
|
}
|
2023-09-28 12:30:27 +03:00
|
|
|
}
|
|
|
|
|
2023-10-05 18:53:45 +03:00
|
|
|
dprintln("Using PIC instead of APIC");
|
|
|
|
s_instance = PIC::create();
|
|
|
|
ASSERT(s_instance);
|
2023-09-28 12:30:27 +03:00
|
|
|
|
2023-10-05 18:53:45 +03:00
|
|
|
s_instance->m_using_apic = false;
|
|
|
|
}
|
2023-09-28 12:30:27 +03:00
|
|
|
|
2024-03-26 13:59:09 +02:00
|
|
|
bool InterruptController::is_initialized()
|
|
|
|
{
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
2023-09-28 12:30:27 +03:00
|
|
|
}
|