2024-05-22 12:25:52 -04:00
|
|
|
#ifndef RK_IDT_H_
|
|
|
|
#define RK_IDT_H_
|
2024-05-21 22:07:04 -04:00
|
|
|
|
|
|
|
#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,
|
|
|
|
};
|
|
|
|
|
2024-05-24 19:53:28 -04:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2024-05-21 22:07:04 -04:00
|
|
|
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);
|
2024-05-24 19:53:28 -04:00
|
|
|
void exception_handler(struct registers regs);
|
2024-05-21 22:07:04 -04:00
|
|
|
|
2024-05-27 14:18:37 -04:00
|
|
|
void interrupts_init(struct idt_entry idt[], struct idtr idtr);
|
|
|
|
|
2024-05-21 22:07:04 -04:00
|
|
|
#endif
|