Skip to content

Commit

Permalink
Interrupt callbacks refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed Nov 19, 2016
1 parent 446c404 commit ff5a91f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
8 changes: 2 additions & 6 deletions src/platform/include/interrupts.hpp
Expand Up @@ -17,6 +17,7 @@
#pragma once
#include "kernlib.hpp"
#include "heap.hpp"
#include "list.hpp"

struct INTERRUPT32 {
uint16_t offset_low;
Expand Down Expand Up @@ -170,14 +171,9 @@ struct intcb_regs {

typedef bool intcb(uint32_t intr, uint32_t code, intcb_regs *regs);

struct intcbreg {
intcb *cb;
intcbreg *next;
};

class Interrupts {
private:
static intcbreg *callbacks[256];
static List<intcb*> *callbacks;
static Mutex callback_locks[256];
static Mutex fault;
static int_handler* handlers;
Expand Down
25 changes: 6 additions & 19 deletions src/platform/interrupts.cpp
Expand Up @@ -21,7 +21,7 @@
INTERRUPT64 *Interrupts::idt = 0;
GDT *Interrupts::gdt = 0;
TSS64_ENT *Interrupts::tss = 0;
intcbreg *Interrupts::callbacks[256];
List<intcb*> *Interrupts::callbacks;
Mutex Interrupts::callback_locks[256];
Mutex Interrupts::fault;
int_handler* Interrupts::handlers = 0;
Expand Down Expand Up @@ -239,14 +239,12 @@ uint64_t __attribute__((sysv_abi)) Interrupts::handle(
regs->r8, regs->r9, regs->r10, regs->r11, regs->r12, regs->r13, regs->r14,
regs->r15 };

intcbreg *reg = 0;
size_t idx = 0;
intcb *cb;
for (;;) {
callback_locks[intr].lock();
reg = reg ? reg->next : callbacks[intr];
while (reg != 0 && reg->cb == 0)
reg = reg->next;
cb = (reg != 0) ? reg->cb : 0;
cb = (callbacks[intr].getCount() > idx) ? callbacks[intr][idx] : 0;
idx++;
callback_locks[intr].release();
if (cb == 0) break;
handled = cb(intr, error_code, &cb_regs);
Expand Down Expand Up @@ -342,8 +340,8 @@ void Interrupts::init() {

uintptr_t hptr = (uintptr_t)(&handlers[i]);
idt[i] = INTERRUPT64(hptr, 8, 1, 0xE, 0, true);
callbacks[i] = 0;
}
callbacks = new List<intcb*>[256]();

outportb(0x20, 0x11);
outportb(0xA0, 0x11);
Expand Down Expand Up @@ -389,20 +387,9 @@ uint16_t Interrupts::getIRQmask() {
}

void Interrupts::addCallback(uint8_t intr, intcb* cb) {
intcbreg *reg = new intcbreg();
reg->cb = cb;
reg->next = 0;

uint64_t t = EnterCritical();
callback_locks[intr].lock();
intcbreg *last = callbacks[intr];
if (last == 0) {
callbacks[intr] = reg;
} else {
while (last->next != 0)
last = last->next;
last->next = reg;
}
callbacks[intr].add(cb);
callback_locks[intr].release();
LeaveCritical(t);
}

0 comments on commit ff5a91f

Please sign in to comment.