gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
interrupts.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 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) 2007 The Hewlett-Packard Development Company
15  * All rights reserved.
16  *
17  * The license below extends only to copyright in the software and shall
18  * not be construed as granting a license to any other intellectual
19  * property including but not limited to intellectual property relating
20  * to a hardware implementation of the functionality of the software
21  * licensed hereunder. You may use the software subject to the license
22  * terms below provided that you ensure that this notice is replicated
23  * unmodified and in its entirety in all distributions of the software,
24  * modified or unmodified, in source code or in binary form.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions are
28  * met: redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer;
30  * redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in the
32  * documentation and/or other materials provided with the distribution;
33  * neither the name of the copyright holders nor the names of its
34  * contributors may be used to endorse or promote products derived from
35  * this software without specific prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  *
49  * Authors: Gabe Black
50  * Andreas Hansson
51  */
52 
53 #ifndef __ARCH_X86_INTERRUPTS_HH__
54 #define __ARCH_X86_INTERRUPTS_HH__
55 
57 #include "arch/x86/faults.hh"
58 #include "arch/x86/intmessage.hh"
59 #include "arch/x86/regs/apic.hh"
60 #include "base/bitfield.hh"
61 #include "cpu/thread_context.hh"
62 #include "dev/io_device.hh"
63 #include "dev/x86/intdev.hh"
64 #include "params/X86LocalApic.hh"
65 #include "sim/eventq.hh"
66 
67 class ThreadContext;
68 class BaseCPU;
69 
70 int divideFromConf(uint32_t conf);
71 
72 namespace X86ISA {
73 
75 
76 class Interrupts : public BaseInterrupts
77 {
78  protected:
81 
82  // Storage for the APIC registers
83  uint32_t regs[NUM_APIC_REGS];
84 
85  BitUnion32(LVTEntry)
86  Bitfield<7, 0> vector;
87  Bitfield<10, 8> deliveryMode;
88  Bitfield<12> status;
89  Bitfield<13> polarity;
90  Bitfield<14> remoteIRR;
91  Bitfield<15> trigger;
92  Bitfield<16> masked;
93  Bitfield<17> periodic;
94  EndBitUnion(LVTEntry)
95 
96  /*
97  * Timing related stuff.
98  */
99  EventFunctionWrapper apicTimerEvent;
100  void processApicTimerEvent();
101 
102  /*
103  * A set of variables to keep track of interrupts that don't go through
104  * the IRR.
105  */
107  uint8_t smiVector;
109  uint8_t nmiVector;
111  uint8_t extIntVector;
113  uint8_t initVector;
115  uint8_t startupVector;
116  bool startedUp;
117 
118  // This is a quick check whether any of the above (except ExtInt) are set.
120 
121  // A count of how many IPIs are in flight.
123 
124  /*
125  * IRR and ISR maintenance.
126  */
127  uint8_t IRRV;
128  uint8_t ISRV;
129 
130  int
132  {
133  int offset = 7;
134  do {
135  if (regs[base + offset] != 0) {
136  return offset * 32 + findMsbSet(regs[base + offset]);
137  }
138  } while (offset--);
139  return 0;
140  }
141 
142  void
144  {
146  }
147 
148  void
150  {
152  }
153 
154  void
156  {
157  regs[base + (vector / 32)] |= (1 << (vector % 32));
158  }
159 
160  void
162  {
163  regs[base + (vector / 32)] &= ~(1 << (vector % 32));
164  }
165 
166  bool
168  {
169  return bits(regs[base + (vector / 32)], vector % 32);
170  }
171 
172  Tick clockPeriod() const { return clockDomain.clockPeriod(); }
173 
174  void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level);
175 
177 
179 
180  // Ports for interrupts.
183 
184  // Port for memory mapped register accesses.
186 
189 
190  public:
191 
192  int getInitialApicId() { return initialApicId; }
193 
194  /*
195  * Params stuff.
196  */
197  typedef X86LocalApicParams Params;
198 
199  void setCPU(BaseCPU * newCPU) override;
200 
201  const Params *
202  params() const
203  {
204  return dynamic_cast<const Params *>(_params);
205  }
206 
207  /*
208  * Initialize this object by registering it with the IO APIC.
209  */
210  void init() override;
211 
212  /*
213  * Functions to interact with the interrupt port.
214  */
215  Tick read(PacketPtr pkt);
216  Tick write(PacketPtr pkt);
218  void completeIPI(PacketPtr pkt);
219 
220  bool
222  {
223  LVTEntry entry = regs[APIC_LVT_TIMER];
224  if (!entry.masked)
225  requestInterrupt(entry.vector, entry.deliveryMode, entry.trigger);
226  return entry.periodic;
227  }
228 
231 
232  Port &getPort(const std::string &if_name,
233  PortID idx=InvalidPortID) override
234  {
235  if (if_name == "int_master") {
236  return intMasterPort;
237  } else if (if_name == "int_slave") {
238  return intSlavePort;
239  } else if (if_name == "pio") {
240  return pioPort;
241  }
242  return SimObject::getPort(if_name, idx);
243  }
244 
245  /*
246  * Functions to access and manipulate the APIC's registers.
247  */
248 
249  uint32_t readReg(ApicRegIndex miscReg);
250  void setReg(ApicRegIndex reg, uint32_t val);
251  void
252  setRegNoEffect(ApicRegIndex reg, uint32_t val)
253  {
254  regs[reg] = val;
255  }
256 
257  /*
258  * Constructor.
259  */
260 
261  Interrupts(Params * p);
262 
263  /*
264  * Functions for retrieving interrupts for the CPU to handle.
265  */
266 
267  bool checkInterrupts(ThreadContext *tc) const override;
274  bool checkInterruptsRaw() const;
281  Fault getInterrupt(ThreadContext *tc) override;
282  void updateIntrInfo(ThreadContext *tc) override;
283 
284  /*
285  * Serialization.
286  */
287  void serialize(CheckpointOut &cp) const override;
288  void unserialize(CheckpointIn &cp) override;
289 
290  /*
291  * Old functions needed for compatability but which will be phased out
292  * eventually.
293  */
294  void
295  post(int int_num, int index) override
296  {
297  panic("Interrupts::post unimplemented!\n");
298  }
299 
300  void
301  clear(int int_num, int index) override
302  {
303  panic("Interrupts::clear unimplemented!\n");
304  }
305 
306  void
307  clearAll() override
308  {
309  panic("Interrupts::clearAll unimplemented!\n");
310  }
311 };
312 
313 } // namespace X86ISA
314 
315 #endif // __ARCH_X86_INTERRUPTS_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
Bitfield< 14 > remoteIRR
Definition: interrupts.hh:90
offset
Definition: misc.hh:1026
Ports are used to interface objects to each other.
Definition: port.hh:60
virtual Port & getPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a port with a given name and index.
Definition: sim_object.cc:126
Bitfield< 5, 3 > reg
Definition: types.hh:89
void post(int int_num, int index) override
Definition: interrupts.hh:295
Bitfield< 17 > periodic
Definition: interrupts.hh:93
Bitfield< 5, 3 > index
Definition: types.hh:95
const Addr MaxAddr
Definition: types.hh:166
void setCPU(BaseCPU *newCPU) override
Definition: interrupts.cc:276
const PortID InvalidPortID
Definition: types.hh:238
IntMasterPort< Interrupts > intMasterPort
Definition: interrupts.hh:182
Bitfield< 10, 8 > deliveryMode
Definition: interrupts.hh:87
void completeIPI(PacketPtr pkt)
Definition: interrupts.cc:332
uint32_t readReg(ApicRegIndex miscReg)
Definition: interrupts.cc:367
int findRegArrayMSB(ApicRegIndex base)
Definition: interrupts.hh:131
void setRegNoEffect(ApicRegIndex reg, uint32_t val)
Definition: interrupts.hh:252
Bitfield< 16 > masked
Definition: interrupts.hh:92
void updateIntrInfo(ThreadContext *tc) override
Definition: interrupts.cc:687
void setReg(ApicRegIndex reg, uint32_t val)
Definition: interrupts.cc:405
Definition: system.hh:77
Definition: cprintf.cc:42
bool hasPendingUnmaskable() const
Check if there are pending unmaskable interrupts.
Definition: interrupts.hh:280
AddrRangeList getAddrRanges() const
Definition: interrupts.cc:346
ThreadContext is the external interface to all thread state for anything outside of the CPU...
BitUnion32(LVTEntry) Bitfield< 7
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: interrupts.cc:291
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition: interrupts.hh:232
Bitfield< 63 > val
Definition: misc.hh:771
EndBitUnion(LVTEntry) EventFunctionWrapper apicTimerEvent
Bitfield< 13 > polarity
Definition: interrupts.hh:89
Interrupts(Params *p)
Definition: interrupts.cc:598
bool checkInterrupts(ThreadContext *tc) const override
Definition: interrupts.cc:623
X86LocalApicParams Params
Definition: interrupts.hh:197
Fault getInterrupt(ThreadContext *tc) override
Definition: interrupts.cc:653
void setRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:155
uint64_t Tick
Tick count type.
Definition: types.hh:63
bool getRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:167
PioPort< Interrupts > pioPort
Definition: interrupts.hh:185
void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level)
Definition: interrupts.cc:226
Bitfield< 51, 12 > base
Definition: pagetable.hh:142
ApicRegIndex decodeAddr(Addr paddr)
Definition: interrupts.cc:83
uint32_t regs[NUM_APIC_REGS]
Definition: interrupts.hh:83
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Tick recvMessage(PacketPtr pkt)
Definition: interrupts.cc:304
ApicRegIndex
Definition: apic.hh:38
Tick read(PacketPtr pkt)
Definition: interrupts.cc:192
Bitfield< 20 > level
Definition: intmessage.hh:49
bool checkInterruptsRaw() const
Check if there are pending interrupts without ignoring the interrupts disabled flag.
Definition: interrupts.cc:645
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: interrupts.cc:722
void clear(int int_num, int index) override
Definition: interrupts.hh:301
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain...
Definition: clock_domain.hh:73
std::ostream CheckpointOut
Definition: serialize.hh:68
int divideFromConf(uint32_t conf)
Definition: interrupts.cc:69
This is exposed globally, independent of the ISA.
Definition: acpi.hh:57
Tick write(PacketPtr pkt)
Definition: interrupts.cc:209
IntSlavePort< Interrupts > intSlavePort
Definition: interrupts.hh:181
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
Bitfield< 12 > status
Definition: interrupts.hh:88
int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:204
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
Bitfield< 0 > p
Definition: pagetable.hh:152
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: interrupts.cc:747
const Params * params() const
Definition: interrupts.hh:202
T bits(T val, int first, int last)
Extract the bitfield from position &#39;first&#39; to &#39;last&#39; (inclusive) from &#39;val&#39; and right justify it...
Definition: bitfield.hh:72
bool triggerTimerInterrupt()
Definition: interrupts.hh:221
The PioPort class is a programmed i/o port that all devices that are sensitive to an address range us...
Definition: io_device.hh:63
void processApicTimerEvent()
Definition: interrupts.cc:785
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
void clearAll() override
Definition: interrupts.hh:307
void clearRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:161
Bitfield< 15 > trigger
Definition: interrupts.hh:91
Tick clockPeriod() const
Definition: interrupts.hh:172
ClockDomain & clockDomain
Definition: interrupts.hh:80
Tick clockPeriod() const
Get the clock period.
AddrRangeList getIntAddrRange() const
Definition: interrupts.cc:356

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13