FreeNOS
IntelPIC.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "IntelPIC.h"
19
27
29{
30 // ICW1: Initialize PIC's (Edge triggered, Cascade)
33
34 // ICW2: Remap IRQ's to interrupts 32-47
37
38 // ICW3: PIC2 is connected to PIC1 via IRQ2
39 m_master.outb(Data, 0x4);
40 m_slave.outb(Data, 0x2);
41
42 // ICW4: 8086 mode, fully nested, not buffered, no implicit EOI
45
46 // OCW1: Disable all IRQ's
47 m_master.outb(Data, 0xff);
48 m_slave.outb(Data, 0xff);
49
50 // Make sure to enable PIC2's interrupt in the Master (IRQ2)
51 enable(2);
52 return Success;
53}
54
56{
57 if (irq > 15)
58 return InvalidIRQ;
59
60 if (irq < 8)
61 m_master.outb(Data, m_master.inb(Data) & ~(1 << irq));
62 else
63 m_slave.outb(Data, m_slave.inb(Data) & ~(1 << (irq - 8)));
64
65 return Success;
66}
67
69{
70 if (irq > 15)
71 return InvalidIRQ;
72
73 if (irq < 8)
74 m_master.outb(Data, m_master.inb(Data) | (1 << irq));
75 else
76 m_slave.outb(Data, m_slave.inb(Data) | (1 << (irq - 8)));
77
78 return Success;
79}
80
82{
83 if (irq > 15)
84 return InvalidIRQ;
85
86 // End-Of-Interrupt to slave needed?
87 if (irq >= 8)
89
90 // Always signal End-Of-Interrupt to the master
92 return Success;
93}
Interrupt controller interface.
uint m_base
Interrupt number base offset.
Result
Result codes.
u8 inb(u16 port) const
Read a byte from a port.
Definition IntelIO.h:68
void setPortBase(const u16 base)
Set port I/O base address.
Definition IntelIO.h:56
void outb(u16 port, u8 byte)
Output a byte to a port.
Definition IntelIO.h:97
IntelPIC()
Constructor.
Definition IntelPIC.cpp:20
virtual Result disable(uint irq)
Disable hardware interrupt (IRQ).
Definition IntelPIC.cpp:68
static const uint SlaveBase
Slave PIC I/O port base offset.
Definition IntelPIC.h:56
static const uint MasterBase
Master PIC I/O port base offset.
Definition IntelPIC.h:53
IntelIO m_slave
I/O instance for slave.
Definition IntelPIC.h:130
Result initialize()
Initialize the PIC.
Definition IntelPIC.cpp:28
virtual Result enable(uint irq)
Enable hardware interrupt (IRQ).
Definition IntelPIC.cpp:55
@ Command
Definition IntelPIC.h:63
@ EndOfInterrupt
Definition IntelPIC.h:76
@ LevelTriggered
Definition IntelPIC.h:74
@ Mode8086
Definition IntelPIC.h:75
@ CascadeMode
Definition IntelPIC.h:73
virtual Result clear(uint irq)
Clear hardware interrupt (IRQ).
Definition IntelPIC.cpp:81
static const uint InterruptBase
Base offset for interrupt vectors from the PIC.
Definition IntelPIC.h:50
IntelIO m_master
I/O instance for master.
Definition IntelPIC.h:127
unsigned int uint
Unsigned integer number.
Definition Types.h:44