comparison cos/kernel/handlers.c @ 36:91f91ff07ea8

Removed test variables
author windel
date Mon, 16 Jan 2012 20:47:05 +0100
parents d8185ddb6c7b
children 24ce177e01e8
comparison
equal deleted inserted replaced
35:bcb3b68c8147 36:91f91ff07ea8
43 IDT_entry *idt = (IDT_entry*)0x5000; 43 IDT_entry *idt = (IDT_entry*)0x5000;
44 volatile idtPointer idtP; 44 volatile idtPointer idtP;
45 45
46 void setIDTentry(int num, void (*handler)(), uint16_t selector, uint8_t flags) 46 void setIDTentry(int num, void (*handler)(), uint16_t selector, uint8_t flags)
47 { 47 {
48 // Fill one entry with IDT info: 48 // Fill one entry with IDT info:
49 uint64_t offset; 49 uint64_t offset;
50 50
51 // Typecast the function pointer to a number: 51 // Typecast the function pointer to a number:
52 offset = (uint64_t)handler; 52 offset = (uint64_t)handler;
53 53
54 // Set offset: 54 // Set offset:
55 idt[num].baseLow = offset & 0xFFFF; 55 idt[num].baseLow = offset & 0xFFFF;
56 idt[num].baseMid = (offset >> 16) & 0xFFFF; 56 idt[num].baseMid = (offset >> 16) & 0xFFFF;
57 idt[num].baseHigh = (offset >> 32) & 0xFFFFFFFF; 57 idt[num].baseHigh = (offset >> 32) & 0xFFFFFFFF;
58 58
59 // Set flags and selector: 59 // Set flags and selector:
60 idt[num].selector = selector; 60 idt[num].selector = selector;
61 idt[num].flags = flags; 61 idt[num].flags = flags;
62 62
63 // Set reserved fields: 63 // Set reserved fields:
64 idt[num].reserved1 = 0; 64 idt[num].reserved1 = 0;
65 idt[num].reserved2 = 0; 65 idt[num].reserved2 = 0;
66 } 66 }
67 67
68 void setupIDT(void) { 68 void setupIDT(void) {
69 int i; 69 int i;
70 70
147 147
148 outb(0x21, maskmaster); 148 outb(0x21, maskmaster);
149 outb(0xA1, maskslave); 149 outb(0xA1, maskslave);
150 } 150 }
151 151
152 /* Function that prints the contents of all registers
153 on the interrupted stack. */
154 void display_registers(uint64_t *regs)
155 {
156 // Pushed by interrupt handler assembler:
157 printf("rax: %x\n", regs[6]);
158 printf("rbx: %x\n", regs[3]);
159 printf("rcx: %x\n", regs[5]);
160 printf("rdx: %x\n", regs[4]);
161 printf("rsi: %x\n", regs[1]);
162 printf("rdi: %x\n", regs[0]);
163 printf("rbp: %x\n", regs[2]);
164 // Pushed by CPU:
165 printf("rip: %x\n", regs[9]);
166 }
167
152 void gp_fault(uint64_t *regs) 168 void gp_fault(uint64_t *regs)
153 { 169 {
154 printf("GP fault\n"); 170 printf("GP fault\n");
155 printf("Error code: %x\n", regs[8]); 171 printf("Error code: %x\n", regs[8]);
156 printf("RIP: %x\n", regs[9]); 172 display_registers(regs);
157 panic("No resolution to general protection fault!"); 173 panic("No resolution to general protection fault!");
158 } 174 }
159 175
160 void page_fault(uint64_t *regs) 176 void page_fault(uint64_t *regs)
161 { 177 {
162 printf("Page fault\n"); 178 printf("Page fault\n");
163 uint64_t faulting_address; 179 uint64_t faulting_address;
164 asm volatile("mov %%cr2, %0" : "=r" (faulting_address)); 180 asm volatile("mov %%cr2, %0" : "=r" (faulting_address));
165 printf("Error code: %x\n", regs[8]); 181 printf("Error code: %x\n", regs[8]);
166 printf("RIP: %x\n", regs[9]); 182 display_registers(regs);
167 printf("Faulting address: %x\n", faulting_address); 183 printf("Faulting address: %x\n", faulting_address);
168 panic("No resolution to page fault!"); 184 panic("No resolution to page fault!");
169 185
170 } 186 }
171 // Global isr handler: 187 // Global isr handler: