2 * Copyright 2019 Google, Inc.
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.
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.
30 #ifndef __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__
31 #define __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__
37 #include "cpu/base.hh"
38 #include "cpu/thread_context.hh"
39 #include "iris/IrisInstance.h"
40 #include "iris/detail/IrisErrorCode.h"
41 #include "iris/detail/IrisObjects.h"
42 #include "sim/system.hh"
47 // This class is the base for ThreadContexts which read and write state using
49 class ThreadContext : public ::ThreadContext
52 typedef std::map<std::string, iris::ResourceInfo> ResourceMap;
54 typedef std::vector<iris::ResourceId> ResourceIds;
55 typedef std::map<int, std::string> IdxNameMap;
65 std::string _irisPath;
66 iris::InstanceId _instId = iris::IRIS_UINT64_MAX;
68 // Temporary holding places for the vector reg accessors to return.
69 // These are not updated live, only when requested.
70 mutable std::vector<ArmISA::VecRegContainer> vecRegs;
71 mutable std::vector<ArmISA::VecPredRegContainer> vecPredRegs;
73 Status _status = Active;
75 virtual void initFromIrisInstance(const ResourceMap &resources);
77 iris::ResourceId extractResourceId(
78 const ResourceMap &resources, const std::string &name);
79 void extractResourceMap(ResourceIds &ids,
80 const ResourceMap &resources, const IdxNameMap &idx_names);
83 ResourceIds miscRegIds;
84 ResourceIds intReg32Ids;
85 ResourceIds intReg64Ids;
87 iris::ResourceId pcRscId = iris::IRIS_UINT64_MAX;
88 iris::ResourceId icountRscId;
90 ResourceIds vecRegIds;
91 ResourceIds vecPredRegIds;
93 std::vector<iris::MemorySpaceInfo> memorySpaces;
94 std::vector<iris::MemorySupportedAddressTranslationResult> translations;
96 std::unique_ptr<PortProxy> virtProxy = nullptr;
97 std::unique_ptr<PortProxy> physProxy = nullptr;
100 // A queue to keep track of instruction count based events.
101 EventQueue comInstEventQueue;
102 // A helper function to maintain the IRIS step count. This makes sure the
103 // step count is correct even after IRIS resets it for us, and also handles
104 // events which are supposed to happen at the current instruction count.
105 void maintainStepping();
108 using BpId = uint64_t;
113 std::list<PCEvent *> events;
115 BpInfo(Addr _pc) : pc(_pc), id(iris::IRIS_UINT64_MAX) {}
117 bool empty() const { return events.empty(); }
118 bool validId() const { return id != iris::IRIS_UINT64_MAX; }
119 void clearId() { id = iris::IRIS_UINT64_MAX; }
122 using BpInfoPtr = std::unique_ptr<BpInfo>;
123 using BpInfoMap = std::map<Addr, BpInfoPtr>;
124 using BpInfoIt = BpInfoMap::iterator;
128 BpInfoIt getOrAllocBp(Addr pc);
130 void installBp(BpInfoIt it);
131 void uninstallBp(BpInfoIt it);
132 void delBp(BpInfoIt it);
134 virtual iris::MemorySpaceId getBpSpaceId(Addr pc) const = 0;
137 iris::IrisErrorCode instanceRegistryChanged(
138 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
139 uint64_t sInstId, bool syncEc, std::string &error_message_out);
140 iris::IrisErrorCode phaseInitLeave(
141 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
142 uint64_t sInstId, bool syncEc, std::string &error_message_out);
143 iris::IrisErrorCode simulationTimeEvent(
144 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
145 uint64_t sInstId, bool syncEc, std::string &error_message_out);
146 iris::IrisErrorCode breakpointHit(
147 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
148 uint64_t sInstId, bool syncEc, std::string &error_message_out);
150 iris::EventStreamId regEventStreamId;
151 iris::EventStreamId initEventStreamId;
152 iris::EventStreamId timeEventStreamId;
153 iris::EventStreamId breakpointEventStreamId;
155 mutable iris::IrisInstance client;
156 iris::IrisCppAdapter &call() const { return client.irisCall(); }
157 iris::IrisCppAdapter &noThrow() const { return client.irisCallNoThrow(); }
159 bool translateAddress(Addr &paddr, iris::MemorySpaceId p_space,
160 Addr vaddr, iris::MemorySpaceId v_space);
163 ThreadContext(::BaseCPU *cpu, int id, System *system,
164 ::BaseTLB *dtb, ::BaseTLB *itb,
165 iris::IrisConnectionInterface *iris_if,
166 const std::string &iris_path);
167 virtual ~ThreadContext();
169 virtual bool translateAddress(Addr &paddr, Addr vaddr) = 0;
171 bool schedule(PCEvent *e) override;
172 bool remove(PCEvent *e) override;
174 void scheduleInstCountEvent(Event *event, Tick count) override;
175 void descheduleInstCountEvent(Event *event) override;
176 Tick getCurrentInstCount() override;
178 ::BaseCPU *getCpuPtr() override { return _cpu; }
179 int cpuId() const override { return _cpu->cpuId(); }
180 uint32_t socketId() const override { return _cpu->socketId(); }
182 int threadId() const override { return _threadId; }
183 void setThreadId(int id) override { _threadId = id; }
185 int contextId() const override { return _contextId; }
186 void setContextId(int id) override { _contextId = id; }
199 getCheckerCpuPtr() override
201 panic("%s not implemented.", __FUNCTION__);
204 getDecoderPtr() override
206 panic("%s not implemented.", __FUNCTION__);
209 System *getSystemPtr() override { return _cpu->system; }
214 panic("%s not implemented.", __FUNCTION__);
218 getKernelStats() override
220 panic("%s not implemented.", __FUNCTION__);
223 PortProxy &getPhysProxy() override { return *physProxy; }
224 PortProxy &getVirtProxy() override { return *virtProxy; }
225 void initMemProxies(::ThreadContext *tc) override;
228 getProcessPtr() override
230 panic("%s not implemented.", __FUNCTION__);
233 setProcessPtr(Process *p) override
235 panic("%s not implemented.", __FUNCTION__);
238 Status status() const override;
239 void setStatus(Status new_status) override;
240 void activate() override { setStatus(Active); }
241 void suspend() override { setStatus(Suspended); }
242 void halt() override { setStatus(Halted); }
245 dumpFuncProfile() override
247 panic("%s not implemented.", __FUNCTION__);
251 takeOverFrom(::ThreadContext *old_context) override
253 panic("%s not implemented.", __FUNCTION__);
256 void regStats(const std::string &name) override {}
259 getQuiesceEvent() override
261 panic("%s not implemented.", __FUNCTION__);
264 // Not necessarily the best location for these...
265 // Having an extra function just to read these is obnoxious
267 readLastActivate() override
269 panic("%s not implemented.", __FUNCTION__);
271 Tick readLastSuspend() override
273 panic("%s not implemented.", __FUNCTION__);
277 profileClear() override
279 panic("%s not implemented.", __FUNCTION__);
282 profileSample() override
284 panic("%s not implemented.", __FUNCTION__);
288 copyArchRegs(::ThreadContext *tc) override
290 panic("%s not implemented.", __FUNCTION__);
294 clearArchRegs() override
296 panic("%s not implemented.", __FUNCTION__);
300 // New accessors for new decoder.
302 RegVal readIntReg(RegIndex reg_idx) const override;
305 readFloatReg(RegIndex reg_idx) const override
307 panic("%s not implemented.", __FUNCTION__);
310 const VecRegContainer &readVecReg(const RegId ®) const override;
312 getWritableVecReg(const RegId ®) override
314 panic("%s not implemented.", __FUNCTION__);
317 /** Vector Register Lane Interfaces. */
319 /** Reads source vector 8bit operand. */
321 readVec8BitLaneReg(const RegId ®) const override
323 panic("%s not implemented.", __FUNCTION__);
326 /** Reads source vector 16bit operand. */
328 readVec16BitLaneReg(const RegId ®) const override
330 panic("%s not implemented.", __FUNCTION__);
333 /** Reads source vector 32bit operand. */
335 readVec32BitLaneReg(const RegId ®) const override
337 panic("%s not implemented.", __FUNCTION__);
340 /** Reads source vector 64bit operand. */
342 readVec64BitLaneReg(const RegId ®) const override
344 panic("%s not implemented.", __FUNCTION__);
347 /** Write a lane of the destination vector register. */
349 setVecLane(const RegId ®, const LaneData<LaneSize::Byte> &val) override
351 panic("%s not implemented.", __FUNCTION__);
354 setVecLane(const RegId ®,
355 const LaneData<LaneSize::TwoByte> &val) override
357 panic("%s not implemented.", __FUNCTION__);
360 setVecLane(const RegId ®,
361 const LaneData<LaneSize::FourByte> &val) override
363 panic("%s not implemented.", __FUNCTION__);
366 setVecLane(const RegId ®,
367 const LaneData<LaneSize::EightByte> &val) override
369 panic("%s not implemented.", __FUNCTION__);
374 readVecElem(const RegId ®) const override
376 panic("%s not implemented.", __FUNCTION__);
379 const VecPredRegContainer &readVecPredReg(const RegId ®) const override;
380 VecPredRegContainer &
381 getWritableVecPredReg(const RegId ®) override
383 panic("%s not implemented.", __FUNCTION__);
387 readCCReg(RegIndex reg_idx) const override
389 panic("%s not implemented.", __FUNCTION__);
392 void setIntReg(RegIndex reg_idx, RegVal val) override;
395 setFloatReg(RegIndex reg_idx, RegVal val) override
397 panic("%s not implemented.", __FUNCTION__);
401 setVecReg(const RegId ®, const VecRegContainer &val) override
403 panic("%s not implemented.", __FUNCTION__);
407 setVecElem(const RegId& reg, const VecElem& val) override
409 panic("%s not implemented.", __FUNCTION__);
413 setVecPredReg(const RegId ®,
414 const VecPredRegContainer &val) override
416 panic("%s not implemented.", __FUNCTION__);
420 setCCReg(RegIndex reg_idx, RegVal val) override
422 panic("%s not implemented.", __FUNCTION__);
425 void pcStateNoRecord(const ArmISA::PCState &val) override { pcState(val); }
426 MicroPC microPC() const override { return 0; }
428 ArmISA::PCState pcState() const override;
429 void pcState(const ArmISA::PCState &val) override;
430 Addr instAddr() const override;
431 Addr nextInstAddr() const override;
433 RegVal readMiscRegNoEffect(RegIndex misc_reg) const override;
435 readMiscReg(RegIndex misc_reg) override
437 return readMiscRegNoEffect(misc_reg);
440 void setMiscRegNoEffect(RegIndex misc_reg, const RegVal val) override;
442 setMiscReg(RegIndex misc_reg, const RegVal val) override
444 setMiscRegNoEffect(misc_reg, val);
448 flattenRegId(const RegId& regId) const override
450 panic("%s not implemented.", __FUNCTION__);
453 // Also not necessarily the best location for these two. Hopefully will go
454 // away once we decide upon where st cond failures goes.
456 readStCondFailures() const override
458 panic("%s not implemented.", __FUNCTION__);
462 setStCondFailures(unsigned sc_failures) override
464 panic("%s not implemented.", __FUNCTION__);
467 // Same with st cond failures.
469 readFuncExeInst() const override
471 panic("%s not implemented.", __FUNCTION__);
475 syscall(Fault *fault) override
477 panic("%s not implemented.", __FUNCTION__);
482 * Flat register interfaces
484 * Some architectures have different registers visible in
485 * different modes. Such architectures "flatten" a register (see
486 * flattenRegId()) to map it into the
487 * gem5 register file. This interface provides a flat interface to
488 * the underlying register file, which allows for example
489 * serialization code to access all registers.
493 readIntRegFlat(RegIndex idx) const override
495 panic("%s not implemented.", __FUNCTION__);
498 setIntRegFlat(RegIndex idx, uint64_t val) override
500 panic("%s not implemented.", __FUNCTION__);
504 readFloatRegFlat(RegIndex idx) const override
506 panic("%s not implemented.", __FUNCTION__);
509 setFloatRegFlat(RegIndex idx, RegVal val) override
511 panic("%s not implemented.", __FUNCTION__);
514 const VecRegContainer &readVecRegFlat(RegIndex idx) const override;
516 getWritableVecRegFlat(RegIndex idx) override
518 panic("%s not implemented.", __FUNCTION__);
521 setVecRegFlat(RegIndex idx, const VecRegContainer &val) override
523 panic("%s not implemented.", __FUNCTION__);
527 readVecElemFlat(RegIndex idx, const ElemIndex& elemIdx) const override
529 panic("%s not implemented.", __FUNCTION__);
532 setVecElemFlat(RegIndex idx, const ElemIndex &elemIdx,
533 const VecElem &val) override
535 panic("%s not implemented.", __FUNCTION__);
538 const VecPredRegContainer &readVecPredRegFlat(RegIndex idx) const override;
539 VecPredRegContainer &
540 getWritableVecPredRegFlat(RegIndex idx) override
542 panic("%s not implemented.", __FUNCTION__);
545 setVecPredRegFlat(RegIndex idx, const VecPredRegContainer &val) override
547 panic("%s not implemented.", __FUNCTION__);
551 readCCRegFlat(RegIndex idx) const override
553 panic("%s not implemented.", __FUNCTION__);
556 setCCRegFlat(RegIndex idx, RegVal val) override
558 panic("%s not implemented.", __FUNCTION__);
566 #endif // __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__