summaryrefslogtreecommitdiff
path: root/kernel
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
parentae33cc6557790a502a01b380b0926944ca2f3cfa (diff)
claning up interrupts
Diffstat (limited to 'kernel')
-rw-r--r--kernel/apic.c8
-rw-r--r--kernel/interrupts.c93
-rw-r--r--kernel/interrupts.h39
-rw-r--r--kernel/kernel.c2
-rw-r--r--kernel/smashing.c22
-rw-r--r--kernel/smashing.h1
6 files changed, 88 insertions, 77 deletions
diff --git a/kernel/apic.c b/kernel/apic.c
index f78a03a..4bc2bb3 100644
--- a/kernel/apic.c
+++ b/kernel/apic.c
@@ -156,10 +156,10 @@ void ioapic_config()
// ioapic_config_entry(2,0x90|0xa000,0x3<<24); // level trigger on low
// CPU
- ioapic_config_entry(2, 0x90, 0x0<<24); // pit
- ioapic_config_entry(1, 0x91, 0x0<<24); // kb
- ioapic_config_entry(12, 0x92, 0x0<<24); // mouse
- ioapic_config_entry(11, 0x93|0x8000, 0x0<<24); // e1000 (level trigger on high)
+ ioapic_config_entry(2, INTERRUPT_PIT_TIMER, 0x0<<24); // pit
+ ioapic_config_entry(1, INTERRUPT_KEYBOARD, 0x0<<24); // kb
+ ioapic_config_entry(12, INTERRUPT_MOUSE, 0x0<<24); // mouse
+ ioapic_config_entry(11, INTERRUPT_E1000|0x8000, 0x0<<24); // e1000 (level trigger on high)
}
/** startup other cpus*/
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 */
diff --git a/kernel/interrupts.h b/kernel/interrupts.h
index 344369d..b3b8a93 100644
--- a/kernel/interrupts.h
+++ b/kernel/interrupts.h
@@ -11,51 +11,44 @@
*
* Exceptions
* ----------
- * * 0x00-0x12 Exceptions
+ * * 0x00-0x20 Exceptions
*
* Legacy PIC
* ----------
* * 0x20-0x27 disabled pic
* * 0x28-0x36 disabled pic
*
- * Hardware Interrupts
+ * Software Interrupts / Ring 3
* -------------------
- * This interrupts are remapped by the IOAPIC
- *
- * * 0x0 PIT Timer -> 0x90
- * * 0x1 Keyboard -> 0x91
- * * 0xC Mouse -> 0x92
+ * * 0x80 System Call
*
- * Local Interrupts from LAPICs
- * ----------------------
- * * 0x8C APIC Timer
- *
- * Software Interrupts
+ * Hardware Interrupts / Ring 1
* -------------------
- * * 0x80 System Call
- * * 0x81 IPI
+ * * 0x81-0xA0
*
* Usage
* -----
*
- * Run interrupts_init() once first with the desired selector, usually 0x08.
- * After that you can install the interrupts on each cpu via interrupts_install.
+ * Run interrupts_init() ONCE first.
+ * After that you can install the interruptAs on each cpu via interrupts_install();
* interrupt_handler() and exception_handler() will be called accordingly from
* the interrupt handlers this functionality is backed by. You can find them
- * in asm_int.h
+ * in asm_int.h. The selector 0x08 is used.
*/
+#define INTERRUPT_SYSCALL 0x80 // can be called from user code / ring 3
+
+#define INTERRUPT_IPI 0x81 // ipi1 more might folllow
+
#define INTERRUPT_PIT_TIMER 0x90
#define INTERRUPT_KEYBOARD 0x91
#define INTERRUPT_MOUSE 0x92
#define INTERRUPT_E1000 0x93
+#define INTERRUPT_APIC_TIMER 0x94
-#define INTERRUPT_APIC_TIMER 0x8C
-#define INTERRUPT_SYSCALL 0x80
-#define INTERRUPT_IPI 0x81 // ipi1 more might folllow
-void interrupts_init(uint16_t sel);
-void interrupts_install();
-uint32_t interrupt_handler(uint32_t esp, uint32_t irq);
+void interrupts_init();
+void interrupts_install();
+void interrupt_handler_register(uint32_t irq, uint32_t func_addr);
#endif
diff --git a/kernel/kernel.c b/kernel/kernel.c
index c244b9a..e4d7eba 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -65,7 +65,7 @@ void kernel_main(uint32_t eax,uint32_t ebx)
// -- GET CONFIGS -- //
klog("Read Multiboot Structures ...");
multiboot_information *cfg_multiboot;
- cfg_multiboot=multiboot_read(eax, ebx,false); // true-silent
+ cfg_multiboot=multiboot_read(eax, ebx,true); // true-silent
// elf_multiboot_read(cfg_multiboot); // just show kernel section headers
klog("Read Advanced Power Configuration Interface (ACPI) Structures ...");
diff --git a/kernel/smashing.c b/kernel/smashing.c
deleted file mode 100644
index d4365b9..0000000
--- a/kernel/smashing.c
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "kernel/kernel.h"
-#include "log.h"
-#include <stdint.h>
-
-// CODE FOR Stack Smashing Protector.
-// Do not duplicate with userspace / sys.c
-// http://wiki.osdev.org/Stack_Smashing_Protector
-
-#if UINT32_MAX == UINTPTR_MAX
-#define STACK_CHK_GUARD 0xe2dee396
-#else
-#define STACK_CHK_GUARD 0x595e9fbd94fda766
-#endif
-
-uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
-
-__attribute__((noreturn))
-void __stack_chk_fail(void)
-{
- kpanic("Stack smashing detected");
-}
-//
diff --git a/kernel/smashing.h b/kernel/smashing.h
deleted file mode 100644
index 760b7c9..0000000
--- a/kernel/smashing.h
+++ /dev/null
@@ -1 +0,0 @@
-/*empty*/