feat(idt): add documentation

This commit is contained in:
Malo Lecomte 2021-07-15 04:55:18 +02:00
parent a3596f3656
commit 79c2edc93f
4 changed files with 27 additions and 20 deletions

View File

@ -50,7 +50,7 @@ struct gdt
struct gdt_r
{
uint16_t limit; // total size of the GDT - 1 in bytes
uint32_t addr; // base address of the DGT
uint32_t addr; // base address of the GDT
} __attribute__ ((packed));
struct segment_selector

View File

@ -1,4 +1,5 @@
#include "idt.h"
#include "stdio.h"
static struct idt idt = { 0 };
@ -18,6 +19,7 @@ struct idt_entry_info infos[] = {
void handle_interrupt(struct int_args args)
{
(void)args;
printf("INTERRUPT\r\n");
return;
}

41
k/idt.h
View File

@ -11,31 +11,19 @@
#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
{
uint16_t offset_1 : 16;
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
uint8_t size : 1;
uint8_t size : 1; // 0 => 16-bits 1 => 32-bits
uint8_t zero_2 : 1; // set to 0 for interrupt and trap gates
uint8_t desc_priv : 2; // Descriptor privilege
uint8_t present : 1;
uint8_t desc_priv : 2; // descriptor privilege
uint8_t present : 1; // always 1
uint16_t offset_2 : 16;
uint16_t offset_2 : 16; // 16 msb of isr address
} __attribute__ ((packed));
struct idt
@ -45,10 +33,25 @@ struct idt
struct idt_r
{
uint16_t limit;
uint32_t addr;
uint16_t limit; // total size of the IDT - 1 in bytes
uint32_t addr; // base address of the IDT
} __attribute__ ((packed));
// FIXME: This struct is used to get int_code and err_code pushed to the stack
// by the isr (but isn't working now)
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);

View File

@ -1,6 +1,8 @@
#ifndef ISR_H
#define ISR_H
// Every ISR for the 21 first intel-defined interrupts.
void int_de(void); // Divide Error
void int_db(void); // Debug Exception
void int_nmi(void); // NMI Interrupt