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.
28 #ifndef __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__
29 #define __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__
35 #include "cpu/base.hh"
36 #include "cpu/thread_context.hh"
37 #include "iris/IrisInstance.h"
38 #include "iris/detail/IrisErrorCode.h"
39 #include "iris/detail/IrisObjects.h"
40 #include "sim/system.hh"
45 // This class is the base for ThreadContexts which read and write state using
47 class ThreadContext : public ::ThreadContext
50 typedef std::map<std::string, iris::ResourceInfo> ResourceMap;
52 typedef std::vector<iris::ResourceId> ResourceIds;
53 typedef std::map<int, std::string> IdxNameMap;
63 std::string _irisPath;
64 iris::InstanceId _instId = iris::IRIS_UINT64_MAX;
66 // Temporary holding places for the vector reg accessors to return.
67 // These are not updated live, only when requested.
68 mutable std::vector<ArmISA::VecRegContainer> vecRegs;
69 mutable std::vector<ArmISA::VecPredRegContainer> vecPredRegs;
71 Status _status = Active;
73 virtual void initFromIrisInstance(const ResourceMap &resources);
75 iris::ResourceId extractResourceId(
76 const ResourceMap &resources, const std::string &name);
77 void extractResourceMap(ResourceIds &ids,
78 const ResourceMap &resources, const IdxNameMap &idx_names);
81 ResourceIds miscRegIds;
82 ResourceIds intReg32Ids;
83 ResourceIds intReg64Ids;
84 ResourceIds flattenedIntIds;
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;
112 std::vector<BpId> ids;
113 using EventList = std::list<PCEvent *>;
114 std::shared_ptr<EventList> events;
116 BpInfo(Addr _pc) : pc(_pc), events(new EventList) {}
118 bool empty() const { return events->empty(); }
119 bool validIds() const { return !ids.empty(); }
120 void clearIds() { ids.clear(); }
123 using BpInfoPtr = std::unique_ptr<BpInfo>;
124 using BpInfoMap = std::map<Addr, BpInfoPtr>;
125 using BpInfoIt = BpInfoMap::iterator;
129 BpInfoIt getOrAllocBp(Addr pc);
131 void installBp(BpInfoIt it);
132 void uninstallBp(BpInfoIt it);
133 void delBp(BpInfoIt it);
135 virtual const std::vector<iris::MemorySpaceId> &getBpSpaceIds() const = 0;
138 iris::IrisErrorCode instanceRegistryChanged(
139 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
140 uint64_t sInstId, bool syncEc, std::string &error_message_out);
141 iris::IrisErrorCode phaseInitLeave(
142 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
143 uint64_t sInstId, bool syncEc, std::string &error_message_out);
144 iris::IrisErrorCode simulationTimeEvent(
145 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
146 uint64_t sInstId, bool syncEc, std::string &error_message_out);
147 iris::IrisErrorCode breakpointHit(
148 uint64_t esId, const iris::IrisValueMap &fields, uint64_t time,
149 uint64_t sInstId, bool syncEc, std::string &error_message_out);
151 iris::EventStreamId regEventStreamId;
152 iris::EventStreamId initEventStreamId;
153 iris::EventStreamId timeEventStreamId;
154 iris::EventStreamId breakpointEventStreamId;
156 mutable iris::IrisInstance client;
157 iris::IrisCppAdapter &call() const { return client.irisCall(); }
158 iris::IrisCppAdapter &noThrow() const { return client.irisCallNoThrow(); }
160 bool translateAddress(Addr &paddr, iris::MemorySpaceId p_space,
161 Addr vaddr, iris::MemorySpaceId v_space);
164 ThreadContext(::BaseCPU *cpu, int id, System *system,
165 ::BaseTLB *dtb, ::BaseTLB *itb,
166 iris::IrisConnectionInterface *iris_if,
167 const std::string &iris_path);
168 virtual ~ThreadContext();
170 virtual bool translateAddress(Addr &paddr, Addr vaddr) = 0;
172 bool schedule(PCEvent *e) override;
173 bool remove(PCEvent *e) override;
175 void scheduleInstCountEvent(Event *event, Tick count) override;
176 void descheduleInstCountEvent(Event *event) override;
177 Tick getCurrentInstCount() override;
179 ::BaseCPU *getCpuPtr() override { return _cpu; }
180 int cpuId() const override { return _cpu->cpuId(); }
181 uint32_t socketId() const override { return _cpu->socketId(); }
183 int threadId() const override { return _threadId; }
184 void setThreadId(int id) override { _threadId = id; }
186 int contextId() const override { return _contextId; }
187 void setContextId(int id) override { _contextId = id; }
199 CheckerCPU *getCheckerCpuPtr() override { return nullptr; }
201 getDecoderPtr() override
203 panic("%s not implemented.", __FUNCTION__);
206 System *getSystemPtr() override { return _cpu->system; }
211 panic("%s not implemented.", __FUNCTION__);
215 getKernelStats() override
217 panic("%s not implemented.", __FUNCTION__);
220 PortProxy &getPhysProxy() override { return *physProxy; }
221 PortProxy &getVirtProxy() override { return *virtProxy; }
222 void initMemProxies(::ThreadContext *tc) override;
225 getProcessPtr() override
227 panic("%s not implemented.", __FUNCTION__);
230 setProcessPtr(Process *p) override
232 panic("%s not implemented.", __FUNCTION__);
235 Status status() const override;
236 void setStatus(Status new_status) override;
237 void activate() override { setStatus(Active); }
238 void suspend() override { setStatus(Suspended); }
239 void halt() override { setStatus(Halted); }
242 dumpFuncProfile() override
244 panic("%s not implemented.", __FUNCTION__);
248 takeOverFrom(::ThreadContext *old_context) override
250 panic("%s not implemented.", __FUNCTION__);
253 void regStats(const std::string &name) override {}
256 getQuiesceEvent() override
258 panic("%s not implemented.", __FUNCTION__);
261 // Not necessarily the best location for these...
262 // Having an extra function just to read these is obnoxious
264 readLastActivate() override
266 panic("%s not implemented.", __FUNCTION__);
268 Tick readLastSuspend() override
270 panic("%s not implemented.", __FUNCTION__);
274 profileClear() override
276 panic("%s not implemented.", __FUNCTION__);
279 profileSample() override
281 panic("%s not implemented.", __FUNCTION__);
285 copyArchRegs(::ThreadContext *tc) override
287 panic("%s not implemented.", __FUNCTION__);
291 clearArchRegs() override
293 warn("Ignoring clearArchRegs()");
297 // New accessors for new decoder.
299 RegVal readIntReg(RegIndex reg_idx) const override;
302 readFloatReg(RegIndex reg_idx) const override
304 panic("%s not implemented.", __FUNCTION__);
307 const VecRegContainer &readVecReg(const RegId ®) const override;
309 getWritableVecReg(const RegId ®) override
311 panic("%s not implemented.", __FUNCTION__);
314 /** Vector Register Lane Interfaces. */
316 /** Reads source vector 8bit operand. */
318 readVec8BitLaneReg(const RegId ®) const override
320 panic("%s not implemented.", __FUNCTION__);
323 /** Reads source vector 16bit operand. */
325 readVec16BitLaneReg(const RegId ®) const override
327 panic("%s not implemented.", __FUNCTION__);
330 /** Reads source vector 32bit operand. */
332 readVec32BitLaneReg(const RegId ®) const override
334 panic("%s not implemented.", __FUNCTION__);
337 /** Reads source vector 64bit operand. */
339 readVec64BitLaneReg(const RegId ®) const override
341 panic("%s not implemented.", __FUNCTION__);
344 /** Write a lane of the destination vector register. */
346 setVecLane(const RegId ®, const LaneData<LaneSize::Byte> &val) override
348 panic("%s not implemented.", __FUNCTION__);
351 setVecLane(const RegId ®,
352 const LaneData<LaneSize::TwoByte> &val) override
354 panic("%s not implemented.", __FUNCTION__);
357 setVecLane(const RegId ®,
358 const LaneData<LaneSize::FourByte> &val) override
360 panic("%s not implemented.", __FUNCTION__);
363 setVecLane(const RegId ®,
364 const LaneData<LaneSize::EightByte> &val) override
366 panic("%s not implemented.", __FUNCTION__);
371 readVecElem(const RegId ®) const override
373 panic("%s not implemented.", __FUNCTION__);
376 const VecPredRegContainer &readVecPredReg(const RegId ®) const override;
377 VecPredRegContainer &
378 getWritableVecPredReg(const RegId ®) override
380 panic("%s not implemented.", __FUNCTION__);
384 readCCReg(RegIndex reg_idx) const override
386 return readCCRegFlat(reg_idx);
389 void setIntReg(RegIndex reg_idx, RegVal val) override;
392 setFloatReg(RegIndex reg_idx, RegVal val) override
394 panic("%s not implemented.", __FUNCTION__);
398 setVecReg(const RegId ®, const VecRegContainer &val) override
400 panic("%s not implemented.", __FUNCTION__);
404 setVecElem(const RegId& reg, const VecElem& val) override
406 panic("%s not implemented.", __FUNCTION__);
410 setVecPredReg(const RegId ®,
411 const VecPredRegContainer &val) override
413 panic("%s not implemented.", __FUNCTION__);
417 setCCReg(RegIndex reg_idx, RegVal val) override
419 setCCRegFlat(reg_idx, val);
422 void pcStateNoRecord(const ArmISA::PCState &val) override { pcState(val); }
423 MicroPC microPC() const override { return 0; }
425 ArmISA::PCState pcState() const override;
426 void pcState(const ArmISA::PCState &val) override;
427 Addr instAddr() const override;
428 Addr nextInstAddr() const override;
430 RegVal readMiscRegNoEffect(RegIndex misc_reg) const override;
432 readMiscReg(RegIndex misc_reg) override
434 return readMiscRegNoEffect(misc_reg);
437 void setMiscRegNoEffect(RegIndex misc_reg, const RegVal val) override;
439 setMiscReg(RegIndex misc_reg, const RegVal val) override
441 setMiscRegNoEffect(misc_reg, val);
445 flattenRegId(const RegId& regId) const override
447 panic("%s not implemented.", __FUNCTION__);
450 // Also not necessarily the best location for these two. Hopefully will go
451 // away once we decide upon where st cond failures goes.
453 readStCondFailures() const override
455 panic("%s not implemented.", __FUNCTION__);
459 setStCondFailures(unsigned sc_failures) override
461 panic("%s not implemented.", __FUNCTION__);
464 // Same with st cond failures.
466 readFuncExeInst() const override
468 panic("%s not implemented.", __FUNCTION__);
472 syscall(Fault *fault) override
474 panic("%s not implemented.", __FUNCTION__);
479 * Flat register interfaces
481 * Some architectures have different registers visible in
482 * different modes. Such architectures "flatten" a register (see
483 * flattenRegId()) to map it into the
484 * gem5 register file. This interface provides a flat interface to
485 * the underlying register file, which allows for example
486 * serialization code to access all registers.
489 RegVal readIntRegFlat(RegIndex idx) const override;
490 void setIntRegFlat(RegIndex idx, uint64_t val) override;
493 readFloatRegFlat(RegIndex idx) const override
495 panic("%s not implemented.", __FUNCTION__);
498 setFloatRegFlat(RegIndex idx, RegVal val) override
500 panic("%s not implemented.", __FUNCTION__);
503 const VecRegContainer &readVecRegFlat(RegIndex idx) const override;
505 getWritableVecRegFlat(RegIndex idx) override
507 panic("%s not implemented.", __FUNCTION__);
510 setVecRegFlat(RegIndex idx, const VecRegContainer &val) override
512 panic("%s not implemented.", __FUNCTION__);
516 readVecElemFlat(RegIndex idx, const ElemIndex& elemIdx) const override
518 panic("%s not implemented.", __FUNCTION__);
521 setVecElemFlat(RegIndex idx, const ElemIndex &elemIdx,
522 const VecElem &val) override
524 panic("%s not implemented.", __FUNCTION__);
527 const VecPredRegContainer &readVecPredRegFlat(RegIndex idx) const override;
528 VecPredRegContainer &
529 getWritableVecPredRegFlat(RegIndex idx) override
531 panic("%s not implemented.", __FUNCTION__);
534 setVecPredRegFlat(RegIndex idx, const VecPredRegContainer &val) override
536 panic("%s not implemented.", __FUNCTION__);
539 RegVal readCCRegFlat(RegIndex idx) const override;
540 void setCCRegFlat(RegIndex idx, RegVal val) override;
547 #endif // __ARCH_ARM_FASTMODEL_IRIS_THREAD_CONTEXT_HH__