now with some interrupt dispatchers
parent
3b0074d546
commit
e65e67846d
|
@ -58,6 +58,7 @@ typedef struct {
|
||||||
|
|
||||||
u8 interrupts_init_idt(void);
|
u8 interrupts_init_idt(void);
|
||||||
void interrupts_setup_irq(u8 IRQ, void *Handler);
|
void interrupts_setup_irq(u8 IRQ, void *Handler);
|
||||||
|
void interrupts_delete_isr(u8 Interrupt);
|
||||||
void interrupts_setup_isr_raw(u8 Interrupt, void *ASMHandler, \
|
void interrupts_setup_isr_raw(u8 Interrupt, void *ASMHandler, \
|
||||||
T_INTERRUPTS_RING Ring);
|
T_INTERRUPTS_RING Ring);
|
||||||
void interrupts_setup_isr(u8 Interrupt, void *Handler, T_INTERRUPTS_RING Ring);
|
void interrupts_setup_isr(u8 Interrupt, void *Handler, T_INTERRUPTS_RING Ring);
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
#ifndef __CINTERRUPT_DISPATCHER__
|
||||||
|
#define __CINTERRUPT_DISPATCHER__
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
#include "preprocessor_hacks.h"
|
||||||
|
extern "C" {
|
||||||
|
#include "Tier0/interrupts.h"
|
||||||
|
#include "Tier0/panic.h"
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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?
|
||||||
|
bool m_Enabled;
|
||||||
|
|
||||||
|
// 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];
|
||||||
|
static bool m_InitializedStatic;
|
||||||
|
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
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
#include "Tier1/CInterruptDispatcher.h"
|
||||||
|
|
||||||
|
namespace cb {
|
||||||
|
class CPageFaultDispatcher : public CInterruptDispatcher {
|
||||||
|
public:
|
||||||
|
CPageFaultDispatcher(void);
|
||||||
|
void Dispatch(void *Registers);
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,267 @@
|
||||||
|
#ifndef __PREPROCESSORHACKS_H__
|
||||||
|
#define __PREPROCESSORHACKS_H__
|
||||||
|
|
||||||
|
// These are nasty...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Do something 256 times
|
||||||
|
#define PPHAX_DO256(x) \
|
||||||
|
x(0); \
|
||||||
|
x(1); \
|
||||||
|
x(2); \
|
||||||
|
x(3); \
|
||||||
|
x(4); \
|
||||||
|
x(5); \
|
||||||
|
x(6); \
|
||||||
|
x(7); \
|
||||||
|
x(8); \
|
||||||
|
x(9); \
|
||||||
|
x(10); \
|
||||||
|
x(11); \
|
||||||
|
x(12); \
|
||||||
|
x(13); \
|
||||||
|
x(14); \
|
||||||
|
x(15); \
|
||||||
|
x(16); \
|
||||||
|
x(17); \
|
||||||
|
x(18); \
|
||||||
|
x(19); \
|
||||||
|
x(20); \
|
||||||
|
x(21); \
|
||||||
|
x(22); \
|
||||||
|
x(23); \
|
||||||
|
x(24); \
|
||||||
|
x(25); \
|
||||||
|
x(26); \
|
||||||
|
x(27); \
|
||||||
|
x(28); \
|
||||||
|
x(29); \
|
||||||
|
x(30); \
|
||||||
|
x(31); \
|
||||||
|
x(32); \
|
||||||
|
x(33); \
|
||||||
|
x(34); \
|
||||||
|
x(35); \
|
||||||
|
x(36); \
|
||||||
|
x(37); \
|
||||||
|
x(38); \
|
||||||
|
x(39); \
|
||||||
|
x(40); \
|
||||||
|
x(41); \
|
||||||
|
x(42); \
|
||||||
|
x(43); \
|
||||||
|
x(44); \
|
||||||
|
x(45); \
|
||||||
|
x(46); \
|
||||||
|
x(47); \
|
||||||
|
x(48); \
|
||||||
|
x(49); \
|
||||||
|
x(50); \
|
||||||
|
x(51); \
|
||||||
|
x(52); \
|
||||||
|
x(53); \
|
||||||
|
x(54); \
|
||||||
|
x(55); \
|
||||||
|
x(56); \
|
||||||
|
x(57); \
|
||||||
|
x(58); \
|
||||||
|
x(59); \
|
||||||
|
x(60); \
|
||||||
|
x(61); \
|
||||||
|
x(62); \
|
||||||
|
x(63); \
|
||||||
|
x(64); \
|
||||||
|
x(65); \
|
||||||
|
x(66); \
|
||||||
|
x(67); \
|
||||||
|
x(68); \
|
||||||
|
x(69); \
|
||||||
|
x(70); \
|
||||||
|
x(71); \
|
||||||
|
x(72); \
|
||||||
|
x(73); \
|
||||||
|
x(74); \
|
||||||
|
x(75); \
|
||||||
|
x(76); \
|
||||||
|
x(77); \
|
||||||
|
x(78); \
|
||||||
|
x(79); \
|
||||||
|
x(80); \
|
||||||
|
x(81); \
|
||||||
|
x(82); \
|
||||||
|
x(83); \
|
||||||
|
x(84); \
|
||||||
|
x(85); \
|
||||||
|
x(86); \
|
||||||
|
x(87); \
|
||||||
|
x(88); \
|
||||||
|
x(89); \
|
||||||
|
x(90); \
|
||||||
|
x(91); \
|
||||||
|
x(92); \
|
||||||
|
x(93); \
|
||||||
|
x(94); \
|
||||||
|
x(95); \
|
||||||
|
x(96); \
|
||||||
|
x(97); \
|
||||||
|
x(98); \
|
||||||
|
x(99); \
|
||||||
|
x(100); \
|
||||||
|
x(101); \
|
||||||
|
x(102); \
|
||||||
|
x(103); \
|
||||||
|
x(104); \
|
||||||
|
x(105); \
|
||||||
|
x(106); \
|
||||||
|
x(107); \
|
||||||
|
x(108); \
|
||||||
|
x(109); \
|
||||||
|
x(110); \
|
||||||
|
x(111); \
|
||||||
|
x(112); \
|
||||||
|
x(113); \
|
||||||
|
x(114); \
|
||||||
|
x(115); \
|
||||||
|
x(116); \
|
||||||
|
x(117); \
|
||||||
|
x(118); \
|
||||||
|
x(119); \
|
||||||
|
x(120); \
|
||||||
|
x(121); \
|
||||||
|
x(122); \
|
||||||
|
x(123); \
|
||||||
|
x(124); \
|
||||||
|
x(125); \
|
||||||
|
x(126); \
|
||||||
|
x(127); \
|
||||||
|
x(128); \
|
||||||
|
x(129); \
|
||||||
|
x(130); \
|
||||||
|
x(131); \
|
||||||
|
x(132); \
|
||||||
|
x(133); \
|
||||||
|
x(134); \
|
||||||
|
x(135); \
|
||||||
|
x(136); \
|
||||||
|
x(137); \
|
||||||
|
x(138); \
|
||||||
|
x(139); \
|
||||||
|
x(140); \
|
||||||
|
x(141); \
|
||||||
|
x(142); \
|
||||||
|
x(143); \
|
||||||
|
x(144); \
|
||||||
|
x(145); \
|
||||||
|
x(146); \
|
||||||
|
x(147); \
|
||||||
|
x(148); \
|
||||||
|
x(149); \
|
||||||
|
x(150); \
|
||||||
|
x(151); \
|
||||||
|
x(152); \
|
||||||
|
x(153); \
|
||||||
|
x(154); \
|
||||||
|
x(155); \
|
||||||
|
x(156); \
|
||||||
|
x(157); \
|
||||||
|
x(158); \
|
||||||
|
x(159); \
|
||||||
|
x(160); \
|
||||||
|
x(161); \
|
||||||
|
x(162); \
|
||||||
|
x(163); \
|
||||||
|
x(164); \
|
||||||
|
x(165); \
|
||||||
|
x(166); \
|
||||||
|
x(167); \
|
||||||
|
x(168); \
|
||||||
|
x(169); \
|
||||||
|
x(170); \
|
||||||
|
x(171); \
|
||||||
|
x(172); \
|
||||||
|
x(173); \
|
||||||
|
x(174); \
|
||||||
|
x(175); \
|
||||||
|
x(176); \
|
||||||
|
x(177); \
|
||||||
|
x(178); \
|
||||||
|
x(179); \
|
||||||
|
x(180); \
|
||||||
|
x(181); \
|
||||||
|
x(182); \
|
||||||
|
x(183); \
|
||||||
|
x(184); \
|
||||||
|
x(185); \
|
||||||
|
x(186); \
|
||||||
|
x(187); \
|
||||||
|
x(188); \
|
||||||
|
x(189); \
|
||||||
|
x(190); \
|
||||||
|
x(191); \
|
||||||
|
x(192); \
|
||||||
|
x(193); \
|
||||||
|
x(194); \
|
||||||
|
x(195); \
|
||||||
|
x(196); \
|
||||||
|
x(197); \
|
||||||
|
x(198); \
|
||||||
|
x(199); \
|
||||||
|
x(200); \
|
||||||
|
x(201); \
|
||||||
|
x(202); \
|
||||||
|
x(203); \
|
||||||
|
x(204); \
|
||||||
|
x(205); \
|
||||||
|
x(206); \
|
||||||
|
x(207); \
|
||||||
|
x(208); \
|
||||||
|
x(209); \
|
||||||
|
x(210); \
|
||||||
|
x(211); \
|
||||||
|
x(212); \
|
||||||
|
x(213); \
|
||||||
|
x(214); \
|
||||||
|
x(215); \
|
||||||
|
x(216); \
|
||||||
|
x(217); \
|
||||||
|
x(218); \
|
||||||
|
x(219); \
|
||||||
|
x(220); \
|
||||||
|
x(221); \
|
||||||
|
x(222); \
|
||||||
|
x(223); \
|
||||||
|
x(224); \
|
||||||
|
x(225); \
|
||||||
|
x(226); \
|
||||||
|
x(227); \
|
||||||
|
x(228); \
|
||||||
|
x(229); \
|
||||||
|
x(230); \
|
||||||
|
x(231); \
|
||||||
|
x(232); \
|
||||||
|
x(233); \
|
||||||
|
x(234); \
|
||||||
|
x(235); \
|
||||||
|
x(236); \
|
||||||
|
x(237); \
|
||||||
|
x(238); \
|
||||||
|
x(239); \
|
||||||
|
x(240); \
|
||||||
|
x(241); \
|
||||||
|
x(242); \
|
||||||
|
x(243); \
|
||||||
|
x(244); \
|
||||||
|
x(245); \
|
||||||
|
x(246); \
|
||||||
|
x(247); \
|
||||||
|
x(248); \
|
||||||
|
x(249); \
|
||||||
|
x(250); \
|
||||||
|
x(251); \
|
||||||
|
x(252); \
|
||||||
|
x(253); \
|
||||||
|
x(254); \
|
||||||
|
x(255); \
|
||||||
|
|
||||||
|
#endif
|
|
@ -48,6 +48,8 @@ u8 interrupts_init_idt(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This creates an ASM stub for
|
||||||
|
|
||||||
// This creates a 12-byte ASM stub for a handler
|
// This creates a 12-byte ASM stub for a handler
|
||||||
void interrupts_create_stub(T_ISR_STUB *Destination, u32 Address)
|
void interrupts_create_stub(T_ISR_STUB *Destination, u32 Address)
|
||||||
{
|
{
|
||||||
|
@ -132,6 +134,11 @@ void interrupts_setup_isr(u8 Interrupt, void *Handler, \
|
||||||
interrupts_setup_isr_raw(Interrupt, (void*)ASMHandler, Ring);
|
interrupts_setup_isr_raw(Interrupt, (void*)ASMHandler, Ring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void interrupts_delete_isr(u8 Interrupt)
|
||||||
|
{
|
||||||
|
*((u32*)&g_idt_entries[Interrupt]) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void interrupts_init_simple(void)
|
void interrupts_init_simple(void)
|
||||||
{
|
{
|
||||||
interrupts_set_chip(E_INTERRUPTS_CHIP_PIC);
|
interrupts_set_chip(E_INTERRUPTS_CHIP_PIC);
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
#include "Tier1/CInterruptDispatcher.h"
|
||||||
|
using namespace cb;
|
||||||
|
|
||||||
|
void CInterruptDispatcher::InitializeStatic(void)
|
||||||
|
{
|
||||||
|
if (m_InitializedStatic)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_InitializedStatic = true;
|
||||||
|
for (u16 i = 0; i < 256; i++)
|
||||||
|
m_Dispatchers[i] = 0;
|
||||||
|
|
||||||
|
PPHAX_DO256(CID_SDID_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
CInterruptDispatcher::CInterruptDispatcher(void)
|
||||||
|
{
|
||||||
|
if (!m_InitializedStatic)
|
||||||
|
InitializeStatic();
|
||||||
|
m_Interrupt = 0;
|
||||||
|
m_Enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInterruptDispatcher::Enable(void)
|
||||||
|
{
|
||||||
|
if (m_Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_Enabled = true;
|
||||||
|
|
||||||
|
m_Dispatchers[m_Interrupt] = this;
|
||||||
|
|
||||||
|
interrupts_setup_isr(m_Interrupt, (void*)m_DispatcherFunctions[m_Interrupt],
|
||||||
|
E_INTERRUPTS_RING0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInterruptDispatcher::Disable(void)
|
||||||
|
{
|
||||||
|
if (!m_Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_Enabled = false;
|
||||||
|
|
||||||
|
interrupts_delete_isr(m_Interrupt);
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 CInterruptDispatcher::GetInterrupt(void)
|
||||||
|
{
|
||||||
|
return m_Interrupt;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CInterruptDispatcher::GetEnabled(void)
|
||||||
|
{
|
||||||
|
return m_Enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInterruptDispatcher::Dispatch(void *Registers)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//All of the interrupt static implementations
|
||||||
|
PPHAX_DO256(CID_SDIS_IMP);
|
||||||
|
|
||||||
|
void *CInterruptDispatcher::m_DispatcherFunctions[256];
|
||||||
|
CInterruptDispatcher *CInterruptDispatcher::m_Dispatchers[256];
|
||||||
|
bool CInterruptDispatcher::m_InitializedStatic = false;
|
|
@ -1,6 +1,7 @@
|
||||||
#include "Tier1/CKernel.h"
|
#include "Tier1/CKernel.h"
|
||||||
#include "Tier1/Drivers/Misc/CDriverDummy.h"
|
#include "Tier1/Drivers/Misc/CDriverDummy.h"
|
||||||
#include "Tier1/Drivers/Device/CDriverRamdisk.h"
|
#include "Tier1/Drivers/Device/CDriverRamdisk.h"
|
||||||
|
#include "Tier1/CPageFaultDispatcher.h"
|
||||||
using namespace cb;
|
using namespace cb;
|
||||||
|
|
||||||
CKernel g_Kernel;
|
CKernel g_Kernel;
|
||||||
|
@ -48,6 +49,9 @@ void CKernel::Start(void)
|
||||||
m_DriverManager->LoadNew();
|
m_DriverManager->LoadNew();
|
||||||
|
|
||||||
//PANIC("the programmer is an idiot");
|
//PANIC("the programmer is an idiot");
|
||||||
|
new CPageFaultDispatcher();
|
||||||
|
u32 *a = (u32*)0x51515151;
|
||||||
|
*a = 1337;
|
||||||
|
|
||||||
for (;;) {}
|
for (;;) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#include "Tier1/CPageFaultDispatcher.h"
|
||||||
|
using namespace cb;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "Tier0/panic.h"
|
||||||
|
};
|
||||||
|
|
||||||
|
CPageFaultDispatcher::CPageFaultDispatcher(void)
|
||||||
|
{
|
||||||
|
m_Interrupt = 0x0E;
|
||||||
|
Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPageFaultDispatcher::Dispatch(void *Registers)
|
||||||
|
{
|
||||||
|
PANIC("PAGE FAULT LAWL");
|
||||||
|
}
|
Loading…
Reference in New Issue