implemented interrupts handler & stub crash screen

This commit is contained in:
Alex
2022-10-16 20:53:57 +03:00
parent 04757bd11c
commit b8c5c15a47
15 changed files with 978 additions and 80 deletions

View File

@ -4,9 +4,7 @@
#include <debug.h>
#include <io.h>
// #include "../timer.h"
// #include "apic.hpp"
// #include "smp.hpp"
#include "cpu/apic.hpp"
#define ACPI_TIMER 0x0001
#define ACPI_BUSMASTER 0x0010
@ -31,7 +29,7 @@ namespace ACPI
#define ACPI_GAS_IO 1
#define ACPI_GAS_PCI 2
void DSDT::SCIHandler(CPU::x64::TrapFrame *regs)
void DSDT::OnInterruptReceived(CPU::x64::TrapFrame *Frame)
{
debug("SCI Handle Triggered");
uint16_t event = this->GetSCIevent();
@ -58,7 +56,7 @@ namespace ACPI
return;
}
}
UNUSED(regs);
UNUSED(Frame);
}
void DSDT::Shutdown()
@ -163,24 +161,12 @@ namespace ACPI
GetSCIevent();
}
void DSDT::InitSCI()
{
// this should be done for all CPUs
if (ACPIShutdownSupported)
{
debug("Registering SCI Handler to vector IRQ%d", acpi->FADT->SCI_Interrupt);
this->RegisterSCIEvents();
// RegisterInterrupt(this->SCIHandler, acpi->FADT->SCI_Interrupt + CPU::x64::IRQ0, true, true);
}
}
DSDT::DSDT(ACPI *acpi)
DSDT::DSDT(ACPI *acpi) : Interrupts::Handler(acpi->FADT->SCI_Interrupt + CPU::x64::IRQ0)
{
uint64_t Address = ((IsCanonical(acpi->FADT->X_Dsdt) && acpi->XSDTSupported) ? acpi->FADT->X_Dsdt : acpi->FADT->Dsdt);
uint8_t *S5Address = (uint8_t *)(Address) + 36;
ACPI::ACPI::ACPIHeader *Header = (ACPI::ACPI::ACPIHeader *)Address;
uint64_t Length = Header->Length;
Address *= 2;
while (Length-- > 0)
{
if (!memcmp(S5Address, "_S5_", 4))
@ -213,6 +199,8 @@ namespace ACPI
SCI_EN = 1;
trace("ACPI Shutdown is supported");
ACPIShutdownSupported = true;
this->RegisterSCIEvents();
((APIC::APIC *)Interrupts::apic)->RedirectIRQ(0, acpi->FADT->SCI_Interrupt, 1);
return;
}
warn("Failed to parse _S5 in ACPI");

View File

@ -246,7 +246,7 @@ namespace ACPI
~MADT();
};
class DSDT
class DSDT : public Interrupts::Handler
{
private:
uint32_t SMI_CMD = 0;
@ -262,10 +262,17 @@ namespace ACPI
ACPI *acpi;
#if defined(__amd64__)
void OnInterruptReceived(CPU::x64::TrapFrame *Frame);
#elif defined(__i386__)
void OnInterruptReceived(void *Frame);
#elif defined(__aarch64__)
void OnInterruptReceived(void *Frame);
#endif
public:
bool ACPIShutdownSupported = false;
void SCIHandler(CPU::x64::TrapFrame *regs);
void RegisterSCIEvents();
void SetSCIevent(uint16_t value);
uint16_t GetSCIevent();
@ -273,7 +280,6 @@ namespace ACPI
void Reboot();
void Shutdown();
void InitSCI();
DSDT(ACPI *acpi);
~DSDT();
};

View File

@ -5,21 +5,8 @@
#include "gdt.hpp"
// TODO: IMPLEMENT "MainInterruptHandler"
extern "C" void MainInterruptHandler(void *Data)
{
debug("Interrupt: %p", Data);
asmv("cli");
asmv("hlt");
}
// TODO: IMPLEMENT "ExceptionHandler"
extern "C" void ExceptionHandler(void *Data)
{
debug("Exception: %p", Data);
asmv("cli");
asmv("hlt");
}
extern "C" void MainInterruptHandler(void *Data);
extern "C" void ExceptionHandler(void *Data);
namespace InterruptDescriptorTable
{

View File

@ -70,6 +70,7 @@ extern "C" void StartCPU()
// Initialize GDT and IDT
Interrupts::Initialize(CPU_ID);
((APIC::APIC *)Interrupts::apic)->RedirectIRQs(CPU_ID);
CPU::Interrupts(CPU::Enable);
KPrint("CPU %d is online", CPU_ID);

View File

@ -52,7 +52,6 @@ namespace APIC
void RedirectIRQs(int CPU = 0);
void IPI(uint8_t CPU, uint32_t InterruptNumber);
void OneShot(uint32_t Vector, uint64_t Miliseconds);
bool APICSupported();
uint32_t IOGetMaxRedirect(uint32_t APICID);
void RawRedirectIRQ(uint8_t Vector, uint32_t GSI, uint16_t Flags, int CPU, int Status);
void RedirectIRQ(int CPU, uint8_t IRQ, int Status);