285 lines
5.5 KiB
C
285 lines
5.5 KiB
C
#include "../include/idt.h"
|
|
#include "../include/isr.h"
|
|
#include "../include/types.h"
|
|
#include "../include/pic.h"
|
|
#include "../include/pit.h"
|
|
#include "../include/keyboard.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
typedef size_t uword_t;
|
|
struct interrupt_frame
|
|
{
|
|
uword_t ip;
|
|
uword_t cs;
|
|
uword_t flags;
|
|
uword_t sp;
|
|
uword_t ss;
|
|
};
|
|
|
|
__attribute__((interrupt)) void isr_timer(struct interrupt_frame *frame);
|
|
void isr_custom();
|
|
void default_handler();
|
|
|
|
void isr_install() {
|
|
idt_set_descriptor(0, (uint32)isr0, 0x8E);
|
|
idt_set_descriptor(1, (uint32)isr1, 0x8E);
|
|
idt_set_descriptor(2, (uint32)isr2, 0x8E);
|
|
idt_set_descriptor(3, (uint32)isr3, 0x8E);
|
|
idt_set_descriptor(4, (uint32)isr4, 0x8E);
|
|
idt_set_descriptor(5, (uint32)isr5, 0x8E);
|
|
idt_set_descriptor(6, (uint32)isr6, 0x8E);
|
|
idt_set_descriptor(7, (uint32)isr7, 0x8E);
|
|
idt_set_descriptor(8, (uint32)isr8, 0x8E);
|
|
idt_set_descriptor(9, (uint32)isr9, 0x8E);
|
|
idt_set_descriptor(10, (uint32)isr10, 0x8E);
|
|
idt_set_descriptor(11, (uint32)isr11, 0x8E);
|
|
idt_set_descriptor(12, (uint32)isr12, 0x8E);
|
|
idt_set_descriptor(13, (uint32)isr13, 0x8E);
|
|
idt_set_descriptor(14, (uint32)isr14, 0x8E);
|
|
idt_set_descriptor(15, (uint32)isr15, 0x8E);
|
|
idt_set_descriptor(16, (uint32)isr16, 0x8E);
|
|
idt_set_descriptor(17, (uint32)isr17, 0x8E);
|
|
idt_set_descriptor(18, (uint32)isr18, 0x8E);
|
|
idt_set_descriptor(19, (uint32)isr19, 0x8E);
|
|
idt_set_descriptor(20, (uint32)isr20, 0x8E);
|
|
idt_set_descriptor(21, (uint32)isr21, 0x8E);
|
|
idt_set_descriptor(22, (uint32)isr22, 0x8E);
|
|
idt_set_descriptor(23, (uint32)isr23, 0x8E);
|
|
idt_set_descriptor(24, (uint32)isr24, 0x8E);
|
|
idt_set_descriptor(25, (uint32)isr25, 0x8E);
|
|
idt_set_descriptor(26, (uint32)isr26, 0x8E);
|
|
idt_set_descriptor(27, (uint32)isr27, 0x8E);
|
|
idt_set_descriptor(28, (uint32)isr28, 0x8E);
|
|
idt_set_descriptor(29, (uint32)isr29, 0x8E);
|
|
idt_set_descriptor(30, (uint32)isr30, 0x8E);
|
|
idt_set_descriptor(31, (uint32)isr31, 0x8E);
|
|
|
|
for(int i = 32; i < 255; i++)
|
|
idt_set_descriptor(i, (uint32)default_handler, 0x8E);
|
|
|
|
idt_set_descriptor(0x20, (uint32)isr_timer, 0x8E);
|
|
idt_set_descriptor(0x21, (uint32)isr_custom, 0x8E);
|
|
|
|
|
|
idt_set(); // Load with ASM
|
|
printf("isr_install done\n");
|
|
}
|
|
|
|
void default_handler()
|
|
{
|
|
|
|
}
|
|
|
|
__attribute__((interrupt)) void isr_timer(struct interrupt_frame *frame)
|
|
{
|
|
pit_init(100);
|
|
pic_end_int(0x0);
|
|
}
|
|
|
|
__attribute__((interrupt)) void isr_custom(struct interrupt_frame *frame)
|
|
{
|
|
//terminal_writestring("YOOOOO!!!!!! I LOVE KATYA!!!!");
|
|
handle_keyboard();
|
|
pic_end_int(0x1);
|
|
}
|
|
|
|
void isr0()
|
|
{
|
|
printf(exception_messages[0]);
|
|
asm("hlt");
|
|
}
|
|
void isr1()
|
|
{
|
|
printf(exception_messages[1]);
|
|
asm("hlt");
|
|
}
|
|
void isr2()
|
|
{
|
|
printf(exception_messages[2]);
|
|
asm("hlt");
|
|
}
|
|
void isr3()
|
|
{
|
|
printf(exception_messages[3]);
|
|
asm("hlt");
|
|
}
|
|
void isr4()
|
|
{
|
|
printf(exception_messages[4]);
|
|
asm("hlt");
|
|
}
|
|
void isr5()
|
|
{
|
|
printf(exception_messages[5]);
|
|
asm("hlt");
|
|
}
|
|
void isr6()
|
|
{
|
|
printf(exception_messages[6]);
|
|
asm("hlt");
|
|
}
|
|
void isr7()
|
|
{
|
|
printf(exception_messages[7]);
|
|
asm("hlt");
|
|
}
|
|
void isr8()
|
|
{
|
|
printf(exception_messages[8]);
|
|
asm("hlt");
|
|
}
|
|
void isr9()
|
|
{
|
|
printf(exception_messages[9]);
|
|
asm("hlt");
|
|
}
|
|
void isr10()
|
|
{
|
|
printf(exception_messages[10]);
|
|
asm("hlt");
|
|
}
|
|
void isr11()
|
|
{
|
|
printf(exception_messages[11]);
|
|
asm("hlt");
|
|
}
|
|
void isr12()
|
|
{
|
|
printf(exception_messages[12]);
|
|
asm("hlt");
|
|
}
|
|
void isr13()
|
|
{
|
|
printf(exception_messages[13]);
|
|
asm("hlt");
|
|
}
|
|
void isr14()
|
|
{
|
|
printf(exception_messages[14]);
|
|
asm("hlt");
|
|
}
|
|
void isr15()
|
|
{
|
|
printf(exception_messages[15]);
|
|
asm("hlt");
|
|
}
|
|
void isr16()
|
|
{
|
|
printf(exception_messages[16]);
|
|
asm("hlt");
|
|
}
|
|
void isr17()
|
|
{
|
|
printf(exception_messages[17]);
|
|
asm("hlt");
|
|
}
|
|
void isr18()
|
|
{
|
|
printf(exception_messages[18]);
|
|
asm("hlt");
|
|
}
|
|
void isr19()
|
|
{
|
|
printf(exception_messages[19]);
|
|
asm("hlt");
|
|
}
|
|
void isr20()
|
|
{
|
|
printf(exception_messages[20]);
|
|
asm("hlt");
|
|
}
|
|
void isr21()
|
|
{
|
|
printf(exception_messages[21]);
|
|
asm("hlt");
|
|
}
|
|
void isr22()
|
|
{
|
|
printf(exception_messages[22]);
|
|
asm("hlt");
|
|
}
|
|
void isr23()
|
|
{
|
|
printf(exception_messages[23]);
|
|
asm("hlt");
|
|
}
|
|
void isr24()
|
|
{
|
|
printf(exception_messages[24]);
|
|
asm("hlt");
|
|
}
|
|
void isr25()
|
|
{
|
|
printf(exception_messages[25]);
|
|
asm("hlt");
|
|
}
|
|
void isr26()
|
|
{
|
|
printf(exception_messages[26]);
|
|
asm("hlt");
|
|
}
|
|
void isr27()
|
|
{
|
|
printf(exception_messages[27]);
|
|
asm("hlt");
|
|
}
|
|
void isr28()
|
|
{
|
|
printf(exception_messages[28]);
|
|
asm("hlt");
|
|
}
|
|
void isr29()
|
|
{
|
|
printf(exception_messages[29]);
|
|
asm("hlt");
|
|
}
|
|
void isr30()
|
|
{
|
|
printf(exception_messages[30]);
|
|
asm("hlt");
|
|
}
|
|
void isr31()
|
|
{
|
|
printf(exception_messages[31]);
|
|
asm("hlt");
|
|
}
|
|
|
|
static string exception_messages[] = {
|
|
"Division By Zero",
|
|
"Debug",
|
|
"Non Maskable Interrupt",
|
|
"Breakpoint",
|
|
"Into Detected Overflow",
|
|
"Out of Bounds",
|
|
"Invalid Opcode",
|
|
"No Coprocessor",
|
|
|
|
"Double Fault",
|
|
"Coprocessor Segment Overrun",
|
|
"Bad TSS",
|
|
"Segment Not Present",
|
|
"Stack Fault",
|
|
"General Protection Fault",
|
|
"Page Fault",
|
|
"Unknown Interrupt",
|
|
|
|
"Coprocessor Fault",
|
|
"Alignment Check",
|
|
"Machine Check",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved"
|
|
};
|