gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
interrupts.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 The Regents of The University of Michigan
3  * Copyright (c) 2007 MIPS Technologies, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "arch/mips/interrupts.hh"
31 
32 #include "arch/mips/isa_traits.hh"
34 #include "base/trace.hh"
35 #include "cpu/thread_context.hh"
36 #include "debug/Interrupt.hh"
37 
38 namespace MipsISA
39 {
40 
41 static inline uint8_t
43  CauseReg cause = tc->readMiscRegNoEffect(MISCREG_CAUSE);
44  return cause.ip;
45 }
46 
47 static inline void
48 setCauseIP(ThreadContext *tc, uint8_t val) {
49  CauseReg cause = tc->readMiscRegNoEffect(MISCREG_CAUSE);
50  cause.ip = val;
52 }
53 
54 void
56 {
57  DPRINTF(Interrupt, "Interrupt %d posted\n", int_num);
58  if (int_num < 0 || int_num >= NumInterruptLevels)
59  panic("int_num out of bounds\n");
60 
61  uint8_t intstatus = getCauseIP(tc);
62  intstatus |= 1 << int_num;
63  setCauseIP(tc, intstatus);
64 }
65 
66 void
67 Interrupts::post(int int_num, int index)
68 {
69  fatal("Must use Thread Context when posting MIPS Interrupts in M5");
70 }
71 
72 void
74 {
75  DPRINTF(Interrupt, "Interrupt %d cleared\n", int_num);
76  if (int_num < 0 || int_num >= NumInterruptLevels)
77  panic("int_num out of bounds\n");
78 
79  uint8_t intstatus = getCauseIP(tc);
80  intstatus &= ~(1 << int_num);
81  setCauseIP(tc, intstatus);
82 }
83 
84 void
85 Interrupts::clear(int int_num, int index)
86 {
87  fatal("Must use Thread Context when clearing MIPS Interrupts in M5");
88 }
89 
90 void
92 {
93  DPRINTF(Interrupt, "Interrupts all cleared\n");
94  uint8_t intstatus = 0;
95  setCauseIP(tc, intstatus);
96 }
97 
98 void
100 {
101  fatal("Must use Thread Context when clearing MIPS Interrupts in M5");
102 }
103 
104 
105 bool
107 {
108  if (!interruptsPending(tc))
109  return false;
110 
111  //Check if there are any outstanding interrupts
112  StatusReg status = tc->readMiscRegNoEffect(MISCREG_STATUS);
113  // Interrupts must be enabled, error level must be 0 or interrupts
114  // inhibited, and exception level must be 0 or interrupts inhibited
115  if ((status.ie == 1) && (status.erl == 0) && (status.exl == 0)) {
116  // Software interrupts & hardware interrupts are handled in software.
117  // So if any interrupt that isn't masked is detected, jump to interrupt
118  // handler
119  CauseReg cause = tc->readMiscRegNoEffect(MISCREG_CAUSE);
120  if (status.im && cause.ip)
121  return true;
122 
123  }
124 
125  return false;
126 }
127 
128 Fault
130 {
131  assert(checkInterrupts(tc));
132 
133  StatusReg M5_VAR_USED status = tc->readMiscRegNoEffect(MISCREG_STATUS);
134  CauseReg M5_VAR_USED cause = tc->readMiscRegNoEffect(MISCREG_CAUSE);
135  DPRINTF(Interrupt, "Interrupt! IM[7:0]=%d IP[7:0]=%d \n",
136  (unsigned)status.im, (unsigned)cause.ip);
137 
138  return std::make_shared<InterruptFault>();
139 }
140 
141 bool
143 {
146  if (compare == count && count != 0)
147  return true;
148  return false;
149 }
150 
151 void
153 {
154  //Nothing needs to be done.
155 }
156 
157 bool
159 {
160  //if there is a on cpu timer interrupt (i.e. Compare == Count)
161  //update CauseIP before proceeding to interrupt
162  if (onCpuTimerInterrupt(tc)) {
163  DPRINTF(Interrupt, "Interrupts OnCpuTimerINterrupt(tc) == true\n");
164  //determine timer interrupt IP #
165  IntCtlReg intCtl = tc->readMiscRegNoEffect(MISCREG_INTCTL);
166  uint8_t intStatus = getCauseIP(tc);
167  intStatus |= 1 << intCtl.ipti;
168  setCauseIP(tc, intStatus);
169  }
170 
171  return (getCauseIP(tc) != 0);
172 
173 }
174 
175 }
176 
178 MipsInterruptsParams::create()
179 {
180  return new MipsISA::Interrupts(this);
181 }
count
Definition: misc.hh:703
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
#define DPRINTF(x,...)
Definition: trace.hh:222
void post(int int_num, ThreadContext *tc)
Definition: interrupts.cc:55
Bitfield< 30, 0 > index
void clear(int int_num, ThreadContext *tc)
Definition: interrupts.cc:73
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:171
bool interruptsPending(ThreadContext *tc) const
Definition: interrupts.cc:158
bool checkInterrupts(ThreadContext *tc) const override
Definition: interrupts.cc:106
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
void updateIntrInfo(ThreadContext *tc) override
Definition: interrupts.cc:152
uint64_t RegVal
Definition: types.hh:166
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Bitfield< 63 > val
Definition: misc.hh:769
Bitfield< 5, 0 > status
static uint8_t getCauseIP(ThreadContext *tc)
Definition: interrupts.cc:42
Fault getInterrupt(ThreadContext *tc) override
Definition: interrupts.cc:129
void clearAll() override
Definition: interrupts.cc:99
static void setCauseIP(ThreadContext *tc, uint8_t val)
Definition: interrupts.cc:48
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
bool compare(T src0, T src1, Brig::BrigCompareOperation cmpOp)
Definition: decl.hh:592
bool onCpuTimerInterrupt(ThreadContext *tc) const
Definition: interrupts.cc:142
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238

Generated on Mon Jun 8 2020 15:34:39 for gem5 by doxygen 1.8.13