Mercurial > lcfOS
comparison cos/kernel/handlers.c @ 33:d8185ddb6c7b
Added more interrupt handlers
author | windel |
---|---|
date | Sun, 15 Jan 2012 13:39:49 +0100 |
parents | 3a6a9b929db0 |
children | 91f91ff07ea8 |
comparison
equal
deleted
inserted
replaced
32:3a6a9b929db0 | 33:d8185ddb6c7b |
---|---|
19 void INT14(void); | 19 void INT14(void); |
20 void INT16(void); | 20 void INT16(void); |
21 void INT17(void); | 21 void INT17(void); |
22 void INT18(void); | 22 void INT18(void); |
23 void INT19(void); | 23 void INT19(void); |
24 // Remapped handlers: | 24 // Remapped irq assembler wrappers: |
25 void INT32(void); | 25 void INT32(void); |
26 void INT33(void); | 26 void INT33(void); |
27 void INT34(void); | 27 void INT34(void); |
28 void INT35(void); | |
29 void INT36(void); | |
30 void INT37(void); | |
31 void INT38(void); | |
32 void INT39(void); | |
33 void INT40(void); | |
34 void INT41(void); | |
35 void INT42(void); | |
36 void INT43(void); | |
37 void INT44(void); | |
38 void INT45(void); | |
39 void INT46(void); | |
40 void INT47(void); | |
28 | 41 |
29 // THE interrupt descriptor table: | 42 // THE interrupt descriptor table: |
30 IDT_entry *idt = (IDT_entry*)0x5000; | 43 IDT_entry *idt = (IDT_entry*)0x5000; |
31 volatile idtPointer idtP; | 44 volatile idtPointer idtP; |
32 | 45 |
84 /* reserved interrupts: */ | 97 /* reserved interrupts: */ |
85 // From int20 - int31 | 98 // From int20 - int31 |
86 setIDTentry(32, INT32, 0x08, 0x8F); | 99 setIDTentry(32, INT32, 0x08, 0x8F); |
87 setIDTentry(33, INT33, 0x08, 0x8F); | 100 setIDTentry(33, INT33, 0x08, 0x8F); |
88 setIDTentry(34, INT34, 0x08, 0x8F); | 101 setIDTentry(34, INT34, 0x08, 0x8F); |
102 setIDTentry(35, INT35, 0x08, 0x8F); | |
103 setIDTentry(36, INT36, 0x08, 0x8F); | |
104 setIDTentry(37, INT37, 0x08, 0x8F); | |
105 setIDTentry(38, INT38, 0x08, 0x8F); | |
106 setIDTentry(39, INT39, 0x08, 0x8F); | |
107 setIDTentry(40, INT40, 0x08, 0x8F); | |
108 setIDTentry(41, INT41, 0x08, 0x8F); | |
109 setIDTentry(42, INT42, 0x08, 0x8F); | |
110 setIDTentry(43, INT43, 0x08, 0x8F); | |
111 setIDTentry(44, INT44, 0x08, 0x8F); | |
112 setIDTentry(45, INT45, 0x08, 0x8F); | |
113 setIDTentry(46, INT46, 0x08, 0x8F); | |
114 setIDTentry(47, INT47, 0x08, 0x8F); | |
89 | 115 |
90 // Set the correct values in the IDT pointer: | 116 // Set the correct values in the IDT pointer: |
91 idtP.base = (uint64_t)idt; | 117 idtP.base = (uint64_t)idt; |
92 idtP.limit = (sizeof(IDT_entry) * 256) - 1; | 118 idtP.limit = (sizeof(IDT_entry) * 256) - 1; |
93 // call load IDT asm function: | 119 // call load IDT asm function: |
121 | 147 |
122 outb(0x21, maskmaster); | 148 outb(0x21, maskmaster); |
123 outb(0xA1, maskslave); | 149 outb(0xA1, maskslave); |
124 } | 150 } |
125 | 151 |
152 void gp_fault(uint64_t *regs) | |
153 { | |
154 printf("GP fault\n"); | |
155 printf("Error code: %x\n", regs[8]); | |
156 printf("RIP: %x\n", regs[9]); | |
157 panic("No resolution to general protection fault!"); | |
158 } | |
159 | |
160 void page_fault(uint64_t *regs) | |
161 { | |
162 printf("Page fault\n"); | |
163 uint64_t faulting_address; | |
164 asm volatile("mov %%cr2, %0" : "=r" (faulting_address)); | |
165 printf("Error code: %x\n", regs[8]); | |
166 printf("RIP: %x\n", regs[9]); | |
167 printf("Faulting address: %x\n", faulting_address); | |
168 panic("No resolution to page fault!"); | |
169 | |
170 } | |
126 // Global isr handler: | 171 // Global isr handler: |
127 | 172 |
128 // Hopefully, this function get called with the correct registers. | 173 // Hopefully, this function get called with the correct registers. |
129 void isr_handler(uint64_t* registers) | 174 void isr_handler(uint64_t* registers) |
130 { | 175 { |
137 } | 182 } |
138 else if (intnum == 33) | 183 else if (intnum == 33) |
139 { | 184 { |
140 keyboardDriverUpdate(); | 185 keyboardDriverUpdate(); |
141 } | 186 } |
187 else if (intnum == 13) | |
188 { | |
189 gp_fault(registers); | |
190 } | |
191 else if (intnum == 14) | |
192 { | |
193 page_fault(registers); | |
194 } | |
195 else if (intnum == 39) | |
196 { | |
197 printf("Spurious interrupt\n"); | |
198 } | |
142 else | 199 else |
143 { | 200 { |
144 // printf("Interrupt %d called, registers at: %x\n", registers[7], registers); | 201 printf("Interrupt %d called, registers at: %x\n", registers[7], registers); |
202 panic("Paniek! Unhandled interrupt!"); | |
145 } | 203 } |
146 | 204 |
147 // TODO: EOI to slave? | 205 // TODO: EOI to slave? |
148 // TODO: replace this with APIC code? | 206 // TODO: replace this with APIC code? |
149 outb(0x20, 0x20); // EOI to master | 207 outb(0x20, 0x20); // EOI to master |