This commit is contained in:
Starnakin 2024-09-30 13:01:56 +02:00
parent ab702aabe7
commit 0c540a11da
2 changed files with 45 additions and 0 deletions

9
headers/idt.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
// doc : https://wiki.osdev.org/Interrupt_Descriptor_Table#IDTR
struct {
uint16_t size;
uint32_t offset;
} __attribute__((packed)) idt_descriptor;
#define IDT_SIZE 256

36
src/interrupt/idt.c Normal file
View File

@ -0,0 +1,36 @@
#include <stdbool.h>
#include <stdint.h>
#include "idt.h"
uint16_t idt_entries[IDT_SIZE * 4];
struct idt_descriptor *idtr = (struct gdt_descriptor *)GDT_ADDRESS;
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 << 16;
// Encode the CPU Privilege Levels
target[1] = (0b11 << 14) & dpl;
target[1] &= ~(1 << 13);
// 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;
}