Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::hardwarecommunication::InterruptManager Class Reference

Handles all interrupts and passes them to the correct handler. More...

#include <interrupts.h>

Public Member Functions

 InterruptManager ()
 Constructs the Interrupt Manager and sets up the interrupt descriptor table (does not activate interrupts)
 
 ~InterruptManager ()
 Destroys the Interrupt Manager and deactivates interrupts.
 
void set_interrupt_handler (uint8_t interrupt, InterruptHandler *handler)
 Sets the interrupt handler for the interrupt.
 
void remove_interrupt_handler (uint8_t interrupt)
 Removes the interrupt handler for the interrupt.
 
void set_apic (AdvancedProgrammableInterruptController *apic)
 Sets the APIC.
 
AdvancedProgrammableInterruptController * active_apic ()
 Gets the APIC.
 
void activate ()
 Activates the interrupt manager and starts interrupts (also deactivates the current interrupt manager)
 

Static Public Member Functions

static InterruptManager * active_interrupt_manager ()
 Gets the active interrupt manager.
 
static void load_current ()
 Tell the processor to use the current InterruptManager.
 
static void deactivate ()
 Deactivates the interrupt manager and stops interrupts.
 
static void ForceInterruptReturn (system::cpu_status_t *state)
 Force the CPU to return from an interrupt (see interrupts.s)
 

Protected Member Functions

system::cpu_status_t * handle_interrupt_request (system::cpu_status_t *status)
 Handles the interrupt request by passing it to the appropriate handler.
 

Static Protected Member Functions

static void set_interrupt_descriptor_table_entry (uint8_t interrupt, void(*handler)(), InterruptPrivilegeLevel descriptor_privilege_level)
 Sets an entry in the Interrupt Descriptor Table.
 
static void HandleInterruptRequest0x00 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x01 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x02 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x03 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x04 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x05 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x06 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x07 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x08 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x09 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x0A ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x0B ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x0C ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x0D ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x0E ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x80 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x0F ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x31 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x60 ()
 Stub (see interrupts.s)
 
static void HandleInterruptRequest0x61 ()
 Stub (see interrupts.s)
 
static void HandleException0x00 ()
 Stub (see interrupts.s)
 
static void HandleException0x01 ()
 Stub (see interrupts.s)
 
static void HandleException0x02 ()
 Stub (see interrupts.s)
 
static void HandleException0x03 ()
 Stub (see interrupts.s)
 
static void HandleException0x04 ()
 Stub (see interrupts.s)
 
static void HandleException0x05 ()
 Stub (see interrupts.s)
 
static void HandleException0x06 ()
 Stub (see interrupts.s)
 
static void HandleException0x07 ()
 Stub (see interrupts.s)
 
static void HandleInterruptError0x08 ()
 Stub (see interrupts.s)
 
static void HandleException0x09 ()
 Stub (see interrupts.s)
 
static void HandleInterruptError0x0A ()
 Stub (see interrupts.s)
 
static void HandleInterruptError0x0B ()
 Stub (see interrupts.s)
 
static void HandleInterruptError0x0C ()
 Stub (see interrupts.s)
 
static void HandleInterruptError0x0D ()
 Stub (see interrupts.s)
 
static void HandleInterruptError0x0E ()
 Stub (see interrupts.s)
 
static void HandleException0x0F ()
 Stub (see interrupts.s)
 
static void HandleException0x10 ()
 Stub (see interrupts.s)
 
static void HandleInterruptError0x11 ()
 Stub (see interrupts.s)
 
static void HandleException0x12 ()
 Stub (see interrupts.s)
 
static void HandleException0x13 ()
 Stub (see interrupts.s)
 
static void HandleException0x14 ()
 Stub (see interrupts.s)
 
static void HandleException0x15 ()
 Stub (see interrupts.s)
 
static void HandleException0x16 ()
 Stub (see interrupts.s)
 
static void HandleException0x17 ()
 Stub (see interrupts.s)
 
static void HandleException0x18 ()
 Stub (see interrupts.s)
 
static void HandleException0x19 ()
 Stub (see interrupts.s)
 
static void HandleException0x1A ()
 Stub (see interrupts.s)
 
static void HandleException0x1B ()
 Stub (see interrupts.s)
 
static void HandleException0x1C ()
 Stub (see interrupts.s)
 
static void HandleException0x1D ()
 Stub (see interrupts.s)
 
static void HandleException0x1E ()
 Stub (see interrupts.s)
 
static void HandleException0x1F ()
 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.
 

Protected Attributes

InterruptHandler * m_interrupt_handlers [MAX_INTERRUPT_HANDLERS] = { }
 A map of index-to-interrupt of interrupt handlers to fire when an interrupt occurs.
 

Static Protected Attributes

static InterruptManager * s_active_interrupt_manager = nullptr
 The interrupt manger that is currently handling interrupts and is loaded into the IDTR.
 
static InterruptDescriptor s_interrupt_descriptor_table [MAX_INTERRUPT_HANDLERS] = { }
 The Interrupt Descriptor Table (IDT)
 

Friends

class InterruptHandler
 

Detailed Description

Handles all interrupts and passes them to the correct handler.

Todo:

Remove the max array of handler make vector, add static handlers for page faults and gpe. Make it so that multiple handlers can be registered for the same interrupt

Have a single stub so that we don't need to have 256 different functions for each interrupt

Definition at line 200 of file interrupts.h.

Constructor & Destructor Documentation

◆ InterruptManager()

InterruptManager::InterruptManager ( )

Constructs the Interrupt Manager and sets up the interrupt descriptor table (does not activate interrupts)

Definition at line 205 of file interrupts.cpp.

205 {
206
207 Logger::INFO() << "Setting up Interrupt Manager\n";
209
210 // Clear the table
211 for (auto& descriptor: s_interrupt_descriptor_table) {
212 descriptor.address_low_bits = 0;
213 descriptor.address_mid_bits = 0;
214 descriptor.address_high_bits = 0;
215 descriptor.segment_selector = 0;
216 descriptor.ist = 0;
217 descriptor.flags = 0;
218 }
219
220 //Set Up the base interrupts
221 set_interrupt_descriptor_table_entry(0x00, &HandleException0x00, InterruptPrivilegeLevel::KERNEL_ONLY); // Division by zero
222 set_interrupt_descriptor_table_entry(0x01, &HandleException0x01, InterruptPrivilegeLevel::KERNEL_ONLY); // Debug
223 set_interrupt_descriptor_table_entry(0x02, &HandleException0x02, InterruptPrivilegeLevel::KERNEL_ONLY); // Non-maskable interrupt
224 set_interrupt_descriptor_table_entry(0x03, &HandleException0x03, InterruptPrivilegeLevel::USERSPACE); // Breakpoint
225 set_interrupt_descriptor_table_entry(0x04, &HandleException0x04, InterruptPrivilegeLevel::USERSPACE); // Overflow
226 set_interrupt_descriptor_table_entry(0x05, &HandleException0x05, InterruptPrivilegeLevel::KERNEL_ONLY); // Bound Range Exceeded
227 set_interrupt_descriptor_table_entry(0x06, &HandleException0x06, InterruptPrivilegeLevel::KERNEL_ONLY); // Invalid Opcode
228 set_interrupt_descriptor_table_entry(0x07, &HandleException0x07, InterruptPrivilegeLevel::KERNEL_ONLY); // Device Not Available
229 set_interrupt_descriptor_table_entry(0x08, &HandleInterruptError0x08, InterruptPrivilegeLevel::KERNEL_ONLY); // Double Fault
230 set_interrupt_descriptor_table_entry(0x09, &HandleException0x09, InterruptPrivilegeLevel::KERNEL_ONLY); // Coprocessor Segment Overrun
231 set_interrupt_descriptor_table_entry(0x0A, &HandleInterruptError0x0A, InterruptPrivilegeLevel::KERNEL_ONLY); // Invalid TSS
232 set_interrupt_descriptor_table_entry(0x0B, &HandleInterruptError0x0B, InterruptPrivilegeLevel::KERNEL_ONLY); // Segment Not Present
233 set_interrupt_descriptor_table_entry(0x0C, &HandleInterruptError0x0C, InterruptPrivilegeLevel::KERNEL_ONLY); // Stack-Segment Fault
234 set_interrupt_descriptor_table_entry(0x0D, &HandleInterruptError0x0D, InterruptPrivilegeLevel::KERNEL_ONLY); // General Protection Fault
235 set_interrupt_descriptor_table_entry(0x0E, &HandleInterruptError0x0E, InterruptPrivilegeLevel::KERNEL_ONLY); // Page Fault
236 set_interrupt_descriptor_table_entry(0x0F, &HandleException0x0F, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
237 set_interrupt_descriptor_table_entry(0x10, &HandleException0x10, InterruptPrivilegeLevel::KERNEL_ONLY); // x87 Floating-Point Exception
238 set_interrupt_descriptor_table_entry(0x11, &HandleInterruptError0x11, InterruptPrivilegeLevel::KERNEL_ONLY); // Alignment Check
239 set_interrupt_descriptor_table_entry(0x12, &HandleException0x12, InterruptPrivilegeLevel::KERNEL_ONLY); // Machine Check
240 set_interrupt_descriptor_table_entry(0x13, &HandleException0x13, InterruptPrivilegeLevel::KERNEL_ONLY); // SIMD Floating-Point Exception
241 set_interrupt_descriptor_table_entry(0x14, &HandleException0x14, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved: Virtualization Exception
242 set_interrupt_descriptor_table_entry(0x15, &HandleException0x15, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
243 set_interrupt_descriptor_table_entry(0x16, &HandleException0x16, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
244 set_interrupt_descriptor_table_entry(0x17, &HandleException0x17, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
245 set_interrupt_descriptor_table_entry(0x18, &HandleException0x18, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
246 set_interrupt_descriptor_table_entry(0x19, &HandleException0x19, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
247 set_interrupt_descriptor_table_entry(0x1A, &HandleException0x1A, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
248 set_interrupt_descriptor_table_entry(0x1B, &HandleException0x1B, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
249 set_interrupt_descriptor_table_entry(0x1C, &HandleException0x1C, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
250 set_interrupt_descriptor_table_entry(0x1D, &HandleException0x1D, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
251 set_interrupt_descriptor_table_entry(0x1E, &HandleException0x1E, InterruptPrivilegeLevel::KERNEL_ONLY); // Security Exception
252 set_interrupt_descriptor_table_entry(0x1F, &HandleException0x1F, InterruptPrivilegeLevel::KERNEL_ONLY); // Reserved
253
254 // Set up the hardware interrupts
255 set_interrupt_descriptor_table_entry(HARDWARE_INTERRUPT_OFFSET + 0x00, &HandleInterruptRequest0x00, InterruptPrivilegeLevel::KERNEL_ONLY); // APIC Timer Interrupt
256 set_interrupt_descriptor_table_entry(HARDWARE_INTERRUPT_OFFSET + 0x01, &HandleInterruptRequest0x01, InterruptPrivilegeLevel::KERNEL_ONLY); // Keyboard Interrupt
257 set_interrupt_descriptor_table_entry(HARDWARE_INTERRUPT_OFFSET + 0x02, &HandleInterruptRequest0x02, InterruptPrivilegeLevel::KERNEL_ONLY); // PIT Interrupt
258 set_interrupt_descriptor_table_entry(HARDWARE_INTERRUPT_OFFSET + 0x04, &HandleInterruptRequest0x04, InterruptPrivilegeLevel::KERNEL_ONLY); // Serial Interrupt
259 set_interrupt_descriptor_table_entry(HARDWARE_INTERRUPT_OFFSET + 0x0C, &HandleInterruptRequest0x0C, InterruptPrivilegeLevel::KERNEL_ONLY); // Mouse Interrupt
260
261 // Set up the software interrupts
262 set_interrupt_descriptor_table_entry(HARDWARE_INTERRUPT_OFFSET + 0x60, &HandleInterruptRequest0x60, InterruptPrivilegeLevel::USERSPACE); // System Call Interrupt - Privilege Level 3 so that user space can call it
263 set_interrupt_descriptor_table_entry(HARDWARE_INTERRUPT_OFFSET + 0x61, &HandleInterruptRequest0x61, InterruptPrivilegeLevel::KERNEL_ONLY); // Kill this core
264
265 // Tell the processor to use the IDT
266 load_current();
267}
static LogRecord INFO()
Gets the active logger for info logs.
Definition logger.cpp:195
static InterruptManager * s_active_interrupt_manager
The interrupt manger that is currently handling interrupts and is loaded into the IDTR.
Definition interrupts.h:211
static void HandleException0x15()
Stub (see interrupts.s)
static void HandleInterruptError0x0A()
Stub (see interrupts.s)
static void HandleException0x14()
Stub (see interrupts.s)
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 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)
static void HandleInterruptError0x11()
Stub (see interrupts.s)
static void set_interrupt_descriptor_table_entry(uint8_t interrupt, void(*handler)(), InterruptPrivilegeLevel descriptor_privilege_level)
Sets an entry in the Interrupt Descriptor Table.
static void HandleException0x1E()
Stub (see interrupts.s)
static void HandleInterruptRequest0x60()
Stub (see interrupts.s)
static void HandleException0x1F()
Stub (see interrupts.s)
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 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)
static InterruptDescriptor s_interrupt_descriptor_table[MAX_INTERRUPT_HANDLERS]
The Interrupt Descriptor Table (IDT)
Definition interrupts.h:214
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 HandleInterruptRequest0x61()
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 HandleInterruptRequest0x04()
Stub (see interrupts.s)
static void HandleException0x1C()
Stub (see interrupts.s)
static void HandleInterruptRequest0x02()
Stub (see interrupts.s)
static void HandleException0x1D()
Stub (see interrupts.s)

References HandleException0x00(), HandleException0x01(), HandleException0x02(), HandleException0x03(), HandleException0x04(), HandleException0x05(), HandleException0x06(), HandleException0x07(), HandleException0x09(), HandleException0x0F(), HandleException0x10(), HandleException0x12(), HandleException0x13(), HandleException0x14(), HandleException0x15(), HandleException0x16(), HandleException0x17(), HandleException0x18(), HandleException0x19(), HandleException0x1A(), HandleException0x1B(), HandleException0x1C(), HandleException0x1D(), HandleException0x1E(), HandleException0x1F(), HandleInterruptError0x08(), HandleInterruptError0x0A(), HandleInterruptError0x0B(), HandleInterruptError0x0C(), HandleInterruptError0x0D(), HandleInterruptError0x0E(), HandleInterruptError0x11(), HandleInterruptRequest0x00(), HandleInterruptRequest0x01(), HandleInterruptRequest0x02(), HandleInterruptRequest0x04(), HandleInterruptRequest0x0C(), HandleInterruptRequest0x60(), HandleInterruptRequest0x61(), MaxOS::hardwarecommunication::HARDWARE_INTERRUPT_OFFSET, MaxOS::Logger::INFO(), load_current(), s_active_interrupt_manager, s_interrupt_descriptor_table, and set_interrupt_descriptor_table_entry().

◆ ~InterruptManager()

InterruptManager::~InterruptManager ( )

Destroys the Interrupt Manager and deactivates interrupts.

Definition at line 272 of file interrupts.cpp.

272 {
273 deactivate();
274}
static void deactivate()
Deactivates the interrupt manager and stops interrupts.

References deactivate().

Member Function Documentation

◆ activate()

void InterruptManager::activate ( )

Activates the interrupt manager and starts interrupts (also deactivates the current interrupt manager)

Definition at line 318 of file interrupts.cpp.

318 {
319
320 Logger::INFO() << "Activating Interrupts \n";
321
322 // Deactivate the current (old) interrupt manager
323 deactivate();
324
325 // Set the current interrupt manager and start interrupts
327 asm("sti");
328}

References deactivate(), MaxOS::Logger::INFO(), and s_active_interrupt_manager.

Referenced by kernel_main().

◆ active_apic()

AdvancedProgrammableInterruptController * InterruptManager::active_apic ( )

Gets the APIC.

Returns
The APIC

Definition at line 432 of file interrupts.cpp.

432 {
433
434 return m_apic;
435}

Referenced by MaxOS::hardwarecommunication::InterruptHandler::InterruptHandler().

◆ active_interrupt_manager()

InterruptManager * InterruptManager::active_interrupt_manager ( )
static

Gets the active interrupt manager.

Returns
The active interrupt manager

Definition at line 442 of file interrupts.cpp.

442 {
443
445}

References s_active_interrupt_manager.

Referenced by MaxOS::hardwarecommunication::AdvancedProgrammableInterruptController::AdvancedProgrammableInterruptController().

◆ deactivate()

void InterruptManager::deactivate ( )
static

Deactivates the interrupt manager and stops interrupts.

Definition at line 333 of file interrupts.cpp.

333 {
334
335 // Cant deactivate if it isn't the system one
336 if (s_active_interrupt_manager != nullptr)
337 return;
338
339 // Prevent interrupts from firing when nothing is set up to handle them
340 asm("cli");
342}

References s_active_interrupt_manager.

Referenced by activate(), and ~InterruptManager().

◆ ForceInterruptReturn()

static void MaxOS::hardwarecommunication::InterruptManager::ForceInterruptReturn ( system::cpu_status_t *  state)
static

Force the CPU to return from an interrupt (see interrupts.s)

Parameters
statethe state to return to

Referenced by MaxOS::processes::Thread::yield().

◆ handle_interrupt_request()

cpu_status_t * InterruptManager::handle_interrupt_request ( system::cpu_status_t *  status)
protected

Handles the interrupt request by passing it to the appropriate handler.

Parameters
statusThe current cpu status
Returns
The updated cpu status

Definition at line 389 of file interrupts.cpp.

389 {
390
391 // Handle the interrupt
392 ASSERT(m_interrupt_handlers[status->interrupt_number] != nullptr, "Interrupt 0x%x not handled\n", status->interrupt_number);
393 cpu_status_t* new_status = m_interrupt_handlers[status->interrupt_number]->handle_interrupt(status);
394
395 // Send the EOI to the APIC
396 if (HARDWARE_INTERRUPT_OFFSET <= status->interrupt_number && status->interrupt_number < HARDWARE_INTERRUPT_OFFSET + 16)
398
399 // Return the status
400 return new_status;
401}
virtual void handle_interrupt()
Handles an interrupt.
InterruptHandler * m_interrupt_handlers[MAX_INTERRUPT_HANDLERS]
A map of index-to-interrupt of interrupt handlers to fire when an interrupt occurs.
Definition interrupts.h:213
void send_eoi() const
Acknowledge that the interrupt has been handled, allowing the PIC to process the next interrupt.
Definition apic.cpp:120
static Core * executing_core()
Gets the core that is currently executing.
Definition cpu.cpp:660
hardwarecommunication::LocalAPIC * local_apic
The local APIC for this core.
Definition cpu.h:247
struct PACKED MaxOS::system::CPUStatus cpu_status_t
Alias for CPUStatus struct.

References MaxOS::system::CPU::executing_core(), MaxOS::hardwarecommunication::InterruptHandler::handle_interrupt(), MaxOS::hardwarecommunication::HARDWARE_INTERRUPT_OFFSET, MaxOS::system::Core::local_apic, m_interrupt_handlers, and MaxOS::hardwarecommunication::LocalAPIC::send_eoi().

Referenced by HandleInterrupt().

◆ HandleInterrupt()

cpu_status_t * InterruptManager::HandleInterrupt ( system::cpu_status_t *  status)
staticprotected

Handles the interrupt request by passing it to the interrupt manager.

Parameters
statusThe current cpu status
Returns
The updated cpu status
Todo:
Exception handlers

Definition at line 352 of file interrupts.cpp.

352 {
353
354 // If there is an interrupt manager handle interrupt
355 if (s_active_interrupt_manager != nullptr)
357
358 // CPU Can continue
359 return status;
360}
system::cpu_status_t * handle_interrupt_request(system::cpu_status_t *status)
Handles the interrupt request by passing it to the appropriate handler.

References handle_interrupt_request(), and s_active_interrupt_manager.

◆ load_current()

void InterruptManager::load_current ( )
static

Tell the processor to use the current InterruptManager.

Definition at line 307 of file interrupts.cpp.

307 {
308
309 IDTR idt = {};
310 idt.limit = 256 * sizeof(InterruptDescriptor) - 1;
311 idt.base = (uint64_t) s_interrupt_descriptor_table;
312 asm volatile("lidt %0" : : "m" (idt));
313}
A struct that holds the Interrupt Descriptor Table Register (IDTR)
Definition interrupts.h:145
uint16_t limit
The size of the IDT.
Definition interrupts.h:146
uint64_t base
The start address of the IDT.
Definition interrupts.h:147
An entry in the Interrupt Descriptor Table (IDT)
Definition interrupts.h:157

References MaxOS::hardwarecommunication::IDTR::base, MaxOS::hardwarecommunication::IDTR::limit, and s_interrupt_descriptor_table.

Referenced by MaxOS::system::Core::init(), and InterruptManager().

◆ remove_interrupt_handler()

void InterruptManager::remove_interrupt_handler ( uint8_t  interrupt)

Removes the interrupt handler for the interrupt.

Parameters
interruptThe interrupt number

Definition at line 378 of file interrupts.cpp.

378 {
379
380 m_interrupt_handlers[interrupt] = nullptr;
381}

References m_interrupt_handlers.

◆ set_apic()

void InterruptManager::set_apic ( AdvancedProgrammableInterruptController *  apic)

Sets the APIC.

Parameters
apicThe APIC

Definition at line 408 of file interrupts.cpp.

408 {
409
410 m_apic = apic;
411}

Referenced by MaxOS::hardwarecommunication::AdvancedProgrammableInterruptController::AdvancedProgrammableInterruptController().

◆ set_interrupt_descriptor_table_entry()

void InterruptManager::set_interrupt_descriptor_table_entry ( uint8_t  interrupt,
void(*)()  handler,
InterruptPrivilegeLevel  descriptor_privilege_level 
)
staticprotected

Sets an entry in the Interrupt Descriptor Table.

Parameters
interruptInterrupt number
handlerInterrupt Handler
descriptor_privilege_levelDescriptor Privilege Level

Definition at line 283 of file interrupts.cpp.

283 {
284
285 // Get the address of the handler and the entry in the IDT
286 auto handler_address = (uint64_t) handler;
287 InterruptDescriptor* interrupt_descriptor = &s_interrupt_descriptor_table[interrupt];
288
289 // Set the handler address
290 interrupt_descriptor->address_low_bits = handler_address & 0xFFFF;
291 interrupt_descriptor->address_mid_bits = (handler_address >> 16) & 0xFFFF;
292 interrupt_descriptor->address_high_bits = (handler_address >> 32) & 0xFFFFFFFF;
293
294 // Set the kernel code segment offset
295 interrupt_descriptor->segment_selector = 0x08;
296
297 // Disable IST
298 interrupt_descriptor->ist = 0;
299
300 // Set the flags (Trap Gate, Present and the Descriptor Privilege Level)
301 interrupt_descriptor->flags = 0b1110 | (((uint8_t)descriptor_privilege_level & 0b11) << 5) | (1 << 7);
302}
uint16_t segment_selector
The code segment selector in the GDT to use when this interrupt fires.
Definition interrupts.h:160
uint32_t address_high_bits
The high bits of the handler function address.
Definition interrupts.h:164
uint8_t ist
The offset into the Interrupt Stack Table (0 if not used) (see TSS)
Definition interrupts.h:161
uint16_t address_mid_bits
The middle bits of the handler function address.
Definition interrupts.h:163
uint16_t address_low_bits
The low bits of the handler function address.
Definition interrupts.h:159
uint8_t flags
Flags: The type of gate this entry represents (0xE for interrupt gate, 0xF for trap gate),...
Definition interrupts.h:162

References MaxOS::hardwarecommunication::InterruptDescriptor::address_high_bits, MaxOS::hardwarecommunication::InterruptDescriptor::address_low_bits, MaxOS::hardwarecommunication::InterruptDescriptor::address_mid_bits, MaxOS::hardwarecommunication::InterruptDescriptor::flags, MaxOS::hardwarecommunication::InterruptDescriptor::ist, s_interrupt_descriptor_table, and MaxOS::hardwarecommunication::InterruptDescriptor::segment_selector.

Referenced by InterruptManager().

◆ set_interrupt_handler()

void InterruptManager::set_interrupt_handler ( uint8_t  interrupt,
InterruptHandler *  handler 
)

Sets the interrupt handler for the interrupt.

Parameters
interruptThe interrupt number
handlerThe interrupt handler

Definition at line 368 of file interrupts.cpp.

368 {
369
370 m_interrupt_handlers[interrupt] = handler;
371}

References m_interrupt_handlers.

Referenced by MaxOS::hardwarecommunication::InterruptHandler::InterruptHandler(), and MaxOS::hardwarecommunication::InterruptHandler::~InterruptHandler().

Friends And Related Symbol Documentation

◆ InterruptHandler

friend class InterruptHandler
friend

Definition at line 201 of file interrupts.h.

Member Data Documentation

◆ m_interrupt_handlers

InterruptHandler* MaxOS::hardwarecommunication::InterruptManager::m_interrupt_handlers[MAX_INTERRUPT_HANDLERS] = { }
protected

A map of index-to-interrupt of interrupt handlers to fire when an interrupt occurs.

Definition at line 213 of file interrupts.h.

213{ };

Referenced by handle_interrupt_request(), remove_interrupt_handler(), and set_interrupt_handler().

◆ s_active_interrupt_manager

InterruptManager* MaxOS::hardwarecommunication::InterruptManager::s_active_interrupt_manager = nullptr
inlinestaticprotected

◆ s_interrupt_descriptor_table

InterruptDescriptor MaxOS::hardwarecommunication::InterruptManager::s_interrupt_descriptor_table[MAX_INTERRUPT_HANDLERS] = { }
inlinestaticprotected

The Interrupt Descriptor Table (IDT)

Definition at line 214 of file interrupts.h.

214{ };

Referenced by InterruptManager(), load_current(), and set_interrupt_descriptor_table_entry().


The documentation for this class was generated from the following files: