comparison cos/kernel/handlers.c @ 31:88590c42320f

Changed interrupt handler
author windel
date Tue, 10 Jan 2012 20:40:35 +0100
parents 0148f55bfe24
children 3a6a9b929db0
comparison
equal deleted inserted replaced
30:0148f55bfe24 31:88590c42320f
1 #include "kernel.h" 1 #include "kernel.h"
2 2
3 // Assembler wrapper prototypes: 3 // Assembler wrapper prototypes:
4 void INTDEF(void); 4 void INT255(void);
5 void INT0(void); 5 void INT0(void);
6 void INT1(void); 6 void INT1(void);
7 void INT2(void); 7 void INT2(void);
8 void INT3(void); 8 void INT3(void);
9 void INT4(void); 9 void INT4(void);
15 void INT10(void); 15 void INT10(void);
16 void INT11(void); 16 void INT11(void);
17 void INT12(void); 17 void INT12(void);
18 void INT13(void); 18 void INT13(void);
19 void INT14(void); 19 void INT14(void);
20 void INT15(void);
21 void INT16(void); 20 void INT16(void);
22 void INT17(void); 21 void INT17(void);
23 void INT18(void); 22 void INT18(void);
24 void INT19(void); 23 void INT19(void);
25 // Remapped handlers: 24 // Remapped handlers:
37 uint64_t offset; 36 uint64_t offset;
38 37
39 // Typecast the function pointer to a number: 38 // Typecast the function pointer to a number:
40 offset = (uint64_t)handler; 39 offset = (uint64_t)handler;
41 40
42 //panic("Almost setting an IDT entry");
43
44 // Set offset: 41 // Set offset:
45 idt[num].baseLow = offset & 0xFFFF; 42 idt[num].baseLow = offset & 0xFFFF;
46 idt[num].baseMid = (offset >> 16) & 0xFFFF; 43 idt[num].baseMid = (offset >> 16) & 0xFFFF;
47 idt[num].baseHigh = (offset >> 32) & 0xFFFFFFFF; 44 idt[num].baseHigh = (offset >> 32) & 0xFFFFFFFF;
48 45
58 void setupIDT(void) { 55 void setupIDT(void) {
59 int i; 56 int i;
60 57
61 // Fill all vectors with the default handler: 58 // Fill all vectors with the default handler:
62 for (i=0; i<256; i++) { 59 for (i=0; i<256; i++) {
63 setIDTentry(i, INTDEF, 0x08, 0x8E); 60 setIDTentry(i, INT255, 0x08, 0x8E);
64 } 61 }
65 62
66 // Now set other then default handler: 63 // Now set other then default handler:
67 setIDTentry(0, INT0, 0x08, 0x8E); 64 setIDTentry(0, INT0, 0x08, 0x8E);
68 setIDTentry(1, INT1, 0x08, 0x8E); 65 setIDTentry(1, INT1, 0x08, 0x8E);
77 setIDTentry(10, INT10, 0x08, 0x8E); 74 setIDTentry(10, INT10, 0x08, 0x8E);
78 setIDTentry(11, INT11, 0x08, 0x8E); 75 setIDTentry(11, INT11, 0x08, 0x8E);
79 setIDTentry(12, INT12, 0x08, 0x8E); 76 setIDTentry(12, INT12, 0x08, 0x8E);
80 setIDTentry(13, INT13, 0x08, 0x8E); 77 setIDTentry(13, INT13, 0x08, 0x8E);
81 setIDTentry(14, INT14, 0x08, 0x8E); 78 setIDTentry(14, INT14, 0x08, 0x8E);
82 setIDTentry(15, INT15, 0x08, 0x8E); 79 //setIDTentry(15, INT15, 0x08, 0x8E);
83 setIDTentry(16, INT16, 0x08, 0x8E); 80 setIDTentry(16, INT16, 0x08, 0x8E);
84 setIDTentry(17, INT17, 0x08, 0x8E); 81 setIDTentry(17, INT17, 0x08, 0x8E);
85 setIDTentry(18, INT18, 0x08, 0x8E); 82 setIDTentry(18, INT18, 0x08, 0x8E);
86 setIDTentry(19, INT19, 0x08, 0x8E); 83 setIDTentry(19, INT19, 0x08, 0x8E);
87 /* reserved interrupts: */ 84 /* reserved interrupts: */
124 121
125 outb(0x21, maskmaster); 122 outb(0x21, maskmaster);
126 outb(0xA1, maskslave); 123 outb(0xA1, maskslave);
127 } 124 }
128 125
129 // Interrupt service routines: 126 // Global isr handler:
130 127
131 void INT0handler() 128 // Hopefully, this function get called with the correct registers.
129 void isr_handler(uint64_t* registers)
132 { 130 {
133 printf("INT0 called!\n"); 131
134 panic("Unhandled exception!"); 132 uint64_t intnum = registers[7];
133
134 if (intnum == 32)
135 {
136 timerDriverUpdate();
137 }
138 else if (intnum == 33)
139 {
140 unsigned char scancode = inb(0x60);
141 keyboardDriverUpdate(scancode);
142 }
143 else
144 {
145 printf("Interrupt %d called, registers at: %x\n", registers[7], registers);
146 }
147
148 outb(0x20, 0x20); // EOI to master
135 } 149 }
136 150
137 void INT1handler() 151 // Interrupt service routines:
138 {
139 printf("INT1 called!\n");
140 panic("Unhandled exception!");
141 }
142
143 void INT2handler()
144 {
145 printf("INT2 called!\n");
146 panic("Unhandled exception!");
147 }
148
149 void INT3handler()
150 {
151 printf("INT3 called!\n");
152 panic("Unhandled exception!");
153 }
154
155 void INT4handler()
156 {
157 printf("INT4 called!\n");
158 panic("Unhandled exception!");
159 }
160
161 void INT5handler()
162 {
163 printf("INT5 called!\n");
164 panic("Unhandled exception!");
165 }
166
167 void INT6handler()
168 {
169 printf("INT6 called!\n");
170 panic("Unhandled exception!");
171 }
172
173 void INT7handler()
174 {
175 printf("INT7 called!\n");
176 panic("Unhandled exception!");
177 }
178
179 void INT8handler()
180 {
181 printf("INT8 called!\n");
182 panic("Unhandled exception!");
183 }
184
185 void INT9handler()
186 {
187 printf("INT9 called!\n");
188 panic("Unhandled exception!");
189 }
190
191 void INT10handler()
192 {
193 printf("INT10 called!\n");
194 panic("Unhandled exception!");
195 }
196
197 void INT11handler()
198 {
199 printf("INT11 called!\n");
200 panic("Unhandled exception!");
201 }
202
203 void INT12handler()
204 {
205 printf("INT12 called!\n");
206 panic("Unhandled exception!");
207 }
208
209 void INT13handler()
210 {
211 printf("INT13 called!\n");
212 panic("Unhandled exception!");
213 }
214
215 void* getUnusedPage()
216 {
217 return 0;
218 }
219
220 void mappage(uint64_t address) {
221 uint32_t pageDirIndex = address >> 22;
222 uint32_t pageTableIndex = (address >> 12) & 0x3FF;
223
224 printf("Allocating page at %d, tableindex=%d\n", pageDirIndex, pageTableIndex);
225 //uint32_t *pageTable = (uint32_t*)(pageDirectory[pageDirIndex] & 0xFFFFFC00);
226 }
227 152
228 void INT14handler() 153 void INT14handler()
229 { 154 {
230 uint64_t faulting_address; 155 uint64_t faulting_address;
231 156
233 158
234 // Retrieve failed page from CR2: 159 // Retrieve failed page from CR2:
235 asm volatile("mov %%cr2, %0" : "=r" (faulting_address)); 160 asm volatile("mov %%cr2, %0" : "=r" (faulting_address));
236 161
237 printf("INT14 called! Page fault for address 0x%X!\n", faulting_address); 162 printf("INT14 called! Page fault for address 0x%X!\n", faulting_address);
238 if ( (faulting_address & 0xF0000000) == 0xD0000000 ) {
239 mappage(faulting_address & 0xFFFFF000);
240 return;
241 }
242 163
243 panic("Unhandled exception!"); 164 panic("Unhandled exception!");
244 } 165 }
245 166
246 void INT15handler() 167 void INT15handler()
247 { 168 {
248 printf("INT15 called!\n"); 169 printf("INT15 called!\n");
249 panic("Unhandled exception!");
250 }
251
252 void INT16handler()
253 {
254 printf("INT16 called!\n");
255 panic("Unhandled exception!");
256 }
257
258 void INT17handler()
259 {
260 printf("INT17 called!\n");
261 panic("Unhandled exception!");
262 }
263
264 void INT18handler()
265 {
266 printf("INT18 called!\n");
267 panic("Unhandled exception!");
268 }
269
270 void INT19handler()
271 {
272 printf("INT19 called!\n");
273 panic("Unhandled exception!"); 170 panic("Unhandled exception!");
274 } 171 }
275 172
276 // remapped IRQ from master PIC: 173 // remapped IRQ from master PIC:
277 void INT32handler() 174 void INT32handler()
291 //printf("Scancode = 0x%x\n", scancode); 188 //printf("Scancode = 0x%x\n", scancode);
292 keyboardDriverUpdate(scancode); 189 keyboardDriverUpdate(scancode);
293 outb(0x20, 0x20); // EOI to master 190 outb(0x20, 0x20); // EOI to master
294 } 191 }
295 192
296 void INT34handler()
297 {
298 printf("INT34 called!\n");
299 }
300
301 void INTDEF_handler() 193 void INTDEF_handler()
302 { 194 {
303 panic("Default int handler called\n"); 195 panic("Default int handler called\n");
304 } 196 }
305 197