2017-11-06 05:18:43 -05:00
|
|
|
#include "pic.h"
|
|
|
|
|
|
|
|
#include "logger.h"
|
|
|
|
#include "asm.h"
|
|
|
|
|
2017-11-06 05:28:04 -05:00
|
|
|
#define PIC_MASTER_COMMAND 0x20
|
|
|
|
#define PIC_MASTER_DATA 0x21
|
|
|
|
|
|
|
|
#define PIC_SLAVE_COMMAND 0xA0
|
|
|
|
#define PIC_SLAVE_DATA 0xA1
|
|
|
|
|
2017-11-06 05:32:46 -05:00
|
|
|
void pic_remap(const unsigned char master_irq_start, const unsigned char slave_irq_start)
|
2017-11-06 05:18:43 -05:00
|
|
|
{
|
|
|
|
logger_info_from("pic", "Remap the IRQ table.");
|
|
|
|
|
2017-11-06 05:41:28 -05:00
|
|
|
// Save masks
|
|
|
|
unsigned char master_mask = inportb(PIC_MASTER_DATA);
|
|
|
|
unsigned char slave_mask = inportb(PIC_SLAVE_DATA);
|
|
|
|
|
2017-11-06 05:37:51 -05:00
|
|
|
// Start the initialization sequence
|
2017-11-06 05:28:04 -05:00
|
|
|
outportb(PIC_MASTER_COMMAND, 0x11);
|
|
|
|
outportb(PIC_SLAVE_COMMAND, 0x11);
|
|
|
|
|
2017-11-06 05:37:51 -05:00
|
|
|
// Set IRQ vectors
|
2017-11-06 05:32:46 -05:00
|
|
|
outportb(PIC_MASTER_DATA, master_irq_start);
|
|
|
|
outportb(PIC_SLAVE_DATA, slave_irq_start);
|
2017-11-06 05:28:04 -05:00
|
|
|
|
2017-11-06 05:37:51 -05:00
|
|
|
// Connect master and slave with each other
|
2017-11-06 05:28:04 -05:00
|
|
|
outportb(PIC_MASTER_DATA, 0x04);
|
|
|
|
outportb(PIC_SLAVE_DATA, 0x02);
|
|
|
|
|
2017-11-06 05:37:51 -05:00
|
|
|
// 8086/88 (MCS-80/85) mode
|
2017-11-06 05:28:04 -05:00
|
|
|
outportb(PIC_MASTER_DATA, 0x01);
|
|
|
|
outportb(PIC_SLAVE_DATA, 0x01);
|
|
|
|
|
2017-11-06 05:41:28 -05:00
|
|
|
// Restore masks
|
|
|
|
outportb(PIC_MASTER_DATA, master_mask);
|
|
|
|
outportb(PIC_SLAVE_DATA, slave_mask);
|
2017-11-06 05:18:43 -05:00
|
|
|
}
|