Syncboot/include/kernel/descriptor_tables.h
Curle 4edd4b7cc8 Major refactor. Major improvements.
All ISR/IRQ stuff moved into its own header and source.

Comments added on all major parts.

Some optimisations in important functions.

All ASM removed for ISR and IRQ, instead using new GCC directives.
2019-06-27 19:57:54 +01:00

162 lines
3.3 KiB
C
Executable File

#pragma once
#include <stddef.h>
#include <stdint.h>
void gdt_set_gate(int, uint32_t, uint32_t, uint8_t, uint8_t);
void gdt_install();
struct gdt_item {
uint16_t low_limit;
uint16_t low_base;
uint8_t middle_base;
uint8_t access;
uint8_t granular;
uint8_t high_base;
} __attribute__((packed)); //Prevent compiler optimisation by packing
struct gdt_ptr {
uint16_t limit;
unsigned int base;
} __attribute__((packed));
struct gdt_item gdt[3]; //3-entry gdt
struct gdt_ptr gp;
extern void load_gdt();
void idt_set_gate(unsigned char, unsigned long, unsigned short, unsigned char);
void idt_install();
struct idt_entry {
unsigned short base_low;
unsigned short selector;
unsigned char always0;
unsigned char flags;
unsigned short base_high;
} __attribute__((packed));
struct idt_ptr {
unsigned short limit;
unsigned int base;
}__attribute__((packed));
struct idt_entry idt[256]; //interrupt table of 256 entries
struct idt_ptr idtp; //pointer to idt table
struct int_frame {
void (*eip) (void);
uint16_t cs, :16;
uint32_t eflags;
void* esp;
uint16_t ss, :16;
} __attribute__((packed));
void isr_common(struct int_frame*, size_t);
void isr_error_common(struct int_frame*, size_t, size_t);
void irq_common(struct int_frame*, size_t);
extern void idt_load();
//These are all reserved by Intel, and need to be here.
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();
extern void irq0();
extern void irq1();
extern void irq2();
extern void irq3();
extern void irq4();
extern void irq5();
extern void irq6();
extern void irq7();
extern void irq8();
extern void irq9();
extern void irq10();
extern void irq11();
extern void irq12();
extern void irq13();
extern void irq14();
extern void irq15();
static void* irq_routines[16] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
void irq_install_handler(int irq, void (*handler)(struct int_frame* r));
void irq_uninstall_handler(int);
void irq_install();
void irq_remap();
void timer_install();
static const char* exception_messages[] = {
"Division by Zero",
"Debug",
"Non Maskable Interrupt",
"Breakpoint",
"Into Detected Overflow",
"Out of Bounds",
"Invalid Opcode",
"No Coprocessor",
"Double Fault",
"Coprocessor Segment Overrun",
"Bad TSS",
"Segment Not Present",
"Stack Fault",
"General Protection Fault",
"Page Fault",
"Unknown Interrupt",
"Coprocessor Fault",
"Alignment Check",
"Machine Check",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Reserved"
};