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_traits.hh"
36 #include "arch/regfile.hh"
37 #include "arch/syscallreturn.hh"
38 #include "config/full_system.hh"
39 #include "cpu/thread_context.hh"
40 #include "cpu/thread_state.hh"
41 #include "mem/physical.hh"
42 #include "mem/request.hh"
43 #include "sim/byteswap.hh"
44 #include "sim/eventq.hh"
45 #include "sim/host.hh"
46 #include "sim/serialize.hh"
52 #include "sim/system.hh"
53 #include "arch/tlb.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::RegFile RegFile;
94 typedef TheISA::MachInst MachInst;
95 typedef TheISA::MiscRegFile MiscRegFile;
96 typedef TheISA::MiscReg MiscReg;
97 typedef TheISA::FloatReg FloatReg;
98 typedef TheISA::FloatRegBits FloatRegBits;
100 typedef ThreadContext::Status Status;
103 RegFile regs; // correct-path register context
106 // pointer to CPU associated with this SimpleThread
109 ProxyThreadContext<SimpleThread> *tc;
118 // constructor: initialize SimpleThread from given process structure
120 SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
121 TheISA::ITB *_itb, TheISA::DTB *_dtb,
122 bool use_kernel_stats = true);
124 SimpleThread(BaseCPU *_cpu, int _thread_num, Process *_process, int _asid);
129 virtual ~SimpleThread();
131 virtual void takeOverFrom(ThreadContext *oldContext);
133 void regStats(const std::string &name);
135 void copyTC(ThreadContext *context);
137 void copyState(ThreadContext *oldContext);
139 void serialize(std::ostream &os);
140 void unserialize(Checkpoint *cp, const std::string §ion);
142 /***************************************************************
143 * SimpleThread functions to provide CPU with access to various
144 * state, and to provide address translation methods.
145 **************************************************************/
147 /** Returns the pointer to this SimpleThread's ThreadContext. Used
148 * when a ThreadContext must be passed to objects outside of the
151 ThreadContext *getTC() { return tc; }
154 int getInstAsid() { return regs.instAsid(); }
155 int getDataAsid() { return regs.dataAsid(); }
157 Fault translateInstReq(RequestPtr &req)
159 return itb->translate(req, tc);
162 Fault translateDataReadReq(RequestPtr &req)
164 return dtb->translate(req, tc, false);
167 Fault translateDataWriteReq(RequestPtr &req)
169 return dtb->translate(req, tc, true);
172 void dumpFuncProfile();
176 bool simPalCheck(int palFunc);
179 Fault translateInstReq(RequestPtr &req)
181 return process->pTable->translate(req);
184 Fault translateDataReadReq(RequestPtr &req)
186 return process->pTable->translate(req);
189 Fault translateDataWriteReq(RequestPtr &req)
191 return process->pTable->translate(req);
195 /*******************************************
196 * ThreadContext interface functions.
197 ******************************************/
199 BaseCPU *getCpuPtr() { return cpu; }
201 int getThreadNum() { return tid; }
204 System *getSystemPtr() { return system; }
206 TheISA::ITB *getITBPtr() { return itb; }
208 TheISA::DTB *getDTBPtr() { return dtb; }
210 FunctionalPort *getPhysPort() { return physPort; }
212 /** Return a virtual port. If no thread context is specified then a static
213 * port is returned. Otherwise a port is created and returned. It must be
214 * deleted by deleteVirtPort(). */
215 VirtualPort *getVirtPort(ThreadContext *tc);
217 void delVirtPort(VirtualPort *vp);
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 Unallocated.
234 /// Set the status to Halted.
237 virtual bool misspeculating();
239 Fault instRead(RequestPtr &req)
241 panic("instRead not implemented");
242 // return funcPhysMem->read(req, inst);
246 void copyArchRegs(ThreadContext *tc);
248 void clearArchRegs() { regs.clear(); }
251 // New accessors for new decoder.
253 uint64_t readIntReg(int reg_idx)
255 return regs.readIntReg(TheISA::flattenIntIndex(getTC(), reg_idx));
258 FloatReg readFloatReg(int reg_idx, int width)
260 return regs.readFloatReg(reg_idx, width);
263 FloatReg readFloatReg(int reg_idx)
265 return regs.readFloatReg(reg_idx);
268 FloatRegBits readFloatRegBits(int reg_idx, int width)
270 return regs.readFloatRegBits(reg_idx, width);
273 FloatRegBits readFloatRegBits(int reg_idx)
275 return regs.readFloatRegBits(reg_idx);
278 void setIntReg(int reg_idx, uint64_t val)
280 regs.setIntReg(TheISA::flattenIntIndex(getTC(), reg_idx), val);
283 void setFloatReg(int reg_idx, FloatReg val, int width)
285 regs.setFloatReg(reg_idx, val, width);
288 void setFloatReg(int reg_idx, FloatReg val)
290 regs.setFloatReg(reg_idx, val);
293 void setFloatRegBits(int reg_idx, FloatRegBits val, int width)
295 regs.setFloatRegBits(reg_idx, val, width);
298 void setFloatRegBits(int reg_idx, FloatRegBits val)
300 regs.setFloatRegBits(reg_idx, val);
305 return regs.readPC();
308 void setPC(uint64_t val)
313 uint64_t readMicroPC()
318 void setMicroPC(uint64_t val)
323 uint64_t readNextPC()
325 return regs.readNextPC();
328 void setNextPC(uint64_t val)
333 uint64_t readNextMicroPC()
338 void setNextMicroPC(uint64_t val)
343 uint64_t readNextNPC()
345 return regs.readNextNPC();
348 void setNextNPC(uint64_t val)
350 regs.setNextNPC(val);
353 MiscReg readMiscReg(int misc_reg)
355 return regs.readMiscReg(misc_reg);
358 MiscReg readMiscRegWithEffect(int misc_reg)
360 return regs.readMiscRegWithEffect(misc_reg, tc);
363 void setMiscReg(int misc_reg, const MiscReg &val)
365 return regs.setMiscReg(misc_reg, val);
368 void setMiscRegWithEffect(int misc_reg, const MiscReg &val)
370 return regs.setMiscRegWithEffect(misc_reg, val, tc);
373 unsigned readStCondFailures() { return storeCondFailures; }
375 void setStCondFailures(unsigned sc_failures)
376 { storeCondFailures = sc_failures; }
379 TheISA::IntReg getSyscallArg(int i)
381 return regs.readIntReg(TheISA::flattenIntIndex(getTC(),
382 TheISA::ArgumentReg0 + i));
385 // used to shift args for indirect syscall
386 void setSyscallArg(int i, TheISA::IntReg val)
388 regs.setIntReg(TheISA::flattenIntIndex(getTC(),
389 TheISA::ArgumentReg0 + i), val);
392 void setSyscallReturn(SyscallReturn return_value)
394 TheISA::setSyscallReturn(return_value, getTC());
397 void syscall(int64_t callnum)
399 process->syscall(callnum, tc);
403 void changeRegFileContext(TheISA::RegContextParam param,
404 TheISA::RegContextVal val)
406 regs.changeContext(param, val);
411 // for non-speculative execution context, spec_mode is always false
413 SimpleThread::misspeculating()
418 #endif // __CPU_CPU_EXEC_CONTEXT_HH__