2 * Copyright (c) 2001-2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Steve Reinhardt
32 #ifndef __CPU_SIMPLE_THREAD_HH__
33 #define __CPU_SIMPLE_THREAD_HH__
35 #include "arch/isa.hh"
36 #include "arch/isa_traits.hh"
37 #include "arch/registers.hh"
38 #include "arch/tlb.hh"
39 #include "arch/types.hh"
40 #include "base/types.hh"
41 #include "config/full_system.hh"
42 #include "config/the_isa.hh"
43 #include "cpu/decode.hh"
44 #include "cpu/thread_context.hh"
45 #include "cpu/thread_state.hh"
46 #include "debug/FloatRegs.hh"
47 #include "debug/IntRegs.hh"
48 #include "mem/request.hh"
49 #include "sim/byteswap.hh"
50 #include "sim/eventq.hh"
51 #include "sim/serialize.hh"
57 #include "sim/system.hh"
59 class FunctionProfile;
72 #include "mem/page_table.hh"
73 #include "sim/process.hh"
74 class TranslatingPort;
79 * The SimpleThread object provides a combination of the ThreadState
80 * object and the ThreadContext interface. It implements the
81 * ThreadContext interface so that a ProxyThreadContext class can be
82 * made using SimpleThread as the template parameter (see
83 * thread_context.hh). It adds to the ThreadState object by adding all
84 * the objects needed for simple functional execution, including a
85 * simple architectural register file, and pointers to the ITB and DTB
86 * in full system mode. For CPU models that do not need more advanced
87 * ways to hold state (i.e. a separate physical register file, or
88 * separate fetch and commit PC's), this SimpleThread class provides
89 * all the necessary state for full architecture-level functional
90 * simulation. See the AtomicSimpleCPU or TimingSimpleCPU for
94 class SimpleThread : public ThreadState
97 typedef TheISA::MachInst MachInst;
98 typedef TheISA::MiscReg MiscReg;
99 typedef TheISA::FloatReg FloatReg;
100 typedef TheISA::FloatRegBits FloatRegBits;
102 typedef ThreadContext::Status Status;
106 FloatReg f[TheISA::NumFloatRegs];
107 FloatRegBits i[TheISA::NumFloatRegs];
109 TheISA::IntReg intRegs[TheISA::NumIntRegs];
110 TheISA::ISA isa; // one "instance" of the current ISA.
112 TheISA::PCState _pcState;
114 /** Did this instruction execute or is it predicated false */
118 std::string name() const
120 return csprintf("%s.[tid:%i]", cpu->name(), tc->threadId());
123 // pointer to CPU associated with this SimpleThread
126 ProxyThreadContext<SimpleThread> *tc;
135 // constructor: initialize SimpleThread from given process structure
137 SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
138 TheISA::TLB *_itb, TheISA::TLB *_dtb,
139 bool use_kernel_stats = true);
141 SimpleThread(BaseCPU *_cpu, int _thread_num, Process *_process,
142 TheISA::TLB *_itb, TheISA::TLB *_dtb);
147 virtual ~SimpleThread();
149 virtual void takeOverFrom(ThreadContext *oldContext);
151 void regStats(const std::string &name);
153 void copyTC(ThreadContext *context);
155 void copyState(ThreadContext *oldContext);
157 void serialize(std::ostream &os);
158 void unserialize(Checkpoint *cp, const std::string §ion);
160 /***************************************************************
161 * SimpleThread functions to provide CPU with access to various
163 **************************************************************/
165 /** Returns the pointer to this SimpleThread's ThreadContext. Used
166 * when a ThreadContext must be passed to objects outside of the
169 ThreadContext *getTC() { return tc; }
171 void demapPage(Addr vaddr, uint64_t asn)
173 itb->demapPage(vaddr, asn);
174 dtb->demapPage(vaddr, asn);
177 void demapInstPage(Addr vaddr, uint64_t asn)
179 itb->demapPage(vaddr, asn);
182 void demapDataPage(Addr vaddr, uint64_t asn)
184 dtb->demapPage(vaddr, asn);
188 void dumpFuncProfile();
192 bool simPalCheck(int palFunc);
196 /*******************************************
197 * ThreadContext interface functions.
198 ******************************************/
200 BaseCPU *getCpuPtr() { return cpu; }
202 TheISA::TLB *getITBPtr() { return itb; }
204 TheISA::TLB *getDTBPtr() { return dtb; }
206 Decoder *getDecoderPtr() { return &decoder; }
208 System *getSystemPtr() { return system; }
211 FunctionalPort *getPhysPort() { return physPort; }
213 /** Return a virtual port. This port cannot be cached locally in an object.
214 * After a CPU switch it may point to the wrong memory object which could
217 VirtualPort *getVirtPort() { return virtPort; }
220 Status status() const { return _status; }
222 void setStatus(Status newStatus) { _status = newStatus; }
224 /// Set the status to Active. Optional delay indicates number of
225 /// cycles to wait before beginning execution.
226 void activate(int delay = 1);
228 /// Set the status to Suspended.
231 /// Set the status to Halted.
234 virtual bool misspeculating();
236 void copyArchRegs(ThreadContext *tc);
241 memset(intRegs, 0, sizeof(intRegs));
242 memset(floatRegs.i, 0, sizeof(floatRegs.i));
247 // New accessors for new decoder.
249 uint64_t readIntReg(int reg_idx)
251 int flatIndex = isa.flattenIntIndex(reg_idx);
252 assert(flatIndex < TheISA::NumIntRegs);
253 uint64_t regVal = intRegs[flatIndex];
254 DPRINTF(IntRegs, "Reading int reg %d (%d) as %#x.\n",
255 reg_idx, flatIndex, regVal);
259 FloatReg readFloatReg(int reg_idx)
261 int flatIndex = isa.flattenFloatIndex(reg_idx);
262 assert(flatIndex < TheISA::NumFloatRegs);
263 FloatReg regVal = floatRegs.f[flatIndex];
264 DPRINTF(FloatRegs, "Reading float reg %d (%d) as %f, %#x.\n",
265 reg_idx, flatIndex, regVal, floatRegs.i[flatIndex]);
269 FloatRegBits readFloatRegBits(int reg_idx)
271 int flatIndex = isa.flattenFloatIndex(reg_idx);
272 assert(flatIndex < TheISA::NumFloatRegs);
273 FloatRegBits regVal = floatRegs.i[flatIndex];
274 DPRINTF(FloatRegs, "Reading float reg %d (%d) bits as %#x, %f.\n",
275 reg_idx, flatIndex, regVal, floatRegs.f[flatIndex]);
279 void setIntReg(int reg_idx, uint64_t val)
281 int flatIndex = isa.flattenIntIndex(reg_idx);
282 assert(flatIndex < TheISA::NumIntRegs);
283 DPRINTF(IntRegs, "Setting int reg %d (%d) to %#x.\n",
284 reg_idx, flatIndex, val);
285 intRegs[flatIndex] = val;
288 void setFloatReg(int reg_idx, FloatReg val)
290 int flatIndex = isa.flattenFloatIndex(reg_idx);
291 assert(flatIndex < TheISA::NumFloatRegs);
292 floatRegs.f[flatIndex] = val;
293 DPRINTF(FloatRegs, "Setting float reg %d (%d) to %f, %#x.\n",
294 reg_idx, flatIndex, val, floatRegs.i[flatIndex]);
297 void setFloatRegBits(int reg_idx, FloatRegBits val)
299 int flatIndex = isa.flattenFloatIndex(reg_idx);
300 assert(flatIndex < TheISA::NumFloatRegs);
301 floatRegs.i[flatIndex] = val;
302 DPRINTF(FloatRegs, "Setting float reg %d (%d) bits to %#x, %#f.\n",
303 reg_idx, flatIndex, val, floatRegs.f[flatIndex]);
313 pcState(const TheISA::PCState &val)
321 return _pcState.instAddr();
327 return _pcState.nextInstAddr();
333 return _pcState.microPC();
341 void setPredicate(bool val)
347 readMiscRegNoEffect(int misc_reg, ThreadID tid = 0)
349 return isa.readMiscRegNoEffect(misc_reg);
353 readMiscReg(int misc_reg, ThreadID tid = 0)
355 return isa.readMiscReg(misc_reg, tc);
359 setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid = 0)
361 return isa.setMiscRegNoEffect(misc_reg, val);
365 setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid = 0)
367 return isa.setMiscReg(misc_reg, val, tc);
371 flattenIntIndex(int reg)
373 return isa.flattenIntIndex(reg);
377 flattenFloatIndex(int reg)
379 return isa.flattenFloatIndex(reg);
382 unsigned readStCondFailures() { return storeCondFailures; }
384 void setStCondFailures(unsigned sc_failures)
385 { storeCondFailures = sc_failures; }
388 void syscall(int64_t callnum)
390 process->syscall(callnum, tc);
396 // for non-speculative execution context, spec_mode is always false
398 SimpleThread::misspeculating()
403 #endif // __CPU_CPU_EXEC_CONTEXT_HH__