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

Handles a certain interrupt number. More...

#include <interrupts.h>

Inheritance diagram for MaxOS::hardwarecommunication::InterruptHandler:
MaxOS::hardwarecommunication::CPUStopHandler MaxOS::hardwarecommunication::Clock MaxOS::hardwarecommunication::ExceptionHandler MaxOS::hardwarecommunication::PIT MaxOS::processes::GlobalScheduler MaxOS::runtime::GDBServer MaxOS::system::SyscallManager MaxOS::hardwarecommunication::DivideByZeroHandler MaxOS::hardwarecommunication::GeneralProtectionHandler MaxOS::hardwarecommunication::InvaildOpCodeHandler MaxOS::hardwarecommunication::PageFaultHandler MaxOS::runtime::BreakPointException MaxOS::runtime::TrapFlagExcpetion

Public Member Functions

virtual void handle_interrupt ()
 Handles an interrupt.
 
virtual system::cpu_status_t * handle_interrupt (system::cpu_status_t *status)
 Handles an interrupt and returns the status.
 

Protected Member Functions

 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.
 
virtual ~InterruptHandler ()
 Destroys the interrupt handler and unregisters it from the interrupt manager.
 

Protected Attributes

uint8_t m_interrupt_number
 The interrupt number this handler handles.
 

Detailed Description

Handles a certain interrupt number.

Definition at line 44 of file interrupts.h.

Constructor & Destructor Documentation

◆ InterruptHandler()

InterruptHandler::InterruptHandler ( uint8_t  interrupt_number,
int64_t  redirect = -1,
uint64_t  redirect_index = 0 
)
explicitprotected

Creates a new interrupt handler and registers it with the interrupt manager.

Parameters
interrupt_numberThe interrupt number to handle
redirectWhat legacy interrupt to redirect from (-1 for no redirection)
redirect_indexWhich index of the legacy interrupt to redirect from

Definition at line 24 of file interrupts.cpp.

25: m_interrupt_number(interrupt_number)
26{
27
28 // Get the interrupt manager
30 ASSERT(interrupt_manager != nullptr, "No active interrupt manager");
31
32 // Register the handler
33 interrupt_manager->set_interrupt_handler(m_interrupt_number, this);
34
35 // Not all interrupts need redirecting
36 if (redirect == -1)
37 return;
38
39 // Redirect a legacy interrupt to an interrupt the kernel expects
40 IOAPIC* io_apic = interrupt_manager->active_apic()->io_apic();
42 .type = (uint8_t) redirect,
43 .index = (uint8_t) redirect_index,
44 .interrupt = m_interrupt_number,
45 .destination = 0x00,
46 .flags = 0x00,
47 .mask = false,
48 };
49 io_apic->set_redirect(&temp);
50}
Handles the IO APIC in the system (one per system)
Definition apic.h:205
void set_redirect(interrupt_redirect_t *redirect)
Redirect a system interrupt to a different IRQ.
Definition apic.cpp:412
uint8_t m_interrupt_number
The interrupt number this handler handles.
Definition interrupts.h:46
Handles all interrupts and passes them to the correct handler.
Definition interrupts.h:200
static InterruptManager * s_active_interrupt_manager
The interrupt manger that is currently handling interrupts and is loaded into the IDTR.
Definition interrupts.h:211
void set_interrupt_handler(uint8_t interrupt, InterruptHandler *handler)
Sets the interrupt handler for the interrupt.
AdvancedProgrammableInterruptController * active_apic()
Gets the APIC.
Defines how an interrupt input is redirected to a specific processor via the I/O APIC.
Definition apic.h:174
uint8_t type
The type of redirect (should be 0 for normal interrupts)
Definition apic.h:176

References MaxOS::hardwarecommunication::InterruptManager::active_apic(), MaxOS::hardwarecommunication::AdvancedProgrammableInterruptController::io_apic(), m_interrupt_number, MaxOS::hardwarecommunication::InterruptManager::s_active_interrupt_manager, MaxOS::hardwarecommunication::InterruptManager::set_interrupt_handler(), MaxOS::hardwarecommunication::IOAPIC::set_redirect(), and MaxOS::hardwarecommunication::InterruptRedirect::type.

◆ ~InterruptHandler()

InterruptHandler::~InterruptHandler ( )
protectedvirtual

Destroys the interrupt handler and unregisters it from the interrupt manager.

Definition at line 55 of file interrupts.cpp.

55 {
56
57 // Get the interrupt manager
59 if (interrupt_manager == nullptr) return;
60
61 // Remove the handler
62 interrupt_manager->set_interrupt_handler(m_interrupt_number, nullptr);
63}

References m_interrupt_number, MaxOS::hardwarecommunication::InterruptManager::s_active_interrupt_manager, and MaxOS::hardwarecommunication::InterruptManager::set_interrupt_handler().

Member Function Documentation

◆ handle_interrupt() [1/2]

void InterruptHandler::handle_interrupt ( )
virtual

Handles an interrupt.

Definition at line 68 of file interrupts.cpp.

68 {
69
70}

Referenced by handle_interrupt(), and MaxOS::hardwarecommunication::InterruptManager::handle_interrupt_request().

◆ handle_interrupt() [2/2]

cpu_status_t * InterruptHandler::handle_interrupt ( system::cpu_status_t *  status)
virtual

Handles an interrupt and returns the status.

Parameters
statusThe status of the CPU
Returns
The status of the CPU

Reimplemented in MaxOS::system::SyscallManager, MaxOS::hardwarecommunication::ExceptionHandler, MaxOS::hardwarecommunication::CPUStopHandler, MaxOS::processes::GlobalScheduler, MaxOS::runtime::TrapFlagExcpetion, and MaxOS::runtime::BreakPointException.

Definition at line 78 of file interrupts.cpp.

78 {
79
80 // For handlers that don't care about the status
82
83 // Return the default status
84 return status;
85}
virtual void handle_interrupt()
Handles an interrupt.

References handle_interrupt().

Member Data Documentation

◆ m_interrupt_number

uint8_t MaxOS::hardwarecommunication::InterruptHandler::m_interrupt_number
protected

The interrupt number this handler handles.

Definition at line 46 of file interrupts.h.

Referenced by InterruptHandler(), and ~InterruptHandler().


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