2 * Copyright (c) 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.
31 #ifndef __CPU_CHECKER_THREAD_CONTEXT_HH__
32 #define __CPU_CHECKER_THREAD_CONTEXT_HH__
34 #include "cpu/checker/cpu.hh"
35 #include "cpu/simple_thread.hh"
36 #include "cpu/thread_context.hh"
38 class EndQuiesceEvent;
44 * Derived ThreadContext class for use with the Checker. The template
45 * parameter is the ThreadContext class used by the specific CPU being
46 * verified. This CheckerThreadContext is then used by the main CPU
47 * in place of its usual ThreadContext class. It handles updating the
48 * checker's state any time state is updated externally through the
52 class CheckerThreadContext : public ThreadContext
55 CheckerThreadContext(TC *actual_tc,
56 CheckerCPU *checker_cpu)
57 : actualTC(actual_tc), checkerTC(checker_cpu->thread),
58 checkerCPU(checker_cpu)
62 /** The main CPU's ThreadContext, or class that implements the
63 * ThreadContext interface. */
65 /** The checker's own SimpleThread. Will be updated any time
66 * anything uses this ThreadContext to externally update a
68 SimpleThread *checkerTC;
69 /** Pointer to the checker CPU. */
70 CheckerCPU *checkerCPU;
74 BaseCPU *getCpuPtr() { return actualTC->getCpuPtr(); }
78 actualTC->setCpuId(id);
79 checkerTC->setCpuId(id);
82 int readCpuId() { return actualTC->readCpuId(); }
85 System *getSystemPtr() { return actualTC->getSystemPtr(); }
87 PhysicalMemory *getPhysMemPtr() { return actualTC->getPhysMemPtr(); }
89 AlphaITB *getITBPtr() { return actualTC->getITBPtr(); }
91 AlphaDTB *getDTBPtr() { return actualTC->getDTBPtr(); }
93 Kernel::Statistics *getKernelStats() { return actualTC->getKernelStats(); }
95 FunctionalPort *getPhysPort() { return actualTC->getPhysPort(); }
97 VirtualPort *getVirtPort(ThreadContext *tc = NULL)
98 { return actualTC->getVirtPort(); }
100 void delVirtPort(VirtualPort *vp) { actualTC->delVirtPort(vp); }
102 TranslatingPort *getMemPort() { return actualTC->getMemPort(); }
104 Process *getProcessPtr() { return actualTC->getProcessPtr(); }
107 Status status() const { return actualTC->status(); }
109 void setStatus(Status new_status)
111 actualTC->setStatus(new_status);
112 checkerTC->setStatus(new_status);
115 /// Set the status to Active. Optional delay indicates number of
116 /// cycles to wait before beginning execution.
117 void activate(int delay = 1) { actualTC->activate(delay); }
119 /// Set the status to Suspended.
120 void suspend() { actualTC->suspend(); }
122 /// Set the status to Unallocated.
123 void deallocate(int delay = 0) { actualTC->deallocate(delay); }
125 /// Set the status to Halted.
126 void halt() { actualTC->halt(); }
129 void dumpFuncProfile() { actualTC->dumpFuncProfile(); }
132 void takeOverFrom(ThreadContext *oldContext)
134 actualTC->takeOverFrom(oldContext);
135 checkerTC->takeOverFrom(oldContext);
138 void regStats(const std::string &name) { actualTC->regStats(name); }
140 void serialize(std::ostream &os) { actualTC->serialize(os); }
141 void unserialize(Checkpoint *cp, const std::string §ion)
142 { actualTC->unserialize(cp, section); }
145 EndQuiesceEvent *getQuiesceEvent() { return actualTC->getQuiesceEvent(); }
147 Tick readLastActivate() { return actualTC->readLastActivate(); }
148 Tick readLastSuspend() { return actualTC->readLastSuspend(); }
150 void profileClear() { return actualTC->profileClear(); }
151 void profileSample() { return actualTC->profileSample(); }
154 int getThreadNum() { return actualTC->getThreadNum(); }
156 // @todo: Do I need this?
157 MachInst getInst() { return actualTC->getInst(); }
159 // @todo: Do I need this?
160 void copyArchRegs(ThreadContext *tc)
162 actualTC->copyArchRegs(tc);
163 checkerTC->copyArchRegs(tc);
168 actualTC->clearArchRegs();
169 checkerTC->clearArchRegs();
173 // New accessors for new decoder.
175 uint64_t readIntReg(int reg_idx)
176 { return actualTC->readIntReg(reg_idx); }
178 FloatReg readFloatReg(int reg_idx, int width)
179 { return actualTC->readFloatReg(reg_idx, width); }
181 FloatReg readFloatReg(int reg_idx)
182 { return actualTC->readFloatReg(reg_idx); }
184 FloatRegBits readFloatRegBits(int reg_idx, int width)
185 { return actualTC->readFloatRegBits(reg_idx, width); }
187 FloatRegBits readFloatRegBits(int reg_idx)
188 { return actualTC->readFloatRegBits(reg_idx); }
190 void setIntReg(int reg_idx, uint64_t val)
192 actualTC->setIntReg(reg_idx, val);
193 checkerTC->setIntReg(reg_idx, val);
196 void setFloatReg(int reg_idx, FloatReg val, int width)
198 actualTC->setFloatReg(reg_idx, val, width);
199 checkerTC->setFloatReg(reg_idx, val, width);
202 void setFloatReg(int reg_idx, FloatReg val)
204 actualTC->setFloatReg(reg_idx, val);
205 checkerTC->setFloatReg(reg_idx, val);
208 void setFloatRegBits(int reg_idx, FloatRegBits val, int width)
210 actualTC->setFloatRegBits(reg_idx, val, width);
211 checkerTC->setFloatRegBits(reg_idx, val, width);
214 void setFloatRegBits(int reg_idx, FloatRegBits val)
216 actualTC->setFloatRegBits(reg_idx, val);
217 checkerTC->setFloatRegBits(reg_idx, val);
220 uint64_t readPC() { return actualTC->readPC(); }
222 void setPC(uint64_t val)
224 actualTC->setPC(val);
225 checkerTC->setPC(val);
226 checkerCPU->recordPCChange(val);
229 uint64_t readNextPC() { return actualTC->readNextPC(); }
231 void setNextPC(uint64_t val)
233 actualTC->setNextPC(val);
234 checkerTC->setNextPC(val);
235 checkerCPU->recordNextPCChange(val);
238 uint64_t readNextNPC() { return actualTC->readNextNPC(); }
240 void setNextNPC(uint64_t val)
242 actualTC->setNextNPC(val);
243 checkerTC->setNextNPC(val);
244 checkerCPU->recordNextPCChange(val);
247 MiscReg readMiscReg(int misc_reg)
248 { return actualTC->readMiscReg(misc_reg); }
250 MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault)
251 { return actualTC->readMiscRegWithEffect(misc_reg, fault); }
253 Fault setMiscReg(int misc_reg, const MiscReg &val)
255 checkerTC->setMiscReg(misc_reg, val);
256 return actualTC->setMiscReg(misc_reg, val);
259 Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val)
261 checkerTC->setMiscRegWithEffect(misc_reg, val);
262 return actualTC->setMiscRegWithEffect(misc_reg, val);
265 unsigned readStCondFailures()
266 { return actualTC->readStCondFailures(); }
268 void setStCondFailures(unsigned sc_failures)
270 checkerTC->setStCondFailures(sc_failures);
271 actualTC->setStCondFailures(sc_failures);
274 bool inPalMode() { return actualTC->inPalMode(); }
278 bool misspeculating() { return actualTC->misspeculating(); }
281 IntReg getSyscallArg(int i) { return actualTC->getSyscallArg(i); }
283 // used to shift args for indirect syscall
284 void setSyscallArg(int i, IntReg val)
286 checkerTC->setSyscallArg(i, val);
287 actualTC->setSyscallArg(i, val);
290 void setSyscallReturn(SyscallReturn return_value)
292 checkerTC->setSyscallReturn(return_value);
293 actualTC->setSyscallReturn(return_value);
296 Counter readFuncExeInst() { return actualTC->readFuncExeInst(); }
298 void changeRegFileContext(RegFile::ContextParam param,
299 RegFile::ContextVal val)
301 actualTC->changeRegFileContext(param, val);
302 checkerTC->changeRegFileContext(param, val);
306 #endif // __CPU_CHECKER_EXEC_CONTEXT_HH__