summaryrefslogtreecommitdiff
path: root/kernel/interrupts.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-09-26 11:12:18 +0200
committerMiguel <m.i@gmx.at>2018-09-26 11:12:18 +0200
commit915791f6acedbb35db73216156c1baa790e384d9 (patch)
tree203c1308309fac2a336686ca48f7fbd05013bdb1 /kernel/interrupts.c
parentae33cc6557790a502a01b380b0926944ca2f3cfa (diff)
claning up interrupts
Diffstat (limited to 'kernel/interrupts.c')
-rw-r--r--kernel/interrupts.c93
1 files changed, 67 insertions, 26 deletions
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index 4d3a2c4..b0a473a 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -1,3 +1,5 @@
+#include "interrupts.h"
+
#include "kernel.h"
#include "log.h"
#include "e1000.h"
@@ -5,7 +7,6 @@
#include "asm_pit.h"
#include "driver/mouse.h"
#include "driver/keyboard.h"
-#include "interrupts.h"
#include "scheduler.h"
#include "asm_x86.h"
#include "smp.h"
@@ -15,11 +16,15 @@
ringbuffer mouse_in;
ringbuffer kb_in;
+//
+
/** The size of our interrupts table */
#define INT_MAX 256 // 0-255
+static uint32_t handlers[INT_MAX]; // addresses of interrupt handlers.
+
/** The interrupt descriptor table */
-static struct int_desc
+struct int_desc
{
uint16_t addrLo;
uint16_t sel;
@@ -29,7 +34,7 @@ static struct int_desc
} idt[INT_MAX];
/** The interrupt descriptor table descriptor */
-static struct idt_desc
+struct idt_desc
{
uint16_t size;
uint16_t baseLo;
@@ -48,6 +53,13 @@ static void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr)
idt[irq].sel=sel;
}
+void interrupt_handler_register(uint32_t irq, uint32_t func_addr)
+{
+ if(irq<128||irq>160)kpanic("irq number out of range!");
+ if(handlers[irq]!=0)kpanic("handler already registered!");
+ handlers[irq]=func_addr;
+}
+
/*
* Interrupt dispatcher
*
@@ -109,19 +121,20 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq)
/**
* init interrupt descriptor table
*/
-void interrupts_init(uint16_t sel)
+void interrupts_init()
{
+ // TODO????
klog("Initializing Mouse and Kb input buffers");
fixme("use a regular pipe-file");
kb_in=ringbuffer_init(1);// 4096 bytes ringbuffer;
mouse_in=ringbuffer_init(1);// 4096 bytes ringbuffer;
-
klog("Initializing. IDT: 0x%08x, IDTD: 0x%08X",&idt,&idtd);
+ //
// Default interrupt handling
for(int i=0; i<INT_MAX; i++)
{
- int_install_ir(i, 0b10001110, sel,&int255);
+ int_install_ir(i, 0b10001110, 0x08,&int255);
}
// Exceptions
@@ -144,28 +157,56 @@ void interrupts_init(uint16_t sel)
int_install_ir(16, 0b10001110, 0x08,&exc16);
int_install_ir(17, 0b10001110, 0x08,&exc17);
int_install_ir(18, 0b10001110, 0x08,&exc18);
+ int_install_ir(19, 0b10001110, 0x08,&exc19);
+ int_install_ir(20, 0b10001110, 0x08,&exc20);
+ int_install_ir(21, 0b10001110, 0x08,&exc21);
+ int_install_ir(22, 0b10001110, 0x08,&exc22);
+ int_install_ir(23, 0b10001110, 0x08,&exc23);
+ int_install_ir(24, 0b10001110, 0x08,&exc24);
+ int_install_ir(25, 0b10001110, 0x08,&exc25);
+ int_install_ir(26, 0b10001110, 0x08,&exc26);
+ int_install_ir(27, 0b10001110, 0x08,&exc27);
+ int_install_ir(28, 0b10001110, 0x08,&exc28);
+ int_install_ir(29, 0b10001110, 0x08,&exc29);
+ int_install_ir(30, 0b10001110, 0x08,&exc30);
+ int_install_ir(31, 0b10001110, 0x08,&exc31);
- // PIT (IOAPIC)
- int_install_ir(0x90, 0b10001110, 0x08,&int144);
-
- // Keyboard (IOAPIC)
- int_install_ir(0x91, 0b10001110, 0x08,&int145);
-
- // Mouse (IOAPIC)
- int_install_ir(0x92, 0b10001110, 0x08,&int146);
-
- // E1000
- int_install_ir(0x93, 0b10001110, 0x08,&int147);
-
- // APIC Timer (LAPIC)
- int_install_ir(0x8C, 0b10001110, 0x08,&int140);
-
// System Calls (User Software / Ring 3)
- int_install_ir(0x80, 0b11101110, 0x08,&int128);
-
- // Inter Processesor Interrupts (Kernel Software)
- int_install_ir(0x81, 0b10001110, 0x08,&int129);
-
+ int_install_ir(128, 0b11101110, 0x08,&int128);
+
+ // Ring 1 only
+ int_install_ir(129, 0b10001110, 0x08,&int129);
+ int_install_ir(130, 0b10001110, 0x08,&int130);
+ int_install_ir(131, 0b10001110, 0x08,&int131);
+ int_install_ir(132, 0b10001110, 0x08,&int132);
+ int_install_ir(133, 0b10001110, 0x08,&int133);
+ int_install_ir(134, 0b10001110, 0x08,&int134);
+ int_install_ir(135, 0b10001110, 0x08,&int135);
+ int_install_ir(136, 0b10001110, 0x08,&int136);
+ int_install_ir(137, 0b10001110, 0x08,&int137);
+ int_install_ir(138, 0b10001110, 0x08,&int138);
+ int_install_ir(139, 0b10001110, 0x08,&int139);
+ int_install_ir(140, 0b10001110, 0x08,&int140);
+ int_install_ir(141, 0b10001110, 0x08,&int141);
+ int_install_ir(142, 0b10001110, 0x08,&int142);
+ int_install_ir(143, 0b10001110, 0x08,&int143);
+ int_install_ir(144, 0b10001110, 0x08,&int144);
+ int_install_ir(145, 0b10001110, 0x08,&int145);
+ int_install_ir(146, 0b10001110, 0x08,&int146);
+ int_install_ir(147, 0b10001110, 0x08,&int147);
+ int_install_ir(148, 0b10001110, 0x08,&int148);
+ int_install_ir(149, 0b10001110, 0x08,&int149);
+ int_install_ir(150, 0b10001110, 0x08,&int150);
+ int_install_ir(151, 0b10001110, 0x08,&int151);
+ int_install_ir(152, 0b10001110, 0x08,&int152);
+ int_install_ir(153, 0b10001110, 0x08,&int153);
+ int_install_ir(154, 0b10001110, 0x08,&int154);
+ int_install_ir(155, 0b10001110, 0x08,&int155);
+ int_install_ir(156, 0b10001110, 0x08,&int156);
+ int_install_ir(157, 0b10001110, 0x08,&int157);
+ int_install_ir(158, 0b10001110, 0x08,&int158);
+ int_install_ir(159, 0b10001110, 0x08,&int159);
+ int_install_ir(160, 0b10001110, 0x08,&int160);
}
/** Installs the interrupt table */