# HG changeset patch # User windel # Date 1326631189 -3600 # Node ID d8185ddb6c7b5896a8726942d1874fec204046f5 # Parent 3a6a9b929db0e0280b05ae75ffe9af3bb8c35652 Added more interrupt handlers diff -r 3a6a9b929db0 -r d8185ddb6c7b cos/README --- a/cos/README Fri Jan 13 18:18:17 2012 +0100 +++ b/cos/README Sun Jan 15 13:39:49 2012 +0100 @@ -15,6 +15,7 @@ - nasm: for assembler instructions - gcc: for compiling the C sources - make: for building the system +- python: for building the initial ramdisk Enjoy! diff -r 3a6a9b929db0 -r d8185ddb6c7b cos/kernel/Makefile --- a/cos/kernel/Makefile Fri Jan 13 18:18:17 2012 +0100 +++ b/cos/kernel/Makefile Sun Jan 15 13:39:49 2012 +0100 @@ -11,7 +11,7 @@ klib.o malloc.o task.o mm.o timer.o fs.o initrd.o lcfos.bin: $(CRT0) $(OBJECTS) link.ld - ld -T link.ld -s -o lcfos.bin $(CRT0) $(OBJECTS) + ld -M -T link.ld -s -o lcfos.bin $(CRT0) $(OBJECTS) %.o : %.asm nasm -f elf64 -o $@ $< diff -r 3a6a9b929db0 -r d8185ddb6c7b cos/kernel/asmcode.asm --- a/cos/kernel/asmcode.asm Fri Jan 13 18:18:17 2012 +0100 +++ b/cos/kernel/asmcode.asm Sun Jan 15 13:39:49 2012 +0100 @@ -95,9 +95,23 @@ ISR_NOERRCODE 18 ISR_NOERRCODE 19 +; irq handlers: ISR_NOERRCODE 32 ISR_NOERRCODE 33 ISR_NOERRCODE 34 +ISR_NOERRCODE 35 +ISR_NOERRCODE 36 +ISR_NOERRCODE 37 +ISR_NOERRCODE 38 +ISR_NOERRCODE 39 +ISR_NOERRCODE 40 +ISR_NOERRCODE 41 +ISR_NOERRCODE 42 +ISR_NOERRCODE 43 +ISR_NOERRCODE 44 +ISR_NOERRCODE 45 +ISR_NOERRCODE 46 +ISR_NOERRCODE 47 ; default handler: ISR_NOERRCODE 255 diff -r 3a6a9b929db0 -r d8185ddb6c7b cos/kernel/goto64.asm --- a/cos/kernel/goto64.asm Fri Jan 13 18:18:17 2012 +0100 +++ b/cos/kernel/goto64.asm Sun Jan 15 13:39:49 2012 +0100 @@ -214,6 +214,11 @@ lgdt [gdt64pointer] ; Reload GDT in 64 bits mode +; Test: +mov ax, 0x10 +mov ds, ax +; End of test + ; TODO: determine a good place for the kernel stack. mov rsp, 0xA000 ; Setup stack pointer. diff -r 3a6a9b929db0 -r d8185ddb6c7b cos/kernel/handlers.c --- a/cos/kernel/handlers.c Fri Jan 13 18:18:17 2012 +0100 +++ b/cos/kernel/handlers.c Sun Jan 15 13:39:49 2012 +0100 @@ -21,10 +21,23 @@ void INT17(void); void INT18(void); void INT19(void); -// Remapped handlers: +// Remapped irq assembler wrappers: void INT32(void); void INT33(void); void INT34(void); +void INT35(void); +void INT36(void); +void INT37(void); +void INT38(void); +void INT39(void); +void INT40(void); +void INT41(void); +void INT42(void); +void INT43(void); +void INT44(void); +void INT45(void); +void INT46(void); +void INT47(void); // THE interrupt descriptor table: IDT_entry *idt = (IDT_entry*)0x5000; @@ -86,6 +99,19 @@ setIDTentry(32, INT32, 0x08, 0x8F); setIDTentry(33, INT33, 0x08, 0x8F); setIDTentry(34, INT34, 0x08, 0x8F); + setIDTentry(35, INT35, 0x08, 0x8F); + setIDTentry(36, INT36, 0x08, 0x8F); + setIDTentry(37, INT37, 0x08, 0x8F); + setIDTentry(38, INT38, 0x08, 0x8F); + setIDTentry(39, INT39, 0x08, 0x8F); + setIDTentry(40, INT40, 0x08, 0x8F); + setIDTentry(41, INT41, 0x08, 0x8F); + setIDTentry(42, INT42, 0x08, 0x8F); + setIDTentry(43, INT43, 0x08, 0x8F); + setIDTentry(44, INT44, 0x08, 0x8F); + setIDTentry(45, INT45, 0x08, 0x8F); + setIDTentry(46, INT46, 0x08, 0x8F); + setIDTentry(47, INT47, 0x08, 0x8F); // Set the correct values in the IDT pointer: idtP.base = (uint64_t)idt; @@ -123,6 +149,25 @@ outb(0xA1, maskslave); } +void gp_fault(uint64_t *regs) +{ + printf("GP fault\n"); + printf("Error code: %x\n", regs[8]); + printf("RIP: %x\n", regs[9]); + panic("No resolution to general protection fault!"); +} + +void page_fault(uint64_t *regs) +{ + printf("Page fault\n"); + uint64_t faulting_address; + asm volatile("mov %%cr2, %0" : "=r" (faulting_address)); + printf("Error code: %x\n", regs[8]); + printf("RIP: %x\n", regs[9]); + printf("Faulting address: %x\n", faulting_address); + panic("No resolution to page fault!"); + +} // Global isr handler: // Hopefully, this function get called with the correct registers. @@ -139,9 +184,22 @@ { keyboardDriverUpdate(); } + else if (intnum == 13) + { + gp_fault(registers); + } + else if (intnum == 14) + { + page_fault(registers); + } + else if (intnum == 39) + { + printf("Spurious interrupt\n"); + } else { - // printf("Interrupt %d called, registers at: %x\n", registers[7], registers); + printf("Interrupt %d called, registers at: %x\n", registers[7], registers); + panic("Paniek! Unhandled interrupt!"); } // TODO: EOI to slave? diff -r 3a6a9b929db0 -r d8185ddb6c7b cos/kernel/kernel.c --- a/cos/kernel/kernel.c Fri Jan 13 18:18:17 2012 +0100 +++ b/cos/kernel/kernel.c Sun Jan 15 13:39:49 2012 +0100 @@ -1,4 +1,3 @@ - #include "kernel.h" static void testMalloc() @@ -27,9 +26,20 @@ uint64_t available_memory = 0; + printf("Running with %d MB ram\n", available_memory / 1000000); + + printf("Detecting amount of memory\n"); + + printf("Grub multiboot header location: %x\n", multiboot_info); + // On real hardware, the retrieval of the flags fails into general protection fault?? + + printf("Grub lower mem: %d\n", multiboot_info->mem_lower); + printf("Grub multiboot header flags: %x\n", multiboot_info->flags); + /* Display memory information from multiboot header */ if ((multiboot_info->flags & (1<<6)) == (1<<6)) { + printf("Found GRUB memory map\n"); multiboot_memory_map_t *mmap; for (mmap = (multiboot_memory_map_t*)(uint64_t)multiboot_info->mmap_addr; (uint64_t)mmap < multiboot_info->mmap_addr + multiboot_info->mmap_length; @@ -43,6 +53,10 @@ } } } + else + { + printf("Found no GRUB map\n"); + } printf("Running with %d MB ram\n", available_memory / 1000000); @@ -116,7 +130,15 @@ { magicBochsBreak(); } - } + if (strncmp(buffer, "pf", 2)) + { + /* Test general protection exception */ + uint64_t *x; + x = (uint64_t*)0x4000000; // Address that is not mapped + *x = 0x2; // trigger paging exception + } + + } }