gem5 v24.0.0.0
Loading...
Searching...
No Matches
interrupts.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, 2012-2013, 2016, 2023 Arm Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __ARCH_ARM_INTERRUPT_HH__
42#define __ARCH_ARM_INTERRUPT_HH__
43
44#include "arch/arm/faults.hh"
45#include "arch/arm/regs/misc.hh"
46#include "arch/arm/utility.hh"
48#include "cpu/thread_context.hh"
49#include "debug/Interrupt.hh"
50#include "enums/ArmExtension.hh"
51#include "params/ArmInterrupts.hh"
52
53namespace gem5
54{
55
56namespace ArmISA
57{
58
60{
65 INT_SEV, // Special interrupt for recieving SEV's
69 // Cannot be raised by an external signal
70 // (for now) from the IC so we don't instantiate a
71 // interrupt entry in the state array
73};
74
76{
77 private:
79 uint64_t intStatus;
80
81 public:
82 using Params = ArmInterruptsParams;
83
85 {
86 clearAll();
87 }
88
89
90 void
91 post(int int_num, int index) override
92 {
93 DPRINTF(Interrupt, "Interrupt %d:%d posted\n", int_num, index);
94
95 if (int_num < 0 || int_num >= NumInterruptTypes)
96 panic("int_num out of bounds\n");
97
98 if (index != 0)
99 panic("No support for other interrupt indexes\n");
100
101 interrupts[int_num] = true;
102 intStatus |= 1ULL << int_num;
103 }
104
105 void
106 clear(int int_num, int index) override
107 {
108 DPRINTF(Interrupt, "Interrupt %d:%d cleared\n", int_num, index);
109
110 if (int_num < 0 || int_num >= NumInterruptTypes)
111 panic("int_num out of bounds\n");
112
113 if (index != 0)
114 panic("No support for other interrupt indexes\n");
115
116 interrupts[int_num] = false;
117 intStatus &= ~(1ULL << int_num);
118 }
119
120 void
121 clearAll() override
122 {
123 DPRINTF(Interrupt, "Interrupts all cleared\n");
124 intStatus = 0;
125 memset(interrupts, 0, sizeof(interrupts));
126 }
127
129 {
130 INT_MASK_M, // masked (subject to PSTATE.{A,I,F} mask bit
131 INT_MASK_T, // taken regardless of mask
132 INT_MASK_P // pending
133 };
134
135 bool takeInt(InterruptTypes int_type) const;
136 bool takeInt32(InterruptTypes int_type) const;
137 bool takeInt64(InterruptTypes int_type) const;
138
139 bool takeVirtualInt(InterruptTypes int_type) const;
140 bool takeVirtualInt32(InterruptTypes int_type) const;
141 bool takeVirtualInt64(InterruptTypes int_type) const;
142
143 bool
144 checkInterrupts() const override
145 {
146 HCR hcr = tc->readMiscReg(MISCREG_HCR_EL2);
147
148 if (!(intStatus || hcr.va || hcr.vi || hcr.vf))
149 return false;
150
151 return ((interrupts[INT_IRQ] && takeInt(INT_IRQ)) ||
154 ((interrupts[INT_VIRT_IRQ] || hcr.vi) &&
156 ((interrupts[INT_VIRT_FIQ] || hcr.vf) &&
158 (hcr.va && takeVirtualInt(INT_VIRT_ABT)) ||
159 (interrupts[INT_RST]) ||
161 );
162 }
163
169 bool
170 checkWfiWake(HCR hcr, CPSR cpsr, SCR scr) const
171 {
172 uint64_t masked_int_status;
173 bool virt_wake;
174
175 masked_int_status = intStatus & ~((1 << INT_VIRT_IRQ) |
176 (1 << INT_VIRT_FIQ));
177 virt_wake = (hcr.vi || interrupts[INT_VIRT_IRQ]) && hcr.imo;
178 virt_wake |= (hcr.vf || interrupts[INT_VIRT_FIQ]) && hcr.fmo;
179 virt_wake |= hcr.va && hcr.amo;
180 virt_wake &= currEL(cpsr) < EL2 && EL2Enabled(tc);
181 return masked_int_status || virt_wake;
182 }
183
184 uint32_t
185 getISR(HCR hcr, CPSR cpsr, SCR scr)
186 {
187 bool use_hcr_mux = currEL(cpsr) < EL2 && EL2Enabled(tc);
188 ISR isr = 0;
189
190 isr.i = (use_hcr_mux & hcr.imo) ? (interrupts[INT_VIRT_IRQ] || hcr.vi)
192 isr.f = (use_hcr_mux & hcr.fmo) ? (interrupts[INT_VIRT_FIQ] || hcr.vf)
194 isr.a = (use_hcr_mux & hcr.amo) ? hcr.va : interrupts[INT_ABT];
195 return isr;
196 }
197
208 bool
209 checkRaw(InterruptTypes interrupt) const
210 {
211 if (interrupt >= NumInterruptTypes)
212 panic("Interrupt number out of range.\n");
213
214 return interrupts[interrupt];
215 }
216
217 Fault
218 getInterrupt() override
219 {
220 assert(checkInterrupts());
221
222 HCR hcr = tc->readMiscReg(MISCREG_HCR_EL2);
223
225 return std::make_shared<Interrupt>();
226 if ((interrupts[INT_VIRT_IRQ] || hcr.vi) &&
228 return std::make_shared<VirtualInterrupt>();
230 return std::make_shared<FastInterrupt>();
231 if ((interrupts[INT_VIRT_FIQ] || hcr.vf) &&
233 return std::make_shared<VirtualFastInterrupt>();
235 return std::make_shared<SystemError>();
236 if (hcr.va && takeVirtualInt(INT_VIRT_ABT))
237 return std::make_shared<VirtualDataAbort>(
240 if (interrupts[INT_RST])
241 return std::make_shared<Reset>();
242 if (interrupts[INT_SEV])
243 return std::make_shared<ArmSev>();
244
245 panic("intStatus and interrupts not in sync\n");
246 }
247
248 void updateIntrInfo() override {} // nothing to do
249
250 void
256
257 void
263};
264
265} // namespace ARM_ISA
266} // namespace gem5
267
268#endif // __ARCH_ARM_INTERRUPT_HH__
#define DPRINTF(x,...)
Definition trace.hh:210
void clearAll() override
bool checkInterrupts() const override
uint32_t getISR(HCR hcr, CPSR cpsr, SCR scr)
bool takeInt64(InterruptTypes int_type) const
void updateIntrInfo() override
bool takeInt(InterruptTypes int_type) const
bool takeInt32(InterruptTypes int_type) const
Definition interrupts.cc:46
void clear(int int_num, int index) override
bool interrupts[NumInterruptTypes]
Definition interrupts.hh:78
bool takeVirtualInt64(InterruptTypes int_type) const
void serialize(CheckpointOut &cp) const override
Serialize an object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void post(int int_num, int index) override
Definition interrupts.hh:91
bool takeVirtualInt(InterruptTypes int_type) const
bool checkRaw(InterruptTypes interrupt) const
Check the state of a particular interrupt, ignoring CPSR masks.
ArmInterruptsParams Params
Definition interrupts.hh:82
bool takeVirtualInt32(InterruptTypes int_type) const
bool checkWfiWake(HCR hcr, CPSR cpsr, SCR scr) const
This function is used to check if a wfi operation should sleep.
Fault getInterrupt() override
Interrupts(const Params &p)
Definition interrupts.hh:84
ThreadContext * tc
Definition interrupts.hh:44
virtual RegVal readMiscReg(RegIndex misc_reg)=0
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define UNSERIALIZE_ARRAY(member, size)
Definition serialize.hh:618
#define SERIALIZE_ARRAY(member, size)
Definition serialize.hh:610
ExceptionLevel currEL(const ThreadContext *tc)
Returns the current Exception Level (EL) of the provided ThreadContext.
Definition utility.cc:133
bool EL2Enabled(ThreadContext *tc)
Definition utility.cc:267
@ MISCREG_HCR_EL2
Definition misc.hh:595
Bitfield< 30, 0 > index
Bitfield< 0 > p
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
std::ostream CheckpointOut
Definition serialize.hh:66
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

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