Cleanup Interrupt
This commit is contained in:
@ -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 ©) = 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;
|
||||
};
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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};
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user