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 "arch/types.hh"
37 #include "base/statistics.hh"
38 #include "config/full_system.hh"
39 #include "cpu/base.hh"
40 #include "cpu/base_dyn_inst.hh"
41 #include "cpu/cpu_exec_context.hh"
42 #include "cpu/pc_event.hh"
43 #include "cpu/static_inst.hh"
44 #include "sim/eventq.hh"
46 // forward declarations
69 class CheckerCPU : public BaseCPU
72 typedef TheISA::MachInst MachInst;
73 typedef TheISA::FloatReg FloatReg;
74 typedef TheISA::FloatRegBits FloatRegBits;
75 typedef TheISA::MiscReg MiscReg;
77 // main simulation loop (one cycle)
80 struct Params : public BaseCPU::Params
85 FunctionalMemory *mem;
93 CheckerCPU(Params *p);
94 virtual ~CheckerCPU();
96 void setMemory(MemObject *mem);
101 void setSystem(System *system);
107 CPUExecContext *cpuXC;
109 ExecContext *xcProxy;
115 Addr dbg_vtophys(Addr addr);
126 // current instruction
129 // Refcounted pointer to the one memory request.
132 StaticInstPtr curStaticInst;
134 // number of simulated instructions
136 Counter startNumInst;
138 std::queue<int> miscRegIdxs;
140 virtual Counter totalInstructions() const
142 return numInst - startNumInst;
145 // number of simulated loads
147 Counter startNumLoad;
149 virtual void serialize(std::ostream &os);
150 virtual void unserialize(Checkpoint *cp, const std::string §ion);
153 Fault read(Addr addr, T &data, unsigned flags);
156 Fault write(T data, Addr addr, unsigned flags, uint64_t *res);
158 // These functions are only used in CPU models that split
159 // effective address computation from the actual memory access.
160 void setEA(Addr EA) { panic("SimpleCPU::setEA() not implemented\n"); }
161 Addr getEA() { panic("SimpleCPU::getEA() not implemented\n"); }
163 void prefetch(Addr addr, unsigned flags)
165 // need to do this...
168 void writeHint(Addr addr, int size, unsigned flags)
170 // need to do this...
173 Fault copySrcTranslate(Addr src);
175 Fault copy(Addr dest);
177 // The register accessor methods provide the index of the
178 // instruction's operand (e.g., 0 or 1), not the architectural
179 // register index, to simplify the implementation of register
180 // renaming. We find the architectural register index by indexing
181 // into the instruction's own operand index table. Note that a
182 // raw pointer to the StaticInst is provided instead of a
183 // ref-counted StaticInstPtr to redice overhead. This is fine as
184 // long as these methods don't copy the pointer into any long-term
185 // storage (which is pretty hard to imagine they would have reason
188 uint64_t readIntReg(const StaticInst *si, int idx)
190 return cpuXC->readIntReg(si->srcRegIdx(idx));
193 FloatReg readFloatReg(const StaticInst *si, int idx, int width)
195 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
196 return cpuXC->readFloatReg(reg_idx, width);
199 FloatReg readFloatReg(const StaticInst *si, int idx)
201 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
202 return cpuXC->readFloatReg(reg_idx);
205 FloatRegBits readFloatRegBits(const StaticInst *si, int idx, int width)
207 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
208 return cpuXC->readFloatRegBits(reg_idx, width);
211 FloatRegBits readFloatRegBits(const StaticInst *si, int idx)
213 int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Base_DepTag;
214 return cpuXC->readFloatRegBits(reg_idx);
217 void setIntReg(const StaticInst *si, int idx, uint64_t val)
219 cpuXC->setIntReg(si->destRegIdx(idx), val);
220 result.integer = val;
223 void setFloatReg(const StaticInst *si, int idx, FloatReg val, int width)
225 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
226 cpuXC->setFloatReg(reg_idx, val, width);
237 void setFloatReg(const StaticInst *si, int idx, FloatReg val)
239 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
240 cpuXC->setFloatReg(reg_idx, val);
244 void setFloatRegBits(const StaticInst *si, int idx, FloatRegBits val,
247 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
248 cpuXC->setFloatRegBits(reg_idx, val, width);
249 result.integer = val;
252 void setFloatRegBits(const StaticInst *si, int idx, FloatRegBits val)
254 int reg_idx = si->destRegIdx(idx) - TheISA::FP_Base_DepTag;
255 cpuXC->setFloatRegBits(reg_idx, val);
256 result.integer = val;
259 uint64_t readPC() { return cpuXC->readPC(); }
261 uint64_t readNextPC() { return cpuXC->readNextPC(); }
263 void setNextPC(uint64_t val) {
264 cpuXC->setNextPC(val);
267 MiscReg readMiscReg(int misc_reg)
269 return cpuXC->readMiscReg(misc_reg);
272 MiscReg readMiscRegWithEffect(int misc_reg, Fault &fault)
274 return cpuXC->readMiscRegWithEffect(misc_reg, fault);
277 Fault setMiscReg(int misc_reg, const MiscReg &val)
279 result.integer = val;
280 miscRegIdxs.push(misc_reg);
281 return cpuXC->setMiscReg(misc_reg, val);
284 Fault setMiscRegWithEffect(int misc_reg, const MiscReg &val)
286 miscRegIdxs.push(misc_reg);
287 return cpuXC->setMiscRegWithEffect(misc_reg, val);
290 void recordPCChange(uint64_t val) { changedPC = true; }
291 void recordNextPCChange(uint64_t val) { changedNextPC = true; }
293 bool translateInstReq(Request *req);
294 void translateDataWriteReq(Request *req);
295 void translateDataReadReq(Request *req);
298 Fault hwrei() { return cpuXC->hwrei(); }
299 int readIntrFlag() { return cpuXC->readIntrFlag(); }
300 void setIntrFlag(int val) { cpuXC->setIntrFlag(val); }
301 bool inPalMode() { return cpuXC->inPalMode(); }
302 void ev5_trap(Fault fault) { fault->invoke(xcProxy); }
303 bool simPalCheck(int palFunc) { return cpuXC->simPalCheck(palFunc); }
305 // Assume that the normal CPU's call to syscall was successful.
306 // The checker's state would have already been updated by the syscall.
307 void syscall(uint64_t callnum) { }
313 panic("Checker found error!");
315 bool checkFlags(Request *req);
317 ExecContext *xcBase() { return xcProxy; }
318 CPUExecContext *cpuXCBase() { return cpuXC; }
320 Result unverifiedResult;
321 Request *unverifiedReq;
329 InstSeqNum youngestSN;
332 template <class DynInstPtr>
333 class Checker : public CheckerCPU
340 void switchOut(Sampler *s);
341 void takeOverFrom(BaseCPU *oldCPU);
343 void tick(DynInstPtr &inst);
345 void validateInst(DynInstPtr &inst);
346 void validateExecution(DynInstPtr &inst);
347 void validateState();
349 std::list<DynInstPtr> instList;
350 typedef typename std::list<DynInstPtr>::iterator InstListIt;
354 #endif // __CPU_CHECKER_CPU_HH__