1

Cleanup Interrupt

This commit is contained in:
2022-12-08 21:00:42 +01:00
parent d5f4193e4f
commit 5965d6893e
4 changed files with 46 additions and 21 deletions

View File

@ -1,28 +1,28 @@
/*****************************************************************************
* *
* I S R *
* *
*---------------------------------------------------------------------------*
* Beschreibung: Interrupt Service Routine. Jeweils ein Objekt pro ISR. *
* Erlaubt es einen Kontext mit Variablen fuer die Unter- *
* brechungsroutine bereitzustellen. *
* *
* Autor: Michael Schoettner, 06.04.20 *
*****************************************************************************/
#ifndef ISR_include__
#define ISR_include__
#include "lib/util/RestrictedConstructors.h"
namespace Kernel {
/**
* This class implements an interrupt service routine.
*/
class ISR {
friend class IntDispatcher;
public:
ISR(const ISR &copy) = delete; // Verhindere Kopieren
MakeDefault(ISR)
// virtual ~ISR() = default;
MakeUncopyable(ISR)
ISR() = default;
MakeUnmovable(ISR)
// Unterbrechungsbehandlungsroutine
protected:
/**
* This function gets called when an interrupt occurs and
* an interrupt handler is registered for the vector number.
*/
virtual void trigger() = 0;
};

View File

@ -5,11 +5,11 @@
namespace Kernel {
void IntDispatcher::assign(uint8_t vector, ISR &isr) {
void IntDispatcher::assign(Vector vector, ISR &isr) {
handlerMap[vector] = &isr;
}
void IntDispatcher::dispatch(uint8_t vector) {
void IntDispatcher::dispatch(Vector vector) {
ISR *isr = handlerMap[vector];
if (isr == nullptr) {

View File

@ -20,12 +20,18 @@
namespace Kernel {
/**
* This class implements a simple interrupt dispatcher.
* It is part of the 2-step interrupt handling: Instead of registering ISRs
* in the IDT directly, the "dispatch" function is called with the vector number.
*/
class IntDispatcher {
friend class InterruptService;
public:
/**
* Vector numbers (slots in the IDT)
* Vector numbers (slots in the IDT).
* Every IRQ corresponds to one vector number.
*/
enum Vector {
TIMER = 32,
@ -41,9 +47,20 @@ public:
MakeUncopyable(IntDispatcher)
private:
void assign(uint8_t vector, ISR &isr);
/**
* Assign an interrupt handler to a vector number.
*
* @param vector The vector number
* @param isr The interrupt handler
*/
void assign(Vector vector, ISR &isr);
void dispatch(uint8_t vector);
/**
* Call a registered interrupt handler.
*
* @param vector The vector number of the occured interrupt
*/
void dispatch(Vector vector);
private:
Container::Array<ISR *, 256> handlerMap = {nullptr};

View File

@ -2,10 +2,18 @@
#include "kernel/system/System.h"
#include "kernel/service/InterruptService.h"
extern "C" void int_disp(uint8_t vector);
// Called from startup.asm
extern "C" {
/**
* Call an ISR after an interrupt occured.
*
* @param vector The vector number of the occured interrupt
*/
void int_disp(uint8_t vector) {
auto &interruptService = Kernel::System::getService<Kernel::InterruptService>();
interruptService.dispatchInterrupt(static_cast<Kernel::IntDispatcher::Vector>(vector));
}
}