k-tana-zero/k/idt.h

62 lines
1.5 KiB
C
Raw Normal View History

#ifndef IDT_H
#define IDT_H
#include <stdint.h>
#include "gdt.h"
#include "isr.h"
2021-07-15 14:53:58 +00:00
#define IDT_NB_ENTRIES 34
#define IDT_SIZE (IDT_NB_ENTRIES * sizeof(struct idt_entry))
2021-07-15 14:53:58 +00:00
#define INTEL_DEFINED 21
#define INTEL_UNUSED 31
#define INTERRUPT_TYPE 0x6
#define TRAP_TYPE 0x7
struct idt_entry
{
2021-07-15 02:55:18 +00:00
uint16_t offset_1 : 16; // 16 lsb of isr address
struct segment_selector selector;
uint8_t zero_1 : 8; // unused, set to 0
uint8_t type : 3; // gate type
2021-07-15 02:55:18 +00:00
uint8_t size : 1; // 0 => 16-bits 1 => 32-bits
uint8_t zero_2 : 1; // set to 0 for interrupt and trap gates
2021-07-15 02:55:18 +00:00
uint8_t desc_priv : 2; // descriptor privilege
uint8_t present : 1; // always 1
2021-07-15 02:55:18 +00:00
uint16_t offset_2 : 16; // 16 msb of isr address
} __attribute__ ((packed));
struct idt
{
struct idt_entry entries[IDT_NB_ENTRIES];
};
struct idt_r
{
2021-07-15 02:55:18 +00:00
uint16_t limit; // total size of the IDT - 1 in bytes
uint32_t addr; // base address of the IDT
} __attribute__ ((packed));
// This struct is used to get int_code and err_code pushed to the stack
// by the isr.
2021-07-15 02:55:18 +00:00
struct int_args
{
uint32_t int_code;
uint32_t err_code;
} __attribute__ ((packed));
// This struct is used to know how to fill the idt entries
struct idt_entry_info
{
void (*isr)(void); // function pointer on interrupt service routine (isr)
uint32_t type; // gate type
};
void init_idt(void);
void handle_interrupt(struct int_args *args);
#endif /* !IDT_H */