LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
pic.c
Go to the documentation of this file.
1#include "pic.h"
2#include "io.h"
3
4#define PIC1 0x20
5#define PIC2 0xA0
6
7void init_pic(void) {
8 outb(PIC1, 0x11); // starts the initialization sequence (in cascade mode)
9 outb(PIC2, 0x11);
10 outb(PIC1 + 1, 0x20); // ICW2: Master PIC vector offset
11 outb(PIC2 + 1, 0x28); // ICW2: Slave PIC vector offset
12 outb(PIC1 + 1, 4); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
13 outb(PIC2 + 1, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
14
15 outb(PIC1 + 1, 1);
16 outb(PIC2 + 1, 1);
17
18 // unmask IRQ0 / PIT, found in the wild as masked...
19 uint8_t mask = inb(PIC1 + 1) & 0xFE;
20 outb(PIC1 + 1, mask);
21}
22
23void pic_set_handled(int interrupt) {
24 interrupt -= 0x20;
25
26 outb(PIC1, 0x20);
27 if(interrupt > 7) {
28 outb(PIC2, 0x20);
29 }
30}
unsigned char uint8_t
Definition arch.h:5
static uint8_t inb(uint16_t port)
Definition io.h:18
static void outb(uint16_t port, uint8_t data)
Definition io.h:6
#define PIC1
Definition pic.c:4
void pic_set_handled(int interrupt)
Definition pic.c:23
#define PIC2
Definition pic.c:5
void init_pic(void)
Definition pic.c:7