2021-07-26 06:50:31 +00:00
|
|
|
#include "events/idt.h"
|
2021-07-21 18:30:55 +00:00
|
|
|
#include "io.h"
|
|
|
|
#include "pic.h"
|
2021-07-25 22:24:04 +00:00
|
|
|
#include "stdio.h"
|
2021-07-26 08:41:51 +00:00
|
|
|
#include "keyboard.h"
|
2021-07-21 18:30:55 +00:00
|
|
|
|
|
|
|
static void send_icw1(void)
|
|
|
|
{
|
|
|
|
outb(MASTER_PIC_A, ICW1);
|
|
|
|
outb(SLAVE_PIC_A, ICW1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void send_icw2(void)
|
|
|
|
{
|
|
|
|
outb(MASTER_PIC_B, IDT_RESERVED_ENTRIES);
|
|
|
|
outb(SLAVE_PIC_B, IDT_RESERVED_ENTRIES + 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void send_icw3(void)
|
|
|
|
{
|
|
|
|
outb(MASTER_PIC_B, 0x4);
|
|
|
|
outb(SLAVE_PIC_B, 0x2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void send_icw4(void)
|
|
|
|
{
|
|
|
|
outb(MASTER_PIC_B, 0x1);
|
|
|
|
outb(SLAVE_PIC_B, 0x1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mask_irqs(void)
|
|
|
|
{
|
2021-07-26 09:17:52 +00:00
|
|
|
outb(MASTER_PIC_B, IRQ2_PIN | IRQ3_PIN | IRQ4_PIN | IRQ5_PIN | IRQ6_PIN
|
|
|
|
| IRQ7_PIN);
|
2021-07-21 18:30:55 +00:00
|
|
|
outb(SLAVE_PIC_B, 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_pic(void)
|
|
|
|
{
|
|
|
|
send_icw1();
|
|
|
|
send_icw2();
|
|
|
|
send_icw3();
|
|
|
|
send_icw4();
|
|
|
|
mask_irqs();
|
2021-07-26 08:41:51 +00:00
|
|
|
init_keyboard();
|
2021-07-21 18:30:55 +00:00
|
|
|
asm volatile("sti");
|
|
|
|
}
|
2021-07-25 22:24:04 +00:00
|
|
|
|
|
|
|
void acknowledge(uint32_t int_vector)
|
|
|
|
{
|
|
|
|
uint8_t ocw2 = 0x20;
|
|
|
|
if (int_vector >= IDT_RESERVED_ENTRIES + 8)
|
|
|
|
outb(SLAVE_PIC_A, ocw2);
|
|
|
|
outb(MASTER_PIC_A, ocw2);
|
|
|
|
}
|