a6af98d66f17978b9405e8f8593ea4c0b2562a2a
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.
34 #include "cpu/base.hh"
35 #include "cpu/checker/cpu.hh"
36 #include "cpu/simple_thread.hh"
37 #include "cpu/static_inst.hh"
38 #include "cpu/thread_context.hh"
41 #include "arch/kernel_stats.hh"
42 #include "arch/vtophys.hh"
46 //The CheckerCPU does alpha only
47 using namespace AlphaISA
;
54 CheckerCPU::CheckerCPU(Params
*p
)
55 : BaseCPU(p
), thread(NULL
), tc(NULL
)
65 changedPC
= willChangePC
= changedNextPC
= false;
67 exitOnError
= p
->exitOnError
;
68 warnOnlyOnLoadError
= p
->warnOnlyOnLoadError
;
75 thread
= new SimpleThread(this, /* thread_num */ 0, process
,
78 thread
->setStatus(ThreadContext::Suspended
);
80 threadContexts
.push_back(tc
);
86 CheckerCPU::~CheckerCPU()
91 CheckerCPU::setSystem(System
*system
)
96 thread
= new SimpleThread(this, 0, systemPtr
, itb
, dtb
, false);
98 thread
->setStatus(ThreadContext::Suspended
);
100 threadContexts
.push_back(tc
);
101 delete thread
->kernelStats
;
102 thread
->kernelStats
= NULL
;
107 CheckerCPU::setIcachePort(Port
*icache_port
)
109 icachePort
= icache_port
;
113 CheckerCPU::setDcachePort(Port
*dcache_port
)
115 dcachePort
= dcache_port
;
119 CheckerCPU::serialize(ostream
&os
)
122 BaseCPU::serialize(os);
123 SERIALIZE_SCALAR(inst);
124 nameOut(os, csprintf("%s.xc", name()));
125 thread->serialize(os);
126 cacheCompletionEvent.serialize(os);
131 CheckerCPU::unserialize(Checkpoint
*cp
, const string
§ion
)
134 BaseCPU::unserialize(cp, section);
135 UNSERIALIZE_SCALAR(inst);
136 thread->unserialize(cp, csprintf("%s.xc", section));
141 CheckerCPU::copySrcTranslate(Addr src
)
143 panic("Unimplemented!");
147 CheckerCPU::copy(Addr dest
)
149 panic("Unimplemented!");
154 CheckerCPU::read(Addr addr
, T
&data
, unsigned flags
)
156 // need to fill in CPU & thread IDs here
157 memReq
= new Request();
159 memReq
->setVirt(0, addr
, sizeof(T
), flags
, thread
->readPC());
161 // translate to physical address
162 translateDataReadReq(memReq
);
164 PacketPtr pkt
= new Packet(memReq
, Packet::ReadReq
, Packet::Broadcast
);
166 pkt
->dataStatic(&data
);
168 if (!(memReq
->isUncacheable())) {
169 // Access memory to see if we have the same data
170 dcachePort
->sendFunctional(pkt
);
172 // Assume the data is correct if it's an uncached access
173 memcpy(&data
, &unverifiedResult
.integer
, sizeof(T
));
181 #ifndef DOXYGEN_SHOULD_SKIP_THIS
185 CheckerCPU::read(Addr addr
, uint64_t &data
, unsigned flags
);
189 CheckerCPU::read(Addr addr
, uint32_t &data
, unsigned flags
);
193 CheckerCPU::read(Addr addr
, uint16_t &data
, unsigned flags
);
197 CheckerCPU::read(Addr addr
, uint8_t &data
, unsigned flags
);
199 #endif //DOXYGEN_SHOULD_SKIP_THIS
203 CheckerCPU::read(Addr addr
, double &data
, unsigned flags
)
205 return read(addr
, *(uint64_t*)&data
, flags
);
210 CheckerCPU::read(Addr addr
, float &data
, unsigned flags
)
212 return read(addr
, *(uint32_t*)&data
, flags
);
217 CheckerCPU::read(Addr addr
, int32_t &data
, unsigned flags
)
219 return read(addr
, (uint32_t&)data
, flags
);
224 CheckerCPU::write(T data
, Addr addr
, unsigned flags
, uint64_t *res
)
226 // need to fill in CPU & thread IDs here
227 memReq
= new Request();
229 memReq
->setVirt(0, addr
, sizeof(T
), flags
, thread
->readPC());
231 // translate to physical address
232 thread
->translateDataWriteReq(memReq
);
234 // Can compare the write data and result only if it's cacheable,
235 // not a store conditional, or is a store conditional that
237 // @todo: Verify that actual memory matches up with these values.
238 // Right now it only verifies that the instruction data is the
239 // same as what was in the request that got sent to memory; there
240 // is no verification that it is the same as what is in memory.
241 // This is because the LSQ would have to be snooped in the CPU to
244 !(unverifiedReq
->isUncacheable()) &&
245 (!(unverifiedReq
->isLocked()) ||
246 ((unverifiedReq
->isLocked()) &&
247 unverifiedReq
->getExtraData() == 1))) {
250 // This code would work if the LSQ allowed for snooping.
251 PacketPtr pkt = new Packet(memReq, Packet::ReadReq, Packet::Broadcast);
252 pkt.dataStatic(&inst_data);
254 dcachePort->sendFunctional(pkt);
258 memcpy(&inst_data
, unverifiedMemData
, sizeof(T
));
260 if (data
!= inst_data
) {
261 warn("%lli: Store value does not match value in memory! "
262 "Instruction: %#x, memory: %#x",
263 curTick
, inst_data
, data
);
268 // Assume the result was the same as the one passed in. This checker
269 // doesn't check if the SC should succeed or fail, it just checks the
271 if (res
&& unverifiedReq
->scResultValid())
272 *res
= unverifiedReq
->getExtraData();
278 #ifndef DOXYGEN_SHOULD_SKIP_THIS
281 CheckerCPU::write(uint64_t data
, Addr addr
, unsigned flags
, uint64_t *res
);
285 CheckerCPU::write(uint32_t data
, Addr addr
, unsigned flags
, uint64_t *res
);
289 CheckerCPU::write(uint16_t data
, Addr addr
, unsigned flags
, uint64_t *res
);
293 CheckerCPU::write(uint8_t data
, Addr addr
, unsigned flags
, uint64_t *res
);
295 #endif //DOXYGEN_SHOULD_SKIP_THIS
299 CheckerCPU::write(double data
, Addr addr
, unsigned flags
, uint64_t *res
)
301 return write(*(uint64_t*)&data
, addr
, flags
, res
);
306 CheckerCPU::write(float data
, Addr addr
, unsigned flags
, uint64_t *res
)
308 return write(*(uint32_t*)&data
, addr
, flags
, res
);
313 CheckerCPU::write(int32_t data
, Addr addr
, unsigned flags
, uint64_t *res
)
315 return write((uint32_t)data
, addr
, flags
, res
);
321 CheckerCPU::dbg_vtophys(Addr addr
)
323 return vtophys(tc
, addr
);
325 #endif // FULL_SYSTEM
328 CheckerCPU::translateInstReq(Request
*req
)
331 return (thread
->translateInstReq(req
) == NoFault
);
333 thread
->translateInstReq(req
);
339 CheckerCPU::translateDataReadReq(Request
*req
)
341 thread
->translateDataReadReq(req
);
343 if (req
->getVaddr() != unverifiedReq
->getVaddr()) {
344 warn("%lli: Request virtual addresses do not match! Inst: %#x, "
346 curTick
, unverifiedReq
->getVaddr(), req
->getVaddr());
349 req
->setPaddr(unverifiedReq
->getPaddr());
351 if (checkFlags(req
)) {
352 warn("%lli: Request flags do not match! Inst: %#x, checker: %#x",
353 curTick
, unverifiedReq
->getFlags(), req
->getFlags());
359 CheckerCPU::translateDataWriteReq(Request
*req
)
361 thread
->translateDataWriteReq(req
);
363 if (req
->getVaddr() != unverifiedReq
->getVaddr()) {
364 warn("%lli: Request virtual addresses do not match! Inst: %#x, "
366 curTick
, unverifiedReq
->getVaddr(), req
->getVaddr());
369 req
->setPaddr(unverifiedReq
->getPaddr());
371 if (checkFlags(req
)) {
372 warn("%lli: Request flags do not match! Inst: %#x, checker: %#x",
373 curTick
, unverifiedReq
->getFlags(), req
->getFlags());
379 CheckerCPU::checkFlags(Request
*req
)
381 // Remove any dynamic flags that don't have to do with the request itself.
382 unsigned flags
= unverifiedReq
->getFlags();
383 unsigned mask
= LOCKED
| PHYSICAL
| VPTE
| ALTMODE
| UNCACHEABLE
| NO_FAULT
;
384 flags
= flags
& (mask
);
385 if (flags
== req
->getFlags()) {
393 CheckerCPU::dumpAndExit()
395 warn("%lli: Checker PC:%#x, next PC:%#x",
396 curTick
, thread
->readPC(), thread
->readNextPC());
397 panic("Checker found an error!");