13using namespace MaxOS::common;
14using namespace MaxOS::hardwarecommunication;
15using namespace MaxOS::system;
25: m_interrupt_number(interrupt_number)
195 asm volatile(
"lidt %0" : :
"m" (
idt));
236 switch (status->interrupt_number) {
239 CPU::PANIC(
"Device Not Available: FPU Not Enabled", status);
243 return general_protection_fault(status);
246 return page_fault(status);
293 Logger::WARNING() <<
"Interrupt " << (
int) status->interrupt_number <<
" not handled\n";
323 bool present = (status->error_code & 0x1) != 0;
324 bool write = (status->error_code & 0x2) != 0;
325 bool user_mode = (status->error_code & 0x4) != 0;
335 string msg =
StringBuilder() <<
"Page Fault: " << (
user_mode ?
"user" :
"kernel") <<
" code at 0x" << status->rip <<
" tried to " << (write ?
"write" :
"read") <<
" address 0x" <<
faulting_address <<
" which is " << (present ?
"" :
"not") <<
" mapped and " << (
reserved_write ?
"" :
"not") <<
" reserved. " <<
" (instruction fetch: " << (
instruction_fetch ?
"Yes" :
"No") <<
") for core " <<
core_id <<
"\n";
362 uint64_t error_code = status->error_code;
363 string msg =
StringBuilder() <<
"General Protection Fault: (0x" << status->rip <<
"): " << (error_code & 0x1 ?
"Protection-Exception" :
"Not a Protection Exception") <<
" c" <<
core_id <<
"\n";
static Logger WARNING()
Gets active logger set to WARNING level.
static Logger INFO()
Gets active logger set to info level.
Creates a string using a using a combination of parts with the '<<' operator. Simmilar to the logger.
Stores the left, top, width and height of a rectangle.
Handles both the Local APIC (boot core) and IO APIC.
Handles the IO APIC in the system (one per system)
void set_redirect(interrupt_redirect_t *redirect)
Redirect a system interrupt to a different IRQ.
Handles a certain interrupt number.
~InterruptHandler()
Destroys the interrupt handler and unregisters it from the interrupt manager.
InterruptHandler(uint8_t interrupt_number, int64_t redirect=-1, uint64_t redirect_index=0)
Creates a new interrupt handler and registers it with the interrupt manager.
uint8_t m_interrupt_number
The interrupt number this handler handles.
virtual void handle_interrupt()
Handles an interrupt.
Handles all interrupts and passes them to the correct handler.
static InterruptManager * s_active_interrupt_manager
The interrupt manger that is currently handling interrupts and is loaded into the IDTR.
static void HandleException0x15()
Stub (see interrupts.s)
static void HandleInterruptError0x0A()
Stub (see interrupts.s)
static void deactivate()
Deactivates the interrupt manager and stops interrupts.
static void HandleException0x14()
Stub (see interrupts.s)
system::cpu_status_t * handle_interrupt_request(system::cpu_status_t *status)
Handles the interrupt request by passing it to the appropriate handler.
static void HandleException0x00()
Stub (see interrupts.s)
static void HandleInterruptRequest0x0C()
Stub (see interrupts.s)
static void HandleException0x07()
Stub (see interrupts.s)
static void HandleInterruptError0x0D()
Stub (see interrupts.s)
static InterruptManager * active_interrupt_manager()
Gets the active interrupt manager.
static void HandleInterruptError0x08()
Stub (see interrupts.s)
static void HandleException0x13()
Stub (see interrupts.s)
static void HandleInterruptError0x0C()
Stub (see interrupts.s)
static void HandleException0x04()
Stub (see interrupts.s)
static void HandleException0x02()
Stub (see interrupts.s)
static void HandleException0x17()
Stub (see interrupts.s)
static void HandleException0x10()
Stub (see interrupts.s)
static void HandleInterruptRequest0x01()
Stub (see interrupts.s)
void set_apic(AdvancedProgrammableInterruptController *apic)
Sets the APIC.
static void HandleInterruptError0x11()
Stub (see interrupts.s)
static void HandleException0x1E()
Stub (see interrupts.s)
static void HandleInterruptRequest0x60()
Stub (see interrupts.s)
static void HandleException0x1F()
Stub (see interrupts.s)
void remove_interrupt_handler(uint8_t interrupt)
Removes the interrupt handler for the interrupt.
static void load_current()
Tell the processor to use the current InterruptManager.
static void HandleException0x05()
Stub (see interrupts.s)
static void HandleInterruptError0x0B()
Stub (see interrupts.s)
static void HandleException0x19()
Stub (see interrupts.s)
static system::cpu_status_t * HandleInterrupt(system::cpu_status_t *status)
Handles the interrupt request by passing it to the interrupt manager.
~InterruptManager()
Destroys the Interrupt Manager and deactivates interrupts.
static void HandleException0x1A()
Stub (see interrupts.s)
static void HandleException0x01()
Stub (see interrupts.s)
static void HandleException0x18()
Stub (see interrupts.s)
static void HandleException0x1B()
Stub (see interrupts.s)
InterruptManager()
Constructs the Interrupt Manager and sets up the interrupt descriptor table (does not activate interr...
static void set_interrupt_descriptor_table_entry(uint8_t interrupt, void(*handler)(), uint8_t descriptor_privilege_level)
Sets an entry in the Interrupt Descriptor Table.
void activate()
Activates the interrupt manager and starts interrupts (also deactivates the current interrupt manager...
void set_interrupt_handler(uint8_t interrupt, InterruptHandler *handler)
Sets the interrupt handler for the interrupt.
static InterruptDescriptor s_interrupt_descriptor_table[MAX_INTERRUPT_HANDLERS]
The Interrupt Descriptor Table (IDT)
static void HandleException0x12()
Stub (see interrupts.s)
static void HandleInterruptRequest0x00()
Stub (see interrupts.s)
static void HandleException0x09()
Stub (see interrupts.s)
static void HandleException0x16()
Stub (see interrupts.s)
static void HandleInterruptError0x0E()
Stub (see interrupts.s)
static void HandleException0x06()
Stub (see interrupts.s)
static void HandleException0x03()
Stub (see interrupts.s)
static void HandleException0x0F()
Stub (see interrupts.s)
static void HandleException0x1C()
Stub (see interrupts.s)
static void HandleInterruptRequest0x02()
Stub (see interrupts.s)
AdvancedProgrammableInterruptController * active_apic()
Gets the APIC.
static void HandleException0x1D()
Stub (see interrupts.s)
InterruptHandler * m_interrupt_handlers[MAX_INTERRUPT_HANDLERS]
A map of index-to-interrupt of interrupt handlers to fire when an interrupt occurs.
static void PANIC(const char *message, cpu_status_t *status=nullptr)
Puts the CPU into a panic state and halts it. Dumps the stack trace and registers.
static cpu_status_t * prepare_for_panic(cpu_status_t *status=nullptr, const string &msg="")
Ensure the CPU must panic and prepare for it if so.
static Core * executing_core()
Gets the core that is currently executing.
struct PACKED MaxOS::system::CPUStatus cpu_status_t
Alias for CPUStatus struct.
Defines a InterruptManager and InterruptHandler for managing hardware and software interrupts.
constexpr uint16_t HARDWARE_INTERRUPT_OFFSET
The offset in the IDT where interrupts from hardware start.
Defines a Logger class for logging messages with different severity levels to multiple output streams...
#define ASSERT(condition, format,...)
If the specified condition is not met then the kernel will crash with the specified message.
A struct that holds the Interrupt Descriptor Table Register (IDTR)
An entry in the Interrupt Descriptor Table (IDT)
Defines how an interrupt input is redirected to a specific processor via the I/O APIC.