Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
16:ddefe6d97cd7 | 17:f3e3e0e9c4bc |
---|---|
32 void INT32(void); | 32 void INT32(void); |
33 void INT33(void); | 33 void INT33(void); |
34 void INT34(void); | 34 void INT34(void); |
35 | 35 |
36 // THE interrupt descriptor table: | 36 // THE interrupt descriptor table: |
37 static struct IDT_entry idt[256]; | 37 static IDT_entry idt[256]; |
38 | 38 volatile idtPointer idtP; |
39 void setIDTentry(int num, void (*handler)()) | 39 |
40 void setIDTentry(int num, void (*handler)(), uint16_t selector, uint8_t flags) | |
40 { | 41 { |
41 // Fill one entry with IDT info: | 42 // Fill one entry with IDT info: |
42 uint64_t offset; | 43 uint64_t offset; |
43 unsigned short selector = 0x8; // Code selector | 44 |
44 unsigned char type = 0x8E; // 32 bits interrupt gate. Thingy is present | 45 // Typecast the function pointer to a number: |
45 | 46 offset = (uint64_t)handler; |
46 offset = (uint64_t) handler; | 47 |
47 | 48 // Set offset: |
48 idt[num].b[0] = offset & 0xFF; | 49 idt[num].baseLow = offset & 0xFFFF; |
49 idt[num].b[1] = (offset >> 8) & 0xFF; | 50 idt[num].baseMid = (offset >> 16) & 0xFFFF; |
50 idt[num].b[2] = selector & 0xFF; | 51 idt[num].baseHigh = (offset >> 32) & 0xFFFFFFFF; |
51 idt[num].b[3] = (selector >> 8) & 0xFF; | 52 |
52 idt[num].b[4] = 0; // reserved | 53 // Set flags and selector: |
53 idt[num].b[5] = type; | 54 idt[num].selector = selector; |
54 idt[num].b[6] = (offset >> 16) & 0xFF; | 55 idt[num].flags = flags; |
55 idt[num].b[7] = (offset >> 24) & 0xFF; | 56 |
57 // Set reserved fields: | |
58 idt[num].reserved1 = 0; | |
59 idt[num].reserved2 = 0; | |
56 } | 60 } |
57 | 61 |
58 void setupIDT(void) { | 62 void setupIDT(void) { |
59 int i; | 63 int i; |
60 // Fill all vectors with the default handler: | 64 // Fill all vectors with the default handler: |
61 for (i=0; i<256; i++) { | 65 for (i=0; i<256; i++) { |
62 setIDTentry(i, &INTDEF); | 66 setIDTentry(i, &INTDEF, 0x08, 0x8E); |
63 } | 67 } |
64 | 68 |
65 // Now set other then default handler: | 69 // Now set other then default handler: |
66 setIDTentry(0, INT0); | 70 setIDTentry(0, INT0, 0x08, 0x8E); |
67 setIDTentry(1, INT1); | 71 setIDTentry(1, INT1, 0x08, 0x8E); |
68 setIDTentry(2, INT2); | 72 setIDTentry(2, INT2, 0x08, 0x8E); |
69 setIDTentry(3, INT3); | 73 setIDTentry(3, INT3, 0x08, 0x8E); |
70 setIDTentry(4, INT4); | 74 setIDTentry(4, INT4, 0x08, 0x8E); |
71 setIDTentry(5, INT5); | 75 setIDTentry(5, INT5, 0x08, 0x8E); |
72 setIDTentry(6, INT6); | 76 setIDTentry(6, INT6, 0x08, 0x8E); |
73 setIDTentry(7, INT7); | 77 setIDTentry(7, INT7, 0x08, 0x8E); |
74 setIDTentry(8, INT8); | 78 setIDTentry(8, INT8, 0x08, 0x8E); |
75 setIDTentry(9, INT9); | 79 setIDTentry(9, INT9, 0x08, 0x8E); |
76 setIDTentry(10, INT10); | 80 setIDTentry(10, INT10, 0x08, 0x8E); |
77 setIDTentry(11, INT11); | 81 setIDTentry(11, INT11, 0x08, 0x8E); |
78 setIDTentry(12, INT12); | 82 setIDTentry(12, INT12, 0x08, 0x8E); |
79 setIDTentry(13, INT13); | 83 setIDTentry(13, INT13, 0x08, 0x8E); |
80 setIDTentry(14, INT14); | 84 setIDTentry(14, INT14, 0x08, 0x8E); |
81 setIDTentry(15, INT15); | 85 setIDTentry(15, INT15, 0x08, 0x8E); |
82 setIDTentry(16, INT16); | 86 setIDTentry(16, INT16, 0x08, 0x8E); |
83 setIDTentry(17, INT17); | 87 setIDTentry(17, INT17, 0x08, 0x8E); |
84 setIDTentry(18, INT18); | 88 setIDTentry(18, INT18, 0x08, 0x8E); |
85 setIDTentry(19, INT19); | 89 setIDTentry(19, INT19, 0x08, 0x8E); |
86 /* reserved interrupts: */ | 90 /* reserved interrupts: */ |
87 // From int20 - int31 | 91 // From int20 - int31 |
88 setIDTentry(32, INT32); | 92 setIDTentry(32, INT32, 0x08, 0x8E); |
89 setIDTentry(33, INT33); | 93 setIDTentry(33, INT33, 0x08, 0x8E); |
90 setIDTentry(34, INT34); | 94 setIDTentry(34, INT34, 0x08, 0x8E); |
91 | 95 |
96 // Set the correct values in the IDT pointer: | |
97 idtP.base = (uint64_t)&idt; | |
98 idtP.limit = (sizeof(IDT_entry) * 256) - 1; | |
92 // call load IDT asm function: | 99 // call load IDT asm function: |
93 loadIDT(idt, 256*8-1); | 100 loadIDT(); |
94 | 101 |
95 PICremap(); | 102 PICremap(); |
96 enableinterrupts(); | 103 printf("enable ints\n"); |
104 asm("sti"); | |
105 printf("Done!\n"); | |
97 } | 106 } |
98 | 107 |
99 // PIC functions: | 108 // PIC functions: |
100 void PICremap() { | 109 void PICremap() { |
101 unsigned char maskmaster, maskslave, pic1, pic2; | 110 unsigned char maskmaster, maskslave, pic1, pic2; |
206 { | 215 { |
207 printf("INT13 called!\n"); | 216 printf("INT13 called!\n"); |
208 panic("Unhandled exception!"); | 217 panic("Unhandled exception!"); |
209 } | 218 } |
210 | 219 |
211 void* getUnusedPage() { | 220 void* getUnusedPage() |
221 { | |
212 return 0; | 222 return 0; |
213 | 223 } |
214 } | 224 |
215 | 225 void mappage(uint64_t address) { |
216 void mappage(uint32_t address) { | |
217 uint32_t pageDirIndex = address >> 22; | 226 uint32_t pageDirIndex = address >> 22; |
218 uint32_t pageTableIndex = (address >> 12) & 0x3FF; | 227 uint32_t pageTableIndex = (address >> 12) & 0x3FF; |
219 | 228 |
220 printf("Allocating page at %d, tableindex=%d\n", pageDirIndex, pageTableIndex); | 229 printf("Allocating page at %d, tableindex=%d\n", pageDirIndex, pageTableIndex); |
221 //uint32_t *pageTable = (uint32_t*)(pageDirectory[pageDirIndex] & 0xFFFFFC00); | 230 //uint32_t *pageTable = (uint32_t*)(pageDirectory[pageDirIndex] & 0xFFFFFC00); |
222 | |
223 | |
224 } | 231 } |
225 | 232 |
226 void INT14handler(unsigned int address) | 233 void INT14handler(unsigned int address) |
227 { | 234 { |
228 printf("INT14 called! Page fault for address 0x%x!\n", address); | 235 printf("INT14 called! Page fault for address 0x%x!\n", address); |