1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2024-10-30 12:03:52 -04:00

Add function "pic_end_of_interrupt"

This commit is contained in:
Braiden Vasco 2017-11-06 10:57:55 +00:00
parent 5784f88df5
commit 3413fbd3a8
3 changed files with 32 additions and 12 deletions

View file

@ -4,6 +4,7 @@
#include "config.h"
#include "asm.h"
#include "logger.h"
#include "pic.h"
static const char *const messages[] = {
"Unhandled hardware interrupt: 0",
@ -35,15 +36,7 @@ void hwint_handler(struct IsrRegisters regs)
return;
}
// Send an EOI (end of interrupt) signal to the PICs
if (regs.int_no >= 40) { // TODO: hardcoded
// Send reset signal to slave
outportb(0xA0, 0x20); // TODO: hardcoded
}
// Send reset signal to master
outportb(0x20, 0x20); // TODO: hardcoded
pic_end_of_interrupt(regs.int_no);
const unsigned char hwint_no = regs.int_no - INT_HWINT_FIRST;

View file

@ -9,10 +9,19 @@
#define SLAVE_COMMAND 0xA0
#define SLAVE_DATA 0xA1
void pic_remap(const unsigned char master_irq_start, const unsigned char slave_irq_start)
#define IRQS_COUNT 8
static unsigned char master_irq_start = 0;
static unsigned char slave_irq_start = 8;
void pic_remap(const unsigned char new_master_irq_start, const unsigned char new_slave_irq_start)
{
logger_info_from("pic", "Remap the IRQ table.");
// Remember IRQ numbers
master_irq_start = new_master_irq_start;
slave_irq_start = new_slave_irq_start;
// Save masks
unsigned char master_mask = inportb(MASTER_DATA);
unsigned char slave_mask = inportb(SLAVE_DATA);
@ -22,8 +31,8 @@ void pic_remap(const unsigned char master_irq_start, const unsigned char slave_i
outportb(SLAVE_COMMAND, 0x11);
// Set IRQ vectors
outportb(MASTER_DATA, master_irq_start);
outportb(SLAVE_DATA, slave_irq_start);
outportb(MASTER_DATA, new_master_irq_start);
outportb(SLAVE_DATA, new_slave_irq_start);
// Connect master and slave with each other
outportb(MASTER_DATA, 0x04);
@ -37,3 +46,19 @@ void pic_remap(const unsigned char master_irq_start, const unsigned char slave_i
outportb(MASTER_DATA, master_mask);
outportb(SLAVE_DATA, slave_mask);
}
void pic_end_of_interrupt(const unsigned char irq)
{
const unsigned char to_master = master_irq_start <= irq && irq < master_irq_start + IRQS_COUNT;
const unsigned char to_slave = slave_irq_start <= irq && irq < slave_irq_start + IRQS_COUNT;
if (!(to_master || to_slave)) {
return;
}
if (to_slave) {
outportb(SLAVE_COMMAND, 0x20);
}
outportb(MASTER_COMMAND, 0x20);
}

View file

@ -3,4 +3,6 @@
void pic_remap(unsigned char master_irq_start, unsigned char slave_irq_start);
void pic_end_of_interrupt(unsigned char irq);
#endif