gem5  v22.1.0.0
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 
33 #include "base/trace.hh"
34 #include "cpu/thread_context.hh"
35 #include "debug/Interrupt.hh"
36 
37 namespace gem5
38 {
39 
40 namespace MipsISA
41 {
42 
44 {
47 
50 
57 
59 
61 };
62 
63 static inline uint8_t
65 {
66  CauseReg cause = tc->readMiscRegNoEffect(misc_reg::Cause);
67  return cause.ip;
68 }
69 
70 static inline void
72 {
73  CauseReg cause = tc->readMiscRegNoEffect(misc_reg::Cause);
74  cause.ip = val;
76 }
77 
78 void
79 Interrupts::post(int int_num)
80 {
81  DPRINTF(Interrupt, "Interrupt %d posted\n", int_num);
82  if (int_num < 0 || int_num >= NumInterruptLevels)
83  panic("int_num out of bounds\n");
84 
85  uint8_t intstatus = getCauseIP(tc);
86  intstatus |= 1 << int_num;
87  setCauseIP(tc, intstatus);
88 }
89 
90 void
91 Interrupts::post(int int_num, int index)
92 {
93  fatal("Must use Thread Context when posting MIPS Interrupts in M5");
94 }
95 
96 void
97 Interrupts::clear(int int_num)
98 {
99  DPRINTF(Interrupt, "Interrupt %d cleared\n", int_num);
100  if (int_num < 0 || int_num >= NumInterruptLevels)
101  panic("int_num out of bounds\n");
102 
103  uint8_t intstatus = getCauseIP(tc);
104  intstatus &= ~(1 << int_num);
105  setCauseIP(tc, intstatus);
106 }
107 
108 void
109 Interrupts::clear(int int_num, int index)
110 {
111  fatal("Must use Thread Context when clearing MIPS Interrupts in M5");
112 }
113 
114 void
116 {
117  DPRINTF(Interrupt, "Interrupts all cleared\n");
118  uint8_t intstatus = 0;
119  setCauseIP(tc, intstatus);
120 }
121 
122 
123 bool
125 {
126  if (!interruptsPending())
127  return false;
128 
129  //Check if there are any outstanding interrupts
131  // Interrupts must be enabled, error level must be 0 or interrupts
132  // inhibited, and exception level must be 0 or interrupts inhibited
133  if ((status.ie == 1) && (status.erl == 0) && (status.exl == 0)) {
134  // Software interrupts & hardware interrupts are handled in software.
135  // So if any interrupt that isn't masked is detected, jump to interrupt
136  // handler
137  CauseReg cause = tc->readMiscRegNoEffect(misc_reg::Cause);
138  if (status.im && cause.ip)
139  return true;
140 
141  }
142 
143  return false;
144 }
145 
146 Fault
148 {
149  assert(checkInterrupts());
150 
151  [[maybe_unused]] StatusReg status =
153  [[maybe_unused]] CauseReg cause = tc->readMiscRegNoEffect(misc_reg::Cause);
154  DPRINTF(Interrupt, "Interrupt! IM[7:0]=%d IP[7:0]=%d \n",
155  (unsigned)status.im, (unsigned)cause.ip);
156 
157  return std::make_shared<InterruptFault>();
158 }
159 
160 bool
162 {
165  if (compare == count && count != 0)
166  return true;
167  return false;
168 }
169 
170 void Interrupts::updateIntrInfo() {} // Nothing needs to be done.
171 
172 bool
174 {
175  //if there is a on cpu timer interrupt (i.e. Compare == Count)
176  //update CauseIP before proceeding to interrupt
177  if (onCpuTimerInterrupt()) {
178  DPRINTF(Interrupt, "Interrupts OnCpuTimerInterrupt() == true\n");
179  //determine timer interrupt IP #
180  IntCtlReg intCtl = tc->readMiscRegNoEffect(misc_reg::Intctl);
181  uint8_t intStatus = getCauseIP(tc);
182  intStatus |= 1 << intCtl.ipti;
183  setCauseIP(tc, intStatus);
184  }
185 
186  return (getCauseIP(tc) != 0);
187 
188 }
189 
190 } // namespace MipsISA
191 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
ThreadContext * tc
Definition: interrupts.hh:44
bool onCpuTimerInterrupt() const
Definition: interrupts.cc:161
bool interruptsPending() const
Definition: interrupts.cc:173
void updateIntrInfo() override
Definition: interrupts.cc:170
Fault getInterrupt() override
Definition: interrupts.cc:147
void clearAll() override
Definition: interrupts.cc:115
void post(int int_num)
Definition: interrupts.cc:79
bool checkInterrupts() const override
Definition: interrupts.cc:124
void clear(int int_num)
Definition: interrupts.cc:97
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:190
Bitfield< 5, 0 > status
Definition: misc_types.hh:429
@ INTLEVEL_SOFTWARE_MIN
Definition: interrupts.cc:45
@ INTLEVEL_EXTERNAL_MAX
Definition: interrupts.cc:49
@ INTLEVEL_EXTERNAL_MIN
Definition: interrupts.cc:48
@ INTLEVEL_SOFTWARE_MAX
Definition: interrupts.cc:46
static uint8_t getCauseIP(ThreadContext *tc)
Definition: interrupts.cc:64
Bitfield< 30, 0 > index
static void setCauseIP(ThreadContext *tc, uint8_t val)
Definition: interrupts.cc:71
Bitfield< 63 > val
Definition: misc.hh:776
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
uint64_t RegVal
Definition: types.hh:173

Generated on Wed Dec 21 2022 10:22:24 for gem5 by doxygen 1.9.1