comparison 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
comparison
equal deleted inserted replaced
23:5dd47d6eebac 24:d8627924d40d
1 #include "kernel.h" 1 #include "kernel.h"
2
3 void panic(char *msg) {
4 printf("Kernel panic: ");
5 printf(msg);
6 magicBochsBreak();
7 halt();
8 }
9 2
10 // Assembler wrapper prototypes: 3 // Assembler wrapper prototypes:
11 void INTDEF(void); 4 void INTDEF(void);
12 void INT0(void); 5 void INT0(void);
13 void INT1(void); 6 void INT1(void);
33 void INT32(void); 26 void INT32(void);
34 void INT33(void); 27 void INT33(void);
35 void INT34(void); 28 void INT34(void);
36 29
37 // THE interrupt descriptor table: 30 // THE interrupt descriptor table:
38 IDT_entry *idt = (IDT_entry*)0x0; 31 IDT_entry *idt = (IDT_entry*)0x5000;
39 volatile idtPointer idtP; 32 volatile idtPointer idtP;
40 33
41 void setIDTentry(int num, void (*handler)(), uint16_t selector, uint8_t flags) 34 void setIDTentry(int num, void (*handler)(), uint16_t selector, uint8_t flags)
42 { 35 {
43 // Fill one entry with IDT info: 36 // Fill one entry with IDT info:
44 uint64_t offset; 37 uint64_t offset;
45 38
46 // Typecast the function pointer to a number: 39 // Typecast the function pointer to a number:
47 offset = (uint64_t)handler; 40 offset = (uint64_t)handler;
41
42 //panic("Almost setting an IDT entry");
48 43
49 // Set offset: 44 // Set offset:
50 idt[num].baseLow = offset & 0xFFFF; 45 idt[num].baseLow = offset & 0xFFFF;
51 idt[num].baseMid = (offset >> 16) & 0xFFFF; 46 idt[num].baseMid = (offset >> 16) & 0xFFFF;
52 idt[num].baseHigh = (offset >> 32) & 0xFFFFFFFF; 47 idt[num].baseHigh = (offset >> 32) & 0xFFFFFFFF;
60 idt[num].reserved2 = 0; 55 idt[num].reserved2 = 0;
61 } 56 }
62 57
63 void setupIDT(void) { 58 void setupIDT(void) {
64 int i; 59 int i;
60 //panic("Just before filling IDT");
61 // After this line a crash occurs!
65 // Fill all vectors with the default handler: 62 // Fill all vectors with the default handler:
66 for (i=0; i<256; i++) { 63 for (i=0; i<256; i++) {
67 setIDTentry(i, &INTDEF, 0x08, 0x8E); 64 setIDTentry(i, INTDEF, 0x08, 0x8E);
68 } 65 }
66 //panic("Just after setting defhandlers in IDT");
69 67
70 // Now set other then default handler: 68 // Now set other then default handler:
71 setIDTentry(0, INT0, 0x08, 0x8E); 69 setIDTentry(0, INT0, 0x08, 0x8E);
72 setIDTentry(1, INT1, 0x08, 0x8E); 70 setIDTentry(1, INT1, 0x08, 0x8E);
73 setIDTentry(2, INT2, 0x08, 0x8E); 71 setIDTentry(2, INT2, 0x08, 0x8E);
96 94
97 // Set the correct values in the IDT pointer: 95 // Set the correct values in the IDT pointer:
98 idtP.base = (uint64_t)idt; 96 idtP.base = (uint64_t)idt;
99 idtP.limit = (sizeof(IDT_entry) * 256) - 1; 97 idtP.limit = (sizeof(IDT_entry) * 256) - 1;
100 // call load IDT asm function: 98 // call load IDT asm function:
99 //panic("Just before LIDT");
101 loadIDT(); 100 loadIDT();
102 101
103 PICremap(); 102 PICremap();
103 //panic("Just before sti");
104 asm("sti"); 104 asm("sti");
105 } 105 }
106 106
107 // PIC functions: 107 // PIC functions:
108 void PICremap() { 108 void PICremap() {