# HG changeset patch # User windel # Date 1326224435 -3600 # Node ID 88590c42320ffb141c6ea1c6004ad9154ed48e54 # Parent 0148f55bfe24e817698e2d0fbecd111de0186afb Changed interrupt handler diff -r 0148f55bfe24 -r 88590c42320f cos/kernel/asmcode.asm --- a/cos/kernel/asmcode.asm Thu Dec 29 23:51:35 2011 +0100 +++ b/cos/kernel/asmcode.asm Tue Jan 10 20:40:35 2012 +0100 @@ -18,7 +18,27 @@ lidt [idtP] ret -%macro pushAll 0 +; ISR related assembler wrappers: + +%macro ISR_NOERRCODE 1 +global INT%1 +INT%1: + cli + push strict qword 0 ; push dummy error code + push strict qword %1 ; push interrupt number + jmp isr_common_stub +%endmacro + +%macro ISR_ERRCODE 1 +global INT%1 +INT%1: + cli + push strict qword %1 ; push interrupt number + jmp isr_common_stub +%endmacro + +isr_common_stub: + ; Do some saving: push rax push rcx push rdx @@ -26,9 +46,13 @@ push rbp push rsi push rdi -%endmacro + + ; AMD64 calling convention, first parameter is in rdi: + mov rdi, rsp ; Load stack pointer into rdi to indicate where the registers on the stack are (so that we can change them!) -%macro popAll 0 + extern isr_handler + call isr_handler + pop rdi pop rsi pop rbp @@ -36,51 +60,38 @@ pop rdx pop rcx pop rax -%endmacro -; Define macro with two arguments: -%macro INTX 2 -global %1 -%1: - ; Do some saving: - cli - pushAll - ;xchg bx,bx - - extern %2 - call %2 - ; Do restoration - popAll - ;xchg bx, bx - sti - iretq - -%endmacro + add rsp, 16 ; cleanup error code and isr number + sti + iretq ; Exception handlers: -INTX INTDEF, INTDEF_handler -INTX INT0, INT0handler -INTX INT1, INT1handler -INTX INT2, INT2handler -INTX INT3, INT3handler -INTX INT4, INT4handler -INTX INT5, INT5handler -INTX INT6, INT6handler -INTX INT7, INT7handler -INTX INT8, INT8handler -INTX INT9, INT9handler -INTX INT10, INT10handler -INTX INT11, INT11handler -INTX INT12, INT12handler -INTX INT13, INT13handler -INTX INT14, INT14handler -INTX INT15, INT15handler -INTX INT16, INT16handler -INTX INT17, INT17handler -INTX INT18, INT18handler -INTX INT19, INT19handler +ISR_NOERRCODE 0 +ISR_NOERRCODE 1 +ISR_NOERRCODE 2 +ISR_NOERRCODE 3 +ISR_NOERRCODE 4 +ISR_NOERRCODE 5 +ISR_NOERRCODE 6 +ISR_NOERRCODE 7 +ISR_ERRCODE 8 +ISR_NOERRCODE 9 +ISR_ERRCODE 10 +ISR_ERRCODE 11 +ISR_ERRCODE 12 +ISR_ERRCODE 13 +ISR_ERRCODE 14 +; 15 is reserved +ISR_NOERRCODE 16 +ISR_ERRCODE 17 +ISR_NOERRCODE 18 +ISR_NOERRCODE 19 -INTX INT32, INT32handler -INTX INT33, INT33handler -INTX INT34, INT34handler +ISR_NOERRCODE 32 +ISR_NOERRCODE 33 +ISR_NOERRCODE 34 +; default handler: +ISR_NOERRCODE 255 + + diff -r 0148f55bfe24 -r 88590c42320f cos/kernel/handlers.c --- a/cos/kernel/handlers.c Thu Dec 29 23:51:35 2011 +0100 +++ b/cos/kernel/handlers.c Tue Jan 10 20:40:35 2012 +0100 @@ -1,7 +1,7 @@ #include "kernel.h" // Assembler wrapper prototypes: -void INTDEF(void); +void INT255(void); void INT0(void); void INT1(void); void INT2(void); @@ -17,7 +17,6 @@ void INT12(void); void INT13(void); void INT14(void); -void INT15(void); void INT16(void); void INT17(void); void INT18(void); @@ -39,8 +38,6 @@ // Typecast the function pointer to a number: offset = (uint64_t)handler; - //panic("Almost setting an IDT entry"); - // Set offset: idt[num].baseLow = offset & 0xFFFF; idt[num].baseMid = (offset >> 16) & 0xFFFF; @@ -60,7 +57,7 @@ // Fill all vectors with the default handler: for (i=0; i<256; i++) { - setIDTentry(i, INTDEF, 0x08, 0x8E); + setIDTentry(i, INT255, 0x08, 0x8E); } // Now set other then default handler: @@ -79,7 +76,7 @@ setIDTentry(12, INT12, 0x08, 0x8E); setIDTentry(13, INT13, 0x08, 0x8E); setIDTentry(14, INT14, 0x08, 0x8E); - setIDTentry(15, INT15, 0x08, 0x8E); + //setIDTentry(15, INT15, 0x08, 0x8E); setIDTentry(16, INT16, 0x08, 0x8E); setIDTentry(17, INT17, 0x08, 0x8E); setIDTentry(18, INT18, 0x08, 0x8E); @@ -126,104 +123,32 @@ outb(0xA1, maskslave); } -// Interrupt service routines: +// Global isr handler: -void INT0handler() -{ - printf("INT0 called!\n"); - panic("Unhandled exception!"); -} - -void INT1handler() +// Hopefully, this function get called with the correct registers. +void isr_handler(uint64_t* registers) { - printf("INT1 called!\n"); - panic("Unhandled exception!"); -} -void INT2handler() -{ - printf("INT2 called!\n"); - panic("Unhandled exception!"); -} + uint64_t intnum = registers[7]; -void INT3handler() -{ - printf("INT3 called!\n"); - panic("Unhandled exception!"); -} + if (intnum == 32) + { + timerDriverUpdate(); + } + else if (intnum == 33) + { + unsigned char scancode = inb(0x60); + keyboardDriverUpdate(scancode); + } + else + { + printf("Interrupt %d called, registers at: %x\n", registers[7], registers); + } -void INT4handler() -{ - printf("INT4 called!\n"); - panic("Unhandled exception!"); -} - -void INT5handler() -{ - printf("INT5 called!\n"); - panic("Unhandled exception!"); -} - -void INT6handler() -{ - printf("INT6 called!\n"); - panic("Unhandled exception!"); + outb(0x20, 0x20); // EOI to master } -void INT7handler() -{ - printf("INT7 called!\n"); - panic("Unhandled exception!"); -} - -void INT8handler() -{ - printf("INT8 called!\n"); - panic("Unhandled exception!"); -} - -void INT9handler() -{ - printf("INT9 called!\n"); - panic("Unhandled exception!"); -} - -void INT10handler() -{ - printf("INT10 called!\n"); - panic("Unhandled exception!"); -} - -void INT11handler() -{ - printf("INT11 called!\n"); - panic("Unhandled exception!"); -} - -void INT12handler() -{ - printf("INT12 called!\n"); - panic("Unhandled exception!"); -} - -void INT13handler() -{ - printf("INT13 called!\n"); - panic("Unhandled exception!"); -} - -void* getUnusedPage() -{ - return 0; -} - -void mappage(uint64_t address) { - uint32_t pageDirIndex = address >> 22; - uint32_t pageTableIndex = (address >> 12) & 0x3FF; - - printf("Allocating page at %d, tableindex=%d\n", pageDirIndex, pageTableIndex); - //uint32_t *pageTable = (uint32_t*)(pageDirectory[pageDirIndex] & 0xFFFFFC00); -} +// Interrupt service routines: void INT14handler() { @@ -235,10 +160,6 @@ asm volatile("mov %%cr2, %0" : "=r" (faulting_address)); printf("INT14 called! Page fault for address 0x%X!\n", faulting_address); - if ( (faulting_address & 0xF0000000) == 0xD0000000 ) { - mappage(faulting_address & 0xFFFFF000); - return; - } panic("Unhandled exception!"); } @@ -249,30 +170,6 @@ panic("Unhandled exception!"); } -void INT16handler() -{ - printf("INT16 called!\n"); - panic("Unhandled exception!"); -} - -void INT17handler() -{ - printf("INT17 called!\n"); - panic("Unhandled exception!"); -} - -void INT18handler() -{ - printf("INT18 called!\n"); - panic("Unhandled exception!"); -} - -void INT19handler() -{ - printf("INT19 called!\n"); - panic("Unhandled exception!"); -} - // remapped IRQ from master PIC: void INT32handler() { @@ -293,11 +190,6 @@ outb(0x20, 0x20); // EOI to master } -void INT34handler() -{ - printf("INT34 called!\n"); -} - void INTDEF_handler() { panic("Default int handler called\n"); diff -r 0148f55bfe24 -r 88590c42320f cos/kernel/kernel.c --- a/cos/kernel/kernel.c Thu Dec 29 23:51:35 2011 +0100 +++ b/cos/kernel/kernel.c Tue Jan 10 20:40:35 2012 +0100 @@ -1,3 +1,4 @@ + #include "kernel.h" static void testMalloc() @@ -14,9 +15,6 @@ kfree(a); } -// A test program that prints 'Hoi' to the screen: -unsigned char hello_program[] = {0x55, 0x48, 0x89, 0xe5, 0x48, 0x83, 0xec, 0x10, 0x48, 0xc7, 0x45, 0xf8, 0x0, 0x80, 0xb, 0x0, 0x48, 0x8b, 0x45, 0xf8, 0xc6, 0x0, 0x48, 0x48, 0x8b, 0x45, 0xf8, 0x48, 0x83, 0xc0, 0x2, 0xc6, 0x0, 0x6f, 0x48, 0x8b, 0x45, 0xf8, 0x48, 0x83, 0xc0, 0x4, 0xc6, 0x0, 0x69, 0xeb, 0xfe, 0x0, 0x14, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x7a, 0x52, 0x0, 0x1, 0x78, 0x10, 0x1, 0x1b, 0xc, 0x7, 0x8, 0x90, 0x1, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0xb0, 0xff, 0xff, 0xff, 0x2f, 0x0, 0x0, 0x0, 0x0, 0x41, 0xe, 0x10, 0x86, 0x2, 0x43, 0xd, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; - /* This routine initializes the kernel. * We are left here in 64-bit long mode with the first 6 MB identity mapped. * */ @@ -30,8 +28,6 @@ // TODO: get size from grub init_memory(0x1000000); - //new_task(hello_program); - // TODO: make below a user space program! printf("Welcome!\n");