gem5  v22.1.0.0
thread_context.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__
29 #define __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__
30 
31 #include <list>
32 #include <map>
33 #include <memory>
34 #include <unordered_map>
35 
37 #include "arch/arm/regs/vec.hh"
38 #include "cpu/base.hh"
39 #include "cpu/thread_context.hh"
40 #include "iris/IrisInstance.h"
41 #include "iris/detail/IrisErrorCode.h"
42 #include "iris/detail/IrisObjects.h"
43 #include "sim/system.hh"
44 
45 namespace gem5
46 {
47 
48 namespace Iris
49 {
50 
51 // This class is the base for ThreadContexts which read and write state using
52 // the Iris API.
54 {
55  public:
56  typedef std::map<std::string, iris::ResourceInfo> ResourceMap;
57 
59  typedef std::map<int, std::string> IdxNameMap;
60 
61  typedef std::unordered_map<Iris::CanonicalMsn, iris::MemorySpaceId>
63 
64  protected:
66  int _threadId;
71 
72  std::string _irisPath;
73  iris::InstanceId _instId = iris::IRIS_UINT64_MAX;
74 
75  // Temporary holding places for the vector reg accessors to return.
76  // These are not updated live, only when requested.
79 
82 
83  virtual void initFromIrisInstance(const ResourceMap &resources);
84 
85  iris::ResourceId extractResourceId(
86  const ResourceMap &resources, const std::string &name);
88  const ResourceMap &resources, const IdxNameMap &idx_names);
89  iris::MemorySpaceId getMemorySpaceId(const Iris::CanonicalMsn& msn) const;
90 
91 
97 
98  iris::ResourceId pcRscId = iris::IRIS_UINT64_MAX;
99  iris::ResourceId icountRscId;
100 
103 
107 
108  // A queue to keep track of instruction count based events.
110  // A helper function to maintain the IRIS step count. This makes sure the
111  // step count is correct even after IRIS resets it for us, and also handles
112  // events which are supposed to happen at the current instruction count.
113  void maintainStepping();
114 
115 
116  using BpId = uint64_t;
117  struct BpInfo
118  {
122  std::shared_ptr<EventList> events;
123 
124  BpInfo(Addr _pc) : pc(_pc), events(new EventList) {}
125 
126  bool empty() const { return events->empty(); }
127  bool validIds() const { return !ids.empty(); }
128  void clearIds() { ids.clear(); }
129  };
130 
131  using BpInfoPtr = std::unique_ptr<BpInfo>;
132  using BpInfoMap = std::map<Addr, BpInfoPtr>;
133  using BpInfoIt = BpInfoMap::iterator;
134 
136 
138 
139  void installBp(BpInfoIt it);
140  void uninstallBp(BpInfoIt it);
141  void delBp(BpInfoIt it);
142 
144 
145 
146  iris::IrisErrorCode instanceRegistryChanged(
147  uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
148  uint64_t sInstId, bool syncEc, std::string &error_message_out);
149  iris::IrisErrorCode phaseInitLeave(
150  uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
151  uint64_t sInstId, bool syncEc, std::string &error_message_out);
152  iris::IrisErrorCode simulationTimeEvent(
153  uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
154  uint64_t sInstId, bool syncEc, std::string &error_message_out);
155  iris::IrisErrorCode breakpointHit(
156  uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
157  uint64_t sInstId, bool syncEc, std::string &error_message_out);
158  iris::IrisErrorCode semihostingEvent(
159  uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
160  uint64_t sInstId, bool syncEc, std::string &error_message_out);
161 
162  iris::EventStreamId regEventStreamId;
163  iris::EventStreamId initEventStreamId;
164  iris::EventStreamId timeEventStreamId;
165  iris::EventStreamId breakpointEventStreamId;
166  iris::EventStreamId semihostingEventStreamId;
167 
168  mutable iris::IrisInstance client;
169  iris::IrisCppAdapter &call() const { return client.irisCall(); }
170  iris::IrisCppAdapter &noThrow() const { return client.irisCallNoThrow(); }
171 
173 
174  void readMem(iris::MemorySpaceId space,
175  Addr addr, void *p, size_t size);
176  void writeMem(iris::MemorySpaceId space,
177  Addr addr, const void *p, size_t size);
178  bool translateAddress(Addr &paddr, iris::MemorySpaceId p_space,
179  Addr vaddr, iris::MemorySpaceId v_space);
180 
181  public:
182  ThreadContext(gem5::BaseCPU *cpu, int id, System *system,
183  gem5::BaseMMU *mmu, gem5::BaseISA *isa,
184  iris::IrisConnectionInterface *iris_if,
185  const std::string &iris_path);
186  virtual ~ThreadContext();
187 
188  virtual bool translateAddress(Addr &paddr, Addr vaddr) = 0;
189 
190  bool schedule(PCEvent *e) override;
191  bool remove(PCEvent *e) override;
192 
193  void scheduleInstCountEvent(Event *event, Tick count) override;
194  void descheduleInstCountEvent(Event *event) override;
195  Tick getCurrentInstCount() override;
196 
197  gem5::BaseCPU *getCpuPtr() override { return _cpu; }
198  int cpuId() const override { return _cpu->cpuId(); }
199  uint32_t socketId() const override { return _cpu->socketId(); }
200 
201  int threadId() const override { return _threadId; }
202  void setThreadId(int id) override { _threadId = id; }
203 
204  int contextId() const override { return _contextId; }
205  void setContextId(int id) override { _contextId = id; }
206 
207  BaseMMU *
208  getMMUPtr() override
209  {
210  return _mmu;
211  }
212 
213  CheckerCPU *getCheckerCpuPtr() override { return nullptr; }
214  InstDecoder *
215  getDecoderPtr() override
216  {
217  panic("%s not implemented.", __FUNCTION__);
218  }
219 
220  System *getSystemPtr() override { return _cpu->system; }
221 
222  BaseISA *
223  getIsaPtr() const override
224  {
225  return _isa;
226  }
227 
228  void sendFunctional(PacketPtr pkt) override;
229 
230  Process *
231  getProcessPtr() override
232  {
233  panic("%s not implemented.", __FUNCTION__);
234  }
235  void
237  {
238  panic("%s not implemented.", __FUNCTION__);
239  }
240 
241  Status status() const override;
242  void setStatus(Status new_status) override;
243  void activate() override { setStatus(Active); }
244  void suspend() override { setStatus(Suspended); }
245  void halt() override { setStatus(Halted); }
246 
247  void
248  takeOverFrom(gem5::ThreadContext *old_context) override
249  {
250  panic("%s not implemented.", __FUNCTION__);
251  }
252 
253  void regStats(const std::string &name) override {}
254 
255  // Not necessarily the best location for these...
256  // Having an extra function just to read these is obnoxious
257  Tick
258  readLastActivate() override
259  {
260  panic("%s not implemented.", __FUNCTION__);
261  }
263  {
264  panic("%s not implemented.", __FUNCTION__);
265  }
266 
267  void
269  {
270  panic("%s not implemented.", __FUNCTION__);
271  }
272 
273  void
274  clearArchRegs() override
275  {
276  warn("Ignoring clearArchRegs()");
277  }
278 
279  //
280  // New accessors for new decoder.
281  //
282  RegVal getReg(const RegId &reg) const override;
283  void getReg(const RegId &reg, void *val) const override;
284  void *getWritableReg(const RegId &reg) override;
285 
286  void setReg(const RegId &reg, RegVal val) override;
287  void setReg(const RegId &reg, const void *val) override;
288 
289  iris::ResourceId getIntRegRscId(RegIndex int_reg) const;
290  virtual RegVal readIntReg(RegIndex reg_idx) const;
291 
292  iris::ResourceId getVecRegRscId(RegIndex vec_reg) const;
293  virtual const ArmISA::VecRegContainer &readVecReg(const RegId &reg) const;
294  virtual ArmISA::VecRegContainer &
296  {
297  panic("%s not implemented.", __FUNCTION__);
298  }
299 
300  virtual RegVal
301  readVecElem(const RegId &reg) const
302  {
303  panic("%s not implemented.", __FUNCTION__);
304  }
305 
306  iris::ResourceId getVecPredRegRscId(RegIndex vec_reg) const;
307  virtual const ArmISA::VecPredRegContainer &
308  readVecPredReg(const RegId &reg) const;
311  {
312  panic("%s not implemented.", __FUNCTION__);
313  }
314 
315  virtual RegVal
316  readCCReg(RegIndex reg_idx) const
317  {
318  return readCCRegFlat(reg_idx);
319  }
320 
321  virtual void setIntReg(RegIndex reg_idx, RegVal val);
322 
323  virtual void
325  {
326  panic("%s not implemented.", __FUNCTION__);
327  }
328 
329  virtual void
331  {
332  panic("%s not implemented.", __FUNCTION__);
333  }
334 
335  virtual void
338  {
339  panic("%s not implemented.", __FUNCTION__);
340  }
341 
342  virtual void
344  {
345  setCCRegFlat(reg_idx, val);
346  }
347 
348  void pcStateNoRecord(const PCStateBase &val) override { pcState(val); }
349 
350  const PCStateBase &pcState() const override;
351  void pcState(const PCStateBase &val) override;
352 
353  iris::ResourceId getMiscRegRscId(RegIndex misc_reg) const;
354  RegVal readMiscRegNoEffect(RegIndex misc_reg) const override;
355  RegVal
356  readMiscReg(RegIndex misc_reg) override
357  {
358  return readMiscRegNoEffect(misc_reg);
359  }
360 
361  void setMiscRegNoEffect(RegIndex misc_reg, const RegVal val) override;
362  void
363  setMiscReg(RegIndex misc_reg, const RegVal val) override
364  {
365  setMiscRegNoEffect(misc_reg, val);
366  }
367 
368  // Also not necessarily the best location for these two. Hopefully will go
369  // away once we decide upon where st cond failures goes.
370  unsigned
371  readStCondFailures() const override
372  {
373  panic("%s not implemented.", __FUNCTION__);
374  }
375 
376  void
377  setStCondFailures(unsigned sc_failures) override
378  {
379  panic("%s not implemented.", __FUNCTION__);
380  }
381 
394  iris::ResourceId getIntRegFlatRscId(RegIndex int_reg) const;
395  virtual RegVal readIntRegFlat(RegIndex idx) const;
396  virtual void setIntRegFlat(RegIndex idx, uint64_t val);
397 
398  virtual const ArmISA::VecRegContainer &readVecRegFlat(RegIndex idx) const;
399  virtual ArmISA::VecRegContainer &
401  {
402  panic("%s not implemented.", __FUNCTION__);
403  }
404  virtual void
406  {
407  panic("%s not implemented.", __FUNCTION__);
408  }
409 
410  virtual RegVal
412  {
413  panic("%s not implemented.", __FUNCTION__);
414  }
415  virtual void
417  {
418  panic("%s not implemented.", __FUNCTION__);
419  }
420 
424  {
425  panic("%s not implemented.", __FUNCTION__);
426  }
427  virtual void
430  {
431  panic("%s not implemented.", __FUNCTION__);
432  }
433 
434  iris::ResourceId getCCRegFlatRscId(RegIndex cc_reg) const;
435  virtual RegVal readCCRegFlat(RegIndex idx) const;
436  virtual void setCCRegFlat(RegIndex idx, RegVal val);
439  // hardware transactional memory
440  void
441  htmAbortTransaction(uint64_t htm_uid, HtmFailureFaultCause cause) override
442  {
443  panic("%s not implemented.", __FUNCTION__);
444  }
445 
448  {
449  panic("%s not implemented.", __FUNCTION__);
450  }
451 
452  void
454  {
455  panic("%s not implemented.", __FUNCTION__);
456  }
457  void readMemWithCurrentMsn(Addr vaddr, size_t size, char *data);
458  void writeMemWithCurrentMsn(Addr vaddr, size_t size, const char *data);
459 };
460 
461 } // namespace Iris
462 } // namespace gem5
463 
464 #endif // __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__
const char data[]
uint32_t socketId() const
Reads this CPU's Socket ID.
Definition: base.hh:186
System * system
Definition: base.hh:375
int cpuId() const
Reads this CPU's ID.
Definition: base.hh:183
CheckerCPU class.
Definition: cpu.hh:85
Queue of events sorted in time order.
Definition: eventq.hh:623
void clearArchRegs() override
virtual void initFromIrisInstance(const ResourceMap &resources)
BaseISA * getIsaPtr() const override
virtual void setVecPredReg(const RegId &reg, const ArmISA::VecPredRegContainer &val)
void * getWritableReg(const RegId &reg) override
std::vector< iris::ResourceId > ResourceIds
int cpuId() const override
ThreadContext(gem5::BaseCPU *cpu, int id, System *system, gem5::BaseMMU *mmu, gem5::BaseISA *isa, iris::IrisConnectionInterface *iris_if, const std::string &iris_path)
iris::ResourceId getMiscRegRscId(RegIndex misc_reg) const
void htmAbortTransaction(uint64_t htm_uid, HtmFailureFaultCause cause) override
void copyArchRegs(gem5::ThreadContext *tc) override
bool remove(PCEvent *e) override
void uninstallBp(BpInfoIt it)
void setStatus(Status new_status) override
void readMemWithCurrentMsn(Addr vaddr, size_t size, char *data)
virtual RegVal readVecElemFlat(RegIndex idx) const
virtual void setCCReg(RegIndex reg_idx, RegVal val)
virtual void setVecReg(const RegId &reg, const ArmISA::VecRegContainer &val)
void activate() override
Set the status to Active.
std::vector< iris::MemorySupportedAddressTranslationResult > translations
virtual const std::vector< iris::MemorySpaceId > & getBpSpaceIds() const =0
virtual RegVal readCCRegFlat(RegIndex idx) const
iris::IrisCppAdapter & noThrow() const
void installBp(BpInfoIt it)
BaseHTMCheckpointPtr & getHtmCheckpointPtr() override
Process * getProcessPtr() override
iris::ResourceId getIntRegFlatRscId(RegIndex int_reg) const
Flat register interfaces.
Tick readLastActivate() override
void halt() override
Set the status to Halted.
void descheduleInstCountEvent(Event *event) override
virtual RegVal readCCReg(RegIndex reg_idx) const
virtual ArmISA::VecRegContainer & getWritableVecRegFlat(RegIndex idx)
Status status() const override
void takeOverFrom(gem5::ThreadContext *old_context) override
virtual bool translateAddress(Addr &paddr, Addr vaddr)=0
void sendFunctional(PacketPtr pkt) override
void extractResourceMap(ResourceIds &ids, const ResourceMap &resources, const IdxNameMap &idx_names)
iris::ResourceId getVecPredRegRscId(RegIndex vec_reg) const
bool translateAddress(Addr &paddr, iris::MemorySpaceId p_space, Addr vaddr, iris::MemorySpaceId v_space)
iris::ResourceId getVecRegRscId(RegIndex vec_reg) const
void writeMem(iris::MemorySpaceId space, Addr addr, const void *p, size_t size)
std::map< Addr, BpInfoPtr > BpInfoMap
iris::IrisErrorCode phaseInitLeave(uint64_t esId, const iris::IrisValueMap &fields, uint64_t time, uint64_t sInstId, bool syncEc, std::string &error_message_out)
virtual RegVal readIntRegFlat(RegIndex idx) const
iris::IrisCppAdapter & call() const
void regStats(const std::string &name) override
void setStCondFailures(unsigned sc_failures) override
Tick getCurrentInstCount() override
const PCStateBase & pcState() const override
CheckerCPU * getCheckerCpuPtr() override
void setMiscReg(RegIndex misc_reg, const RegVal val) override
virtual const ArmISA::VecPredRegContainer & readVecPredReg(const RegId &reg) const
virtual void setVecPredRegFlat(RegIndex idx, const ArmISA::VecPredRegContainer &val)
iris::IrisErrorCode semihostingEvent(uint64_t esId, const iris::IrisValueMap &fields, uint64_t time, uint64_t sInstId, bool syncEc, std::string &error_message_out)
virtual RegVal readVecElem(const RegId &reg) const
iris::IrisErrorCode simulationTimeEvent(uint64_t esId, const iris::IrisValueMap &fields, uint64_t time, uint64_t sInstId, bool syncEc, std::string &error_message_out)
InstDecoder * getDecoderPtr() override
virtual const ArmISA::VecRegContainer & readVecReg(const RegId &reg) const
iris::ResourceId getCCRegFlatRscId(RegIndex cc_reg) const
std::unique_ptr< BpInfo > BpInfoPtr
RegVal getReg(const RegId &reg) const override
iris::EventStreamId regEventStreamId
virtual void setVecRegFlat(RegIndex idx, const ArmISA::VecRegContainer &val)
BaseMMU * getMMUPtr() override
iris::EventStreamId initEventStreamId
iris::EventStreamId semihostingEventStreamId
void readMem(iris::MemorySpaceId space, Addr addr, void *p, size_t size)
BpInfoIt getOrAllocBp(Addr pc)
Tick readLastSuspend() override
virtual ArmISA::VecPredRegContainer & getWritableVecPredReg(const RegId &reg)
gem5::BaseCPU * getCpuPtr() override
void setProcessPtr(Process *p) override
std::vector< ArmISA::VecRegContainer > vecRegs
void setThreadId(int id) override
std::map< std::string, iris::ResourceInfo > ResourceMap
std::map< int, std::string > IdxNameMap
virtual void setVecElemFlat(RegIndex idx, RegVal val)
iris::ResourceId icountRscId
iris::MemorySpaceId getMemorySpaceId(const Iris::CanonicalMsn &msn) const
virtual ArmISA::VecRegContainer & getWritableVecReg(const RegId &reg)
RegVal readMiscRegNoEffect(RegIndex misc_reg) const override
std::unordered_map< Iris::CanonicalMsn, iris::MemorySpaceId > MemorySpaceMap
void suspend() override
Set the status to Suspended.
void setHtmCheckpointPtr(BaseHTMCheckpointPtr cpt) override
iris::IrisErrorCode breakpointHit(uint64_t esId, const iris::IrisValueMap &fields, uint64_t time, uint64_t sInstId, bool syncEc, std::string &error_message_out)
void setContextId(int id) override
iris::InstanceId _instId
std::vector< ArmISA::VecPredRegContainer > vecPredRegs
virtual void setIntRegFlat(RegIndex idx, uint64_t val)
int threadId() const override
iris::ResourceId pcRscId
RegVal readMiscReg(RegIndex misc_reg) override
virtual ArmISA::VecPredRegContainer readVecPredRegFlat(RegIndex idx) const
BpInfoMap::iterator BpInfoIt
iris::ResourceId extractResourceId(const ResourceMap &resources, const std::string &name)
void writeMemWithCurrentMsn(Addr vaddr, size_t size, const char *data)
virtual RegVal readIntReg(RegIndex reg_idx) const
std::vector< iris::MemorySpaceInfo > memorySpaces
virtual void setVecElem(const RegId &reg, RegVal val)
virtual void setIntReg(RegIndex reg_idx, RegVal val)
iris::EventStreamId timeEventStreamId
bool schedule(PCEvent *e) override
iris::ResourceId getIntRegRscId(RegIndex int_reg) const
iris::EventStreamId breakpointEventStreamId
virtual void setCCRegFlat(RegIndex idx, RegVal val)
void scheduleInstCountEvent(Event *event, Tick count) override
virtual const ArmISA::VecRegContainer & readVecRegFlat(RegIndex idx) const
virtual ArmISA::VecPredRegContainer & getWritableVecPredRegFlat(RegIndex idx)
iris::IrisErrorCode instanceRegistryChanged(uint64_t esId, const iris::IrisValueMap &fields, uint64_t time, uint64_t sInstId, bool syncEc, std::string &error_message_out)
unsigned readStCondFailures() const override
System * getSystemPtr() override
int contextId() const override
void pcStateNoRecord(const PCStateBase &val) override
void setReg(const RegId &reg, RegVal val) override
iris::IrisInstance client
void setMiscRegNoEffect(RegIndex misc_reg, const RegVal val) override
uint32_t socketId() const override
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
ThreadContext is the external interface to all thread state for anything outside of the CPU.
@ Halted
Permanently shut down.
@ Suspended
Temporarily inactive.
Vector Register Abstraction This generic class is the model in a particularization of MVC,...
Definition: vec_reg.hh:124
STL list class.
Definition: stl.hh:51
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define warn(...)
Definition: logging.hh:246
Bitfield< 39, 36 > ids
Definition: misc_types.hh:154
VecPredReg::Container VecPredRegContainer
Definition: vec.hh:71
Bitfield< 9 > e
Definition: misc_types.hh:65
Bitfield< 33 > id
Definition: misc_types.hh:257
Bitfield< 10, 5 > event
GenericISA::DelaySlotPCState< 4 > PCState
Definition: pcstate.hh:40
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 15 > system
Definition: misc.hh:1004
Bitfield< 63 > val
Definition: misc.hh:776
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint16_t RegIndex
Definition: types.hh:176
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint64_t Tick
Tick count type.
Definition: types.hh:58
int ContextID
Globally unique thread context ID.
Definition: types.hh:239
uint64_t RegVal
Definition: types.hh:173
std::unique_ptr< BaseHTMCheckpoint > BaseHTMCheckpointPtr
Definition: htm.hh:125
HtmFailureFaultCause
Definition: htm.hh:48
std::shared_ptr< EventList > events
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:24 for gem5 by doxygen 1.9.1