Mercurial > lcfOS
annotate cos/kernel/handlers.c @ 24:d8627924d40d
Split up in more files and reboot command
author | windel |
---|---|
date | Fri, 02 Dec 2011 14:00:02 +0100 |
parents | 5dd47d6eebac |
children | dcce92b1efbc |
rev | line source |
---|---|
14 | 1 #include "kernel.h" |
2 | |
3 // Assembler wrapper prototypes: | |
4 void INTDEF(void); | |
5 void INT0(void); | |
6 void INT1(void); | |
7 void INT2(void); | |
8 void INT3(void); | |
9 void INT4(void); | |
10 void INT5(void); | |
11 void INT6(void); | |
12 void INT7(void); | |
13 void INT8(void); | |
14 void INT9(void); | |
15 void INT10(void); | |
16 void INT11(void); | |
17 void INT12(void); | |
18 void INT13(void); | |
19 void INT14(void); | |
20 void INT15(void); | |
21 void INT16(void); | |
22 void INT17(void); | |
23 void INT18(void); | |
24 void INT19(void); | |
25 // Remapped handlers: | |
26 void INT32(void); | |
27 void INT33(void); | |
28 void INT34(void); | |
29 | |
30 // THE interrupt descriptor table: | |
24 | 31 IDT_entry *idt = (IDT_entry*)0x5000; |
17 | 32 volatile idtPointer idtP; |
14 | 33 |
17 | 34 void setIDTentry(int num, void (*handler)(), uint16_t selector, uint8_t flags) |
14 | 35 { |
36 // Fill one entry with IDT info: | |
37 uint64_t offset; | |
38 | |
17 | 39 // Typecast the function pointer to a number: |
40 offset = (uint64_t)handler; | |
14 | 41 |
24 | 42 //panic("Almost setting an IDT entry"); |
43 | |
17 | 44 // Set offset: |
45 idt[num].baseLow = offset & 0xFFFF; | |
46 idt[num].baseMid = (offset >> 16) & 0xFFFF; | |
47 idt[num].baseHigh = (offset >> 32) & 0xFFFFFFFF; | |
48 | |
49 // Set flags and selector: | |
50 idt[num].selector = selector; | |
51 idt[num].flags = flags; | |
52 | |
53 // Set reserved fields: | |
54 idt[num].reserved1 = 0; | |
55 idt[num].reserved2 = 0; | |
14 | 56 } |
57 | |
58 void setupIDT(void) { | |
59 int i; | |
24 | 60 //panic("Just before filling IDT"); |
61 // After this line a crash occurs! | |
14 | 62 // Fill all vectors with the default handler: |
63 for (i=0; i<256; i++) { | |
24 | 64 setIDTentry(i, INTDEF, 0x08, 0x8E); |
14 | 65 } |
24 | 66 //panic("Just after setting defhandlers in IDT"); |
14 | 67 |
68 // Now set other then default handler: | |
17 | 69 setIDTentry(0, INT0, 0x08, 0x8E); |
70 setIDTentry(1, INT1, 0x08, 0x8E); | |
71 setIDTentry(2, INT2, 0x08, 0x8E); | |
72 setIDTentry(3, INT3, 0x08, 0x8E); | |
73 setIDTentry(4, INT4, 0x08, 0x8E); | |
74 setIDTentry(5, INT5, 0x08, 0x8E); | |
75 setIDTentry(6, INT6, 0x08, 0x8E); | |
76 setIDTentry(7, INT7, 0x08, 0x8E); | |
77 setIDTentry(8, INT8, 0x08, 0x8E); | |
78 setIDTentry(9, INT9, 0x08, 0x8E); | |
79 setIDTentry(10, INT10, 0x08, 0x8E); | |
80 setIDTentry(11, INT11, 0x08, 0x8E); | |
81 setIDTentry(12, INT12, 0x08, 0x8E); | |
82 setIDTentry(13, INT13, 0x08, 0x8E); | |
83 setIDTentry(14, INT14, 0x08, 0x8E); | |
84 setIDTentry(15, INT15, 0x08, 0x8E); | |
85 setIDTentry(16, INT16, 0x08, 0x8E); | |
86 setIDTentry(17, INT17, 0x08, 0x8E); | |
87 setIDTentry(18, INT18, 0x08, 0x8E); | |
88 setIDTentry(19, INT19, 0x08, 0x8E); | |
14 | 89 /* reserved interrupts: */ |
90 // From int20 - int31 | |
18
6129643f5c34
Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents:
17
diff
changeset
|
91 setIDTentry(32, INT32, 0x08, 0x8F); |
6129643f5c34
Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents:
17
diff
changeset
|
92 setIDTentry(33, INT33, 0x08, 0x8F); |
6129643f5c34
Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents:
17
diff
changeset
|
93 setIDTentry(34, INT34, 0x08, 0x8F); |
14 | 94 |
17 | 95 // Set the correct values in the IDT pointer: |
21 | 96 idtP.base = (uint64_t)idt; |
17 | 97 idtP.limit = (sizeof(IDT_entry) * 256) - 1; |
14 | 98 // call load IDT asm function: |
24 | 99 //panic("Just before LIDT"); |
17 | 100 loadIDT(); |
14 | 101 |
102 PICremap(); | |
24 | 103 //panic("Just before sti"); |
17 | 104 asm("sti"); |
14 | 105 } |
106 | |
107 // PIC functions: | |
108 void PICremap() { | |
109 unsigned char maskmaster, maskslave, pic1, pic2; | |
110 pic1 = 0x20; // remapping location master | |
111 pic2 = 0x28; | |
112 maskmaster = inb(0x21); // master cmd=0x20, data=0x21 | |
113 maskslave = inb(0xA1); // slave command=0xA0, data=0xA1 | |
114 | |
115 outb(0x20, 0x20); // end of init | |
116 | |
117 outb(0x20, 0x11); // init + ICW1_ICW2 | |
118 outb(0xA0, 0x11); // init + ICW1_ICW2 | |
119 | |
120 outb(0x21, pic1); // ICW2, write offset | |
121 outb(0xA1, pic2); // ICW2 | |
122 | |
123 outb(0x21, 4); // ICW3, write a 4! | |
124 outb(0xA1, 2); // ICW3, write a 2! | |
125 | |
126 outb(0x21, 1); // ICW4, 8086 mode | |
127 outb(0xA1, 1); // ICW4 | |
128 | |
129 outb(0x21, maskmaster); | |
130 outb(0xA1, maskslave); | |
131 } | |
132 | |
133 // Interrupt service routines: | |
134 | |
135 void INT0handler() | |
136 { | |
137 printf("INT0 called!\n"); | |
138 panic("Unhandled exception!"); | |
139 } | |
140 | |
141 void INT1handler() | |
142 { | |
143 printf("INT1 called!\n"); | |
144 panic("Unhandled exception!"); | |
145 } | |
146 | |
147 void INT2handler() | |
148 { | |
149 printf("INT2 called!\n"); | |
150 panic("Unhandled exception!"); | |
151 } | |
152 | |
153 void INT3handler() | |
154 { | |
155 printf("INT3 called!\n"); | |
156 panic("Unhandled exception!"); | |
157 } | |
158 | |
159 void INT4handler() | |
160 { | |
161 printf("INT4 called!\n"); | |
162 panic("Unhandled exception!"); | |
163 } | |
164 | |
165 void INT5handler() | |
166 { | |
167 printf("INT5 called!\n"); | |
168 panic("Unhandled exception!"); | |
169 } | |
170 | |
171 void INT6handler() | |
172 { | |
173 printf("INT6 called!\n"); | |
174 panic("Unhandled exception!"); | |
175 } | |
176 | |
177 void INT7handler() | |
178 { | |
179 printf("INT7 called!\n"); | |
180 panic("Unhandled exception!"); | |
181 } | |
182 | |
183 void INT8handler() | |
184 { | |
185 printf("INT8 called!\n"); | |
186 panic("Unhandled exception!"); | |
187 } | |
188 | |
189 void INT9handler() | |
190 { | |
191 printf("INT9 called!\n"); | |
192 panic("Unhandled exception!"); | |
193 } | |
194 | |
195 void INT10handler() | |
196 { | |
197 printf("INT10 called!\n"); | |
198 panic("Unhandled exception!"); | |
199 } | |
200 | |
201 void INT11handler() | |
202 { | |
203 printf("INT11 called!\n"); | |
204 panic("Unhandled exception!"); | |
205 } | |
206 | |
207 void INT12handler() | |
208 { | |
209 printf("INT12 called!\n"); | |
210 panic("Unhandled exception!"); | |
211 } | |
212 | |
213 void INT13handler() | |
214 { | |
215 printf("INT13 called!\n"); | |
216 panic("Unhandled exception!"); | |
217 } | |
218 | |
17 | 219 void* getUnusedPage() |
220 { | |
14 | 221 return 0; |
222 } | |
223 | |
17 | 224 void mappage(uint64_t address) { |
14 | 225 uint32_t pageDirIndex = address >> 22; |
226 uint32_t pageTableIndex = (address >> 12) & 0x3FF; | |
227 | |
228 printf("Allocating page at %d, tableindex=%d\n", pageDirIndex, pageTableIndex); | |
229 //uint32_t *pageTable = (uint32_t*)(pageDirectory[pageDirIndex] & 0xFFFFFC00); | |
230 } | |
231 | |
20 | 232 void INT14handler() |
14 | 233 { |
20 | 234 uint64_t faulting_address; |
235 | |
236 // Retrieve failed page from CR2: | |
237 asm volatile("mov %%cr2, %0" : "=r" (faulting_address)); | |
238 | |
239 printf("INT14 called! Page fault for address 0x%X!\n", faulting_address); | |
240 if ( (faulting_address & 0xF0000000) == 0xD0000000 ) { | |
241 mappage(faulting_address & 0xFFFFF000); | |
14 | 242 return; |
243 } | |
244 | |
245 panic("Unhandled exception!"); | |
246 } | |
247 | |
248 void INT15handler() | |
249 { | |
250 printf("INT15 called!\n"); | |
251 panic("Unhandled exception!"); | |
252 } | |
253 | |
254 void INT16handler() | |
255 { | |
256 printf("INT16 called!\n"); | |
257 panic("Unhandled exception!"); | |
258 } | |
259 | |
260 void INT17handler() | |
261 { | |
262 printf("INT17 called!\n"); | |
263 panic("Unhandled exception!"); | |
264 } | |
265 | |
266 void INT18handler() | |
267 { | |
268 printf("INT18 called!\n"); | |
269 panic("Unhandled exception!"); | |
270 } | |
271 | |
272 void INT19handler() | |
273 { | |
274 printf("INT19 called!\n"); | |
275 panic("Unhandled exception!"); | |
276 } | |
277 | |
278 // remapped IRQ from master PIC: | |
279 void INT32handler() | |
280 { | |
281 // System timer. | |
282 //printf("INT32 called!\n"); | |
283 // called very frequent, what is this? | |
284 timerDriverUpdate(); | |
18
6129643f5c34
Fixed interrupt issue, ds, es, ss, fs and gs were not initialized to 0
windel
parents:
17
diff
changeset
|
285 // Acknowledge int: |
14 | 286 outb(0x20, 0x20); // EOI to master |
287 } | |
288 | |
289 void INT33handler() | |
290 { | |
291 //printf("INT33 called, key pressed????\n"); | |
292 unsigned char scancode = inb(0x60); | |
293 //printf("Scancode = 0x%x\n", scancode); | |
294 keyboardDriverUpdate(scancode); | |
295 outb(0x20, 0x20); // EOI to master | |
296 } | |
297 | |
298 void INT34handler() | |
299 { | |
300 printf("INT34 called!\n"); | |
301 } | |
302 | |
303 void INTDEF_handler() | |
304 { | |
305 printf("Default int handler called\n"); | |
306 } | |
307 | |
308 |