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

Base class for handing CPU expection interrupts. More...

#include <interrupts.h>

Inheritance diagram for MaxOS::hardwarecommunication::ExceptionHandler:
MaxOS::hardwarecommunication::InterruptHandler MaxOS::hardwarecommunication::DivideByZeroHandler MaxOS::hardwarecommunication::GeneralProtectionHandler MaxOS::hardwarecommunication::InvaildOpCodeHandler MaxOS::hardwarecommunication::PageFaultHandler MaxOS::runtime::BreakPointException MaxOS::runtime::TrapFlagExcpetion

Public Member Functions

 ExceptionHandler (uint8_t interrupt_number)
 Create a new base exception handler for an interrupt.
 
 ~ExceptionHandler ()
 
virtual string get_message (system::cpu_status_t *status)
 Get an human readable error message explaining this exception.
 
virtual system::cpu_status_t * handle_interrupt (system::cpu_status_t *status)
 Handle the interrupt relating to this exception.
 
- Public Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler
virtual void handle_interrupt ()
 Handles an interrupt.
 

Additional Inherited Members

- Protected Member Functions inherited from MaxOS::hardwarecommunication::InterruptHandler
 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 inherited from MaxOS::hardwarecommunication::InterruptHandler
uint8_t m_interrupt_number
 The interrupt number this handler handles.
 

Detailed Description

Base class for handing CPU expection interrupts.

Definition at line 61 of file interrupts.h.

Constructor & Destructor Documentation

◆ ExceptionHandler()

ExceptionHandler::ExceptionHandler ( uint8_t  interrupt_number)

Create a new base exception handler for an interrupt.

Parameters
interrupt_numberThe interrupt this exception handles

Definition at line 92 of file interrupts.cpp.

93: InterruptHandler(interrupt_number)
94{
95}
Handles a certain interrupt number.
Definition interrupts.h:44

◆ ~ExceptionHandler()

ExceptionHandler::~ExceptionHandler ( )
default

Default destructor for a ExceptionHandler

Member Function Documentation

◆ get_message()

string ExceptionHandler::get_message ( system::cpu_status_t *  status)
virtual

Get an human readable error message explaining this exception.

Parameters
statusThe CPU state at time of exception
Returns
The error message

Reimplemented in MaxOS::hardwarecommunication::DivideByZeroHandler, MaxOS::hardwarecommunication::InvaildOpCodeHandler, MaxOS::hardwarecommunication::GeneralProtectionHandler, and MaxOS::hardwarecommunication::PageFaultHandler.

Definition at line 108 of file interrupts.cpp.

108 {
109
110 return "Unimplemented message for exception\n";
111
112}

Referenced by handle_interrupt().

◆ handle_interrupt()

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

Handle the interrupt relating to this exception.

Parameters
statusThe CPU state at time of exception
Returns
The new CPU state to move to or null if no recoverable state

Reimplemented from MaxOS::hardwarecommunication::InterruptHandler.

Reimplemented in MaxOS::runtime::TrapFlagExcpetion, and MaxOS::runtime::BreakPointException.

Definition at line 120 of file interrupts.cpp.

120 {
121
122 // Get the message
123 string msg = get_message(status);
124
125 // Try to avoid the panic
126 cpu_status_t* can_avoid = CPU::prepare_for_panic(status, msg);
127 if (can_avoid != nullptr)
128 return can_avoid;
129
130 // Have to panic (must have occurred in kernel)
131 CPU::PANIC(msg.c_str(), status);
132
133 // Shouldn't return, fault if this happens
134 return nullptr;
135
136}
virtual string get_message(system::cpu_status_t *status)
Get an human readable error message explaining this exception.
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.
Definition cpu.cpp:463
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.
Definition cpu.cpp:521
struct PACKED MaxOS::system::CPUStatus cpu_status_t
Alias for CPUStatus struct.

References get_message(), MaxOS::system::CPU::PANIC(), and MaxOS::system::CPU::prepare_for_panic().


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