#include <it.h>
#include <panic.h>
#include <gdt.h>
#include <system.h>
#include <system_data_structs.h>
#include <system_structs.h>
#include <asm.h>
static struct descr_struct idt[256];
static void set_interrupt_gate(unsigned int index, int dpl, void *handler)
{
struct descr_data_struct ig_dat;
ig_dat.type = 0;
ig_dat.system_type = SDT_386INTGT;
ig_dat.dpl = dpl;
ig_dat.present = 1;
ig_dat.selector = KERNEL_CODE_SEL;
ig_dat.offset = (unsigned long)handler;
set_descr(&idt[index], &ig_dat);
}
static void set_trap_gate(unsigned int index, int dpl, void *handler)
{
struct descr_data_struct tg_dat;
tg_dat.type = 0;
tg_dat.system_type = SDT_386TRAPGT;
tg_dat.dpl = dpl;
tg_dat.present = 1;
tg_dat.selector = KERNEL_CODE_SEL;
tg_dat.offset = (unsigned long)handler;
set_descr(&idt[index], &tg_dat);
}
void setup_idt()
{
struct __attribute__ ((packed)) {
unsigned short limit;
unsigned long base;
} idt_descr;
unsigned int i;
for (i = 0; i <= 31; i++)
set_interrupt_gate(i, 0, die);
for (i = 32; i <= 255; i++)
set_interrupt_gate(i, 0, ignore_it);
idt_descr.limit = sizeof idt - 1;
idt_descr.base = (unsigned long)idt;
lidt(idt_descr);
}
void idt_set_trap_gate(unsigned int id, void *handler)
{
set_trap_gate(id, 0, handler);
}
void idt_set_interrupt_gate(unsigned int id, void *handler)
{
set_interrupt_gate(id, 0, handler);
}
void idt_set_system_gate(unsigned int id, void *handler)
{
set_trap_gate(id, 3, handler);
}