Commit ab42a3e9 by malcolm

Added IDT c code

parent 7ff5b79f
Showing with 75 additions and 0 deletions
#include "idt.h"
struct idtr {
uint16_t limit;
uint32_t base;
};
static struct idt_desc _idt [MAX_IDT_INT];
static struct idtr _idtr;
static void idt_install () {
//TODO: VOODOO MAGIC
}
static void _cdecl default_handler () {
//DEBUG OUTPUT MAYBE?
for(;;);
}
idt_descriptor* get_ir (uint32_t i) {
if (i>MAX_IDT_INT)
return 0;
return &_idt[i];
}
int install_ir (uint32_t i, uint16_t flags, uint16_t sel, IRQ_HANDLER irq) {
if (i>MAX_IDT_INT)
return 0;
if (!irq)
return 0;
uint64_t uiBase = (uint64_t)&(*irq);
_idt[i].low_base = uint16_t(uiBase & 0xffff);
_idt[i].high_base = uint16_t((uiBase >> 16) & 0xffff);
_idt[i].reserved = 0;
_idt[i].flags = uint8_t(flags);
_idt[i].code_sel = sel;
return 0;
}
int idt_init (uint16_t code_sel) {
_idtr.limit = sizeof (struct idt_desc) * MAX_IDT_INT -1;
_idtr.base = (uint32_t)&_idt[0];
memset ((void*)&_idt[0], 0, sizeof (idt_desc) * MAX_IDT_INT-1);
for (int i=0; i<MAX_IDT_INT; i++)
install_ir (i, IDT_PR|IDT_32,code_sel,(IRQ_HANDLER)default_handler);
idt_install ();
return 0;
}
#ifndef _IDT_INC
#define _IDT_INC
#include <stdint.h>
#define MAX_IDT_INT 256
#define IDT_16 0x06
#define IDT_32 0x0E
#define IDT_R1 0x40
#define IDT_R2 0x20
#define IDT_R3 0x60
#define IDT_PR 0x80
//voodoo magic. find out what it does.
typedef void (_cdecl *IRQ_HANDLER)(void);
struct idt_desc{
uint16_t low_base;
uint16_t code_sel;
uint8_t reserved;
uint8_t flags;
uint16_t high_base;
};
extern idt_desc* get_ir (uint32_t i);
extern int install_ir (uint32_t i, uint16_t flags, uint16_c code_sel, IRQ_HANDLER);
extern int idt_init (uint16_t code_sel);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment