Mercurial > lcfOS
diff cos/kernel/handlers.c @ 17:f3e3e0e9c4bc
First attempt IDT loader 64 bits. INT13 occurs
author | windel |
---|---|
date | Sat, 19 Nov 2011 20:01:28 +0100 |
parents | a58904747019 |
children | 6129643f5c34 |
line wrap: on
line diff
--- a/cos/kernel/handlers.c Fri Nov 18 14:41:53 2011 +0100 +++ b/cos/kernel/handlers.c Sat Nov 19 20:01:28 2011 +0100 @@ -34,66 +34,75 @@ void INT34(void); // THE interrupt descriptor table: -static struct IDT_entry idt[256]; +static IDT_entry idt[256]; +volatile idtPointer idtP; -void setIDTentry(int num, void (*handler)()) +void setIDTentry(int num, void (*handler)(), uint16_t selector, uint8_t flags) { // Fill one entry with IDT info: uint64_t offset; - unsigned short selector = 0x8; // Code selector - unsigned char type = 0x8E; // 32 bits interrupt gate. Thingy is present - offset = (uint64_t) handler; + // Typecast the function pointer to a number: + offset = (uint64_t)handler; - idt[num].b[0] = offset & 0xFF; - idt[num].b[1] = (offset >> 8) & 0xFF; - idt[num].b[2] = selector & 0xFF; - idt[num].b[3] = (selector >> 8) & 0xFF; - idt[num].b[4] = 0; // reserved - idt[num].b[5] = type; - idt[num].b[6] = (offset >> 16) & 0xFF; - idt[num].b[7] = (offset >> 24) & 0xFF; + // Set offset: + idt[num].baseLow = offset & 0xFFFF; + idt[num].baseMid = (offset >> 16) & 0xFFFF; + idt[num].baseHigh = (offset >> 32) & 0xFFFFFFFF; + + // Set flags and selector: + idt[num].selector = selector; + idt[num].flags = flags; + + // Set reserved fields: + idt[num].reserved1 = 0; + idt[num].reserved2 = 0; } void setupIDT(void) { int i; // Fill all vectors with the default handler: for (i=0; i<256; i++) { - setIDTentry(i, &INTDEF); + setIDTentry(i, &INTDEF, 0x08, 0x8E); } // Now set other then default handler: - setIDTentry(0, INT0); - setIDTentry(1, INT1); - setIDTentry(2, INT2); - setIDTentry(3, INT3); - setIDTentry(4, INT4); - setIDTentry(5, INT5); - setIDTentry(6, INT6); - setIDTentry(7, INT7); - setIDTentry(8, INT8); - setIDTentry(9, INT9); - setIDTentry(10, INT10); - setIDTentry(11, INT11); - setIDTentry(12, INT12); - setIDTentry(13, INT13); - setIDTentry(14, INT14); - setIDTentry(15, INT15); - setIDTentry(16, INT16); - setIDTentry(17, INT17); - setIDTentry(18, INT18); - setIDTentry(19, INT19); + setIDTentry(0, INT0, 0x08, 0x8E); + setIDTentry(1, INT1, 0x08, 0x8E); + setIDTentry(2, INT2, 0x08, 0x8E); + setIDTentry(3, INT3, 0x08, 0x8E); + setIDTentry(4, INT4, 0x08, 0x8E); + setIDTentry(5, INT5, 0x08, 0x8E); + setIDTentry(6, INT6, 0x08, 0x8E); + setIDTentry(7, INT7, 0x08, 0x8E); + setIDTentry(8, INT8, 0x08, 0x8E); + setIDTentry(9, INT9, 0x08, 0x8E); + setIDTentry(10, INT10, 0x08, 0x8E); + setIDTentry(11, INT11, 0x08, 0x8E); + setIDTentry(12, INT12, 0x08, 0x8E); + setIDTentry(13, INT13, 0x08, 0x8E); + setIDTentry(14, INT14, 0x08, 0x8E); + setIDTentry(15, INT15, 0x08, 0x8E); + setIDTentry(16, INT16, 0x08, 0x8E); + setIDTentry(17, INT17, 0x08, 0x8E); + setIDTentry(18, INT18, 0x08, 0x8E); + setIDTentry(19, INT19, 0x08, 0x8E); /* reserved interrupts: */ // From int20 - int31 - setIDTentry(32, INT32); - setIDTentry(33, INT33); - setIDTentry(34, INT34); + setIDTentry(32, INT32, 0x08, 0x8E); + setIDTentry(33, INT33, 0x08, 0x8E); + setIDTentry(34, INT34, 0x08, 0x8E); + // Set the correct values in the IDT pointer: + idtP.base = (uint64_t)&idt; + idtP.limit = (sizeof(IDT_entry) * 256) - 1; // call load IDT asm function: - loadIDT(idt, 256*8-1); + loadIDT(); PICremap(); - enableinterrupts(); + printf("enable ints\n"); + asm("sti"); + printf("Done!\n"); } // PIC functions: @@ -208,19 +217,17 @@ panic("Unhandled exception!"); } -void* getUnusedPage() { +void* getUnusedPage() +{ return 0; - } -void mappage(uint32_t address) { +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); - - } void INT14handler(unsigned int address)