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 "arch/tlb.hh"
39 #include "config/full_system.hh"
40 #include "cpu/thread_context.hh"
41 #include "cpu/thread_state.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"
54 class FunctionProfile;
67 #include "sim/process.hh"
68 #include "mem/page_table.hh"
69 class TranslatingPort;
74 * The SimpleThread object provides a combination of the ThreadState
75 * object and the ThreadContext interface. It implements the
76 * ThreadContext interface so that a ProxyThreadContext class can be
77 * made using SimpleThread as the template parameter (see
78 * thread_context.hh). It adds to the ThreadState object by adding all
79 * the objects needed for simple functional execution, including a
80 * simple architectural register file, and pointers to the ITB and DTB
81 * in full system mode. For CPU models that do not need more advanced
82 * ways to hold state (i.e. a separate physical register file, or
83 * separate fetch and commit PC's), this SimpleThread class provides
84 * all the necessary state for full architecture-level functional
85 * simulation. See the AtomicSimpleCPU or TimingSimpleCPU for
89 class SimpleThread : public ThreadState
92 typedef TheISA::RegFile RegFile;
93 typedef TheISA::MachInst MachInst;
94 typedef TheISA::MiscRegFile MiscRegFile;
95 typedef TheISA::MiscReg MiscReg;
96 typedef TheISA::FloatReg FloatReg;
97 typedef TheISA::FloatRegBits FloatRegBits;
99 typedef ThreadContext::Status Status;
102 RegFile regs; // correct-path register context
105 // pointer to CPU associated with this SimpleThread
108 ProxyThreadContext<SimpleThread> *tc;
115 // constructor: initialize SimpleThread from given process structure
117 SimpleThread(BaseCPU *_cpu, int _thread_num, System *_system,
118 TheISA::ITB *_itb, TheISA::DTB *_dtb,
119 bool use_kernel_stats = true);
121 SimpleThread(BaseCPU *_cpu, int _thread_num, Process *_process,
122 TheISA::ITB *_itb, TheISA::DTB *_dtb, int _asid);
127 virtual ~SimpleThread();
129 virtual void takeOverFrom(ThreadContext *oldContext);
131 void regStats(const std::string &name);
133 void copyTC(ThreadContext *context);
135 void copyState(ThreadContext *oldContext);
137 void serialize(std::ostream &os);
138 void unserialize(Checkpoint *cp, const std::string §ion);
140 /***************************************************************
141 * SimpleThread functions to provide CPU with access to various
143 **************************************************************/
145 /** Returns the pointer to this SimpleThread's ThreadContext. Used
146 * when a ThreadContext must be passed to objects outside of the
149 ThreadContext *getTC() { return tc; }
151 void demapPage(Addr vaddr, uint64_t asn)
153 itb->demapPage(vaddr, asn);
154 dtb->demapPage(vaddr, asn);
157 void demapInstPage(Addr vaddr, uint64_t asn)
159 itb->demapPage(vaddr, asn);
162 void demapDataPage(Addr vaddr, uint64_t asn)
164 dtb->demapPage(vaddr, asn);
168 int getInstAsid() { return regs.instAsid(); }
169 int getDataAsid() { return regs.dataAsid(); }
171 void dumpFuncProfile();
175 bool simPalCheck(int palFunc);
179 /*******************************************
180 * ThreadContext interface functions.
181 ******************************************/
183 BaseCPU *getCpuPtr() { return cpu; }
185 TheISA::ITB *getITBPtr() { return itb; }
187 TheISA::DTB *getDTBPtr() { return dtb; }
189 System *getSystemPtr() { return system; }
192 FunctionalPort *getPhysPort() { return physPort; }
194 /** Return a virtual port. This port cannot be cached locally in an object.
195 * After a CPU switch it may point to the wrong memory object which could
198 VirtualPort *getVirtPort() { return virtPort; }
201 Status status() const { return _status; }
203 void setStatus(Status newStatus) { _status = newStatus; }
205 /// Set the status to Active. Optional delay indicates number of
206 /// cycles to wait before beginning execution.
207 void activate(int delay = 1);
209 /// Set the status to Suspended.
212 /// Set the status to Unallocated.
215 /// Set the status to Halted.
218 virtual bool misspeculating();
220 Fault instRead(RequestPtr &req)
222 panic("instRead not implemented");
223 // return funcPhysMem->read(req, inst);
227 void copyArchRegs(ThreadContext *tc);
229 void clearArchRegs() { regs.clear(); }
232 // New accessors for new decoder.
234 uint64_t readIntReg(int reg_idx)
236 int flatIndex = TheISA::flattenIntIndex(getTC(), reg_idx);
237 return regs.readIntReg(flatIndex);
240 FloatReg readFloatReg(int reg_idx, int width)
242 int flatIndex = TheISA::flattenFloatIndex(getTC(), reg_idx);
243 return regs.readFloatReg(flatIndex, width);
246 FloatReg readFloatReg(int reg_idx)
248 int flatIndex = TheISA::flattenFloatIndex(getTC(), reg_idx);
249 return regs.readFloatReg(flatIndex);
252 FloatRegBits readFloatRegBits(int reg_idx, int width)
254 int flatIndex = TheISA::flattenFloatIndex(getTC(), reg_idx);
255 return regs.readFloatRegBits(flatIndex, width);
258 FloatRegBits readFloatRegBits(int reg_idx)
260 int flatIndex = TheISA::flattenFloatIndex(getTC(), reg_idx);
261 return regs.readFloatRegBits(flatIndex);
264 void setIntReg(int reg_idx, uint64_t val)
266 int flatIndex = TheISA::flattenIntIndex(getTC(), reg_idx);
267 regs.setIntReg(flatIndex, val);
270 void setFloatReg(int reg_idx, FloatReg val, int width)
272 int flatIndex = TheISA::flattenFloatIndex(getTC(), reg_idx);
273 regs.setFloatReg(flatIndex, val, width);
276 void setFloatReg(int reg_idx, FloatReg val)
278 int flatIndex = TheISA::flattenFloatIndex(getTC(), reg_idx);
279 regs.setFloatReg(flatIndex, val);
282 void setFloatRegBits(int reg_idx, FloatRegBits val, int width)
284 int flatIndex = TheISA::flattenFloatIndex(getTC(), reg_idx);
285 regs.setFloatRegBits(flatIndex, val, width);
288 void setFloatRegBits(int reg_idx, FloatRegBits val)
290 int flatIndex = TheISA::flattenFloatIndex(getTC(), reg_idx);
291 regs.setFloatRegBits(flatIndex, val);
296 return regs.readPC();
299 void setPC(uint64_t val)
304 uint64_t readMicroPC()
309 void setMicroPC(uint64_t val)
314 uint64_t readNextPC()
316 return regs.readNextPC();
319 void setNextPC(uint64_t val)
324 uint64_t readNextMicroPC()
329 void setNextMicroPC(uint64_t val)
334 uint64_t readNextNPC()
336 return regs.readNextNPC();
339 void setNextNPC(uint64_t val)
341 regs.setNextNPC(val);
344 MiscReg readMiscRegNoEffect(int misc_reg, unsigned tid = 0)
346 return regs.readMiscRegNoEffect(misc_reg);
349 MiscReg readMiscReg(int misc_reg, unsigned tid = 0)
351 return regs.readMiscReg(misc_reg, tc);
354 void setMiscRegNoEffect(int misc_reg, const MiscReg &val, unsigned tid = 0)
356 return regs.setMiscRegNoEffect(misc_reg, val);
359 void setMiscReg(int misc_reg, const MiscReg &val, unsigned tid = 0)
361 return regs.setMiscReg(misc_reg, val, tc);
364 unsigned readStCondFailures() { return storeCondFailures; }
366 void setStCondFailures(unsigned sc_failures)
367 { storeCondFailures = sc_failures; }
370 TheISA::IntReg getSyscallArg(int i)
372 assert(i < TheISA::NumArgumentRegs);
373 TheISA::IntReg val = regs.readIntReg(
374 TheISA::flattenIntIndex(getTC(), TheISA::ArgumentReg[i]));
375 #if THE_ISA == SPARC_ISA
376 if (bits(this->readMiscRegNoEffect(
377 SparcISA::MISCREG_PSTATE), 3, 3)) {
378 val = bits(val, 31, 0);
384 // used to shift args for indirect syscall
385 void setSyscallArg(int i, TheISA::IntReg val)
387 assert(i < TheISA::NumArgumentRegs);
388 regs.setIntReg(TheISA::flattenIntIndex(getTC(),
389 TheISA::ArgumentReg[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);
405 // for non-speculative execution context, spec_mode is always false
407 SimpleThread::misspeculating()
412 #endif // __CPU_CPU_EXEC_CONTEXT_HH__