2 * Copyright (c) 2011 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 #include "arch/kernel_stats.hh"
48 #include "arch/vtophys.hh"
49 #include "cpu/checker/cpu.hh"
50 #include "cpu/base.hh"
51 #include "cpu/simple_thread.hh"
52 #include "cpu/static_inst.hh"
53 #include "cpu/thread_context.hh"
54 #include "params/CheckerCPU.hh"
58 using namespace TheISA
;
65 CheckerCPU::CheckerCPU(Params
*p
)
66 : BaseCPU(p
), thread(NULL
), tc(NULL
)
70 curMacroStaticInst
= NULL
;
78 changedPC
= willChangePC
= changedNextPC
= false;
80 exitOnError
= p
->exitOnError
;
81 warnOnlyOnLoadError
= p
->warnOnlyOnLoadError
;
85 workload
= p
->workload
;
86 // XXX: This is a hack to get this to work some
87 thread
= new SimpleThread(this, /* thread_num */ 0, workload
[0], itb
, dtb
);
90 threadContexts
.push_back(tc
);
95 CheckerCPU::~CheckerCPU()
100 CheckerCPU::setSystem(System
*system
)
104 thread
= new SimpleThread(this, 0, systemPtr
, itb
, dtb
, false);
106 tc
= thread
->getTC();
107 threadContexts
.push_back(tc
);
108 delete thread
->kernelStats
;
109 thread
->kernelStats
= NULL
;
113 CheckerCPU::setIcachePort(Port
*icache_port
)
115 icachePort
= icache_port
;
119 CheckerCPU::setDcachePort(Port
*dcache_port
)
121 dcachePort
= dcache_port
;
125 CheckerCPU::serialize(ostream
&os
)
130 CheckerCPU::unserialize(Checkpoint
*cp
, const string
§ion
)
135 CheckerCPU::readMem(Addr addr
, uint8_t *data
, unsigned size
, unsigned flags
)
137 Fault fault
= NoFault
;
138 unsigned blockSize
= dcachePort
->peerBlockSize();
140 Addr secondAddr
= roundDown(addr
+ size
- 1, blockSize
);
141 bool checked_flags
= false;
142 bool flags_match
= true;
146 if (secondAddr
> addr
)
147 size
= secondAddr
- addr
;
149 // Need to account for multiple accesses like the Atomic and TimingSimple
151 memReq
= new Request();
152 memReq
->setVirt(0, addr
, size
, flags
, thread
->pcState().instAddr());
154 // translate to physical address
155 fault
= dtb
->translateFunctional(memReq
, tc
, BaseTLB::Read
);
157 if (!checked_flags
&& fault
== NoFault
&& unverifiedReq
) {
158 flags_match
= checkFlags(unverifiedReq
, memReq
->getVaddr(),
159 memReq
->getPaddr(), memReq
->getFlags());
160 pAddr
= memReq
->getPaddr();
161 checked_flags
= true;
165 if (fault
== NoFault
&&
166 !memReq
->getFlags().isSet(Request::NO_ACCESS
)) {
167 PacketPtr pkt
= new Packet(memReq
,
169 MemCmd::LoadLockedReq
: MemCmd::ReadReq
,
172 pkt
->dataStatic(data
);
174 if (!(memReq
->isUncacheable() || memReq
->isMmappedIpr())) {
175 // Access memory to see if we have the same data
176 dcachePort
->sendFunctional(pkt
);
178 // Assume the data is correct if it's an uncached access
179 memcpy(data
, unverifiedMemData
, size
);
187 if (fault
!= NoFault
) {
188 if (memReq
->isPrefetch()) {
196 if (memReq
!= NULL
) {
200 //If we don't need to access a second cache line, stop now.
201 if (secondAddr
<= addr
)
206 // Setup for accessing next cache line
208 unverifiedMemData
+= size
;
209 size
= addr
+ fullSize
- secondAddr
;
214 warn("%lli: Flags do not match CPU:%#x %#x %#x Checker:%#x %#x %#x\n",
215 curTick(), unverifiedReq
->getVaddr(), unverifiedReq
->getPaddr(),
216 unverifiedReq
->getFlags(), addr
, pAddr
, flags
);
224 CheckerCPU::writeMem(uint8_t *data
, unsigned size
,
225 Addr addr
, unsigned flags
, uint64_t *res
)
227 Fault fault
= NoFault
;
228 bool checked_flags
= false;
229 bool flags_match
= true;
232 unsigned blockSize
= dcachePort
->peerBlockSize();
235 Addr secondAddr
= roundDown(addr
+ size
- 1, blockSize
);
237 if (secondAddr
> addr
)
238 size
= secondAddr
- addr
;
240 // Need to account for a multiple access like Atomic and Timing CPUs
242 memReq
= new Request();
243 memReq
->setVirt(0, addr
, size
, flags
, thread
->pcState().instAddr());
245 // translate to physical address
246 fault
= dtb
->translateFunctional(memReq
, tc
, BaseTLB::Write
);
248 if (!checked_flags
&& fault
== NoFault
&& unverifiedReq
) {
249 flags_match
= checkFlags(unverifiedReq
, memReq
->getVaddr(),
250 memReq
->getPaddr(), memReq
->getFlags());
251 pAddr
= memReq
->getPaddr();
252 checked_flags
= true;
256 * We don't actually check memory for the store because there
257 * is no guarantee it has left the lsq yet, and therefore we
258 * can't verify the memory on stores without lsq snooping
259 * enabled. This is left as future work for the Checker: LSQ snooping
260 * and memory validation after stores have committed.
265 //If we don't need to access a second cache line, stop now.
266 if (fault
!= NoFault
|| secondAddr
<= addr
)
268 if (fault
!= NoFault
&& memReq
->isPrefetch()) {
274 //Update size and access address
275 size
= addr
+ fullSize
- secondAddr
;
276 //And access the right address.
281 warn("%lli: Flags do not match CPU:%#x %#x Checker:%#x %#x %#x\n",
282 curTick(), unverifiedReq
->getVaddr(), unverifiedReq
->getPaddr(),
283 unverifiedReq
->getFlags(), addr
, pAddr
, flags
);
287 // Assume the result was the same as the one passed in. This checker
288 // doesn't check if the SC should succeed or fail, it just checks the
290 if (unverifiedReq
&& res
&& unverifiedReq
->extraDataValid())
291 *res
= unverifiedReq
->getExtraData();
293 // Entire purpose here is to make sure we are getting the
294 // same data to send to the mem system as the CPU did.
295 // Cannot check this is actually what went to memory because
296 // there stores can be in ld/st queue or coherent operations
297 // overwriting values.
300 extraData
= unverifiedReq
->extraDataValid() ?
301 unverifiedReq
->getExtraData() : 1;
304 if (unverifiedReq
&& unverifiedMemData
&&
305 memcmp(data
, unverifiedMemData
, fullSize
) && extraData
) {
306 warn("%lli: Store value does not match value sent to memory!\
307 data: %#x inst_data: %#x", curTick(), data
,
316 CheckerCPU::dbg_vtophys(Addr addr
)
318 return vtophys(tc
, addr
);
322 * Checks if the flags set by the Checker and Checkee match.
325 CheckerCPU::checkFlags(Request
*unverified_req
, Addr vAddr
,
326 Addr pAddr
, int flags
)
328 Addr unverifiedVAddr
= unverified_req
->getVaddr();
329 Addr unverifiedPAddr
= unverified_req
->getPaddr();
330 int unverifiedFlags
= unverified_req
->getFlags();
332 if (unverifiedVAddr
!= vAddr
||
333 unverifiedPAddr
!= pAddr
||
334 unverifiedFlags
!= flags
) {
342 CheckerCPU::dumpAndExit()
344 warn("%lli: Checker PC:%s",
345 curTick(), thread
->pcState());
346 panic("Checker found an error!");