2019-07-17 14:12:48 +00:00
|
|
|
/************************
|
|
|
|
*** Team Kitty, 2019 ***
|
|
|
|
*** Sync ***
|
|
|
|
***********************/
|
|
|
|
|
2019-04-07 12:16:53 +00:00
|
|
|
#pragma once
|
2019-04-07 18:25:27 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2019-06-27 18:57:54 +00:00
|
|
|
void gdt_set_gate(int, uint32_t, uint32_t, uint8_t, uint8_t);
|
|
|
|
void gdt_install();
|
2019-04-07 12:16:53 +00:00
|
|
|
|
2019-06-27 18:57:54 +00:00
|
|
|
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
|
2019-04-07 22:43:09 +00:00
|
|
|
|
2019-06-27 18:57:54 +00:00
|
|
|
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();
|
2019-04-07 12:16:53 +00:00
|
|
|
|
|
|
|
void idt_set_gate(unsigned char, unsigned long, unsigned short, unsigned char);
|
2019-04-07 18:25:27 +00:00
|
|
|
void idt_install();
|
|
|
|
|
2019-06-27 18:57:54 +00:00
|
|
|
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);
|
|
|
|
|
2019-07-17 14:12:48 +00:00
|
|
|
extern void load_idt();
|
2019-04-07 18:25:27 +00:00
|
|
|
|
2019-04-07 22:43:09 +00:00
|
|
|
//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
|
|
|
|
};
|
|
|
|
|
2019-06-27 18:57:54 +00:00
|
|
|
void irq_install_handler(int irq, void (*handler)(struct int_frame* r));
|
2019-04-07 22:43:09 +00:00
|
|
|
|
|
|
|
void irq_uninstall_handler(int);
|
|
|
|
|
|
|
|
void irq_install();
|
|
|
|
|
2019-06-27 18:57:54 +00:00
|
|
|
void irq_remap();
|
2019-04-07 22:43:09 +00:00
|
|
|
|
|
|
|
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"
|
2019-06-27 18:57:54 +00:00
|
|
|
};
|