OurOS 0.1
Operating System built by McGill Students
 
Loading...
Searching...
No Matches
pic.h
1#ifndef _PIC_H
2#define _PIC_H
3
4#include "port_io.h"
5#include <stdint.h>
6#define PIC1 0x20 /* IO base address for master PIC */
7#define PIC2 0xA0 /* IO base address for slave PIC */
8#define PIC1_COMMAND PIC1
9#define PIC1_DATA (PIC1+1)
10#define PIC2_COMMAND PIC2
11#define PIC2_DATA (PIC2+1)
12
13#define PIC_EOI 0x20 /* End-of-interrupt command code */
14
15// ICW stands for Initialization Command Words
16// Initializing PIC goes from ICW1 -> ICW4 (if it is present, which is indicated by byte 0 during ICW1)
17// From wiki.osdev.org: "This command (ICW1) makes the PIC wait for 3 extra "initialisation words" on the data port."
18// ICW1: Start initialization
19// ICW2: Vector offset
20// ICW3: Wiring (Master/slave relationship)
21// ICW4: Mode
22#define ICW1_ICW4 0x01 /* Indicates that ICW4 will be present */
23#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
24#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
25#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
26#define ICW1_INIT 0x10 /* Initialization - required! */
27
28#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
29#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
30#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
31#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
32#define ICW4_SFNM 0x10 /* Special fully nested (not) */
33
34#define PIC_MASTER_IRQ_OFFSET 0x20
35#define PIC_SLAVE_IRQ_OFFSET 0x28
36
37#define CASCADE_IRQ 2
38
39static inline void PIC_sendEOI(uint8_t irq) {
40 if(irq >= 8)
41 outb(PIC2_COMMAND,PIC_EOI);
42 outb(PIC1_COMMAND,PIC_EOI);
43}
44
45void PIC_init();
46void PIC_remap(int offset1, int offset2);
47void PIC_unmask(void);
48void PIC_mask(void);
49
50void PIC_set_mask(uint8_t IRQline);
51void PIC_clear_mask(uint8_t IRQline);
52#endif
c wrappers for asm port operations
static void outb(uint16_t port, uint8_t val)
write byte to low level port
Definition port_io.h:29