gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
thread_context.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2012, 2016-2018 ARM Limited
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 2006 The Regents of The University of Michigan
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Authors: Kevin Lim
42  */
43 
44 #ifndef __CPU_THREAD_CONTEXT_HH__
45 #define __CPU_THREAD_CONTEXT_HH__
46 
47 #include <iostream>
48 #include <string>
49 
50 #include "arch/generic/isa.hh"
51 #include "arch/registers.hh"
52 #include "arch/types.hh"
53 #include "base/types.hh"
54 #include "config/the_isa.hh"
55 #include "cpu/pc_event.hh"
56 #include "cpu/reg_class.hh"
57 
58 // @todo: Figure out a more architecture independent way to obtain the ITB and
59 // DTB pointers.
60 namespace TheISA
61 {
62  class ISA;
63  class Decoder;
64 }
65 class BaseCPU;
66 class BaseTLB;
67 class CheckerCPU;
68 class Checkpoint;
69 class EndQuiesceEvent;
70 class PortProxy;
71 class Process;
72 class System;
73 namespace Kernel {
74  class Statistics;
75 }
76 
94 {
95  protected:
100 
101  public:
102 
103  enum Status
104  {
108 
112 
116 
120  Halted
121  };
122 
123  virtual ~ThreadContext() { };
124 
125  virtual BaseCPU *getCpuPtr() = 0;
126 
127  virtual int cpuId() const = 0;
128 
129  virtual uint32_t socketId() const = 0;
130 
131  virtual int threadId() const = 0;
132 
133  virtual void setThreadId(int id) = 0;
134 
135  virtual ContextID contextId() const = 0;
136 
137  virtual void setContextId(ContextID id) = 0;
138 
139  virtual BaseTLB *getITBPtr() = 0;
140 
141  virtual BaseTLB *getDTBPtr() = 0;
142 
143  virtual CheckerCPU *getCheckerCpuPtr() = 0;
144 
145  virtual BaseISA *getIsaPtr() = 0;
146 
147  virtual TheISA::Decoder *getDecoderPtr() = 0;
148 
149  virtual System *getSystemPtr() = 0;
150 
151  virtual ::Kernel::Statistics *getKernelStats() = 0;
152 
153  virtual PortProxy &getPhysProxy() = 0;
154 
155  virtual PortProxy &getVirtProxy() = 0;
156 
163  virtual void initMemProxies(ThreadContext *tc) = 0;
164 
165  virtual Process *getProcessPtr() = 0;
166 
167  virtual void setProcessPtr(Process *p) = 0;
168 
169  virtual Status status() const = 0;
170 
171  virtual void setStatus(Status new_status) = 0;
172 
174  virtual void activate() = 0;
175 
177  virtual void suspend() = 0;
178 
180  virtual void halt() = 0;
181 
183  void quiesce();
184 
186  void quiesceTick(Tick resume);
187 
188  virtual void dumpFuncProfile() = 0;
189 
190  virtual void takeOverFrom(ThreadContext *old_context) = 0;
191 
192  virtual void regStats(const std::string &name) = 0;
193 
194  virtual EndQuiesceEvent *getQuiesceEvent() = 0;
195 
196  virtual void scheduleInstCountEvent(Event *event, Tick count) = 0;
197  virtual void descheduleInstCountEvent(Event *event) = 0;
198  virtual Tick getCurrentInstCount() = 0;
199 
200  // Not necessarily the best location for these...
201  // Having an extra function just to read these is obnoxious
202  virtual Tick readLastActivate() = 0;
203  virtual Tick readLastSuspend() = 0;
204 
205  virtual void profileClear() = 0;
206  virtual void profileSample() = 0;
207 
208  virtual void copyArchRegs(ThreadContext *tc) = 0;
209 
210  virtual void clearArchRegs() = 0;
211 
212  //
213  // New accessors for new decoder.
214  //
215  virtual RegVal readIntReg(RegIndex reg_idx) const = 0;
216 
217  virtual RegVal readFloatReg(RegIndex reg_idx) const = 0;
218 
219  virtual const VecRegContainer& readVecReg(const RegId& reg) const = 0;
220  virtual VecRegContainer& getWritableVecReg(const RegId& reg) = 0;
221 
225  virtual ConstVecLane8
226  readVec8BitLaneReg(const RegId& reg) const = 0;
227 
229  virtual ConstVecLane16
230  readVec16BitLaneReg(const RegId& reg) const = 0;
231 
233  virtual ConstVecLane32
234  readVec32BitLaneReg(const RegId& reg) const = 0;
235 
237  virtual ConstVecLane64
238  readVec64BitLaneReg(const RegId& reg) const = 0;
239 
241  virtual void setVecLane(const RegId& reg,
242  const LaneData<LaneSize::Byte>& val) = 0;
243  virtual void setVecLane(const RegId& reg,
244  const LaneData<LaneSize::TwoByte>& val) = 0;
245  virtual void setVecLane(const RegId& reg,
246  const LaneData<LaneSize::FourByte>& val) = 0;
247  virtual void setVecLane(const RegId& reg,
248  const LaneData<LaneSize::EightByte>& val) = 0;
251  virtual const VecElem& readVecElem(const RegId& reg) const = 0;
252 
253  virtual const VecPredRegContainer& readVecPredReg(const RegId& reg)
254  const = 0;
255  virtual VecPredRegContainer& getWritableVecPredReg(const RegId& reg) = 0;
256 
257  virtual RegVal readCCReg(RegIndex reg_idx) const = 0;
258 
259  virtual void setIntReg(RegIndex reg_idx, RegVal val) = 0;
260 
261  virtual void setFloatReg(RegIndex reg_idx, RegVal val) = 0;
262 
263  virtual void setVecReg(const RegId& reg, const VecRegContainer& val) = 0;
264 
265  virtual void setVecElem(const RegId& reg, const VecElem& val) = 0;
266 
267  virtual void setVecPredReg(const RegId& reg,
268  const VecPredRegContainer& val) = 0;
269 
270  virtual void setCCReg(RegIndex reg_idx, RegVal val) = 0;
271 
272  virtual TheISA::PCState pcState() const = 0;
273 
274  virtual void pcState(const TheISA::PCState &val) = 0;
275 
276  void
278  {
279  TheISA::PCState pc_state = pcState();
280  pc_state.setNPC(val);
281  pcState(pc_state);
282  }
283 
284  virtual void pcStateNoRecord(const TheISA::PCState &val) = 0;
285 
286  virtual Addr instAddr() const = 0;
287 
288  virtual Addr nextInstAddr() const = 0;
289 
290  virtual MicroPC microPC() const = 0;
291 
292  virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const = 0;
293 
294  virtual RegVal readMiscReg(RegIndex misc_reg) = 0;
295 
296  virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val) = 0;
297 
298  virtual void setMiscReg(RegIndex misc_reg, RegVal val) = 0;
299 
300  virtual RegId flattenRegId(const RegId& regId) const = 0;
301 
302  // Also not necessarily the best location for these two. Hopefully will go
303  // away once we decide upon where st cond failures goes.
304  virtual unsigned readStCondFailures() const = 0;
305 
306  virtual void setStCondFailures(unsigned sc_failures) = 0;
307 
308  // Same with st cond failures.
309  virtual Counter readFuncExeInst() const = 0;
310 
311  virtual void syscall(Fault *fault) = 0;
312 
313  // This function exits the thread context in the CPU and returns
314  // 1 if the CPU has no more active threads (meaning it's OK to exit);
315  // Used in syscall-emulation mode when a thread calls the exit syscall.
316  virtual int exit() { return 1; };
317 
319  static void compare(ThreadContext *one, ThreadContext *two);
320 
333  virtual RegVal readIntRegFlat(RegIndex idx) const = 0;
334  virtual void setIntRegFlat(RegIndex idx, RegVal val) = 0;
335 
336  virtual RegVal readFloatRegFlat(RegIndex idx) const = 0;
337  virtual void setFloatRegFlat(RegIndex idx, RegVal val) = 0;
338 
339  virtual const VecRegContainer& readVecRegFlat(RegIndex idx) const = 0;
340  virtual VecRegContainer& getWritableVecRegFlat(RegIndex idx) = 0;
341  virtual void setVecRegFlat(RegIndex idx, const VecRegContainer& val) = 0;
342 
343  virtual const VecElem& readVecElemFlat(RegIndex idx,
344  const ElemIndex& elemIdx) const = 0;
345  virtual void setVecElemFlat(RegIndex idx, const ElemIndex& elemIdx,
346  const VecElem& val) = 0;
347 
348  virtual const VecPredRegContainer &
349  readVecPredRegFlat(RegIndex idx) const = 0;
350  virtual VecPredRegContainer& getWritableVecPredRegFlat(RegIndex idx) = 0;
351  virtual void setVecPredRegFlat(RegIndex idx,
352  const VecPredRegContainer& val) = 0;
353 
354  virtual RegVal readCCRegFlat(RegIndex idx) const = 0;
355  virtual void setCCRegFlat(RegIndex idx, RegVal val) = 0;
358 };
359 
370 void serialize(const ThreadContext &tc, CheckpointOut &cp);
372 
386 void takeOverFrom(ThreadContext &new_tc, ThreadContext &old_tc);
387 
388 #endif
count
Definition: misc.hh:705
TheISA::VecElem VecElem
Bitfield< 5, 3 > reg
Definition: types.hh:89
const std::string & name()
Definition: trace.cc:54
CheckerCPU class.
Definition: cpu.hh:87
Trying to exit and waiting for an event to completely exit.
Vector Register Abstraction This generic class is the model in a particularization of MVC...
Definition: vec_reg.hh:160
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
uint64_t RegVal
Definition: types.hh:168
Definition: system.hh:77
Definition: cprintf.cc:42
TLB * getDTBPtr(T *tc)
Definition: ev5.cc:57
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Event for timing out quiesce instruction.
Bitfield< 63 > val
Definition: misc.hh:771
void unserialize(ThreadContext &tc, CheckpointIn &cp)
uint32_t MachInst
Definition: types.hh:40
Bitfield< 5, 0 > status
Definition: tlb.hh:52
LaneSize is an abstraction of a LS byte value for the execution and thread contexts to handle values ...
Definition: vec_reg.hh:457
void quiesce(ThreadContext *tc)
Definition: pseudo_inst.cc:102
uint16_t RegIndex
Definition: types.hh:42
::DummyVecPredRegContainer VecPredRegContainer
Definition: registers.hh:60
uint64_t Tick
Tick count type.
Definition: types.hh:63
::DummyVecRegContainer VecRegContainer
Definition: registers.hh:53
uint16_t MicroPC
Definition: types.hh:144
void setNPC(Addr val)
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
int64_t Counter
Statistics counter type.
Definition: types.hh:58
Bitfield< 10, 5 > event
void takeOverFrom(ThreadContext &new_tc, ThreadContext &old_tc)
Copy state between thread contexts in preparation for CPU handover.
Bitfield< 3 > one
Definition: types.hh:112
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:82
std::ostream CheckpointOut
Definition: serialize.hh:68
TLB * getITBPtr(T *tc)
Definition: ev5.cc:48
uint16_t ElemIndex
Logical vector register elem index type.
Definition: types.hh:45
Definition: eventq.hh:189
XReg readVecElem(VReg src, int index, int eSize)
Read a single NEON vector element.
Definition: neon64_mem.hh:94
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
Generic predicate register container.
Definition: vec_pred_reg.hh:51
bool compare(T src0, T src1, Brig::BrigCompareOperation cmpOp)
Definition: decl.hh:592
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:79
virtual int exit()
Temporarily inactive.
Definition: isa.hh:35
::DummyVecElem VecElem
Definition: registers.hh:50
Vector Lane abstraction Another view of a container.
Definition: vec_reg.hh:262
TheISA::MachInst MachInst
Bitfield< 0 > p
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
virtual ~ThreadContext()
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
Bitfield< 26 > halt
Definition: dt_constants.hh:46

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13