Max OS 0.3
Loading...
Searching...
No Matches
interrupts.h
Go to the documentation of this file.
1
9#ifndef MAX_OS_HARDWARECOMMUNICATION_INTERRUPTS_H
10#define MAX_OS_HARDWARECOMMUNICATION_INTERRUPTS_H
11
12#include <cstdint>
14#include <system/gdt.h>
15#include <common/inputStream.h>
16#include <common/outputStream.h>
17#include <common/map.h>
18#include <system/cpu.h>
20
21
22namespace MaxOS::hardwarecommunication {
23
24 class InterruptManager;
25
31 protected:
33
34 explicit InterruptHandler(uint8_t interrupt_number, int64_t redirect = -1, uint64_t redirect_index = 0);
36
37 public:
38 virtual void handle_interrupt();
40
41 };
42
50 typedef struct PACKED IDTR {
51 uint16_t limit;
52 uint64_t base;
53 } idtr_t;
54
62 typedef struct PACKED InterruptDescriptor {
63
66 uint8_t ist;
67 uint8_t flags;
70 uint32_t reserved;
71
72 } interrupt_descriptor_t;
73
74 constexpr uint16_t HARDWARE_INTERRUPT_OFFSET = 0x20;
75 constexpr uint16_t MAX_INTERRUPT_HANDLERS = 256;
76
85 friend class InterruptHandler;
86
87 private:
89
90 static system::cpu_status_t* page_fault(system::cpu_status_t* status);
91 static system::cpu_status_t* general_protection_fault(system::cpu_status_t* status);
92
93 protected:
94
96
99
100 static void set_interrupt_descriptor_table_entry(uint8_t interrupt, void (* handler)(), uint8_t descriptor_privilege_level);
101
102 //Various Interrupts
122
123 // Exceptions
124 static void HandleException0x00();
125 static void HandleException0x01();
126 static void HandleException0x02();
127 static void HandleException0x03();
128 static void HandleException0x04();
129 static void HandleException0x05();
130 static void HandleException0x06();
131 static void HandleException0x07();
133 static void HandleException0x09();
139 static void HandleException0x0F();
140 static void HandleException0x10();
142 static void HandleException0x12();
143 static void HandleException0x13();
144 static void HandleException0x14();
145 static void HandleException0x15();
146 static void HandleException0x16();
147 static void HandleException0x17();
148 static void HandleException0x18();
149 static void HandleException0x19();
150 static void HandleException0x1A();
151 static void HandleException0x1B();
152 static void HandleException0x1C();
153 static void HandleException0x1D();
154 static void HandleException0x1E();
155 static void HandleException0x1F();
156
159
160 public:
163
165
166 void set_interrupt_handler(uint8_t interrupt, InterruptHandler* handler);
167 void remove_interrupt_handler(uint8_t interrupt);
168
171
172 static void load_current();
173 void activate();
174 static void deactivate();
175
181
182 };
183}
184
185
186#endif //MAX_OS_HARDWARECOMMUNICATION_INTERRUPTS_H
Defines classes and structures for handling the Advanced Programmable Interrupt Controller (APIC) in ...
Handles both the Local APIC (boot core) and IO APIC.
Definition apic.h:228
Handles a certain interrupt number.
Definition interrupts.h:30
~InterruptHandler()
Destroys the interrupt handler and unregisters it from the interrupt manager.
uint8_t m_interrupt_number
The interrupt number this handler handles.
Definition interrupts.h:32
virtual void handle_interrupt()
Handles an interrupt.
Handles all interrupts and passes them to the correct handler.
Definition interrupts.h:84
static InterruptManager * s_active_interrupt_manager
The interrupt manger that is currently handling interrupts and is loaded into the IDTR.
Definition interrupts.h:95
static void HandleInterruptRequest0x06()
Stub (see interrupts.s)
static void HandleException0x15()
Stub (see interrupts.s)
static void HandleInterruptError0x0A()
Stub (see interrupts.s)
static void HandleInterruptRequest0x05()
Stub (see interrupts.s)
static void HandleInterruptRequest0x31()
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 HandleInterruptRequest0x0A()
Stub (see interrupts.s)
static void HandleException0x00()
Stub (see interrupts.s)
static void HandleInterruptRequest0x0C()
Stub (see interrupts.s)
static void HandleInterruptRequest0x0F()
Stub (see interrupts.s)
static void HandleInterruptRequest0x07()
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 HandleInterruptRequest0x0E()
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 HandleInterruptRequest0x09()
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 HandleInterruptRequest0x0B()
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 ForceInterruptReturn(system::cpu_status_t *state)
Force the CPU to return from an interrupt (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 void HandleInterruptRequest0x80()
Stub (see interrupts.s)
static InterruptDescriptor s_interrupt_descriptor_table[MAX_INTERRUPT_HANDLERS]
The Interrupt Descriptor Table (IDT)
Definition interrupts.h:98
static void HandleException0x12()
Stub (see interrupts.s)
static void HandleInterruptRequest0x00()
Stub (see interrupts.s)
static void HandleInterruptRequest0x08()
Stub (see interrupts.s)
static void HandleException0x09()
Stub (see interrupts.s)
static void HandleException0x16()
Stub (see interrupts.s)
static void HandleInterruptRequest0x0D()
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 HandleInterruptRequest0x04()
Stub (see interrupts.s)
static void HandleInterruptRequest0x03()
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.
Definition interrupts.h:97
Defines Central Processing Unit (CPU) structures and functions for managing CPU state and features.
struct PACKED MaxOS::system::CPUStatus cpu_status_t
Alias for CPUStatus struct.
Defines a Global Descriptor Table (GDT) for setting up memory segments in protected mode.
Defines a generic input stream and related classes for handling input data streams.
constexpr uint16_t MAX_INTERRUPT_HANDLERS
The maximum number of interrupt handlers.
Definition interrupts.h:75
constexpr uint16_t HARDWARE_INTERRUPT_OFFSET
The offset in the IDT where interrupts from hardware start.
Definition interrupts.h:74
Defines a Map class for storing key-value pairs.
Defines OutputStream and GenericOutputStream classes for writing data to streams.
Defines classes for handling hardware communication ports (8, 16, and 32 bit)
A struct that holds the Interrupt Descriptor Table Register (IDTR)
Definition interrupts.h:50
uint16_t limit
The size of the IDT.
Definition interrupts.h:51
uint64_t base
The start address of the IDT.
Definition interrupts.h:52
An entry in the Interrupt Descriptor Table (IDT)
Definition interrupts.h:62
uint16_t segment_selector
The code segment selector in the GDT to use when this interrupt fires.
Definition interrupts.h:65
uint32_t address_high_bits
The high bits of the handler function address.
Definition interrupts.h:69
uint32_t reserved
Reserved, must be zero.
Definition interrupts.h:70
uint8_t ist
The offset into the Interrupt Stack Table (0 if not used) (see TSS)
Definition interrupts.h:66
uint16_t address_mid_bits
The middle bits of the handler function address.
Definition interrupts.h:68
uint16_t address_low_bits
The low bits of the handler function address.
Definition interrupts.h:64
uint8_t flags
Flags: The type of gate this entry represents (0xE for interrupt gate, 0xF for trap gate),...
Definition interrupts.h:67