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 "cpu/thread_context.hh"
43 #include "cpu/thread_state.hh"
44 #include "mem/request.hh"
45 #include "sim/byteswap.hh"
46 #include "sim/eventq.hh"
47 #include "sim/serialize.hh"
53 #include "sim/system.hh"
55 class FunctionProfile;
68 #include "sim/process.hh"
69 #include "mem/page_table.hh"
70 class TranslatingPort;
75 * The SimpleThread object provides a combination of the ThreadState
76 * object and the ThreadContext interface. It implements the
77 * ThreadContext interface so that a ProxyThreadContext class can be
78 * made using SimpleThread as the template parameter (see
79 * thread_context.hh). It adds to the ThreadState object by adding all
80 * the objects needed for simple functional execution, including a
81 * simple architectural register file, and pointers to the ITB and DTB
82 * in full system mode. For CPU models that do not need more advanced
83 * ways to hold state (i.e. a separate physical register file, or
84 * separate fetch and commit PC's), this SimpleThread class provides
85 * all the necessary state for full architecture-level functional
86 * simulation. See the AtomicSimpleCPU or TimingSimpleCPU for
90 class SimpleThread : public ThreadState
93 typedef TheISA::MachInst MachInst;
94 typedef TheISA::MiscReg MiscReg;
95 typedef TheISA::FloatReg FloatReg;
96 typedef TheISA::FloatRegBits FloatRegBits;
98 typedef ThreadContext::Status Status;
102 FloatReg f[TheISA::NumFloatRegs];
103 FloatRegBits i[TheISA::NumFloatRegs];
105 TheISA::IntReg intRegs[TheISA::NumIntRegs];
106 TheISA::ISA isa; // one "instance" of the current ISA.
108 /** The current microcode pc for the currently executing macro
113 /** The next microcode pc for the currently executing macro
126 /** The next next pc.
131 // pointer to CPU associated with this SimpleThread
134 ProxyThreadContext<SimpleThread> *tc;
141 // constructor: initialize SimpleThread from given process structure
143 SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
144 TheISA::TLB *_itb, TheISA::TLB *_dtb,
145 bool use_kernel_stats = true);
147 SimpleThread(BaseCPU *_cpu, int _thread_num, Process *_process,
148 TheISA::TLB *_itb, TheISA::TLB *_dtb);
153 virtual ~SimpleThread();
155 virtual void takeOverFrom(ThreadContext *oldContext);
157 void regStats(const std::string &name);
159 void copyTC(ThreadContext *context);
161 void copyState(ThreadContext *oldContext);
163 void serialize(std::ostream &os);
164 void unserialize(Checkpoint *cp, const std::string §ion);
166 /***************************************************************
167 * SimpleThread functions to provide CPU with access to various
169 **************************************************************/
171 /** Returns the pointer to this SimpleThread's ThreadContext. Used
172 * when a ThreadContext must be passed to objects outside of the
175 ThreadContext *getTC() { return tc; }
177 void demapPage(Addr vaddr, uint64_t asn)
179 itb->demapPage(vaddr, asn);
180 dtb->demapPage(vaddr, asn);
183 void demapInstPage(Addr vaddr, uint64_t asn)
185 itb->demapPage(vaddr, asn);
188 void demapDataPage(Addr vaddr, uint64_t asn)
190 dtb->demapPage(vaddr, asn);
194 void dumpFuncProfile();
198 bool simPalCheck(int palFunc);
202 /*******************************************
203 * ThreadContext interface functions.
204 ******************************************/
206 BaseCPU *getCpuPtr() { return cpu; }
208 TheISA::TLB *getITBPtr() { return itb; }
210 TheISA::TLB *getDTBPtr() { return dtb; }
212 System *getSystemPtr() { return system; }
215 FunctionalPort *getPhysPort() { return physPort; }
217 /** Return a virtual port. This port cannot be cached locally in an object.
218 * After a CPU switch it may point to the wrong memory object which could
221 VirtualPort *getVirtPort() { return virtPort; }
224 Status status() const { return _status; }
226 void setStatus(Status newStatus) { _status = newStatus; }
228 /// Set the status to Active. Optional delay indicates number of
229 /// cycles to wait before beginning execution.
230 void activate(int delay = 1);
232 /// Set the status to Suspended.
235 /// Set the status to Halted.
238 virtual bool misspeculating();
240 Fault instRead(RequestPtr &req)
242 panic("instRead not implemented");
243 // return funcPhysMem->read(req, inst);
247 void copyArchRegs(ThreadContext *tc);
253 PC = nextPC = nextNPC = 0;
254 memset(intRegs, 0, sizeof(intRegs));
255 memset(floatRegs.i, 0, sizeof(floatRegs.i));
259 // New accessors for new decoder.
261 uint64_t readIntReg(int reg_idx)
263 int flatIndex = isa.flattenIntIndex(reg_idx);
264 assert(flatIndex < TheISA::NumIntRegs);
265 return intRegs[flatIndex];
268 FloatReg readFloatReg(int reg_idx)
270 int flatIndex = isa.flattenFloatIndex(reg_idx);
271 assert(flatIndex < TheISA::NumFloatRegs);
272 return floatRegs.f[flatIndex];
275 FloatRegBits readFloatRegBits(int reg_idx)
277 int flatIndex = isa.flattenFloatIndex(reg_idx);
278 assert(flatIndex < TheISA::NumFloatRegs);
279 return floatRegs.i[flatIndex];
282 void setIntReg(int reg_idx, uint64_t val)
284 int flatIndex = isa.flattenIntIndex(reg_idx);
285 assert(flatIndex < TheISA::NumIntRegs);
286 intRegs[flatIndex] = val;
289 void setFloatReg(int reg_idx, FloatReg val)
291 int flatIndex = isa.flattenFloatIndex(reg_idx);
292 assert(flatIndex < TheISA::NumFloatRegs);
293 floatRegs.f[flatIndex] = val;
296 void setFloatRegBits(int reg_idx, FloatRegBits val)
298 int flatIndex = isa.flattenFloatIndex(reg_idx);
299 assert(flatIndex < TheISA::NumFloatRegs);
300 floatRegs.i[flatIndex] = val;
308 void setPC(uint64_t val)
313 uint64_t readMicroPC()
318 void setMicroPC(uint64_t val)
323 uint64_t readNextPC()
328 void setNextPC(uint64_t val)
333 uint64_t readNextMicroPC()
338 void setNextMicroPC(uint64_t val)
343 uint64_t readNextNPC()
345 #if ISA_HAS_DELAY_SLOT
348 return nextPC + sizeof(TheISA::MachInst);
352 void setNextNPC(uint64_t val)
354 #if ISA_HAS_DELAY_SLOT
360 readMiscRegNoEffect(int misc_reg, ThreadID tid = 0)
362 return isa.readMiscRegNoEffect(misc_reg);
366 readMiscReg(int misc_reg, ThreadID tid = 0)
368 return isa.readMiscReg(misc_reg, tc);
372 setMiscRegNoEffect(int misc_reg, const MiscReg &val, ThreadID tid = 0)
374 return isa.setMiscRegNoEffect(misc_reg, val);
378 setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid = 0)
380 return isa.setMiscReg(misc_reg, val, tc);
384 flattenIntIndex(int reg)
386 return isa.flattenIntIndex(reg);
390 flattenFloatIndex(int reg)
392 return isa.flattenFloatIndex(reg);
395 unsigned readStCondFailures() { return storeCondFailures; }
397 void setStCondFailures(unsigned sc_failures)
398 { storeCondFailures = sc_failures; }
401 void syscall(int64_t callnum)
403 process->syscall(callnum, tc);
409 // for non-speculative execution context, spec_mode is always false
411 SimpleThread::misspeculating()
416 #endif // __CPU_CPU_EXEC_CONTEXT_HH__