os-k/include/kernel/idt.h

153 lines
3.3 KiB
C
Raw Normal View History

2019-04-24 11:40:28 +02:00
#ifndef _KALKERN_BASE_H
#include <kernel/base.h>
#endif
#ifndef _KALKERN_IDT_H
#define _KALKERN_IDT_H
typedef struct IdtDescriptor_t IdtDescriptor_t;
typedef struct IdtEntry_t IdtEntry_t;
typedef struct IdtPtr_t IdtPtr_t;
typedef struct IRQList_t IRQList_t;
2019-04-26 20:11:08 +02:00
typedef struct ISRFrame_t ISRFrame_t;
2019-04-24 11:40:28 +02:00
// -------------------------------------------------------------------------- //
#define interrupt(n) asm volatile ("int %0" : : "N" (n) : "cc", "memory") \
// -------------------------------------------------------------------------- //
struct IdtDescriptor_t {
ushort limit;
ulong base;
} __attribute__((packed)) ;
struct IdtEntry_t
{
ushort baseLow;
ushort selector;
uchar reservedIst;
uchar flags;
ushort baseMid;
uint baseHigh;
uint reserved;
} __attribute__((packed));
struct IdtPtr_t
{
ushort limit;
void *base;
} __attribute__((packed));
struct IRQList_t
{
uchar n; //number of entries in the list
struct entry {
void (*isr)(void);
uchar irq;
uchar flags;
2019-04-24 21:08:44 +02:00
} entry[224];
2019-04-24 11:40:28 +02:00
};
2019-04-26 20:11:08 +02:00
struct ISRFrame_t {
/* the register file */
uint64_t regs[15];
/* the error code and interrupt id */
uint64_t id;
uint64_t error;
/* these are pushed automatically by the CPU */
uint64_t rip;
uint64_t cs;
uint64_t rflags;
uint64_t rsp;
uint64_t ss;
} __attribute__((__packed__));
typedef struct
{
} __attribute__((__packed__)) cpu_state_t;
2019-04-24 11:40:28 +02:00
static char *IsrExceptions[32] = {
"Divide Error Fault",
"Debug Exception Trap",
"Non-maskable Interrupt",
"Breakpoint Trap",
"Overflow Trap",
"Bound Range Exceeded Fault",
"Invalid Opcode Fault",
"Device Not Available or No Math Coprocessor Fault",
"Double Fault Abort",
2019-04-26 20:11:08 +02:00
"Coprocessor Segment Overrun Fault (Legacy)",
2019-04-24 11:40:28 +02:00
"Invalid TSS Fault",
"Segment Not Present Fault",
"Stack Segment fault",
"General Protection Fault",
"Page Fault",
"Intel Reserved",
"x87 FPU Floating Point or Math Fault",
"Alignment Check Fault",
"Machine Check Abort",
"SIMD Floating Point Fault",
"Virtualization Exception Fault",
"Intel Reserved",
"Intel Reserved",
"Intel Reserved",
"Intel Reserved",
"Intel Reserved",
"Intel Reserved",
"Intel Reserved",
"Intel Reserved",
"Intel Reserved",
2019-04-26 20:11:08 +02:00
"Security Exception",
2019-04-24 11:40:28 +02:00
"Intel Reserved"
};
// -------------------------------------------------------------------------- //
void IdtRegisterIrq(void (*isr)(void), uchar irq, uchar flags);
void IdtSetup(void);
void IdtSetGate(uchar rank, ulong base, ushort selector, uchar flags);
2019-04-25 23:09:04 +02:00
//void IdtHandler(ulong intNo);
2019-04-24 18:42:38 +02:00
static void EnablePIC(void);
void SendEOItoPIC(uchar isr);
2019-04-24 11:40:28 +02:00
2019-04-24 18:42:38 +02:00
extern void IdtInit();
2019-04-24 11:40:28 +02:00
extern void isr0();
extern void isr1();
extern void isr2();
extern void isr3();
extern void isr4();
extern void isr5();
extern void isr6();
extern void isr7();
extern void isr8();
extern void isr9();
extern void isr10();
extern void isr11();
extern void isr12();
extern void isr13();
extern void isr14();
extern void isr15();
extern void isr16();
extern void isr17();
extern void isr18();
extern void isr19();
extern void isr20();
extern void isr21();
extern void isr22();
extern void isr23();
extern void isr24();
extern void isr25();
extern void isr26();
extern void isr27();
extern void isr28();
extern void isr29();
extern void isr30();
extern void isr31();
#endif