From 915791f6acedbb35db73216156c1baa790e384d9 Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 26 Sep 2018 11:12:18 +0200 Subject: claning up interrupts --- kernel/apic.c | 8 ++--- kernel/interrupts.c | 93 ++++++++++++++++++++++++++++++++++++++--------------- kernel/interrupts.h | 39 +++++++++------------- kernel/kernel.c | 2 +- kernel/smashing.c | 22 ------------- kernel/smashing.h | 1 - 6 files changed, 88 insertions(+), 77 deletions(-) delete mode 100644 kernel/smashing.c delete mode 100644 kernel/smashing.h (limited to 'kernel') 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 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 - -// 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*/ -- cgit v1.2.3