idt.c
#include "idt.h"
#include "main.h"
#include "text.h"
extern void isr_0(void);
extern void isr_1(void);
extern void isr_2(void);
extern void isr_3(void);
extern void isr_4(void);
extern void isr_5(void);
extern void isr_6(void);
extern void isr_7(void);
extern void isr_8(void);
extern void isr_9(void);
extern void isr_10(void);
extern void isr_11(void);
extern void isr_12(void);
extern void isr_13(void);
extern void isr_14(void);
extern void isr_15(void);
extern void isr_16(void);
extern void isr_17(void);
extern void isr_18(void);
extern void isr_19(void);
//IRQs
extern void isr_32(void);
interrupt IDT[256];
void SetupIDT()
{
//Exceptions
AddInterrupt(0 ,isr_0 , 0);
AddInterrupt(1 ,isr_1 , 0);
AddInterrupt(2 ,isr_2 , 0);
AddInterrupt(3 ,isr_3 , 0);
AddInterrupt(4 ,isr_4 , 0);
AddInterrupt(5 ,isr_5 , 0);
AddInterrupt(6 ,isr_6 , 0);
AddInterrupt(7 ,isr_7 , 0);
AddInterrupt(8 ,isr_8 , 0);
AddInterrupt(9 ,isr_9 , 0);
AddInterrupt(10,isr_10, 0);
AddInterrupt(11,isr_11, 0);
AddInterrupt(12,isr_12, 0);
AddInterrupt(13,isr_13, 0);
AddInterrupt(14,isr_14, 0);
AddInterrupt(15,isr_15, 0);
AddInterrupt(16,isr_16, 0);
AddInterrupt(17,isr_17, 0);
AddInterrupt(18,isr_18, 0);
AddInterrupt(19,isr_19, 0);
//IRQs
AddInterrupt(32,isr_32, 0);
LoadIDT();
}
void LoadIDT()
{
idtr IDTR[1];
IDTR[0].limit = (256*sizeof(interrupt))-1;
IDTR[0].base = IDT;
//idtp = IDTR;
//loadIDT();
asm volatile ("LIDT (%0) ": :"r" ((char *)idtr));
}
void AddInterrupt(unsigned int _number, void (*_handler)(), unsigned int _ATT)
{
unsigned short int attributes=0;
unsigned long offset = (unsigned long)_handler;
unsigned short selector = 0x08;
switch(_ATT)
{
case 0: attributes = 0x8E00; break;
case 1: attributes = 0xAE00; break;
case 2: attributes = 0xCE00; break;
default: attributes = 0xEE00; break;
}
asm volatile ("movw %%cs, %0 " : "=g" (selector));
IDT[_number].l_offset = (offset & 0xFFFF);
IDT[_number].h_offset = (offset >> 16);
IDT[_number].segment = selector;
IDT[_number].attributes = attributes;
}
void interrupt_0() { print "Excption 0", 0x07, 10, 0); }
void interrupt_1() { print "Excption 1", 0x07, 10, 0);}
void interrupt_2() { print "Excption 2", 0x07, 10, 0);}
void interrupt_3() { print "Excption 3", 0x07, 10, 0);}
void interrupt_4() { print "Excption 4", 0x07, 10, 0);}
void interrupt_5() { print "Excption 5", 0x07, 10, 0);}
void interrupt_6() { print "Excption 6", 0x07, 10, 0);}
void interrupt_7() { print "Excption 7", 0x07, 10, 0);}
void interrupt_8() { print "Excption 8", 0x07, 10, 0);}
void interrupt_9() { print "Excption 9", 0x07, 10, 0);}
void interrupt_10() { print "Excption 10", 0x07, 10, 0);}
void interrupt_11() { print "Excption 11", 0x07, 10, 0);}
void interrupt_12() { print "Excption 12", 0x07, 10, 0);}
void interrupt_13() { print "Excption 13", 0x07, 10, 0);}
void interrupt_14() { print "Excption 14", 0x07, 10, 0);}
void interrupt_15() { print "Excption 15", 0x07, 10, 0);}
void interrupt_16() { print "Excption 16", 0x07, 10, 0);}
void interrupt_17() { print "Excption 17", 0x07, 10, 0);}
void interrupt_18() { print "Excption 18", 0x07, 10, 0);}
void interrupt_19() { print "Excption 19", 0x07, 10, 0);}
void IRQ0() { timer_handler(); }
idt.h
#ifndef IDT_H
#define IDT_H
typedef struct
{
unsigned short l_offset;
unsigned short segment;
unsigned short attributes;
unsigned short h_offset;
} interrupt;
typedef struct
{
unsigned short limit;
interrupt *base;
} idtr;
void SetupIDT();
void LoadIDT();
void AddInterrupt(unsigned int , void (*_handler)(), unsigned int);
/*Exceptions*/
void interrupt_0();
void interrupt_1();
void interrupt_2();
void interrupt_3();
void interrupt_4();
void interrupt_5();
void interrupt_6();
void interrupt_7();
void interrupt_8();
void interrupt_9();
void interrupt_10();
void interrupt_11();
void interrupt_12();
void interrupt_13();
void interrupt_14();
void interrupt_15();
void interrupt_16();
void interrupt_17();
void interrupt_18();
void interrupt_19();
void IRQ0();
#endif
pic.c (falls es am remappen von den pics liegen könnte)
#include "pic.h"
#include "ports.h"
void EnableIRQ(unsigned char mask1, unsigned charmask2)
{
out (0x21, mask1);
out (0xA1, mask2);
}
void SetupPIC()
{
//ICW1
out (0x20, 0x11);
out (0x21, 0x11);
//ICW2
out (0x21, 0x20);
out (0xA1, 0x28);
//ICW3
out (0x21, 0x04);
out (0xA1, 0x02);
//ICW4
out (0x21, 0x01);
out (0xA1, 0x01);
}
beim starten schaltet der kernel zuerst die interrupts aus, remappt die pics, schaltet die irqs aus, lädt die idt und schaltet die interrupts an.
dann sollten die interrupts wieder akiviert werden...