2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "base/bitfield.hh"
32 #include "dev/x86/i82094aa.hh"
33 #include "dev/x86/i8259.hh"
35 X86ISA::I8259::I8259(Params
* p
) : BasicPioDevice(p
), IntDev(this),
36 latency(p
->pio_latency
), output(p
->output
),
37 mode(p
->mode
), slave(NULL
),
38 IRR(0), ISR(0), IMR(0),
39 readIRR(true), initControlWord(0), autoEOI(false)
43 master
= dynamic_cast<I8259
*>(output
->getDevice());
45 master
->setSlave(this);
47 ioApic
= dynamic_cast<I82094AA
*>(output
->getDevice());
49 ioApic
->setExtIntPic(this);
55 X86ISA::I8259::read(PacketPtr pkt
)
57 assert(pkt
->getSize() == 1);
58 switch(pkt
->getAddr() - pioAddr
)
62 DPRINTF(I8259
, "Reading IRR as %#x.\n", IRR
);
65 DPRINTF(I8259
, "Reading ISR as %#x.\n", ISR
);
70 DPRINTF(I8259
, "Reading IMR as %#x.\n", IMR
);
78 X86ISA::I8259::write(PacketPtr pkt
)
80 assert(pkt
->getSize() == 1);
81 uint8_t val
= pkt
->get
<uint8_t>();
82 switch (pkt
->getAddr() - pioAddr
) {
85 DPRINTF(I8259
, "Received initialization command word 1.\n");
87 edgeTriggered
= bits(val
, 3);
88 DPRINTF(I8259
, "%s triggered mode.\n",
89 edgeTriggered
? "Edge" : "Level");
90 cascadeMode
= !bits(val
, 1);
91 DPRINTF(I8259
, "%s mode.\n",
92 cascadeMode
? "Cascade" : "Single");
93 expectICW4
= bits(val
, 0);
98 DPRINTF(I8259
, "Expecting %d more bytes.\n", expectICW4
? 3 : 2);
99 } else if (bits(val
, 4, 3) == 0) {
100 DPRINTF(I8259
, "Received operation command word 2.\n");
101 switch (bits(val
, 7, 5)) {
104 "Subcommand: Rotate in auto-EOI mode (clear).\n");
108 int line
= findMsbSet(ISR
);
109 DPRINTF(I8259
, "Subcommand: Nonspecific EOI on line %d.\n",
115 DPRINTF(I8259
, "Subcommand: No operation.\n");
119 int line
= bits(val
, 2, 0);
120 DPRINTF(I8259
, "Subcommand: Specific EIO on line %d.\n",
126 DPRINTF(I8259
, "Subcommand: Rotate in auto-EOI mode (set).\n");
129 DPRINTF(I8259
, "Subcommand: Rotate on nonspecific EOI.\n");
132 DPRINTF(I8259
, "Subcommand: Set priority command.\n");
133 DPRINTF(I8259
, "Lowest: IRQ%d Highest IRQ%d.\n",
134 bits(val
, 2, 0), (bits(val
, 2, 0) + 1) % 8);
137 DPRINTF(I8259
, "Subcommand: Rotate on specific EOI.\n");
138 DPRINTF(I8259
, "Lowest: IRQ%d Highest IRQ%d.\n",
139 bits(val
, 2, 0), (bits(val
, 2, 0) + 1) % 8);
142 } else if (bits(val
, 4, 3) == 1) {
143 DPRINTF(I8259
, "Received operation command word 3.\n");
145 DPRINTF(I8259
, "%s special mask mode.\n",
146 bits(val
, 6) ? "Set" : "Clear");
149 readIRR
= bits(val
, 0);
150 DPRINTF(I8259
, "Read %s.\n", readIRR
? "IRR" : "ISR");
155 switch (initControlWord
) {
157 DPRINTF(I8259
, "Received operation command word 1.\n");
158 DPRINTF(I8259
, "Wrote IMR value %#x.\n", val
);
162 DPRINTF(I8259
, "Received initialization command word 2.\n");
163 vectorOffset
= val
& ~mask(3);
164 DPRINTF(I8259
, "Responsible for vectors %#x-%#x.\n",
165 vectorOffset
, vectorOffset
| mask(3));
174 DPRINTF(I8259
, "Received initialization command word 3.\n");
175 if (mode
== Enums::I8259Master
) {
176 DPRINTF(I8259
, "Slaves attached to IRQs:%s%s%s%s%s%s%s%s\n",
177 bits(val
, 0) ? " 0" : "",
178 bits(val
, 1) ? " 1" : "",
179 bits(val
, 2) ? " 2" : "",
180 bits(val
, 3) ? " 3" : "",
181 bits(val
, 4) ? " 4" : "",
182 bits(val
, 5) ? " 5" : "",
183 bits(val
, 6) ? " 6" : "",
184 bits(val
, 7) ? " 7" : "");
187 DPRINTF(I8259
, "Slave ID is %d.\n", val
& mask(3));
188 cascadeBits
= val
& mask(3);
196 DPRINTF(I8259
, "Received initialization command word 4.\n");
198 DPRINTF(I8259
, "Special fully nested mode.\n");
200 DPRINTF(I8259
, "Not special fully nested mode.\n");
202 if (bits(val
, 3) == 0) {
203 DPRINTF(I8259
, "Nonbuffered.\n");
204 } else if (bits(val
, 2) == 0) {
205 DPRINTF(I8259
, "Buffered.\n");
207 DPRINTF(I8259
, "Unrecognized buffer mode.\n");
209 autoEOI
= bits(val
, 1);
210 DPRINTF(I8259
, "%s End Of Interrupt.\n",
211 autoEOI
? "Automatic" : "Normal");
213 DPRINTF(I8259
, "%s mode.\n", bits(val
, 0) ? "80x86" : "MCX-80/85");
223 X86ISA::I8259::handleEOI(int line
)
226 // There may be an interrupt that was waiting which can
229 requestInterrupt(findMsbSet(IRR
));
233 X86ISA::I8259::requestInterrupt(int line
)
235 if (bits(ISR
, 7, line
) == 0) {
237 DPRINTF(I8259
, "Propogating interrupt.\n");
238 output
->signalInterrupt();
240 warn("Received interrupt but didn't have "
241 "anyone to tell about it.\n");
247 X86ISA::I8259::signalInterrupt(int line
)
249 DPRINTF(I8259
, "Interrupt raised on line %d.\n", line
);
250 if (line
>= NumLines
)
251 fatal("Line number %d doesn't exist. The max is %d.\n",
253 if (bits(IMR
, line
)) {
254 DPRINTF(I8259
, "Interrupt %d was masked.\n", line
);
257 requestInterrupt(line
);
262 X86ISA::I8259::getVector()
265 * This code only handles one slave. Since that's how the PC platform
266 * always uses the 8259 PIC, there shouldn't be any need for more. If
267 * there -is- a need for more for some reason, "slave" can become a
270 int line
= findMsbSet(IRR
);
272 DPRINTF(I8259
, "Interrupt %d was accepted.\n", line
);
278 if (slave
&& bits(cascadeBits
, line
)) {
279 DPRINTF(I8259
, "Interrupt was from slave who will "
280 "provide the vector.\n");
281 return slave
->getVector();
283 return line
| vectorOffset
;
287 I8259Params::create()
289 return new X86ISA::I8259(this);