diff options
| author | Miguel <m.i@gmx.at> | 2018-09-26 11:12:18 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-26 11:12:18 +0200 |
| commit | 915791f6acedbb35db73216156c1baa790e384d9 (patch) | |
| tree | 203c1308309fac2a336686ca48f7fbd05013bdb1 | |
| parent | ae33cc6557790a502a01b380b0926944ca2f3cfa (diff) | |
claning up interrupts
| -rw-r--r-- | asm/asm_int.h | 84 | ||||
| -rw-r--r-- | asm/asm_int.s | 172 | ||||
| -rw-r--r-- | grubiso/boot/grub/grub.cfg | 2 | ||||
| -rw-r--r-- | kernel/apic.c | 8 | ||||
| -rw-r--r-- | kernel/interrupts.c | 93 | ||||
| -rw-r--r-- | kernel/interrupts.h | 39 | ||||
| -rw-r--r-- | kernel/kernel.c | 2 | ||||
| -rw-r--r-- | xxx/smashing.c (renamed from kernel/smashing.c) | 0 | ||||
| -rw-r--r-- | xxx/smashing.h (renamed from kernel/smashing.h) | 0 |
9 files changed, 251 insertions, 149 deletions
diff --git a/asm/asm_int.h b/asm/asm_int.h index d28a321..78326c8 100644 --- a/asm/asm_int.h +++ b/asm/asm_int.h @@ -2,38 +2,10 @@ * @file * * interrrupt handlers: - * * excX() call handle_exception - * * excX() call hadnle_interrupt + * * exc0() - exc31() call handle_exception() + * * int128() - int160() call hadnle_interrupt() */ -void int0(); -void int1(); -void int2(); -void int3(); -void int4(); -void int5(); -void int6(); -void int7(); -void int8(); -void int9(); -void int10(); -void int11(); -void int12(); -void int13(); -void int14(); -void int15(); - -void int128(); // syscalls -void int129(); // scheduler -void int140(); // scheduler -void int144(); // scheduler -void int145(); // scheduler -void int146(); // scheduler -void int147(); // scheduler -void int200(); // apic timer -void int170(); // smp scheduler -void int255(); // unhandled - void exc0(); void exc1(); void exc2(); @@ -53,3 +25,55 @@ void exc15(); void exc16(); void exc17(); void exc18(); +void exc19(); +void exc20(); +void exc21(); +void exc22(); +void exc23(); +void exc24(); +void exc25(); +void exc26(); +void exc27(); +void exc28(); +void exc29(); +void exc30(); +void exc31(); + +// + +void int128(); +void int129(); +void int130(); +void int131(); +void int132(); +void int133(); +void int134(); +void int135(); +void int136(); +void int137(); +void int138(); +void int139(); +void int140(); +void int141(); +void int142(); +void int143(); +void int144(); +void int145(); +void int146(); +void int147(); +void int148(); +void int149(); +void int150(); +void int151(); +void int152(); +void int153(); +void int154(); +void int155(); +void int156(); +void int157(); +void int158(); +void int159(); +void int160(); + +// +void int255(); diff --git a/asm/asm_int.s b/asm/asm_int.s index 9ea0d4b..8a95482 100644 --- a/asm/asm_int.s +++ b/asm/asm_int.s @@ -1,32 +1,4 @@ -.global int0 -.global int1 -.global int2 -.global int3 -.global int4 -.global int5 -.global int6 -.global int7 - -.global int8 -.global int9 -.global int10 -.global int11 -.global int12 -.global int13 -.global int14 -.global int15 - -.global int128 -.global int129 -.global int200 -.global int140 -.global int144 -.global int145 -.global int146 -.global int147 -.global int170 -.global int255 - +// .global exc0 .global exc1 .global exc2 @@ -46,12 +18,61 @@ .global exc16 .global exc17 .global exc18 +.global exc19 +.global exc20 +.global exc21 +.global exc22 +.global exc23 +.global exc24 +.global exc25 +.global exc26 +.global exc27 +.global exc28 +.global exc29 +.global exc30 +.global exc31 + +.global int128 +.global int129 +.global int130 +.global int131 +.global int132 +.global int133 +.global int134 +.global int135 +.global int136 +.global int137 +.global int138 +.global int139 +.global int140 +.global int141 +.global int142 +.global int143 +.global int144 +.global int145 +.global int146 +.global int147 +.global int148 +.global int149 +.global int150 +.global int151 +.global int152 +.global int153 +.global int154 +.global int155 +.global int156 +.global int157 +.global int158 +.global int159 +.global int160 -// nothing to ack +.global int255 + +// nothing to ack / macro .macro ack0 .endm -// ack master +// ack master pic / macro .macro ack1 push %eax // persist mov $0x20,%al @@ -59,7 +80,7 @@ pop %eax // load original .endm -// ack master and servant +// ack master and servant pic / macro .macro ack2 push %eax // persist mov $0x20,%al @@ -68,13 +89,16 @@ pop %eax // load original .endm +// no error / macro .macro err0 .endm +// exception with error / macro .macro err1 add $4,%esp .endm +// interrupt / macro .macro intx ack num func /* @@ -139,8 +163,10 @@ .endm +// cpu exception / macro .macro excx num err func - cli // exception does not prevent from rescheduling? + + cli // exception does not prevent from rescheduling, it seems? mov %esp,%eax // remember THIS stack position and $-16,%esp // padding to align stack on 16byte boundary before CALL sub $8,%esp // ... @@ -172,16 +198,16 @@ .endm -exc0: excx $0 err0 exception_handle -exc1: excx $1 err0 exception_handle -exc2: excx $2 err0 exception_handle -exc3: excx $3 err0 exception_handle -exc4: excx $4 err0 exception_handle -exc5: excx $5 err0 exception_handle -exc6: excx $6 err0 exception_handle -exc7: excx $7 err0 exception_handle -exc8: excx $8 err1 exception_handle -exc9: excx $9 err0 exception_handle +exc0: excx $0 err0 exception_handle +exc1: excx $1 err0 exception_handle +exc2: excx $2 err0 exception_handle +exc3: excx $3 err0 exception_handle +exc4: excx $4 err0 exception_handle +exc5: excx $5 err0 exception_handle +exc6: excx $6 err0 exception_handle +exc7: excx $7 err0 exception_handle +exc8: excx $8 err1 exception_handle +exc9: excx $9 err0 exception_handle exc10: excx $10 err1 exception_handle exc11: excx $11 err1 exception_handle exc12: excx $12 err1 exception_handle @@ -191,34 +217,52 @@ exc15: excx $15 err0 exception_handle exc16: excx $16 err0 exception_handle exc17: excx $17 err1 exception_handle exc18: excx $18 err0 exception_handle - -int0: intx ack0 $0 interrupt_handler -int1: intx ack0 $1 interrupt_handler -int2: intx ack0 $2 interrupt_handler -int3: intx ack0 $3 interrupt_handler -int4: intx ack0 $4 interrupt_handler -int5: intx ack0 $5 interrupt_handler -int6: intx ack0 $6 interrupt_handler -int7: intx ack0 $7 interrupt_handler -int8: intx ack0 $8 interrupt_handler -int9: intx ack0 $9 interrupt_handler -int10: intx ack0 $10 interrupt_handler -int11: intx ack0 $11 interrupt_handler -int12: intx ack0 $12 interrupt_handler -int13: intx ack0 $13 interrupt_handler -int14: intx ack0 $14 interrupt_handler -int15: intx ack0 $15 interrupt_handler +exc19: excx $19 err0 exception_handle +exc20: excx $20 err0 exception_handle +exc21: excx $21 err0 exception_handle +exc22: excx $22 err0 exception_handle +exc23: excx $23 err0 exception_handle +exc24: excx $24 err0 exception_handle +exc25: excx $25 err0 exception_handle +exc26: excx $26 err0 exception_handle +exc27: excx $27 err0 exception_handle +exc28: excx $28 err0 exception_handle +exc29: excx $29 err0 exception_handle +exc30: excx $30 err1 exception_handle +exc31: excx $31 err0 exception_handle int128: intx ack0 $128 interrupt_handler int129: intx ack0 $129 interrupt_handler - +int130: intx ack0 $130 interrupt_handler +int131: intx ack0 $131 interrupt_handler +int132: intx ack0 $132 interrupt_handler +int133: intx ack0 $133 interrupt_handler +int134: intx ack0 $134 interrupt_handler +int135: intx ack0 $135 interrupt_handler +int136: intx ack0 $136 interrupt_handler +int137: intx ack0 $137 interrupt_handler +int138: intx ack0 $138 interrupt_handler +int139: intx ack0 $139 interrupt_handler int140: intx ack0 $140 interrupt_handler +int141: intx ack0 $141 interrupt_handler +int142: intx ack0 $142 interrupt_handler +int143: intx ack0 $143 interrupt_handler int144: intx ack0 $144 interrupt_handler int145: intx ack0 $145 interrupt_handler int146: intx ack0 $146 interrupt_handler int147: intx ack0 $147 interrupt_handler +int148: intx ack0 $148 interrupt_handler +int149: intx ack0 $149 interrupt_handler +int150: intx ack0 $150 interrupt_handler +int151: intx ack0 $151 interrupt_handler +int152: intx ack0 $152 interrupt_handler +int153: intx ack0 $153 interrupt_handler +int154: intx ack0 $154 interrupt_handler +int155: intx ack0 $155 interrupt_handler +int156: intx ack0 $156 interrupt_handler +int157: intx ack0 $157 interrupt_handler +int158: intx ack0 $158 interrupt_handler +int159: intx ack0 $159 interrupt_handler +int160: intx ack0 $160 interrupt_handler int255: intx ack0 $255 interrupt_handler -int200: intx ack0 $200 interrupt_handler -int170: intx ack0 $170 interrupt_handler - diff --git a/grubiso/boot/grub/grub.cfg b/grubiso/boot/grub/grub.cfg index b9fa2ac..692138a 100644 --- a/grubiso/boot/grub/grub.cfg +++ b/grubiso/boot/grub/grub.cfg @@ -1,4 +1,4 @@ -set timeout=1 //seconds +set timeout=0 //seconds if loadfont ${prefix}/fonts/unicode.pf2 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/xxx/smashing.c index d4365b9..d4365b9 100644 --- a/kernel/smashing.c +++ b/xxx/smashing.c diff --git a/kernel/smashing.h b/xxx/smashing.h index 760b7c9..760b7c9 100644 --- a/kernel/smashing.h +++ b/xxx/smashing.h |
