164 lines
6.2 KiB
C
164 lines
6.2 KiB
C
#include <system.h>
|
|
#include <console.h>
|
|
|
|
extern void isr0();
|
|
extern void isr1();
|
|
extern void isr2();
|
|
extern void isr3();
|
|
extern void isr4();
|
|
extern void isr5();
|
|
extern void isr6();
|
|
extern void isr7();
|
|
extern void isr8();
|
|
extern void isr9();
|
|
extern void isr10();
|
|
extern void isr11();
|
|
extern void isr12();
|
|
extern void isr13();
|
|
extern void isr14();
|
|
extern void isr15();
|
|
extern void isr16();
|
|
extern void isr17();
|
|
extern void isr18();
|
|
extern void isr19();
|
|
extern void isr20();
|
|
extern void isr21();
|
|
extern void isr22();
|
|
extern void isr23();
|
|
extern void isr24();
|
|
extern void isr25();
|
|
extern void isr26();
|
|
extern void isr27();
|
|
extern void isr28();
|
|
extern void isr29();
|
|
extern void isr30();
|
|
extern void isr31();
|
|
|
|
/* This is a very repetitive function... it's not hard, it's
|
|
* just annoying. As you can see, we set the first 32 entries
|
|
* in the IDT to the first 32 ISRs. We can't use a for loop
|
|
* for this, because there is no way to get the function names
|
|
* that correspond to that given entry. We set the access
|
|
* flags to 0x8E. This means that the entry is present, is
|
|
* running in ring 0 (kernel level), and has the lower 5 bits
|
|
* set to the required '14', which is represented by 'E' in
|
|
* hex. */
|
|
void isrs_install()
|
|
{
|
|
idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E);
|
|
idt_set_gate(1, (unsigned)isr1, 0x08, 0x8E);
|
|
idt_set_gate(2, (unsigned)isr2, 0x08, 0x8E);
|
|
idt_set_gate(3, (unsigned)isr3, 0x08, 0x8E);
|
|
idt_set_gate(4, (unsigned)isr4, 0x08, 0x8E);
|
|
idt_set_gate(5, (unsigned)isr5, 0x08, 0x8E);
|
|
idt_set_gate(6, (unsigned)isr6, 0x08, 0x8E);
|
|
idt_set_gate(7, (unsigned)isr7, 0x08, 0x8E);
|
|
idt_set_gate(8, (unsigned)isr8, 0x08, 0x8E);
|
|
idt_set_gate(9, (unsigned)isr9, 0x08, 0x8E);
|
|
idt_set_gate(10, (unsigned)isr10, 0x08, 0x8E);
|
|
idt_set_gate(11, (unsigned)isr11, 0x08, 0x8E);
|
|
idt_set_gate(12, (unsigned)isr12, 0x08, 0x8E);
|
|
idt_set_gate(13, (unsigned)isr13, 0x08, 0x8E);
|
|
idt_set_gate(14, (unsigned)isr14, 0x08, 0x8E);
|
|
idt_set_gate(15, (unsigned)isr15, 0x08, 0x8E);
|
|
idt_set_gate(16, (unsigned)isr16, 0x08, 0x8E);
|
|
idt_set_gate(17, (unsigned)isr17, 0x08, 0x8E);
|
|
idt_set_gate(18, (unsigned)isr18, 0x08, 0x8E);
|
|
idt_set_gate(19, (unsigned)isr19, 0x08, 0x8E);
|
|
idt_set_gate(20, (unsigned)isr20, 0x08, 0x8E);
|
|
idt_set_gate(21, (unsigned)isr21, 0x08, 0x8E);
|
|
idt_set_gate(22, (unsigned)isr22, 0x08, 0x8E);
|
|
idt_set_gate(23, (unsigned)isr23, 0x08, 0x8E);
|
|
idt_set_gate(24, (unsigned)isr24, 0x08, 0x8E);
|
|
idt_set_gate(25, (unsigned)isr25, 0x08, 0x8E);
|
|
idt_set_gate(26, (unsigned)isr26, 0x08, 0x8E);
|
|
idt_set_gate(27, (unsigned)isr27, 0x08, 0x8E);
|
|
idt_set_gate(28, (unsigned)isr28, 0x08, 0x8E);
|
|
idt_set_gate(29, (unsigned)isr29, 0x08, 0x8E);
|
|
idt_set_gate(30, (unsigned)isr30, 0x08, 0x8E);
|
|
idt_set_gate(31, (unsigned)isr31, 0x08, 0x8E);
|
|
}
|
|
|
|
char *exception_messages[] = {
|
|
"Division By Zero Exception",
|
|
"Debug Exception",
|
|
"Non Maskable Interrupt Exception",
|
|
"Breakpoint Exception",
|
|
"Into Detected Overflow Exception",
|
|
"Out of Bounds Exception",
|
|
"Invalid Opcode Exception",
|
|
"No Coprocessor",
|
|
"Double Fault Exception",
|
|
"Coprocessor Segment Overrun Exception",
|
|
"Bad TSS Exception",
|
|
"Segment Not Present Exception",
|
|
"Stack Fault Exception",
|
|
"General Protection Fault Exception",
|
|
"Page Fault Exception",
|
|
"Unknown Interrupt Exception",
|
|
"Coprocessor Fault Exception",
|
|
"Alignment Check Exception",
|
|
"Machine Check Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception",
|
|
"Reserved Exception"
|
|
};
|
|
|
|
|
|
/* All of our Exception handling Interrupt Service Routines will
|
|
* point to this function. This will tell us what exception has
|
|
* happened! Right now, we simply halt the system by hitting an
|
|
* endless loop. All ISRs disable interrupts while they are being
|
|
* serviced as a 'locking' mechanism to prevent an IRQ from
|
|
* happening and messing up kernel data structures */
|
|
void fault_handler(regs *r)
|
|
{
|
|
/* Is this a fault whose number is from 0 to 31? */
|
|
if (r->int_no < 32)
|
|
{
|
|
/* Display the description for the Exception that occurred.*/
|
|
|
|
// Put on the BSOD screen
|
|
set_default_colors (0x01, 0x0F); clrscr();
|
|
puts (" Blue Screen Of Death\n");
|
|
int i; for (i = 79; i>=0; i--) putc('=');
|
|
puts_pos_font (15, 2, "A fatal error has occured, CTA OS has been halted.", 0x01, 0x0C);
|
|
puts_pos_font (10, 4, "gs", 0x01, 0x0B); put_hex(15, 4, r->gs);
|
|
puts_pos_font (10, 5, "fs", 0x01, 0x0B); put_hex(15, 5, r->fs);
|
|
puts_pos_font (10, 6, "es", 0x01, 0x0B); put_hex(15, 6, r->es);
|
|
puts_pos_font (10, 7, "ds", 0x01, 0x0B); put_hex(15, 7, r->ds);
|
|
|
|
puts_pos_font (40, 4, "edi", 0x01, 0x0B); put_hex(45, 4, r->edi);
|
|
puts_pos_font (40, 5, "esi", 0x01, 0x0B); put_hex(45, 5, r->esi);
|
|
puts_pos_font (40, 6, "ebp", 0x01, 0x0B); put_hex(45, 6, r->ebp);
|
|
puts_pos_font (40, 7, "esp", 0x01, 0x0B); put_hex(45, 7, r->esp);
|
|
|
|
puts_pos_font (10, 9, "eax", 0x01, 0x0B); put_hex(15, 9, r->eax);
|
|
puts_pos_font (10, 10, "ebx", 0x01, 0x0B); put_hex(15, 10, r->ebx);
|
|
puts_pos_font (40, 9, "ecx", 0x01, 0x0B); put_hex(45, 9, r->ecx);
|
|
puts_pos_font (40, 10, "edx", 0x01, 0x0B); put_hex(45, 10, r->edx);
|
|
|
|
puts_pos_font (10, 12, "int_no", 0x01, 0x0B); put_hex(17, 12, r->int_no);
|
|
puts_pos_font (10, 14, "Error code:", 0x01, 0x0B); put_hex(24, 14, r->err_code);
|
|
puts_pos_font (10, 15, "Error msg: ", 0x01, 0x0B); puts_pos(24, 15, exception_messages[r->int_no]);
|
|
|
|
puts_pos_font (10, 17, "eip", 0x01, 0x0B); put_hex(17, 17, r->eip);
|
|
puts_pos_font (10, 18, "cs", 0x01, 0x0B); put_hex(17, 18, r->cs);
|
|
puts_pos_font (10, 19, "eflags", 0x01, 0x0B); put_hex(17, 19, r->eflags);
|
|
puts_pos_font (10, 20, "useresp", 0x01, 0x0B); put_hex(17, 20, r->useresp);
|
|
puts_pos_font (10, 21, "ss", 0x01, 0x0B); put_hex(17, 21, r->ss);
|
|
|
|
puts_pos_font (29, 24, "!!! System Halted !!!", 0x01, 0x0C);
|
|
for (;;);
|
|
}
|
|
}
|