limine/common/sys/pic.c

49 lines
810 B
C
Raw Normal View History

#if defined (__x86_64__) || defined (__i386__)
2020-09-02 03:32:04 +03:00
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
2020-09-18 21:02:10 +03:00
#include <sys/pic.h>
2020-09-21 13:15:55 +03:00
#include <sys/cpu.h>
2022-08-27 00:44:47 +03:00
#include <lib/misc.h>
2020-09-02 03:32:04 +03:00
void pic_eoi(int irq) {
if (irq >= 8) {
outb(0xa0, 0x20);
2020-09-02 03:32:04 +03:00
}
outb(0x20, 0x20);
2020-09-02 03:32:04 +03:00
}
// Flush all potentially pending IRQs
void pic_flush(void) {
for (int i = 0; i < 16; i++)
pic_eoi(i);
}
void pic_set_mask(int line, bool status) {
uint16_t port;
uint8_t value;
if (line < 8) {
port = 0x21;
} else {
port = 0xa1;
line -= 8;
}
if (!status)
value = inb(port) & ~((uint8_t)1 << line);
2020-09-02 03:32:04 +03:00
else
value = inb(port) | ((uint8_t)1 << line);
2020-09-02 03:32:04 +03:00
outb(port, value);
2020-09-02 03:32:04 +03:00
}
void pic_mask_all(void) {
outb(0xa1, 0xff);
outb(0x21, 0xff);
2020-09-02 03:32:04 +03:00
}
#endif