gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
31
33#include "base/trace.hh"
34#include "cpu/thread_context.hh"
35#include "debug/Interrupt.hh"
36
37namespace gem5
38{
39
40namespace MipsISA
41{
42
62
63static inline uint8_t
65{
66 CauseReg cause = tc->readMiscRegNoEffect(misc_reg::Cause);
67 return cause.ip;
68}
69
70static inline void
72{
73 CauseReg cause = tc->readMiscRegNoEffect(misc_reg::Cause);
74 cause.ip = val;
76}
77
78void
79Interrupts::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
90void
91Interrupts::post(int int_num, int index)
92{
93 fatal("Must use Thread Context when posting MIPS Interrupts in M5");
94}
95
96void
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
108void
109Interrupts::clear(int int_num, int index)
110{
111 fatal("Must use Thread Context when clearing MIPS Interrupts in M5");
112}
113
114void
116{
117 DPRINTF(Interrupt, "Interrupts all cleared\n");
118 uint8_t intstatus = 0;
119 setCauseIP(tc, intstatus);
120}
121
122
123bool
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
146Fault
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
160bool
162{
165 if (compare == count && count != 0)
166 return true;
167 return false;
168}
169
170void Interrupts::updateIntrInfo() {} // Nothing needs to be done.
171
172bool
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:210
ThreadContext * tc
Definition interrupts.hh:44
bool onCpuTimerInterrupt() const
bool interruptsPending() const
void updateIntrInfo() override
Fault getInterrupt() override
void clearAll() override
void post(int int_num)
Definition interrupts.cc:79
bool checkInterrupts() const override
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:188
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
Bitfield< 5, 0 > status
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:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
uint64_t RegVal
Definition types.hh:173

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0