Espresso 0.0.2c
This commit is contained in:
@ -3,46 +3,74 @@
|
||||
#include <drivers/pit.h>
|
||||
#include <port_io.h>
|
||||
|
||||
/* TEMP DEBUG */
|
||||
#include <tty.h>
|
||||
|
||||
#include <kernel/syscall.h>
|
||||
|
||||
#include <drivers/irq.h>
|
||||
|
||||
#define NUM_IRQS 0x90
|
||||
|
||||
irq_func_t func_list[NUM_IRQS];
|
||||
#define MAX_IRQ_HANDLERS 128 /* the maximum number of irq handlers */
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t irq_no;
|
||||
irq_func_t func;
|
||||
} irq_handler_t;
|
||||
|
||||
static volatile uint32_t num_irqs_missed = 0;
|
||||
uint32_t num_irq_handlers = 0;
|
||||
irq_handler_t handler_list[MAX_IRQ_HANDLERS];
|
||||
|
||||
volatile uint32_t num_irqs_missed = 0;
|
||||
|
||||
void irq_init(void)
|
||||
{
|
||||
for (int i = 0; i < NUM_IRQS; i++)
|
||||
for (int i = 0; i < MAX_IRQ_HANDLERS; i++)
|
||||
{
|
||||
func_list[i] = 0x0;
|
||||
handler_list[i].irq_no = 0;
|
||||
handler_list[i].func = NULL;
|
||||
}
|
||||
set_irq_handler(0, (irq_func_t*) pit_handler);
|
||||
set_irq_handler(1, (irq_func_t*) keyboard_handler);
|
||||
set_irq_handler(0, (irq_func_t) pit_handler);
|
||||
//set_irq_handler(1, (irq_func_t) ps2_keyboard_handler);
|
||||
}
|
||||
|
||||
void irq_handler(uint8_t irq_number)
|
||||
registers_t* irq_handler(uint32_t irq, registers_t* regs)
|
||||
{
|
||||
if (irq_number < NUM_IRQS)
|
||||
{
|
||||
if (func_list[irq_number])
|
||||
uint8_t funcs_called = 0;
|
||||
|
||||
if (num_irq_handlers > 0)
|
||||
{
|
||||
for (unsigned int i = 0; i < MAX_IRQ_HANDLERS; i++)
|
||||
{
|
||||
func_list[irq_number]();
|
||||
outb(0x20, 0x20); /* Acknowledge the IRQ to PIC */
|
||||
}
|
||||
else
|
||||
{
|
||||
num_irqs_missed++;
|
||||
if (handler_list[i].irq_no == irq && handler_list[i].func != NULL)
|
||||
{
|
||||
regs = handler_list[i].func(regs);
|
||||
funcs_called++;
|
||||
/* PIC IRQ acknowledgement happens in idt.c */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (funcs_called == 0)
|
||||
{
|
||||
num_irqs_missed++;
|
||||
}
|
||||
|
||||
return regs;
|
||||
}
|
||||
|
||||
void set_irq_handler(uint32_t num, irq_func_t* handler)
|
||||
uint32_t get_interrupts_missed(void)
|
||||
{
|
||||
if (num < NUM_IRQS)
|
||||
return num_irqs_missed;
|
||||
}
|
||||
|
||||
void set_irq_handler(uint32_t num, irq_func_t handler)
|
||||
{
|
||||
if (num < MAX_IRQ_HANDLERS)
|
||||
{
|
||||
func_list[num] = (irq_func_t)handler;
|
||||
handler_list[num].irq_no = num;
|
||||
handler_list[num].func = handler;
|
||||
|
||||
num_irq_handlers++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user