mirror of
https://github.com/tailix/kernel.git
synced 2024-12-04 11:34:42 -05:00
Add function "pic_end_of_interrupt"
This commit is contained in:
parent
5784f88df5
commit
3413fbd3a8
3 changed files with 32 additions and 12 deletions
11
arch/hwint.c
11
arch/hwint.c
|
@ -4,6 +4,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "asm.h"
|
#include "asm.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "pic.h"
|
||||||
|
|
||||||
static const char *const messages[] = {
|
static const char *const messages[] = {
|
||||||
"Unhandled hardware interrupt: 0",
|
"Unhandled hardware interrupt: 0",
|
||||||
|
@ -35,15 +36,7 @@ void hwint_handler(struct IsrRegisters regs)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send an EOI (end of interrupt) signal to the PICs
|
pic_end_of_interrupt(regs.int_no);
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
const unsigned char hwint_no = regs.int_no - INT_HWINT_FIRST;
|
const unsigned char hwint_no = regs.int_no - INT_HWINT_FIRST;
|
||||||
|
|
||||||
|
|
31
arch/pic.c
31
arch/pic.c
|
@ -9,10 +9,19 @@
|
||||||
#define SLAVE_COMMAND 0xA0
|
#define SLAVE_COMMAND 0xA0
|
||||||
#define SLAVE_DATA 0xA1
|
#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.");
|
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
|
// Save masks
|
||||||
unsigned char master_mask = inportb(MASTER_DATA);
|
unsigned char master_mask = inportb(MASTER_DATA);
|
||||||
unsigned char slave_mask = inportb(SLAVE_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);
|
outportb(SLAVE_COMMAND, 0x11);
|
||||||
|
|
||||||
// Set IRQ vectors
|
// Set IRQ vectors
|
||||||
outportb(MASTER_DATA, master_irq_start);
|
outportb(MASTER_DATA, new_master_irq_start);
|
||||||
outportb(SLAVE_DATA, slave_irq_start);
|
outportb(SLAVE_DATA, new_slave_irq_start);
|
||||||
|
|
||||||
// Connect master and slave with each other
|
// Connect master and slave with each other
|
||||||
outportb(MASTER_DATA, 0x04);
|
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(MASTER_DATA, master_mask);
|
||||||
outportb(SLAVE_DATA, slave_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);
|
||||||
|
}
|
||||||
|
|
|
@ -3,4 +3,6 @@
|
||||||
|
|
||||||
void pic_remap(unsigned char master_irq_start, unsigned char slave_irq_start);
|
void pic_remap(unsigned char master_irq_start, unsigned char slave_irq_start);
|
||||||
|
|
||||||
|
void pic_end_of_interrupt(unsigned char irq);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue