:: limine / common / sys / pic.c 810 B raw

1
#if defined (__x86_64__) || defined (__i386__)
2
3
#include <stddef.h>
4
#include <stdint.h>
5
#include <stdbool.h>
6
#include <sys/pic.h>
7
#include <sys/cpu.h>
8
#include <lib/misc.h>
9
10
void pic_eoi(int irq) {
11
    if (irq >= 8) {
12
        outb(0xa0, 0x20);
13
    }
14
15
    outb(0x20, 0x20);
16
}
17
18
// Flush all potentially pending IRQs
19
void pic_flush(void) {
20
    for (int i = 0; i < 16; i++)
21
        pic_eoi(i);
22
}
23
24
void pic_set_mask(int line, bool status) {
25
    uint16_t port;
26
    uint8_t value;
27
28
    if (line < 8) {
29
        port = 0x21;
30
    } else {
31
        port = 0xa1;
32
        line -= 8;
33
    }
34
35
    if (!status)
36
        value = inb(port) & ~((uint8_t)1 << line);
37
    else
38
        value = inb(port) | ((uint8_t)1 << line);
39
40
    outb(port, value);
41
}
42
43
void pic_mask_all(void) {
44
    outb(0xa1, 0xff);
45
    outb(0x21, 0xff);
46
}
47
48
#endif
tab: 248 wrap: offon