rk/include/kernel/idt.h
2024-05-26 01:33:18 -05:00

53 lines
1.1 KiB
C

#ifndef RK_IDT_H_
#define RK_IDT_H_
#include <stdint.h>
#define GDT_SEGMENT_SELECTOR(i, p) ((i << 3) | p)
#define LDT_SEGMENT_SELECTOR(i, p) ((i << 3) | 0x04 | p)
#define IDT_ENTRY_COUNT 256
struct idt_entry {
uint16_t offset_lo;
uint16_t seg_select;
uint8_t reserved;
uint8_t attributes;
uint16_t offset_hi;
} __attribute__ ((packed));
struct idtr {
uint16_t size;
uint32_t base;
} __attribute__ ((packed));
enum IDT_ATTRIBUTES {
TASK_GATE = 0x05,
INT_GATE_16 = 0x06,
TRAP_GATE_16 = 0x07,
INT_GATE_32 = 0x0E,
TRAP_GATE_32 = 0x0F,
INT_RING0 = 0x00,
INT_RING1 = 0x20,
INT_RING2 = 0x40,
INT_RING3 = 0x60,
INT_PRESENT = 0x80,
};
struct registers {
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; /* Pushed by pusha. */
uint32_t int_no, err_code; /* Interrupt number and error code (if applicable) */
uint32_t eip;
uint32_t cs;
uint32_t eflags;
};
void encode_idt_entry(struct idt_entry idt[], int i, uint32_t offset, uint16_t segment_selector, uint8_t attributes);
void flush_idt(uint32_t idt_pointer);
void exception_handler(struct registers regs);
#endif