gem5 v24.0.0.0
Loading...
Searching...
No Matches
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 <optional>
35#include <unordered_map>
36
38#include "arch/arm/regs/vec.hh"
39#include "cpu/base.hh"
40#include "cpu/thread_context.hh"
41#include "iris/IrisInstance.h"
42#include "iris/detail/IrisErrorCode.h"
43#include "iris/detail/IrisObjects.h"
44#include "sim/system.hh"
45
46namespace gem5
47{
48
49namespace Iris
50{
51
52// This class is the base for ThreadContexts which read and write state using
53// the Iris API.
55{
56 public:
57 typedef std::map<std::string, iris::ResourceInfo> ResourceMap;
58
60 typedef std::map<int, std::string> IdxNameMap;
61
62 typedef std::unordered_map<Iris::CanonicalMsn, iris::MemorySpaceId>
64
65 protected:
72
73 std::string _irisPath;
74 iris::InstanceId _instId = iris::IRIS_UINT64_MAX;
75
76 // Temporary holding places for the vector reg accessors to return.
77 // These are not updated live, only when requested.
80
83
84 virtual void initFromIrisInstance(const ResourceMap &resources);
85
86 iris::ResourceId extractResourceId(
87 const ResourceMap &resources, const std::string &name);
89 const ResourceMap &resources, const IdxNameMap &idx_names);
90 iris::MemorySpaceId getMemorySpaceId(const Iris::CanonicalMsn& msn) const;
91
92
98
99 iris::ResourceId pcRscId = iris::IRIS_UINT64_MAX;
100 iris::ResourceId icountRscId;
101
104
108
109 // A queue to keep track of instruction count based events.
111 // A helper function to maintain the IRIS step count. This makes sure the
112 // step count is correct even after IRIS resets it for us, and also handles
113 // events which are supposed to happen at the current instruction count.
114 void maintainStepping();
115
116
117 using BpId = uint64_t;
118 struct BpInfo
119 {
123 std::shared_ptr<EventList> events;
124
125 BpInfo(Addr _pc) : pc(_pc), events(new EventList) {}
126
127 bool empty() const { return events->empty(); }
128 bool validIds() const { return !ids.empty(); }
129 void clearIds() { ids.clear(); }
130 };
131
132 using BpInfoPtr = std::unique_ptr<BpInfo>;
133 using BpInfoMap = std::map<Addr, BpInfoPtr>;
134 using BpInfoIt = BpInfoMap::iterator;
135
137 std::optional<Addr> bpAddr;
138
140
141 void installBp(BpInfoIt it);
142 void uninstallBp(BpInfoIt it);
143 void delBp(BpInfoIt it);
144
146
147
148 iris::IrisErrorCode instanceRegistryChanged(
149 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
150 uint64_t sInstId, bool syncEc, std::string &error_message_out);
151 iris::IrisErrorCode phaseInitLeave(
152 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
153 uint64_t sInstId, bool syncEc, std::string &error_message_out);
154 iris::IrisErrorCode simulationTimeEvent(
155 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
156 uint64_t sInstId, bool syncEc, std::string &error_message_out);
157 iris::IrisErrorCode breakpointHit(
158 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
159 uint64_t sInstId, bool syncEc, std::string &error_message_out);
160 iris::IrisErrorCode semihostingEvent(
161 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
162 uint64_t sInstId, bool syncEc, std::string &error_message_out);
163
164 iris::EventStreamId regEventStreamId;
165 iris::EventStreamId initEventStreamId;
166 iris::EventStreamId timeEventStreamId;
167 iris::EventStreamId breakpointEventStreamId;
168 iris::EventStreamId semihostingEventStreamId;
169
170 mutable iris::IrisInstance client;
171 iris::IrisCppAdapter &call() const { return client.irisCall(); }
172 iris::IrisCppAdapter &noThrow() const { return client.irisCallNoThrow(); }
173
174 mutable ArmISA::PCState pc;
175
176 void readMem(iris::MemorySpaceId space,
177 Addr addr, void *p, size_t size);
178 void writeMem(iris::MemorySpaceId space,
179 Addr addr, const void *p, size_t size);
180 bool translateAddress(Addr &paddr, iris::MemorySpaceId p_space,
181 Addr vaddr, iris::MemorySpaceId v_space);
182
183 public:
185 gem5::BaseMMU *mmu, gem5::BaseISA *isa,
186 iris::IrisConnectionInterface *iris_if,
187 const std::string &iris_path);
188 virtual ~ThreadContext();
189
190 virtual bool translateAddress(Addr &paddr, Addr vaddr) = 0;
191
192 bool schedule(PCEvent *e) override;
193 bool remove(PCEvent *e) override;
194
196 void descheduleInstCountEvent(Event *event) override;
197 Tick getCurrentInstCount() override;
198
199 gem5::BaseCPU *getCpuPtr() override { return _cpu; }
200 int cpuId() const override { return _cpu->cpuId(); }
201 uint32_t socketId() const override { return _cpu->socketId(); }
202
203 int threadId() const override { return _threadId; }
204 void setThreadId(int id) override { _threadId = id; }
205
206 int contextId() const override { return _contextId; }
207 void setContextId(int id) override { _contextId = id; }
208
209 BaseMMU *
210 getMMUPtr() override
211 {
212 return _mmu;
213 }
214
215 CheckerCPU *getCheckerCpuPtr() override { return nullptr; }
217 getDecoderPtr() override
218 {
219 panic("%s not implemented.", __FUNCTION__);
220 }
221
222 System *getSystemPtr() override { return _cpu->system; }
223
224 BaseISA *
225 getIsaPtr() const override
226 {
227 return _isa;
228 }
229
230 void sendFunctional(PacketPtr pkt) override;
231
232 Process *
233 getProcessPtr() override
234 {
235 panic("%s not implemented.", __FUNCTION__);
236 }
237 void
239 {
240 panic("%s not implemented.", __FUNCTION__);
241 }
242
243 Status status() const override;
244 void setStatus(Status new_status) override;
245 void activate() override { setStatus(Active); }
246 void suspend() override { setStatus(Suspended); }
247 void halt() override { setStatus(Halted); }
248
249 void
250 takeOverFrom(gem5::ThreadContext *old_context) override
251 {
252 panic("%s not implemented.", __FUNCTION__);
253 }
254
255 void regStats(const std::string &name) override {}
256
257 // Not necessarily the best location for these...
258 // Having an extra function just to read these is obnoxious
259 Tick
261 {
262 panic("%s not implemented.", __FUNCTION__);
263 }
265 {
266 panic("%s not implemented.", __FUNCTION__);
267 }
268
269 void
271 {
272 panic("%s not implemented.", __FUNCTION__);
273 }
274
275 void
276 clearArchRegs() override
277 {
278 warn("Ignoring clearArchRegs()");
279 }
280
281 //
282 // New accessors for new decoder.
283 //
284 RegVal getReg(const RegId &reg) const override;
285 void getReg(const RegId &reg, void *val) const override;
286 void *getWritableReg(const RegId &reg) override;
287
288 void setReg(const RegId &reg, RegVal val) override;
289 void setReg(const RegId &reg, const void *val) override;
290
291 iris::ResourceId getIntRegRscId(RegIndex int_reg) const;
292 virtual RegVal readIntReg(RegIndex reg_idx) const;
293
294 iris::ResourceId getVecRegRscId(RegIndex vec_reg) const;
295 virtual const ArmISA::VecRegContainer &readVecReg(const RegId &reg) const;
298 {
299 panic("%s not implemented.", __FUNCTION__);
300 }
301
302 virtual RegVal
303 readVecElem(const RegId &reg) const
304 {
305 panic("%s not implemented.", __FUNCTION__);
306 }
307
308 iris::ResourceId getVecPredRegRscId(RegIndex vec_reg) const;
309 virtual const ArmISA::VecPredRegContainer &
310 readVecPredReg(const RegId &reg) const;
313 {
314 panic("%s not implemented.", __FUNCTION__);
315 }
316
317 virtual RegVal
318 readCCReg(RegIndex reg_idx) const
319 {
320 return readCCRegFlat(reg_idx);
321 }
322
323 virtual void setIntReg(RegIndex reg_idx, RegVal val);
324
325 virtual void
327 {
328 panic("%s not implemented.", __FUNCTION__);
329 }
330
331 virtual void
333 {
334 panic("%s not implemented.", __FUNCTION__);
335 }
336
337 virtual void
340 {
341 panic("%s not implemented.", __FUNCTION__);
342 }
343
344 virtual void
346 {
347 setCCRegFlat(reg_idx, val);
348 }
349
350 void pcStateNoRecord(const PCStateBase &val) override { pcState(val); }
351
352 const PCStateBase &pcState() const override;
353 void pcState(const PCStateBase &val) override;
354
355 iris::ResourceId getMiscRegRscId(RegIndex misc_reg) const;
356 RegVal readMiscRegNoEffect(RegIndex misc_reg) const override;
357 RegVal
358 readMiscReg(RegIndex misc_reg) override
359 {
360 return readMiscRegNoEffect(misc_reg);
361 }
362
363 void setMiscRegNoEffect(RegIndex misc_reg, const RegVal val) override;
364 void
365 setMiscReg(RegIndex misc_reg, const RegVal val) override
366 {
367 setMiscRegNoEffect(misc_reg, val);
368 }
369
370 // Also not necessarily the best location for these two. Hopefully will go
371 // away once we decide upon where st cond failures goes.
372 unsigned
373 readStCondFailures() const override
374 {
375 panic("%s not implemented.", __FUNCTION__);
376 }
377
378 void
379 setStCondFailures(unsigned sc_failures) override
380 {
381 panic("%s not implemented.", __FUNCTION__);
382 }
383
396 iris::ResourceId getIntRegFlatRscId(RegIndex int_reg) const;
397 virtual RegVal readIntRegFlat(RegIndex idx) const;
398 virtual void setIntRegFlat(RegIndex idx, uint64_t val);
399
400 virtual const ArmISA::VecRegContainer &readVecRegFlat(RegIndex idx) const;
403 {
404 panic("%s not implemented.", __FUNCTION__);
405 }
406 virtual void
408 {
409 panic("%s not implemented.", __FUNCTION__);
410 }
411
412 virtual RegVal
414 {
415 panic("%s not implemented.", __FUNCTION__);
416 }
417 virtual void
419 {
420 panic("%s not implemented.", __FUNCTION__);
421 }
422
426 {
427 panic("%s not implemented.", __FUNCTION__);
428 }
429 virtual void
432 {
433 panic("%s not implemented.", __FUNCTION__);
434 }
435
436 iris::ResourceId getCCRegFlatRscId(RegIndex cc_reg) const;
437 virtual RegVal readCCRegFlat(RegIndex idx) const;
438 virtual void setCCRegFlat(RegIndex idx, RegVal val);
441 // hardware transactional memory
442 void
443 htmAbortTransaction(uint64_t htm_uid, HtmFailureFaultCause cause) override
444 {
445 panic("%s not implemented.", __FUNCTION__);
446 }
447
450 {
451 panic("%s not implemented.", __FUNCTION__);
452 }
453
454 void
456 {
457 panic("%s not implemented.", __FUNCTION__);
458 }
459 void readMemWithCurrentMsn(Addr vaddr, size_t size, char *data);
460 void writeMemWithCurrentMsn(Addr vaddr, size_t size, const char *data);
461};
462
463} // namespace Iris
464} // namespace gem5
465
466#endif // __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__
const char data[]
uint32_t socketId() const
Reads this CPU's Socket ID.
Definition base.hh:190
System * system
Definition base.hh:392
int cpuId() const
Reads this CPU's ID.
Definition base.hh:187
CheckerCPU class.
Definition cpu.hh:85
Queue of events sorted in time order.
Definition eventq.hh:616
virtual void initFromIrisInstance(const ResourceMap &resources)
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 ArmISA::VecRegContainer & getWritableVecReg(const RegId &reg)
virtual RegVal readCCRegFlat(RegIndex idx) const
Process * getProcessPtr() override
void installBp(BpInfoIt it)
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
BaseMMU * getMMUPtr() override
Status status() const override
void takeOverFrom(gem5::ThreadContext *old_context) override
virtual bool translateAddress(Addr &paddr, Addr vaddr)=0
virtual ArmISA::VecRegContainer & getWritableVecRegFlat(RegIndex idx)
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
void regStats(const std::string &name) override
void setStCondFailures(unsigned sc_failures) override
Tick getCurrentInstCount() override
const PCStateBase & pcState() const override
void setMiscReg(RegIndex misc_reg, const RegVal val) override
InstDecoder * getDecoderPtr() 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)
iris::IrisCppAdapter & noThrow() const
virtual const std::vector< iris::MemorySpaceId > & getBpSpaceIds() const =0
virtual const ArmISA::VecRegContainer & readVecReg(const RegId &reg) const
iris::ResourceId getCCRegFlatRscId(RegIndex cc_reg) const
BaseHTMCheckpointPtr & getHtmCheckpointPtr() override
std::unique_ptr< BpInfo > BpInfoPtr
RegVal getReg(const RegId &reg) const override
iris::EventStreamId regEventStreamId
virtual void setVecRegFlat(RegIndex idx, const ArmISA::VecRegContainer &val)
iris::EventStreamId initEventStreamId
iris::EventStreamId semihostingEventStreamId
void readMem(iris::MemorySpaceId space, Addr addr, void *p, size_t size)
CheckerCPU * getCheckerCpuPtr() override
BpInfoIt getOrAllocBp(Addr pc)
Tick readLastSuspend() override
void setProcessPtr(Process *p) override
gem5::BaseCPU * getCpuPtr() 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::MemorySpaceId getMemorySpaceId(const Iris::CanonicalMsn &msn) const
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)
BaseISA * getIsaPtr() const override
void setContextId(int id) override
virtual ArmISA::VecPredRegContainer & getWritableVecPredRegFlat(RegIndex idx)
virtual ArmISA::VecPredRegContainer & getWritableVecPredReg(const RegId &reg)
std::vector< ArmISA::VecPredRegContainer > vecPredRegs
virtual void setIntRegFlat(RegIndex idx, uint64_t val)
iris::IrisCppAdapter & call() const
int threadId() const override
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)
System * getSystemPtr() override
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
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
int contextId() const override
void pcStateNoRecord(const PCStateBase &val) override
void setReg(const RegId &reg, RegVal val) override
iris::IrisInstance client
std::optional< Addr > bpAddr
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:295
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
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:126
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define warn(...)
Definition logging.hh:256
Bitfield< 39, 36 > ids
Bitfield< 9 > e
Definition misc_types.hh:65
Bitfield< 33 > id
VecPredReg::Container VecPredRegContainer
Definition vec.hh:71
Bitfield< 10, 5 > event
Bitfield< 0 > p
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 15 > system
Definition misc.hh:1032
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint16_t RegIndex
Definition types.hh:176
uint64_t RegVal
Definition types.hh:173
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
std::unique_ptr< BaseHTMCheckpoint > BaseHTMCheckpointPtr
Definition htm.hh:127
HtmFailureFaultCause
Definition htm.hh:48
std::shared_ptr< EventList > events
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0