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.
29 #ifndef __CPU_CHECKER_CPU_HH__
30 #define __CPU_CHECKER_CPU_HH__
36 #include "base/statistics.hh"
37 #include "config/full_system.hh"
38 #include "cpu/base.hh"
39 #include "cpu/base_dyn_inst.hh"
40 #include "cpu/cpu_exec_context.hh"
41 #include "cpu/pc_event.hh"
42 #include "cpu/static_inst.hh"
43 #include "sim/eventq.hh"
45 // forward declarations
68 * CheckerCPU class. Dynamically verifies instructions as they are
69 * completed by making sure that the instruction and its results match
70 * the independent execution of the benchmark inside the checker. The
71 * checker verifies instructions in order, regardless of the order in
72 * which instructions complete. There are certain results that can
73 * not be verified, specifically the result of a store conditional or
74 * the values of uncached accesses. In these cases, and with
75 * instructions marked as "IsUnverifiable", the checker assumes that
76 * the value from the main CPU's execution is correct and simply
77 * copies that value. It provides a CheckerExecContext (see
78 * checker/exec_context.hh) that provides hooks for updating the
79 * Checker's state through any ExecContext accesses. This allows the
80 * checker to be able to correctly verify instructions, even with
81 * external accesses to the ExecContext that change state.
83 class CheckerCPU : public BaseCPU
86 typedef TheISA::MachInst MachInst;
87 typedef TheISA::MiscReg MiscReg;
91 struct Params : public BaseCPU::Params
96 FunctionalMemory *mem;
105 CheckerCPU(Params *p);
106 virtual ~CheckerCPU();
108 void setMemory(FunctionalMemory *mem);
110 FunctionalMemory *memPtr;
113 void setSystem(System *system);
119 CPUExecContext *cpuXC;
121 ExecContext *xcProxy;
127 Addr dbg_vtophys(Addr addr);
138 // current instruction
141 // Refcounted pointer to the one memory request.
144 StaticInstPtr curStaticInst;
146 // number of simulated instructions
148 Counter startNumInst;
150 std::queue<int> miscRegIdxs;
152 virtual Counter totalInstructions() const
157 // number of simulated loads
159 Counter startNumLoad;
161 virtual void serialize(std::ostream &os);
162 virtual void unserialize(Checkpoint *cp, const std::string §ion);
165 Fault read(Addr addr, T &data, unsigned flags);
168 Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
170 // These functions are only used in CPU models that split
171 // effective address computation from the actual memory access.
172 void setEA(Addr EA) { panic("SimpleCPU::setEA() not implemented\n"); }
173 Addr getEA() { panic("SimpleCPU::getEA() not implemented\n"); }
175 void prefetch(Addr addr, unsigned flags)
177 // need to do this...
180 void writeHint(Addr addr, int size, unsigned flags)
182 // need to do this...
185 Fault copySrcTranslate(Addr src);
187 Fault copy(Addr dest);
189 // The register accessor methods provide the index of the
190 // instruction's operand (e.g., 0 or 1), not the architectural
191 // register index, to simplify the implementation of register
192 // renaming. We find the architectural register index by indexing
193 // into the instruction's own operand index table. Note that a
194 // raw pointer to the StaticInst is provided instead of a
195 // ref-counted StaticInstPtr to redice overhead. This is fine as
196 // long as these methods don't copy the pointer into any long-term
197 // storage (which is pretty hard to imagine they would have reason
200 uint64_t readIntReg(const StaticInst *si, int idx)
202 return cpuXC->readIntReg(si->srcRegIdx(idx));
205 float readFloatRegSingle(const StaticInst *si, int idx)
207 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
208 return cpuXC->readFloatRegSingle(reg_idx);
211 double readFloatRegDouble(const StaticInst *si, int idx)
213 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
214 return cpuXC->readFloatRegDouble(reg_idx);
217 uint64_t readFloatRegInt(const StaticInst *si, int idx)
219 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
220 return cpuXC->readFloatRegInt(reg_idx);
223 void setIntReg(const StaticInst *si, int idx, uint64_t val)
225 cpuXC->setIntReg(si->destRegIdx(idx), val);
226 result.integer = val;
229 void setFloatRegSingle(const StaticInst *si, int idx, float val)
231 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
232 cpuXC->setFloatRegSingle(reg_idx, val);
236 void setFloatRegDouble(const StaticInst *si, int idx, double val)
238 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
239 cpuXC->setFloatRegDouble(reg_idx, val);
243 void setFloatRegInt(const StaticInst *si, int idx, uint64_t val)
245 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
246 cpuXC->setFloatRegInt(reg_idx, val);
247 result.integer = val;
250 uint64_t readPC() { return cpuXC->readPC(); }
251 void setNextPC(uint64_t val) {
252 cpuXC->setNextPC(val);
255 MiscReg readMiscReg(int misc_reg)
257 return cpuXC->readMiscReg(misc_reg);
260 MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault)
262 return cpuXC->readMiscRegWithEffect(misc_reg, fault);
265 Fault setMiscReg(int misc_reg, const MiscReg &val)
267 result.integer = val;
268 miscRegIdxs.push(misc_reg);
269 return cpuXC->setMiscReg(misc_reg, val);
272 Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val)
274 miscRegIdxs.push(misc_reg);
275 return cpuXC->setMiscRegWithEffect(misc_reg, val);
278 void recordPCChange(uint64_t val) { changedPC = true; }
279 void recordNextPCChange(uint64_t val) { changedNextPC = true; }
281 bool translateInstReq(MemReqPtr &req);
282 void translateDataWriteReq(MemReqPtr &req);
283 void translateDataReadReq(MemReqPtr &req);
286 Fault hwrei() { return cpuXC->hwrei(); }
287 int readIntrFlag() { return cpuXC->readIntrFlag(); }
288 void setIntrFlag(int val) { cpuXC->setIntrFlag(val); }
289 bool inPalMode() { return cpuXC->inPalMode(); }
290 void ev5_trap(Fault fault) { fault->invoke(xcProxy); }
291 bool simPalCheck(int palFunc) { return cpuXC->simPalCheck(palFunc); }
293 // Assume that the normal CPU's call to syscall was successful.
294 // The checker's state would have already been updated by the syscall.
298 virtual void handleError() = 0;
300 bool checkFlags(MemReqPtr &req);
302 ExecContext *xcBase() { return xcProxy; }
303 CPUExecContext *cpuXCBase() { return cpuXC; }
305 Result unverifiedResult;
306 MemReqPtr unverifiedReq;
315 InstSeqNum youngestSN;
319 * Templated Checker class. This Checker class is templated on the
320 * DynInstPtr of the instruction type that will be verified. Proper
321 * template instantiations of the Checker must be placed at the bottom
324 template <class DynInstPtr>
325 class Checker : public CheckerCPU
329 : CheckerCPU(p), updateThisCycle(false), unverifiedInst(NULL)
332 void switchOut(Sampler *s);
333 void takeOverFrom(BaseCPU *oldCPU);
335 void tick(DynInstPtr &inst);
337 void validateInst(DynInstPtr &inst);
338 void validateExecution(DynInstPtr &inst);
339 void validateState();
341 virtual void handleError()
344 panic("Checker found error!");
345 else if (updateOnError)
346 updateThisCycle = true;
349 bool updateThisCycle;
351 DynInstPtr unverifiedInst;
353 std::list<DynInstPtr> instList;
354 typedef typename std::list<DynInstPtr>::iterator InstListIt;
358 #endif // __CPU_CHECKER_CPU_HH__