gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
simple_thread.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2012 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) 2001-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: Steve Reinhardt
42  * Nathan Binkert
43  */
44 
45 #ifndef __CPU_SIMPLE_THREAD_HH__
46 #define __CPU_SIMPLE_THREAD_HH__
47 
48 #include "arch/decoder.hh"
49 #include "arch/isa.hh"
50 #include "arch/isa_traits.hh"
51 #include "arch/registers.hh"
52 #include "arch/tlb.hh"
53 #include "arch/types.hh"
54 #include "base/types.hh"
55 #include "config/the_isa.hh"
56 #include "cpu/thread_context.hh"
57 #include "cpu/thread_state.hh"
58 #include "debug/CCRegs.hh"
59 #include "debug/FloatRegs.hh"
60 #include "debug/IntRegs.hh"
61 #include "mem/page_table.hh"
62 #include "mem/request.hh"
63 #include "sim/byteswap.hh"
64 #include "sim/eventq.hh"
65 #include "sim/process.hh"
66 #include "sim/serialize.hh"
67 #include "sim/system.hh"
68 
69 class BaseCPU;
70 class CheckerCPU;
71 
72 class FunctionProfile;
73 class ProfileNode;
74 
75 namespace TheISA {
76  namespace Kernel {
77  class Statistics;
78  }
79 }
80 
97 class SimpleThread : public ThreadState
98 {
99  protected:
105  public:
107 
108  protected:
109  union {
112  } floatRegs;
114 #ifdef ISA_HAS_CC_REGS
116 #endif
117  TheISA::ISA *const isa; // one "instance" of the current ISA.
118 
120 
122  bool predicate;
123 
124  public:
125  std::string name() const
126  {
127  return csprintf("%s.[tid:%i]", baseCpu->name(), tc->threadId());
128  }
129 
131 
133 
134  TheISA::TLB *itb;
135  TheISA::TLB *dtb;
136 
137  TheISA::Decoder decoder;
138 
139  // constructor: initialize SimpleThread from given process structure
140  // FS
141  SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
142  TheISA::TLB *_itb, TheISA::TLB *_dtb, TheISA::ISA *_isa,
143  bool use_kernel_stats = true);
144  // SE
145  SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
146  Process *_process, TheISA::TLB *_itb, TheISA::TLB *_dtb,
147  TheISA::ISA *_isa);
148 
149  virtual ~SimpleThread();
150 
151  virtual void takeOverFrom(ThreadContext *oldContext);
152 
153  void regStats(const std::string &name);
154 
155  void copyState(ThreadContext *oldContext);
156 
157  void serialize(CheckpointOut &cp) const override;
158  void unserialize(CheckpointIn &cp) override;
159  void startup();
160 
161  /***************************************************************
162  * SimpleThread functions to provide CPU with access to various
163  * state.
164  **************************************************************/
165 
170  ThreadContext *getTC() { return tc; }
171 
172  void demapPage(Addr vaddr, uint64_t asn)
173  {
174  itb->demapPage(vaddr, asn);
175  dtb->demapPage(vaddr, asn);
176  }
177 
178  void demapInstPage(Addr vaddr, uint64_t asn)
179  {
180  itb->demapPage(vaddr, asn);
181  }
182 
183  void demapDataPage(Addr vaddr, uint64_t asn)
184  {
185  dtb->demapPage(vaddr, asn);
186  }
187 
188  void dumpFuncProfile();
189 
190  Fault hwrei();
191 
192  bool simPalCheck(int palFunc);
193 
194  /*******************************************
195  * ThreadContext interface functions.
196  ******************************************/
197 
198  BaseCPU *getCpuPtr() { return baseCpu; }
199 
200  TheISA::TLB *getITBPtr() { return itb; }
201 
202  TheISA::TLB *getDTBPtr() { return dtb; }
203 
204  CheckerCPU *getCheckerCpuPtr() { return NULL; }
205 
206  TheISA::Decoder *getDecoderPtr() { return &decoder; }
207 
208  System *getSystemPtr() { return system; }
209 
210  Status status() const { return _status; }
211 
212  void setStatus(Status newStatus) { _status = newStatus; }
213 
215  void activate();
216 
218  void suspend();
219 
221  void halt();
222 
224 
226  {
227  _pcState = 0;
228  memset(intRegs, 0, sizeof(intRegs));
229  memset(floatRegs.i, 0, sizeof(floatRegs.i));
230 #ifdef ISA_HAS_CC_REGS
231  memset(ccRegs, 0, sizeof(ccRegs));
232 #endif
233  isa->clear();
234  }
235 
236  //
237  // New accessors for new decoder.
238  //
239  uint64_t readIntReg(int reg_idx)
240  {
241  int flatIndex = isa->flattenIntIndex(reg_idx);
242  assert(flatIndex < TheISA::NumIntRegs);
243  uint64_t regVal(readIntRegFlat(flatIndex));
244  DPRINTF(IntRegs, "Reading int reg %d (%d) as %#x.\n",
245  reg_idx, flatIndex, regVal);
246  return regVal;
247  }
248 
249  FloatReg readFloatReg(int reg_idx)
250  {
251  int flatIndex = isa->flattenFloatIndex(reg_idx);
252  assert(flatIndex < TheISA::NumFloatRegs);
253  FloatReg regVal(readFloatRegFlat(flatIndex));
254  DPRINTF(FloatRegs, "Reading float reg %d (%d) as %f, %#x.\n",
255  reg_idx, flatIndex, regVal, floatRegs.i[flatIndex]);
256  return regVal;
257  }
258 
260  {
261  int flatIndex = isa->flattenFloatIndex(reg_idx);
262  assert(flatIndex < TheISA::NumFloatRegs);
263  FloatRegBits regVal(readFloatRegBitsFlat(flatIndex));
264  DPRINTF(FloatRegs, "Reading float reg %d (%d) bits as %#x, %f.\n",
265  reg_idx, flatIndex, regVal, floatRegs.f[flatIndex]);
266  return regVal;
267  }
268 
269  CCReg readCCReg(int reg_idx)
270  {
271 #ifdef ISA_HAS_CC_REGS
272  int flatIndex = isa->flattenCCIndex(reg_idx);
273  assert(0 <= flatIndex);
274  assert(flatIndex < TheISA::NumCCRegs);
275  uint64_t regVal(readCCRegFlat(flatIndex));
276  DPRINTF(CCRegs, "Reading CC reg %d (%d) as %#x.\n",
277  reg_idx, flatIndex, regVal);
278  return regVal;
279 #else
280  panic("Tried to read a CC register.");
281  return 0;
282 #endif
283  }
284 
285  void setIntReg(int reg_idx, uint64_t val)
286  {
287  int flatIndex = isa->flattenIntIndex(reg_idx);
288  assert(flatIndex < TheISA::NumIntRegs);
289  DPRINTF(IntRegs, "Setting int reg %d (%d) to %#x.\n",
290  reg_idx, flatIndex, val);
291  setIntRegFlat(flatIndex, val);
292  }
293 
294  void setFloatReg(int reg_idx, FloatReg val)
295  {
296  int flatIndex = isa->flattenFloatIndex(reg_idx);
297  assert(flatIndex < TheISA::NumFloatRegs);
298  setFloatRegFlat(flatIndex, val);
299  DPRINTF(FloatRegs, "Setting float reg %d (%d) to %f, %#x.\n",
300  reg_idx, flatIndex, val, floatRegs.i[flatIndex]);
301  }
302 
303  void setFloatRegBits(int reg_idx, FloatRegBits val)
304  {
305  int flatIndex = isa->flattenFloatIndex(reg_idx);
306  assert(flatIndex < TheISA::NumFloatRegs);
307  // XXX: Fix array out of bounds compiler error for gem5.fast
308  // when checkercpu enabled
309  if (flatIndex < TheISA::NumFloatRegs)
310  setFloatRegBitsFlat(flatIndex, val);
311  DPRINTF(FloatRegs, "Setting float reg %d (%d) bits to %#x, %#f.\n",
312  reg_idx, flatIndex, val, floatRegs.f[flatIndex]);
313  }
314 
315  void setCCReg(int reg_idx, CCReg val)
316  {
317 #ifdef ISA_HAS_CC_REGS
318  int flatIndex = isa->flattenCCIndex(reg_idx);
319  assert(flatIndex < TheISA::NumCCRegs);
320  DPRINTF(CCRegs, "Setting CC reg %d (%d) to %#x.\n",
321  reg_idx, flatIndex, val);
322  setCCRegFlat(flatIndex, val);
323 #else
324  panic("Tried to set a CC register.");
325 #endif
326  }
327 
330  {
331  return _pcState;
332  }
333 
334  void
336  {
337  _pcState = val;
338  }
339 
340  void
342  {
343  _pcState = val;
344  }
345 
346  Addr
348  {
349  return _pcState.instAddr();
350  }
351 
352  Addr
354  {
355  return _pcState.nextInstAddr();
356  }
357 
358  void
360  {
361  _pcState.setNPC(val);
362  }
363 
364  MicroPC
366  {
367  return _pcState.microPC();
368  }
369 
371  {
372  return predicate;
373  }
374 
375  void setPredicate(bool val)
376  {
377  predicate = val;
378  }
379 
380  MiscReg
381  readMiscRegNoEffect(int misc_reg, ThreadID tid = 0) const
382  {
383  return isa->readMiscRegNoEffect(misc_reg);
384  }
385 
386  MiscReg
387  readMiscReg(int misc_reg, ThreadID tid = 0)
388  {
389  return isa->readMiscReg(misc_reg, tc);
390  }
391 
392  void
393  setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid = 0)
394  {
395  return isa->setMiscRegNoEffect(misc_reg, val);
396  }
397 
398  void
399  setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid = 0)
400  {
401  return isa->setMiscReg(misc_reg, val, tc);
402  }
403 
404  int
406  {
407  return isa->flattenIntIndex(reg);
408  }
409 
410  int
412  {
413  return isa->flattenFloatIndex(reg);
414  }
415 
416  int
418  {
419  return isa->flattenCCIndex(reg);
420  }
421 
422  int
424  {
425  return isa->flattenMiscIndex(reg);
426  }
427 
428  unsigned readStCondFailures() { return storeCondFailures; }
429 
430  void setStCondFailures(unsigned sc_failures)
431  { storeCondFailures = sc_failures; }
432 
433  void syscall(int64_t callnum, Fault *fault)
434  {
435  process->syscall(callnum, tc, fault);
436  }
437 
438  uint64_t readIntRegFlat(int idx) { return intRegs[idx]; }
439  void setIntRegFlat(int idx, uint64_t val) { intRegs[idx] = val; }
440 
441  FloatReg readFloatRegFlat(int idx) { return floatRegs.f[idx]; }
442  void setFloatRegFlat(int idx, FloatReg val) { floatRegs.f[idx] = val; }
443 
444  FloatRegBits readFloatRegBitsFlat(int idx) { return floatRegs.i[idx]; }
446  floatRegs.i[idx] = val;
447  }
448 
449 #ifdef ISA_HAS_CC_REGS
450  CCReg readCCRegFlat(int idx) { return ccRegs[idx]; }
451  void setCCRegFlat(int idx, CCReg val) { ccRegs[idx] = val; }
452 #else
454  { panic("readCCRegFlat w/no CC regs!\n"); }
455 
456  void setCCRegFlat(int idx, CCReg val)
457  { panic("setCCRegFlat w/no CC regs!\n"); }
458 #endif
459 };
460 
461 
462 #endif // __CPU_CPU_EXEC_CONTEXT_HH__
#define DPRINTF(x,...)
Definition: trace.hh:212
uint64_t readIntReg(int reg_idx)
int flattenCCIndex(int reg)
void unserialize(CheckpointIn &cp) override
Unserialize an object.
uint8_t CCReg
Definition: registers.hh:57
CCReg readCCRegFlat(int idx)
void setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid=0)
Struct for holding general thread state that is needed across CPU models.
Definition: thread_state.hh:59
std::string name() const
Bitfield< 5, 3 > reg
Definition: types.hh:89
CheckerCPU class.
Definition: cpu.hh:91
System * getSystemPtr()
#define panic(...)
Definition: misc.hh:153
void setStatus(Status newStatus)
TheISA::CCReg CCReg
TheISA::Decoder decoder
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
ProxyThreadContext< SimpleThread > * tc
const int NumFloatRegs
Definition: registers.hh:96
void setFloatRegFlat(int idx, FloatReg val)
TheISA::FloatReg FloatReg
bool simPalCheck(int palFunc)
Check for special simulator handling of specific PAL calls.
Definition: ev5.cc:490
uint64_t MiscReg
Definition: registers.hh:54
void activate()
Set the status to Active.
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
int flattenMiscIndex(int reg)
Definition: system.hh:83
void setFloatRegBitsFlat(int idx, FloatRegBits val)
void setStCondFailures(unsigned sc_failures)
System * system
void pcStateNoRecord(const TheISA::PCState &val)
FloatRegBits i[TheISA::NumFloatRegs]
void setNPC(Addr val)
ThreadContext is the external interface to all thread state for anything outside of the CPU...
TheISA::MiscReg MiscReg
FloatReg readFloatRegFlat(int idx)
void setCCReg(int reg_idx, CCReg val)
TheISA::TLB * dtb
void syscall(int64_t callnum, Fault *fault)
Bitfield< 63 > val
Definition: misc.hh:770
uint32_t MachInst
Definition: types.hh:40
CheckerCPU * getCheckerCpuPtr()
MicroPC microPC()
void suspend()
Set the status to Suspended.
void setIntRegFlat(int idx, uint64_t val)
MiscReg readMiscRegNoEffect(int misc_reg, ThreadID tid=0) const
unsigned readStCondFailures()
Process * process
TheISA::MachInst MachInst
TheISA::PCState _pcState
virtual ~SimpleThread()
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
uint64_t FloatRegBits
Definition: registers.hh:51
void setCCRegFlat(int idx, CCReg val)
void dumpFuncProfile()
TheISA::ISA *const isa
const int NumCCRegs
Definition: registers.hh:97
virtual void takeOverFrom(ThreadContext *oldContext)
union SimpleThread::@38 floatRegs
MiscReg readMiscReg(int misc_reg, ThreadID tid=0)
void setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid=0)
TheISA::TLB * itb
void pcState(const TheISA::PCState &val)
TheISA::Decoder * getDecoderPtr()
uint16_t MicroPC
Definition: types.hh:144
void demapInstPage(Addr vaddr, uint64_t asn)
void demapDataPage(Addr vaddr, uint64_t asn)
double FloatReg
Definition: registers.hh:50
void demapPage(Addr vaddr, uint64_t asn)
void setFloatRegBits(int reg_idx, FloatRegBits 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
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
Fault hwrei()
Definition: ev5.cc:467
int flattenFloatIndex(int reg)
TheISA::TLB * getDTBPtr()
void setFloatReg(int reg_idx, FloatReg val)
virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault)
Definition: process.cc:413
BaseCPU * getCpuPtr()
ThreadContext::Status _status
bool predicate
Did this instruction execute or is it predicated false.
int threadId() const
uint64_t IntReg
Definition: registers.hh:47
TheISA::PCState pcState()
CCReg readCCReg(int reg_idx)
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
void halt()
Set the status to Halted.
FloatReg readFloatReg(int reg_idx)
void setIntReg(int reg_idx, uint64_t val)
Declarations of a non-full system Page Table.
void regStats(const std::string &name)
bool readPredicate()
std::ostream CheckpointOut
Definition: serialize.hh:67
FloatRegBits readFloatRegBits(int reg_idx)
void copyArchRegs(ThreadContext *tc)
void copyState(ThreadContext *oldContext)
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
FloatReg f[TheISA::NumFloatRegs]
TheISA::TLB * getITBPtr()
BaseCPU * baseCpu
Addr nextInstAddr()
ThreadContext::Status Status
uint64_t readIntRegFlat(int idx)
unsigned storeCondFailures
void serialize(CheckpointOut &cp) const override
Serialize an object.
void clearArchRegs()
TheISA::IntReg intRegs[TheISA::NumIntRegs]
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
const int NumIntRegs
Definition: registers.hh:95
int flattenIntIndex(int reg)
SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system, TheISA::TLB *_itb, TheISA::TLB *_dtb, TheISA::ISA *_isa, bool use_kernel_stats=true)
void setPredicate(bool val)
TheISA::FloatRegBits FloatRegBits
Status status() const
FloatRegBits readFloatRegBitsFlat(int idx)

Generated on Fri Jun 9 2017 13:03:44 for gem5 by doxygen 1.8.6