summaryrefslogtreecommitdiff
path: root/kernel/interrupts.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/interrupts.c')
-rw-r--r--kernel/interrupts.c88
1 files changed, 42 insertions, 46 deletions
diff --git a/kernel/interrupts.c b/kernel/interrupts.c
index 150a784..9c485cc 100644
--- a/kernel/interrupts.c
+++ b/kernel/interrupts.c
@@ -9,6 +9,10 @@
#include "asm_x86.h"
#include "smp.h"
#include "apic.h"
+#include "ringbuffer.h"
+
+ringbuffer mouse_in;
+ringbuffer kb_in;
/** The size of our interrupts table */
#define INT_MAX 256 // 0-255
@@ -51,57 +55,45 @@ static void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr)
*/
uint32_t interrupt_handler(uint32_t esp, uint32_t irq)
{
- // pit timer at 1/25 sec.
- if(irq==INTERRUPT_PIT_TIMER)asm_pit_tick();
+ uint32_t *stack;
- // kb
- if(irq==INTERRUPT_KEYBOARD)
+ // process irq
+ switch(irq)
{
- uint32_t in=x86_inb(0x60);
+ case INTERRUPT_PIT_TIMER:
+ asm_pit_tick();
+ break;
+
+ case INTERRUPT_KEYBOARD:
+ ringbuffer_put(&kb_in,x86_inb(0x60));
+ break;
+
+ case INTERRUPT_MOUSE:
+ ringbuffer_put(&mouse_in,x86_inb(0x60));
+ break;
+
+ case INTERRUPT_SYSCALL:
+ stack=esp;
+ task_syscall(stack[11],stack[8],stack[10],stack[9]); //eax,ebx,ecx,edx
+ break;
+
+ case INTERRUPT_APIC_TIMER:
+ case INTERRUPT_IPI:
+ esp=scheduler_run(esp);
+ break;
+
+ case 255: // default or spurious
+ kpanic("Spurious/Unknown Interrupt!?");
+ break;
}
- // mouse
- if(irq==INTERRUPT_MOUSE)
- {
- uint32_t in=x86_inb(0x60);
-
- /*
- if(irq==INTERRUPT_KEYBOARD){
- keyboard_handle(in); // do this in separate thread via syscalls?
- task_wake_all();
- }
- */
- // TODO: mouse
-
- // test ipi
- //apic_ipi(2,0x81); // force cpu16 to autoschedule? just test
- //klog("0x60 in %d",in);
- }
+ // reschedule to kernel worker on these
+ if(irq==INTERRUPT_SYSCALL||irq==INTERRUPT_KEYBOARD||irq==INTERRUPT_MOUSE)
+ esp=scheduler_wake_worker(esp);
- // 0x80 - a syscall is coming in
- if(irq==INTERRUPT_SYSCALL)
- {
- uint32_t *stack=esp;
- uint32_t eax=stack[11];
- uint32_t ebx=stack[8];
- uint32_t ecx=stack[10];
- uint32_t edx=stack[9];
-
- task_syscall(eax,ebx,ecx,edx);
- esp=scheduler_run(esp,2);
- }
-
- // schedules on APIC timer 0x8C and IPI 0x81
- if(irq==INTERRUPT_APIC_TIMER || irq==INTERRUPT_IPI)
- {
- esp=scheduler_run(esp,-1);
- }
-
- // ack all except software syscalls
- if(irq!=INTERRUPT_SYSCALL)apic_eoi();
-
- // default and spurious
- if(irq==255)kpanic("Spurious/Unknown Interrupt!?");
+ // ack all to LAPIC, except software syscalls
+ if(irq!=INTERRUPT_SYSCALL)
+ apic_eoi();
return esp;
}
@@ -111,6 +103,10 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq)
*/
void interrupts_init(uint16_t sel)
{
+ klog("initializing Mouse and Kb input buffers");
+ 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