gem5
v24.0.0.0
Loading...
Searching...
No Matches
arch
mips
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/pra_constants.hh
"
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
43
enum
InterruptLevels
44
{
45
INTLEVEL_SOFTWARE_MIN
= 4,
46
INTLEVEL_SOFTWARE_MAX
= 19,
47
48
INTLEVEL_EXTERNAL_MIN
= 20,
49
INTLEVEL_EXTERNAL_MAX
= 34,
50
51
INTLEVEL_IRQ0
= 20,
52
INTLEVEL_IRQ1
= 21,
53
INTINDEX_ETHERNET
= 0,
54
INTINDEX_SCSI
= 1,
55
INTLEVEL_IRQ2
= 22,
56
INTLEVEL_IRQ3
= 23,
57
58
INTLEVEL_SERIAL
= 33,
59
60
NumInterruptLevels
=
INTLEVEL_EXTERNAL_MAX
61
};
62
63
static
inline
uint8_t
64
getCauseIP
(
ThreadContext
*tc)
65
{
66
CauseReg cause = tc->
readMiscRegNoEffect
(
misc_reg::Cause
);
67
return
cause.ip;
68
}
69
70
static
inline
void
71
setCauseIP
(
ThreadContext
*tc, uint8_t
val
)
72
{
73
CauseReg cause = tc->
readMiscRegNoEffect
(
misc_reg::Cause
);
74
cause.ip =
val
;
75
tc->
setMiscRegNoEffect
(
misc_reg::Cause
, cause);
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
115
Interrupts::clearAll
()
116
{
117
DPRINTF
(
Interrupt
,
"Interrupts all cleared\n"
);
118
uint8_t intstatus = 0;
119
setCauseIP
(
tc
, intstatus);
120
}
121
122
123
bool
124
Interrupts::checkInterrupts
()
const
125
{
126
if
(!
interruptsPending
())
127
return
false
;
128
129
//Check if there are any outstanding interrupts
130
StatusReg
status
=
tc
->
readMiscRegNoEffect
(
misc_reg::Status
);
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
147
Interrupts::getInterrupt
()
148
{
149
assert(
checkInterrupts
());
150
151
[[maybe_unused]] StatusReg
status
=
152
tc
->
readMiscRegNoEffect
(
misc_reg::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
161
Interrupts::onCpuTimerInterrupt
()
const
162
{
163
RegVal
compare =
tc
->
readMiscRegNoEffect
(
misc_reg::Compare
);
164
RegVal
count
=
tc
->
readMiscRegNoEffect
(
misc_reg::Count
);
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
173
Interrupts::interruptsPending
()
const
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
trace.hh
DPRINTF
#define DPRINTF(x,...)
Definition
trace.hh:210
gem5::ArmISA::Interrupt
Definition
faults.hh:593
gem5::BaseInterrupts::tc
ThreadContext * tc
Definition
interrupts.hh:44
gem5::MipsISA::Interrupts::onCpuTimerInterrupt
bool onCpuTimerInterrupt() const
Definition
interrupts.cc:161
gem5::MipsISA::Interrupts::interruptsPending
bool interruptsPending() const
Definition
interrupts.cc:173
gem5::MipsISA::Interrupts::updateIntrInfo
void updateIntrInfo() override
Definition
interrupts.cc:170
gem5::MipsISA::Interrupts::getInterrupt
Fault getInterrupt() override
Definition
interrupts.cc:147
gem5::MipsISA::Interrupts::clearAll
void clearAll() override
Definition
interrupts.cc:115
gem5::MipsISA::Interrupts::post
void post(int int_num)
Definition
interrupts.cc:79
gem5::MipsISA::Interrupts::checkInterrupts
bool checkInterrupts() const override
Definition
interrupts.cc:124
gem5::MipsISA::Interrupts::clear
void clear(int int_num)
Definition
interrupts.cc:97
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition
guest_abi.test.cc:41
gem5::ThreadContext::setMiscRegNoEffect
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
gem5::ThreadContext::readMiscRegNoEffect
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
thread_context.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition
logging.hh:188
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition
logging.hh:200
interrupts.hh
pra_constants.hh
gem5::ArmISA::status
Bitfield< 5, 0 > status
Definition
misc_types.hh:507
gem5::MipsISA::misc_reg::Count
@ Count
Definition
misc.hh:94
gem5::MipsISA::misc_reg::Intctl
@ Intctl
Definition
misc.hh:101
gem5::MipsISA::misc_reg::Compare
@ Compare
Definition
misc.hh:98
gem5::MipsISA::misc_reg::Cause
@ Cause
Definition
misc.hh:105
gem5::MipsISA::misc_reg::Status
@ Status
Definition
misc.hh:100
gem5::MipsISA::InterruptLevels
InterruptLevels
Definition
interrupts.cc:44
gem5::MipsISA::INTLEVEL_IRQ1
@ INTLEVEL_IRQ1
Definition
interrupts.cc:52
gem5::MipsISA::INTLEVEL_SOFTWARE_MIN
@ INTLEVEL_SOFTWARE_MIN
Definition
interrupts.cc:45
gem5::MipsISA::INTLEVEL_IRQ2
@ INTLEVEL_IRQ2
Definition
interrupts.cc:55
gem5::MipsISA::INTLEVEL_IRQ0
@ INTLEVEL_IRQ0
Definition
interrupts.cc:51
gem5::MipsISA::INTINDEX_ETHERNET
@ INTINDEX_ETHERNET
Definition
interrupts.cc:53
gem5::MipsISA::INTINDEX_SCSI
@ INTINDEX_SCSI
Definition
interrupts.cc:54
gem5::MipsISA::INTLEVEL_SERIAL
@ INTLEVEL_SERIAL
Definition
interrupts.cc:58
gem5::MipsISA::INTLEVEL_EXTERNAL_MAX
@ INTLEVEL_EXTERNAL_MAX
Definition
interrupts.cc:49
gem5::MipsISA::NumInterruptLevels
@ NumInterruptLevels
Definition
interrupts.cc:60
gem5::MipsISA::INTLEVEL_EXTERNAL_MIN
@ INTLEVEL_EXTERNAL_MIN
Definition
interrupts.cc:48
gem5::MipsISA::INTLEVEL_IRQ3
@ INTLEVEL_IRQ3
Definition
interrupts.cc:56
gem5::MipsISA::INTLEVEL_SOFTWARE_MAX
@ INTLEVEL_SOFTWARE_MAX
Definition
interrupts.cc:46
gem5::MipsISA::getCauseIP
static uint8_t getCauseIP(ThreadContext *tc)
Definition
interrupts.cc:64
gem5::MipsISA::index
Bitfield< 30, 0 > index
Definition
pra_constants.hh:47
gem5::MipsISA::setCauseIP
static void setCauseIP(ThreadContext *tc, uint8_t val)
Definition
interrupts.cc:71
gem5::X86ISA::count
count
Definition
misc.hh:738
gem5::X86ISA::val
Bitfield< 63 > val
Definition
misc.hh:804
gem5
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition
binary32.hh:36
gem5::Fault
std::shared_ptr< FaultBase > Fault
Definition
types.hh:249
gem5::RegVal
uint64_t RegVal
Definition
types.hh:173
Generated on Tue Jun 18 2024 16:23:57 for gem5 by
doxygen
1.11.0