63 lines
1.2 KiB
C++
63 lines
1.2 KiB
C++
#include "arch/x86_64/CPU.h"
|
|
#include "arch/x86_64/IO.h"
|
|
|
|
#define PIC1_COMMAND 0x20
|
|
#define PIC1_DATA 0x21
|
|
#define PIC2_COMMAND 0xA0
|
|
#define PIC2_DATA 0xA1
|
|
#define PIC_EOI 0x20
|
|
|
|
#define ICW1_INIT 0x10
|
|
#define ICW1_ICW4 0x01
|
|
#define ICW4_8086 0x01
|
|
|
|
#define io_delay() IO::outb(0x80, 0)
|
|
|
|
void remap_pic()
|
|
{
|
|
IO::outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4);
|
|
io_delay();
|
|
IO::outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
|
|
io_delay();
|
|
|
|
IO::outb(PIC1_DATA, 0x20);
|
|
io_delay();
|
|
|
|
IO::outb(PIC2_DATA, 0x28);
|
|
io_delay();
|
|
|
|
IO::outb(PIC1_DATA, 4);
|
|
io_delay();
|
|
IO::outb(PIC2_DATA, 2);
|
|
io_delay();
|
|
|
|
IO::outb(PIC1_DATA, ICW4_8086);
|
|
io_delay();
|
|
IO::outb(PIC2_DATA, ICW4_8086);
|
|
io_delay();
|
|
|
|
IO::outb(PIC1_DATA, 0b11111111);
|
|
io_delay();
|
|
IO::outb(PIC2_DATA, 0b11111111);
|
|
io_delay();
|
|
}
|
|
|
|
void change_pic_masks(u8 pic1_mask, u8 pic2_mask)
|
|
{
|
|
IO::outb(PIC1_DATA, pic1_mask);
|
|
io_delay();
|
|
IO::outb(PIC2_DATA, pic2_mask);
|
|
io_delay();
|
|
}
|
|
|
|
void pic_eoi(unsigned char irq)
|
|
{
|
|
if (irq >= 8) IO::outb(PIC2_COMMAND, PIC_EOI);
|
|
IO::outb(PIC1_COMMAND, PIC_EOI);
|
|
}
|
|
|
|
void pic_eoi(Registers* regs)
|
|
{
|
|
pic_eoi((unsigned char)(regs->error)); // On IRQs, the error code is the IRQ number
|
|
}
|