From a3596f3656193584f596ad93c97ce61914f53050 Mon Sep 17 00:00:00 2001 From: Malo Lecomte Date: Thu, 15 Jul 2021 04:42:11 +0200 Subject: [PATCH] feat(idt): add structs and infos for idt_entry creation --- k/idt.c | 31 +++++++++++++++++++++++-------- k/idt.h | 17 ++++++++++++++++- k/isr.S | 2 +- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/k/idt.c b/k/idt.c index 24ea79d..f19aba2 100644 --- a/k/idt.c +++ b/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; diff --git a/k/idt.h b/k/idt.h index 39a1857..5906f7a 100644 --- a/k/idt.h +++ b/k/idt.h @@ -3,11 +3,25 @@ #include #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 */ diff --git a/k/isr.S b/k/isr.S index 3e65175..57bc674 100644 --- a/k/isr.S +++ b/k/isr.S @@ -4,7 +4,7 @@ isr: pushal // save registers pushl %esp -call generic_c_handler +call handle_interrupt add $4, %esp popal // restore registers