2021-07-14 19:32:15 +00:00
|
|
|
#include "idt.h"
|
|
|
|
|
|
|
|
static struct idt idt = { 0 };
|
|
|
|
|
2021-07-15 02:42:11 +00:00
|
|
|
struct idt_entry_info infos[] = {
|
|
|
|
{int_de, INTERRUPT_TYPE}, {int_db, INTERRUPT_TYPE},
|
|
|
|
{int_nmi, INTERRUPT_TYPE}, {int_bp, TRAP_TYPE},
|
|
|
|
{int_of, TRAP_TYPE}, {int_br, INTERRUPT_TYPE},
|
|
|
|
{int_ud, INTERRUPT_TYPE}, {int_nm, INTERRUPT_TYPE},
|
|
|
|
{int_df, INTERRUPT_TYPE}, {0, INTERRUPT_TYPE},
|
|
|
|
{int_ts, INTERRUPT_TYPE}, {int_np, INTERRUPT_TYPE},
|
|
|
|
{int_ss, INTERRUPT_TYPE}, {int_gp, INTERRUPT_TYPE},
|
|
|
|
{int_pf, INTERRUPT_TYPE}, {0, INTERRUPT_TYPE},
|
|
|
|
{int_mf, INTERRUPT_TYPE}, {int_ac, INTERRUPT_TYPE},
|
|
|
|
{int_mc, INTERRUPT_TYPE}, {int_xm, INTERRUPT_TYPE},
|
|
|
|
{int_ve, INTERRUPT_TYPE}
|
|
|
|
};
|
|
|
|
|
|
|
|
void handle_interrupt(struct int_args args)
|
2021-07-14 20:57:38 +00:00
|
|
|
{
|
2021-07-15 02:42:11 +00:00
|
|
|
printf("INTERRUPT\r\n");
|
2021-07-14 20:57:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:42:11 +00:00
|
|
|
static struct idt_entry create_idt_entry(uint32_t offset,
|
|
|
|
struct segment_selector selector,
|
|
|
|
uint32_t type)
|
2021-07-14 20:57:38 +00:00
|
|
|
{
|
|
|
|
struct idt_entry res = { 0 };
|
|
|
|
|
|
|
|
res.selector = selector;
|
|
|
|
res.offset_1 = offset & 0xffff;
|
|
|
|
res.offset_2 = (offset >> 16) & 0xffff;
|
|
|
|
|
2021-07-15 02:42:11 +00:00
|
|
|
res.type = type;
|
2021-07-14 20:57:38 +00:00
|
|
|
res.size = 1;
|
|
|
|
res.desc_priv = 0;
|
|
|
|
res.present = 1;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_idt(void)
|
|
|
|
{
|
|
|
|
struct segment_selector selector;
|
|
|
|
selector.rpl = 0;
|
|
|
|
selector.table_indicator = 0;
|
|
|
|
selector.index = KERNEL_CS_INDEX;
|
|
|
|
for (int i = 0; i < IDT_NB_ENTRIES; ++i)
|
|
|
|
{
|
2021-07-15 02:42:11 +00:00
|
|
|
struct idt_entry entry = create_idt_entry((uint32_t)infos[i].isr,
|
|
|
|
selector,
|
|
|
|
infos[i].type);
|
2021-07-14 20:57:38 +00:00
|
|
|
idt.entries[i] = entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void load_idt(void)
|
2021-07-14 19:32:15 +00:00
|
|
|
{
|
|
|
|
struct idt_r idtr;
|
|
|
|
idtr.addr = (uint32_t)&idt;
|
|
|
|
idtr.limit = IDT_SIZE - 1;
|
|
|
|
|
|
|
|
asm volatile("lidt %0\n"
|
|
|
|
:
|
|
|
|
: "m" (idtr)
|
|
|
|
: "memory");
|
|
|
|
}
|
|
|
|
|
2021-07-14 20:57:38 +00:00
|
|
|
void init_idt(void)
|
2021-07-14 19:32:15 +00:00
|
|
|
{
|
2021-07-14 20:57:38 +00:00
|
|
|
create_idt();
|
2021-07-14 19:32:15 +00:00
|
|
|
load_idt();
|
|
|
|
}
|