Newer
Older
tree-os / src / interrupts / interrupts.c
@lukas lukas on 4 Aug 872 bytes add real irqs
#include <interrupts.h>
#include <_stdio.h>
#include <alloc.h>
#include <ports.h>
#include <task.h>
#include <timer.h>
#include <exceptions.h>

IDTR idtr;
IDTEntry* entries;
void* buffer;

void setInterrupt(uint8_t vector, void* callback) {
    IDTEntry* descriptor = &entries[vector];
    descriptor->isr_low        = (uint32_t)callback & 0xFFFF;
    descriptor->codeSegment    = 0x08;
    descriptor->attributes     = 0x8E;
    descriptor->isr_high       = (uint32_t)callback >> 16;
    descriptor->reserved       = 0;
}


void initInterrupts() {
    buffer = malloc(sizeof(IDTEntry) * 257);
    entries = (IDTEntry*) (((int) buffer + sizeof(IDTEntry) >> 3) << 3);
    idtr.limit = sizeof(IDTEntry) * 256 - 1;
    idtr.base = (uint32_t) entries;
    setupExceptions();
    setupIRQs();
    __asm__ volatile ("lidt %0" : : "memory"(idtr));
    __asm__ volatile ("sti");
}