hazel/include/kernel/idt.h

55 lines
1.2 KiB
C
Raw Normal View History

2024-07-01 19:28:45 -04:00
#ifndef HAZEL_IDT_H_
#define HAZEL_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,
};
typedef struct {
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;
} int_stack_frame_t;
2024-07-15 14:03:44 -04:00
typedef struct {
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; /* Pushed by pusha. */
} stack_frame_t;
2024-07-01 19:28:45 -04:00
void idt_encode_entry(struct idt_entry idt[], int i, uint32_t offset, uint16_t segment_selector, uint8_t attributes);
#endif