2011-04-02 14:46:31 +00:00
|
|
|
#ifndef __CINTERRUPT_DISPATCHER__
|
|
|
|
#define __CINTERRUPT_DISPATCHER__
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "preprocessor_hacks.h"
|
|
|
|
extern "C" {
|
|
|
|
#include "Tier0/interrupts.h"
|
|
|
|
#include "Tier0/panic.h"
|
2011-05-03 11:59:20 +00:00
|
|
|
#include "Tier0/kstdio.h"
|
2011-04-02 14:46:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// I am going to programmer hell for this
|
|
|
|
|
|
|
|
//CInterruptDispatcher StaticDispatcher Declaration
|
|
|
|
#define CID_SDIS_DEC(n) static void d_Interrupt##n(T_ISR_REGISTERS_ERR R);
|
|
|
|
|
|
|
|
//CInterruptDispatcher StaticDispatcher Implementation
|
|
|
|
#define CID_SDIS_IMP(n) void CInterruptDispatcher::d_Interrupt##n( \
|
|
|
|
T_ISR_REGISTERS_ERR R) { \
|
|
|
|
if (m_Dispatchers[n] != 0) \
|
|
|
|
m_Dispatchers[n]->Dispatch(&R); \
|
|
|
|
}
|
|
|
|
|
|
|
|
//CInterruptDispatcher StaticDispatcher Set
|
|
|
|
#define CID_SDID_SET(n) m_DispatcherFunctions[n] = (void*)d_Interrupt##n;
|
|
|
|
|
|
|
|
//CInterruptsDispatcher StaticDispatcher Function
|
|
|
|
#define CID_SDIS_FUNC(n) d_Interrupt##n
|
|
|
|
|
|
|
|
namespace cb {
|
|
|
|
// A class to.. dispatch interrupts?
|
|
|
|
class CInterruptDispatcher {
|
|
|
|
protected:
|
|
|
|
// Interrupt number
|
|
|
|
u8 m_Interrupt;
|
|
|
|
|
|
|
|
// Enabled?
|
2011-05-08 15:16:00 +00:00
|
|
|
bool m_bEnabled;
|
2011-04-02 14:46:31 +00:00
|
|
|
|
|
|
|
// Private enable function - call it from the constructor, another
|
|
|
|
// public method or whatever
|
|
|
|
void Enable(void);
|
|
|
|
|
|
|
|
// Same, but disables
|
|
|
|
void Disable(void);
|
|
|
|
private:
|
|
|
|
// Internal stuff for translating static calls into member functions
|
|
|
|
static CInterruptDispatcher *m_Dispatchers[256];
|
2011-05-08 15:16:00 +00:00
|
|
|
static bool m_bInitializedStatic;
|
2011-04-02 14:46:31 +00:00
|
|
|
static void InitializeStatic(void);
|
|
|
|
|
|
|
|
// All the static dispatchers for all the interrupts
|
|
|
|
PPHAX_DO256(CID_SDIS_DEC);
|
|
|
|
public:
|
|
|
|
// Default constructor - doesn't do shit
|
|
|
|
CInterruptDispatcher(void);
|
|
|
|
|
|
|
|
// The main point - a virtual dispatch function.
|
|
|
|
// This receives either a T_ISR_REGISTERS_ERR or a T_ISR_REGISTERS
|
|
|
|
// depending on the interrupt - we'll let the deriver decide
|
|
|
|
virtual void Dispatch(void *Registers);
|
|
|
|
|
|
|
|
// The usual getters...
|
|
|
|
u8 GetInterrupt(void);
|
|
|
|
bool GetEnabled(void);
|
|
|
|
|
|
|
|
//Static stuff...
|
|
|
|
static void *m_DispatcherFunctions[256];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|