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 
21  : IntController()
22 {
26 }
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 }
IntController
Interrupt controller interface.
Definition: IntController.h:35
IntelIO::setPortBase
void setPortBase(const u16 base)
Set port I/O base address.
Definition: IntelIO.h:56
IntelPIC::IntelPIC
IntelPIC()
Constructor.
Definition: IntelPIC.cpp:20
IntelPIC::m_slave
IntelIO m_slave
I/O instance for slave.
Definition: IntelPIC.h:130
IntelIO::inb
u8 inb(u16 port) const
Read a byte from a port.
Definition: IntelIO.h:68
IntController::Success
@ Success
Definition: IntController.h:44
IntelPIC::InterruptBase
static const uint InterruptBase
Base offset for interrupt vectors from the PIC.
Definition: IntelPIC.h:50
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
IntelIO::outb
void outb(u16 port, u8 byte)
Output a byte to a port.
Definition: IntelIO.h:97
IntelPIC::m_master
IntelIO m_master
I/O instance for master.
Definition: IntelPIC.h:127
IntelPIC::Mode8086
@ Mode8086
Definition: IntelPIC.h:75
IntelPIC::enable
virtual Result enable(uint irq)
Enable hardware interrupt (IRQ).
Definition: IntelPIC.cpp:55
IntController::InvalidIRQ
@ InvalidIRQ
Definition: IntController.h:45
IntelPIC::Init1
@ Init1
Definition: IntelPIC.h:72
IntelPIC.h
IntelPIC::EndOfInterrupt
@ EndOfInterrupt
Definition: IntelPIC.h:76
IntelPIC::CascadeMode
@ CascadeMode
Definition: IntelPIC.h:73
IntelPIC::initialize
Result initialize()
Initialize the PIC.
Definition: IntelPIC.cpp:28
IntelPIC::Command
@ Command
Definition: IntelPIC.h:63
IntelPIC::SlaveBase
static const uint SlaveBase
Slave PIC I/O port base offset.
Definition: IntelPIC.h:56
IntController::m_base
uint m_base
Interrupt number base offset.
Definition: IntController.h:128
IntelPIC::clear
virtual Result clear(uint irq)
Clear hardware interrupt (IRQ).
Definition: IntelPIC.cpp:81
IntelPIC::disable
virtual Result disable(uint irq)
Disable hardware interrupt (IRQ).
Definition: IntelPIC.cpp:68
IntelPIC::MasterBase
static const uint MasterBase
Master PIC I/O port base offset.
Definition: IntelPIC.h:53
IntelPIC::Data
@ Data
Definition: IntelPIC.h:64
IntelPIC::LevelTriggered
@ LevelTriggered
Definition: IntelPIC.h:74
IntController::Result
Result
Result codes.
Definition: IntController.h:42