feat(idt): add structs and infos for idt_entry creation

This commit is contained in:
Malo Lecomte 2021-07-15 04:42:11 +02:00
parent 2b3d6372cf
commit a3596f3656
3 changed files with 40 additions and 10 deletions

31
k/idt.c

@ -1,15 +1,30 @@
#include "idt.h"
#include "isr.h"
static struct idt idt = { 0 };
void handle_interrupt()
struct idt_entry_info infos[] = {
{int_de, INTERRUPT_TYPE}, {int_db, INTERRUPT_TYPE},
{int_nmi, INTERRUPT_TYPE}, {int_bp, TRAP_TYPE},
{int_of, TRAP_TYPE}, {int_br, INTERRUPT_TYPE},
{int_ud, INTERRUPT_TYPE}, {int_nm, INTERRUPT_TYPE},
{int_df, INTERRUPT_TYPE}, {0, INTERRUPT_TYPE},
{int_ts, INTERRUPT_TYPE}, {int_np, INTERRUPT_TYPE},
{int_ss, INTERRUPT_TYPE}, {int_gp, INTERRUPT_TYPE},
{int_pf, INTERRUPT_TYPE}, {0, INTERRUPT_TYPE},
{int_mf, INTERRUPT_TYPE}, {int_ac, INTERRUPT_TYPE},
{int_mc, INTERRUPT_TYPE}, {int_xm, INTERRUPT_TYPE},
{int_ve, INTERRUPT_TYPE}
};
void handle_interrupt(struct int_args args)
{
printf("INTERRUPT\r\n");
return;
}
struct idt_entry create_idt_entry(uint32_t offset,
struct segment_selector selector)
static struct idt_entry create_idt_entry(uint32_t offset,
struct segment_selector selector,
uint32_t type)
{
struct idt_entry res = { 0 };
@ -17,7 +32,7 @@ struct idt_entry create_idt_entry(uint32_t offset,
res.offset_1 = offset & 0xffff;
res.offset_2 = (offset >> 16) & 0xffff;
res.type = INTERRUPT_TYPE;
res.type = type;
res.size = 1;
res.desc_priv = 0;
res.present = 1;
@ -33,13 +48,13 @@ static void create_idt(void)
selector.index = KERNEL_CS_INDEX;
for (int i = 0; i < IDT_NB_ENTRIES; ++i)
{
struct idt_entry entry = create_idt_entry((uint32_t)&handle_interrupt,
selector);
struct idt_entry entry = create_idt_entry((uint32_t)infos[i].isr,
selector,
infos[i].type);
idt.entries[i] = entry;
}
}
static void load_idt(void)
{
struct idt_r idtr;

17
k/idt.h

@ -3,11 +3,25 @@
#include <stdint.h>
#include "gdt.h"
#include "isr.h"
#define IDT_NB_ENTRIES 32
#define IDT_NB_ENTRIES 21
#define IDT_SIZE (IDT_NB_ENTRIES * sizeof(struct idt_entry))
#define INTERRUPT_TYPE 0x6
#define TRAP_TYPE 0x7
struct int_args
{
uint32_t int_code;
uint32_t err;
} __attribute__ ((packed));
struct idt_entry_info
{
void (*isr)(void);
uint32_t type;
};
struct idt_entry
{
@ -36,5 +50,6 @@ struct idt_r
} __attribute__ ((packed));
void init_idt(void);
void handle_interrupt(struct int_args args);
#endif /* !IDT_H */

@ -4,7 +4,7 @@ isr:
pushal // save registers
pushl %esp
call generic_c_handler
call handle_interrupt
add $4, %esp
popal // restore registers