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/thread_context.hh"
44 #include "cpu/thread_state.hh"
45 #include "mem/request.hh"
46 #include "sim/byteswap.hh"
47 #include "sim/eventq.hh"
48 #include "sim/serialize.hh"
54 #include "sim/system.hh"
56 class FunctionProfile;
69 #include "mem/page_table.hh"
70 #include "sim/process.hh"
71 class TranslatingPort;
76 * The SimpleThread object provides a combination of the ThreadState
77 * object and the ThreadContext interface. It implements the
78 * ThreadContext interface so that a ProxyThreadContext class can be
79 * made using SimpleThread as the template parameter (see
80 * thread_context.hh). It adds to the ThreadState object by adding all
81 * the objects needed for simple functional execution, including a
82 * simple architectural register file, and pointers to the ITB and DTB
83 * in full system mode. For CPU models that do not need more advanced
84 * ways to hold state (i.e. a separate physical register file, or
85 * separate fetch and commit PC's), this SimpleThread class provides
86 * all the necessary state for full architecture-level functional
87 * simulation. See the AtomicSimpleCPU or TimingSimpleCPU for
91 class SimpleThread : public ThreadState
94 typedef TheISA::MachInst MachInst;
95 typedef TheISA::MiscReg MiscReg;
96 typedef TheISA::FloatReg FloatReg;
97 typedef TheISA::FloatRegBits FloatRegBits;
99 typedef ThreadContext::Status Status;
103 FloatReg f[TheISA::NumFloatRegs];
104 FloatRegBits i[TheISA::NumFloatRegs];
106 TheISA::IntReg intRegs[TheISA::NumIntRegs];
107 TheISA::ISA isa; // one "instance" of the current ISA.
109 TheISA::PCState _pcState;
111 /** Did this instruction execute or is it predicated false */
115 // pointer to CPU associated with this SimpleThread
118 ProxyThreadContext<SimpleThread> *tc;
125 // constructor: initialize SimpleThread from given process structure
127 SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
128 TheISA::TLB *_itb, TheISA::TLB *_dtb,
129 bool use_kernel_stats = true);
131 SimpleThread(BaseCPU *_cpu, int _thread_num, Process *_process,
132 TheISA::TLB *_itb, TheISA::TLB *_dtb);
137 virtual ~SimpleThread();
139 virtual void takeOverFrom(ThreadContext *oldContext);
141 void regStats(const std::string &name);
143 void copyTC(ThreadContext *context);
145 void copyState(ThreadContext *oldContext);
147 void serialize(std::ostream &os);
148 void unserialize(Checkpoint *cp, const std::string §ion);
150 /***************************************************************
151 * SimpleThread functions to provide CPU with access to various
153 **************************************************************/
155 /** Returns the pointer to this SimpleThread's ThreadContext. Used
156 * when a ThreadContext must be passed to objects outside of the
159 ThreadContext *getTC() { return tc; }
161 void demapPage(Addr vaddr, uint64_t asn)
163 itb->demapPage(vaddr, asn);
164 dtb->demapPage(vaddr, asn);
167 void demapInstPage(Addr vaddr, uint64_t asn)
169 itb->demapPage(vaddr, asn);
172 void demapDataPage(Addr vaddr, uint64_t asn)
174 dtb->demapPage(vaddr, asn);
178 void dumpFuncProfile();
182 bool simPalCheck(int palFunc);
186 /*******************************************
187 * ThreadContext interface functions.
188 ******************************************/
190 BaseCPU *getCpuPtr() { return cpu; }
192 TheISA::TLB *getITBPtr() { return itb; }
194 TheISA::TLB *getDTBPtr() { return dtb; }
196 System *getSystemPtr() { return system; }
199 FunctionalPort *getPhysPort() { return physPort; }
201 /** Return a virtual port. This port cannot be cached locally in an object.
202 * After a CPU switch it may point to the wrong memory object which could
205 VirtualPort *getVirtPort() { return virtPort; }
208 Status status() const { return _status; }
210 void setStatus(Status newStatus) { _status = newStatus; }
212 /// Set the status to Active. Optional delay indicates number of
213 /// cycles to wait before beginning execution.
214 void activate(int delay = 1);
216 /// Set the status to Suspended.
219 /// Set the status to Halted.
222 virtual bool misspeculating();
224 void copyArchRegs(ThreadContext *tc);
229 memset(intRegs, 0, sizeof(intRegs));
230 memset(floatRegs.i, 0, sizeof(floatRegs.i));
235 // New accessors for new decoder.
237 uint64_t readIntReg(int reg_idx)
239 int flatIndex = isa.flattenIntIndex(reg_idx);
240 assert(flatIndex < TheISA::NumIntRegs);
241 uint64_t regVal = intRegs[flatIndex];
242 DPRINTF(IntRegs, "Reading int reg %d (%d) as %#x.\n",
243 reg_idx, flatIndex, regVal);
247 FloatReg readFloatReg(int reg_idx)
249 int flatIndex = isa.flattenFloatIndex(reg_idx);
250 assert(flatIndex < TheISA::NumFloatRegs);
251 FloatReg regVal = floatRegs.f[flatIndex];
252 DPRINTF(FloatRegs, "Reading float reg %d (%d) as %f, %#x.\n",
253 reg_idx, flatIndex, regVal, floatRegs.i[flatIndex]);
257 FloatRegBits readFloatRegBits(int reg_idx)
259 int flatIndex = isa.flattenFloatIndex(reg_idx);
260 assert(flatIndex < TheISA::NumFloatRegs);
261 FloatRegBits regVal = floatRegs.i[flatIndex];
262 DPRINTF(FloatRegs, "Reading float reg %d (%d) bits as %#x, %f.\n",
263 reg_idx, flatIndex, regVal, floatRegs.f[flatIndex]);
267 void setIntReg(int reg_idx, uint64_t val)
269 int flatIndex = isa.flattenIntIndex(reg_idx);
270 assert(flatIndex < TheISA::NumIntRegs);
271 DPRINTF(IntRegs, "Setting int reg %d (%d) to %#x.\n",
272 reg_idx, flatIndex, val);
273 intRegs[flatIndex] = val;
276 void setFloatReg(int reg_idx, FloatReg val)
278 int flatIndex = isa.flattenFloatIndex(reg_idx);
279 assert(flatIndex < TheISA::NumFloatRegs);
280 floatRegs.f[flatIndex] = val;
281 DPRINTF(FloatRegs, "Setting float reg %d (%d) to %f, %#x.\n",
282 reg_idx, flatIndex, val, floatRegs.i[flatIndex]);
285 void setFloatRegBits(int reg_idx, FloatRegBits val)
287 int flatIndex = isa.flattenFloatIndex(reg_idx);
288 assert(flatIndex < TheISA::NumFloatRegs);
289 floatRegs.i[flatIndex] = val;
290 DPRINTF(FloatRegs, "Setting float reg %d (%d) bits to %#x, %#f.\n",
291 reg_idx, flatIndex, val, floatRegs.f[flatIndex]);
301 pcState(const TheISA::PCState &val)
309 return _pcState.instAddr();
315 return _pcState.nextInstAddr();
321 return _pcState.microPC();
329 void setPredicate(bool val)
335 readMiscRegNoEffect(int misc_reg, ThreadID tid = 0)
337 return isa.readMiscRegNoEffect(misc_reg);
341 readMiscReg(int misc_reg, ThreadID tid = 0)
343 return isa.readMiscReg(misc_reg, tc);
347 setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid = 0)
349 return isa.setMiscRegNoEffect(misc_reg, val);
353 setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid = 0)
355 return isa.setMiscReg(misc_reg, val, tc);
359 flattenIntIndex(int reg)
361 return isa.flattenIntIndex(reg);
365 flattenFloatIndex(int reg)
367 return isa.flattenFloatIndex(reg);
370 unsigned readStCondFailures() { return storeCondFailures; }
372 void setStCondFailures(unsigned sc_failures)
373 { storeCondFailures = sc_failures; }
376 void syscall(int64_t callnum)
378 process->syscall(callnum, tc);
384 // for non-speculative execution context, spec_mode is always false
386 SimpleThread::misspeculating()
391 #endif // __CPU_CPU_EXEC_CONTEXT_HH__