gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
56 #include "arch/x86/regs/apic.hh"
57 #include "arch/x86/faults.hh"
58 #include "arch/x86/intmessage.hh"
59 #include "base/bitfield.hh"
60 #include "cpu/thread_context.hh"
61 #include "dev/x86/intdev.hh"
62 #include "dev/io_device.hh"
63 #include "params/X86LocalApic.hh"
64 #include "sim/eventq.hh"
65 
66 class ThreadContext;
67 class BaseCPU;
68 
69 int divideFromConf(uint32_t conf);
70 
71 namespace X86ISA {
72 
74 
76 {
77  protected:
78  // Storage for the APIC registers
79  uint32_t regs[NUM_APIC_REGS];
80 
81  BitUnion32(LVTEntry)
82  Bitfield<7, 0> vector;
83  Bitfield<10, 8> deliveryMode;
84  Bitfield<12> status;
85  Bitfield<13> polarity;
86  Bitfield<14> remoteIRR;
87  Bitfield<15> trigger;
88  Bitfield<16> masked;
89  Bitfield<17> periodic;
90  EndBitUnion(LVTEntry)
91 
92  /*
93  * Timing related stuff.
94  */
95  class ApicTimerEvent : public Event
96  {
97  private:
98  Interrupts *localApic;
99  public:
100  ApicTimerEvent(Interrupts *_localApic) :
101  Event(), localApic(_localApic)
102  {}
103 
104  void process()
105  {
106  assert(localApic);
107  if (localApic->triggerTimerInterrupt()) {
108  localApic->setReg(APIC_INITIAL_COUNT,
109  localApic->readReg(APIC_INITIAL_COUNT));
110  }
111  }
112  };
113 
115 
116  /*
117  * A set of variables to keep track of interrupts that don't go through
118  * the IRR.
119  */
121  uint8_t smiVector;
123  uint8_t nmiVector;
125  uint8_t extIntVector;
127  uint8_t initVector;
129  uint8_t startupVector;
130  bool startedUp;
131 
132  // This is a quick check whether any of the above (except ExtInt) are set.
134 
135  // A count of how many IPIs are in flight.
137 
138  /*
139  * IRR and ISR maintenance.
140  */
141  uint8_t IRRV;
142  uint8_t ISRV;
143 
144  int
146  {
147  int offset = 7;
148  do {
149  if (regs[base + offset] != 0) {
150  return offset * 32 + findMsbSet(regs[base + offset]);
151  }
152  } while (offset--);
153  return 0;
154  }
155 
156  void
158  {
160  }
161 
162  void
164  {
166  }
167 
168  void
170  {
171  regs[base + (vector / 32)] |= (1 << (vector % 32));
172  }
173 
174  void
176  {
177  regs[base + (vector / 32)] &= ~(1 << (vector % 32));
178  }
179 
180  bool
182  {
183  return bits(regs[base + (vector / 32)], vector % 32);
184  }
185 
186  void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level);
187 
189 
191 
192  // Port for receiving interrupts
193  IntSlavePort intSlavePort;
194 
195  public:
196 
197  int getInitialApicId() { return initialApicId; }
198 
199  /*
200  * Params stuff.
201  */
202  typedef X86LocalApicParams Params;
203 
204  void setCPU(BaseCPU * newCPU);
205 
206  const Params *
207  params() const
208  {
209  return dynamic_cast<const Params *>(_params);
210  }
211 
212  /*
213  * Initialize this object by registering it with the IO APIC.
214  */
215  void init() override;
216 
217  /*
218  * Functions to interact with the interrupt port from IntDevice.
219  */
220  Tick read(PacketPtr pkt) override;
221  Tick write(PacketPtr pkt) override;
222  Tick recvMessage(PacketPtr pkt) override;
223  Tick recvResponse(PacketPtr pkt) override;
224 
225  bool
227  {
228  LVTEntry entry = regs[APIC_LVT_TIMER];
229  if (!entry.masked)
230  requestInterrupt(entry.vector, entry.deliveryMode, entry.trigger);
231  return entry.periodic;
232  }
233 
234  AddrRangeList getIntAddrRange() const override;
235 
236  BaseMasterPort &getMasterPort(const std::string &if_name,
237  PortID idx = InvalidPortID) override
238  {
239  if (if_name == "int_master") {
240  return intMasterPort;
241  }
242  return BasicPioDevice::getMasterPort(if_name, idx);
243  }
244 
245  BaseSlavePort &getSlavePort(const std::string &if_name,
246  PortID idx = InvalidPortID) override
247  {
248  if (if_name == "int_slave") {
249  return intSlavePort;
250  }
251  return BasicPioDevice::getSlavePort(if_name, idx);
252  }
253 
254  /*
255  * Functions to access and manipulate the APIC's registers.
256  */
257 
258  uint32_t readReg(ApicRegIndex miscReg);
259  void setReg(ApicRegIndex reg, uint32_t val);
260  void
262  {
263  regs[reg] = val;
264  }
265 
266  /*
267  * Constructor.
268  */
269 
270  Interrupts(Params * p);
271 
272  /*
273  * Functions for retrieving interrupts for the CPU to handle.
274  */
275 
276  bool checkInterrupts(ThreadContext *tc) const;
283  bool checkInterruptsRaw() const;
291  void updateIntrInfo(ThreadContext *tc);
292 
293  /*
294  * Serialization.
295  */
296  void serialize(CheckpointOut &cp) const override;
297  void unserialize(CheckpointIn &cp) override;
298 
299  /*
300  * Old functions needed for compatability but which will be phased out
301  * eventually.
302  */
303  void
304  post(int int_num, int index)
305  {
306  panic("Interrupts::post unimplemented!\n");
307  }
308 
309  void
310  clear(int int_num, int index)
311  {
312  panic("Interrupts::clear unimplemented!\n");
313  }
314 
315  void
317  {
318  panic("Interrupts::clearAll unimplemented!\n");
319  }
320 };
321 
322 } // namespace X86ISA
323 
324 #endif // __ARCH_X86_INTERRUPTS_HH__
Bitfield< 14 > remoteIRR
Definition: interrupts.hh:86
offset
Definition: misc.hh:977
Bitfield< 5, 3 > reg
Definition: types.hh:89
IntMasterPort intMasterPort
Definition: intdev.hh:112
Bitfield< 17 > periodic
Definition: interrupts.hh:89
Bitfield< 5, 3 > index
Definition: types.hh:95
void post(int int_num, int index)
Definition: interrupts.hh:304
const PortID InvalidPortID
Definition: types.hh:182
#define panic(...)
Definition: misc.hh:153
Bitfield< 10, 8 > deliveryMode
Definition: interrupts.hh:83
void setCPU(BaseCPU *newCPU)
Definition: interrupts.cc:275
uint32_t readReg(ApicRegIndex miscReg)
Definition: interrupts.cc:362
EndBitUnion(TriggerIntMessage) namespace DeliveryMode
Definition: intmessage.hh:50
int findRegArrayMSB(ApicRegIndex base)
Definition: interrupts.hh:145
void setRegNoEffect(ApicRegIndex reg, uint32_t val)
Definition: interrupts.hh:261
Bitfield< 16 > masked
Definition: interrupts.hh:88
Tick recvResponse(PacketPtr pkt) override
Definition: interrupts.cc:335
const Params * params() const
Definition: interrupts.hh:207
AddrRangeList getIntAddrRange() const override
Definition: interrupts.cc:351
void updateIntrInfo(ThreadContext *tc)
Definition: interrupts.cc:674
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: interrupts.cc:191
void setReg(ApicRegIndex reg, uint32_t val)
Definition: interrupts.cc:400
void clear(int int_num, int index)
Definition: interrupts.hh:310
ThreadContext is the external interface to all thread state for anything outside of the CPU...
ApicTimerEvent apicTimerEvent
Definition: interrupts.hh:112
A BaseSlavePort is a protocol-agnostic slave port, responsible only for the structural connection to ...
Definition: port.hh:139
void init() override
Definition: interrupts.cc:290
Bitfield< 63 > val
Definition: misc.hh:770
Tick recvMessage(PacketPtr pkt) override
Definition: interrupts.cc:307
Bitfield< 13 > polarity
Definition: interrupts.hh:85
Fault getInterrupt(ThreadContext *tc)
Definition: interrupts.cc:640
Interrupts(Params *p)
Definition: interrupts.cc:589
X86LocalApicParams Params
Definition: interrupts.hh:202
void setRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:169
uint64_t Tick
Tick count type.
Definition: types.hh:63
bool getRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:181
void requestInterrupt(uint8_t vector, uint8_t deliveryMode, bool level)
Definition: interrupts.cc:225
Bitfield< 51, 12 > base
Definition: pagetable.hh:85
ApicRegIndex decodeAddr(Addr paddr)
Definition: interrupts.cc:82
bool checkInterruptsRaw() const
Check if there are pending interrupts without ignoring the interrupts disabled flag.
Definition: interrupts.cc:632
uint32_t regs[NUM_APIC_REGS]
Definition: interrupts.hh:79
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
virtual BaseSlavePort & getSlavePort(const std::string &if_name, PortID idx=InvalidPortID)
Get a slave port with a given name and index.
Definition: io_device.cc:91
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
ApicRegIndex
Definition: apic.hh:38
Bitfield< 20 > level
Definition: intmessage.hh:48
BaseSlavePort & getSlavePort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a slave port with a given name and index.
Definition: interrupts.hh:245
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: interrupts.cc:709
std::ostream CheckpointOut
Definition: serialize.hh:67
int divideFromConf(uint32_t conf)
Definition: interrupts.cc:68
Definition: eventq.hh:185
ApicTimerEvent(Interrupts *_localApic)
Definition: interrupts.hh:100
bool checkInterrupts(ThreadContext *tc) const
Definition: interrupts.cc:610
A BaseMasterPort is a protocol-agnostic master port, responsible only for the structural connection t...
Definition: port.hh:115
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:107
bool hasPendingUnmaskable() const
Check if there are pending unmaskable interrupts.
Definition: interrupts.hh:289
IntSlavePort intSlavePort
Definition: interrupts.hh:193
Bitfield< 12 > status
Definition: interrupts.hh:84
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: interrupts.cc:208
int findMsbSet(uint64_t val)
Returns the bit position of the MSB that is set in the input.
Definition: bitfield.hh:163
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:181
BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a master port with a given name and index.
Definition: interrupts.hh:236
Bitfield< 0 > p
Definition: pagetable.hh:95
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: interrupts.cc:734
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
Definition: bitfield.hh:67
bool triggerTimerInterrupt()
Definition: interrupts.hh:226
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
BitUnion32(LVTEntry) Bitfield<7
virtual BaseMasterPort & getMasterPort(const std::string &if_name, PortID idx=InvalidPortID)
Get a master port with a given name and index.
Definition: mem_object.cc:52
void clearRegArrayBit(ApicRegIndex base, uint8_t vector)
Definition: interrupts.hh:175
Bitfield< 15 > trigger
Definition: interrupts.hh:87

Generated on Fri Jun 9 2017 13:03:34 for gem5 by doxygen 1.8.6