os/idt.c

44 lines
835 B
C
Raw Normal View History

2024-05-21 18:41:16 +03:00
#include "idt.h"
#include "io.h"
2024-05-22 00:15:05 +03:00
#include "string.h"
2024-05-21 18:41:16 +03:00
#include <stdint.h>
#define IDT_ENTRIES 256
2024-05-22 00:15:05 +03:00
struct idt_entry
{
2024-05-21 18:41:16 +03:00
uint16_t base_lo;
uint16_t sel;
uint8_t always0;
uint8_t flags;
uint16_t base_hi;
} __attribute__((packed));
2024-05-22 00:15:05 +03:00
struct idt_ptr
{
2024-05-21 18:41:16 +03:00
uint16_t limit;
uint32_t base;
} __attribute__((packed));
struct idt_entry idt[IDT_ENTRIES];
struct idt_ptr idtp;
2024-05-22 00:15:05 +03:00
void idt_set_gate(uint8_t num, uint32_t base, uint16_t sel, uint8_t flags)
{
2024-05-21 18:41:16 +03:00
idt[num].base_lo = base & 0xFFFF;
idt[num].base_hi = (base >> 16) & 0xFFFF;
idt[num].sel = sel;
idt[num].always0 = 0;
idt[num].flags = flags | 0x60;
}
2024-05-22 00:15:05 +03:00
void idt_install()
{
2024-05-21 18:41:16 +03:00
idtp.limit = (sizeof(struct idt_entry) * IDT_ENTRIES) - 1;
idtp.base = (uint32_t)&idt;
2024-05-22 00:15:05 +03:00
memset(&idt, 0, sizeof(struct idt_entry) * IDT_ENTRIES);
2024-05-21 18:41:16 +03:00
2024-05-22 00:15:05 +03:00
idt_load();
}