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 "sim/process.hh"
70 #include "mem/page_table.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 /** The current microcode pc for the currently executing macro
114 /** The next microcode pc for the currently executing macro
127 /** The next next pc.
132 // pointer to CPU associated with this SimpleThread
135 ProxyThreadContext<SimpleThread> *tc;
142 // constructor: initialize SimpleThread from given process structure
144 SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
145 TheISA::TLB *_itb, TheISA::TLB *_dtb,
146 bool use_kernel_stats = true);
148 SimpleThread(BaseCPU *_cpu, int _thread_num, Process *_process,
149 TheISA::TLB *_itb, TheISA::TLB *_dtb);
154 virtual ~SimpleThread();
156 virtual void takeOverFrom(ThreadContext *oldContext);
158 void regStats(const std::string &name);
160 void copyTC(ThreadContext *context);
162 void copyState(ThreadContext *oldContext);
164 void serialize(std::ostream &os);
165 void unserialize(Checkpoint *cp, const std::string §ion);
167 /***************************************************************
168 * SimpleThread functions to provide CPU with access to various
170 **************************************************************/
172 /** Returns the pointer to this SimpleThread's ThreadContext. Used
173 * when a ThreadContext must be passed to objects outside of the
176 ThreadContext *getTC() { return tc; }
178 void demapPage(Addr vaddr, uint64_t asn)
180 itb->demapPage(vaddr, asn);
181 dtb->demapPage(vaddr, asn);
184 void demapInstPage(Addr vaddr, uint64_t asn)
186 itb->demapPage(vaddr, asn);
189 void demapDataPage(Addr vaddr, uint64_t asn)
191 dtb->demapPage(vaddr, asn);
195 void dumpFuncProfile();
199 bool simPalCheck(int palFunc);
203 /*******************************************
204 * ThreadContext interface functions.
205 ******************************************/
207 BaseCPU *getCpuPtr() { return cpu; }
209 TheISA::TLB *getITBPtr() { return itb; }
211 TheISA::TLB *getDTBPtr() { return dtb; }
213 System *getSystemPtr() { return system; }
216 FunctionalPort *getPhysPort() { return physPort; }
218 /** Return a virtual port. This port cannot be cached locally in an object.
219 * After a CPU switch it may point to the wrong memory object which could
222 VirtualPort *getVirtPort() { return virtPort; }
225 Status status() const { return _status; }
227 void setStatus(Status newStatus) { _status = newStatus; }
229 /// Set the status to Active. Optional delay indicates number of
230 /// cycles to wait before beginning execution.
231 void activate(int delay = 1);
233 /// Set the status to Suspended.
236 /// Set the status to Halted.
239 virtual bool misspeculating();
241 Fault instRead(RequestPtr &req)
243 panic("instRead not implemented");
244 // return funcPhysMem->read(req, inst);
248 void copyArchRegs(ThreadContext *tc);
254 PC = nextPC = nextNPC = 0;
255 memset(intRegs, 0, sizeof(intRegs));
256 memset(floatRegs.i, 0, sizeof(floatRegs.i));
260 // New accessors for new decoder.
262 uint64_t readIntReg(int reg_idx)
264 int flatIndex = isa.flattenIntIndex(reg_idx);
265 assert(flatIndex < TheISA::NumIntRegs);
266 uint64_t regVal = intRegs[flatIndex];
267 DPRINTF(IntRegs, "Reading int reg %d as %#x.\n", reg_idx, regVal);
271 FloatReg readFloatReg(int reg_idx)
273 int flatIndex = isa.flattenFloatIndex(reg_idx);
274 assert(flatIndex < TheISA::NumFloatRegs);
275 return floatRegs.f[flatIndex];
278 FloatRegBits readFloatRegBits(int reg_idx)
280 int flatIndex = isa.flattenFloatIndex(reg_idx);
281 assert(flatIndex < TheISA::NumFloatRegs);
282 return floatRegs.i[flatIndex];
285 void setIntReg(int reg_idx, uint64_t val)
287 int flatIndex = isa.flattenIntIndex(reg_idx);
288 assert(flatIndex < TheISA::NumIntRegs);
289 DPRINTF(IntRegs, "Setting int reg %d to %#x.\n", reg_idx, val);
290 intRegs[flatIndex] = val;
293 void setFloatReg(int reg_idx, FloatReg val)
295 int flatIndex = isa.flattenFloatIndex(reg_idx);
296 assert(flatIndex < TheISA::NumFloatRegs);
297 floatRegs.f[flatIndex] = val;
300 void setFloatRegBits(int reg_idx, FloatRegBits val)
302 int flatIndex = isa.flattenFloatIndex(reg_idx);
303 assert(flatIndex < TheISA::NumFloatRegs);
304 floatRegs.i[flatIndex] = val;
312 void setPC(uint64_t val)
317 uint64_t readMicroPC()
322 void setMicroPC(uint64_t val)
327 uint64_t readNextPC()
332 void setNextPC(uint64_t val)
337 uint64_t readNextMicroPC()
342 void setNextMicroPC(uint64_t val)
347 uint64_t readNextNPC()
349 #if ISA_HAS_DELAY_SLOT
352 return nextPC + sizeof(TheISA::MachInst);
356 void setNextNPC(uint64_t val)
358 #if ISA_HAS_DELAY_SLOT
364 readMiscRegNoEffect(int misc_reg, ThreadID tid = 0)
366 return isa.readMiscRegNoEffect(misc_reg);
370 readMiscReg(int misc_reg, ThreadID tid = 0)
372 return isa.readMiscReg(misc_reg, tc);
376 setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid = 0)
378 return isa.setMiscRegNoEffect(misc_reg, val);
382 setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid = 0)
384 return isa.setMiscReg(misc_reg, val, tc);
388 flattenIntIndex(int reg)
390 return isa.flattenIntIndex(reg);
394 flattenFloatIndex(int reg)
396 return isa.flattenFloatIndex(reg);
399 unsigned readStCondFailures() { return storeCondFailures; }
401 void setStCondFailures(unsigned sc_failures)
402 { storeCondFailures = sc_failures; }
405 void syscall(int64_t callnum)
407 process->syscall(callnum, tc);
413 // for non-speculative execution context, spec_mode is always false
415 SimpleThread::misspeculating()
420 #endif // __CPU_CPU_EXEC_CONTEXT_HH__