42_KFS/src/interrupt/idt.c

37 lines
741 B
C

#include <stdbool.h>
#include <stdint.h>
#include "idt.h"
uint16_t idt_entries[IDT_SIZE * 4];
struct idt_descriptor idtr;
static void set_idt_entry_value(uint16_t *target, uint32_t offset,
uint16_t selector, uint8_t dpl,
uint8_t gate_type)
{
// Encode the offset
target[0] = offset & 0xFFFF;
target[3] = (offset >> 16) & 0xFFFF;
// Encode the presence
target[1] |= 1 << 15;
// Encode the CPU Privilege Levels
target[1] = (0b11 << 13) & dpl;
target[1] &= ~(1 << 12);
// Encode Gate Type
target[1] |= gate_type & 0x0F00;
// Encode selector
target[2] = selector;
}
void init_idt(void)
{
idtr.size = 8 * IDT_SIZE - 1;
idtr.offset = (uint32_t)&idt_entries;
}