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 threadContexts
.push_back(tc
);
84 CheckerCPU::~CheckerCPU()
89 CheckerCPU::setSystem(System
*system
)
94 thread
= new SimpleThread(this, 0, systemPtr
, itb
, dtb
, false);
97 threadContexts
.push_back(tc
);
98 delete thread
->kernelStats
;
99 thread
->kernelStats
= NULL
;
104 CheckerCPU::setIcachePort(Port
*icache_port
)
106 icachePort
= icache_port
;
110 CheckerCPU::setDcachePort(Port
*dcache_port
)
112 dcachePort
= dcache_port
;
116 CheckerCPU::serialize(ostream
&os
)
119 BaseCPU::serialize(os);
120 SERIALIZE_SCALAR(inst);
121 nameOut(os, csprintf("%s.xc", name()));
122 thread->serialize(os);
123 cacheCompletionEvent.serialize(os);
128 CheckerCPU::unserialize(Checkpoint
*cp
, const string
§ion
)
131 BaseCPU::unserialize(cp, section);
132 UNSERIALIZE_SCALAR(inst);
133 thread->unserialize(cp, csprintf("%s.xc", section));
138 CheckerCPU::copySrcTranslate(Addr src
)
140 panic("Unimplemented!");
144 CheckerCPU::copy(Addr dest
)
146 panic("Unimplemented!");
151 CheckerCPU::read(Addr addr
, T
&data
, unsigned flags
)
153 // need to fill in CPU & thread IDs here
154 memReq
= new Request();
156 memReq
->setVirt(0, addr
, sizeof(T
), flags
, thread
->readPC());
158 // translate to physical address
159 dtb
->translateAtomic(memReq
, tc
, false);
161 PacketPtr pkt
= new Packet(memReq
, Packet::ReadReq
, Packet::Broadcast
);
163 pkt
->dataStatic(&data
);
165 if (!(memReq
->isUncacheable())) {
166 // Access memory to see if we have the same data
167 dcachePort
->sendFunctional(pkt
);
169 // Assume the data is correct if it's an uncached access
170 memcpy(&data
, &unverifiedResult
.integer
, sizeof(T
));
178 #ifndef DOXYGEN_SHOULD_SKIP_THIS
182 CheckerCPU::read(Addr addr
, uint64_t &data
, unsigned flags
);
186 CheckerCPU::read(Addr addr
, uint32_t &data
, unsigned flags
);
190 CheckerCPU::read(Addr addr
, uint16_t &data
, unsigned flags
);
194 CheckerCPU::read(Addr addr
, uint8_t &data
, unsigned flags
);
196 #endif //DOXYGEN_SHOULD_SKIP_THIS
200 CheckerCPU::read(Addr addr
, double &data
, unsigned flags
)
202 return read(addr
, *(uint64_t*)&data
, flags
);
207 CheckerCPU::read(Addr addr
, float &data
, unsigned flags
)
209 return read(addr
, *(uint32_t*)&data
, flags
);
214 CheckerCPU::read(Addr addr
, int32_t &data
, unsigned flags
)
216 return read(addr
, (uint32_t&)data
, flags
);
221 CheckerCPU::write(T data
, Addr addr
, unsigned flags
, uint64_t *res
)
223 // need to fill in CPU & thread IDs here
224 memReq
= new Request();
226 memReq
->setVirt(0, addr
, sizeof(T
), flags
, thread
->readPC());
228 // translate to physical address
229 dtb
->translateAtomic(memReq
, tc
, true);
231 // Can compare the write data and result only if it's cacheable,
232 // not a store conditional, or is a store conditional that
234 // @todo: Verify that actual memory matches up with these values.
235 // Right now it only verifies that the instruction data is the
236 // same as what was in the request that got sent to memory; there
237 // is no verification that it is the same as what is in memory.
238 // This is because the LSQ would have to be snooped in the CPU to
241 !(unverifiedReq
->isUncacheable()) &&
242 (!(unverifiedReq
->isLLSC()) ||
243 ((unverifiedReq
->isLLSC()) &&
244 unverifiedReq
->getExtraData() == 1))) {
247 // This code would work if the LSQ allowed for snooping.
248 PacketPtr pkt = new Packet(memReq, Packet::ReadReq, Packet::Broadcast);
249 pkt.dataStatic(&inst_data);
251 dcachePort->sendFunctional(pkt);
255 memcpy(&inst_data
, unverifiedMemData
, sizeof(T
));
257 if (data
!= inst_data
) {
258 warn("%lli: Store value does not match value in memory! "
259 "Instruction: %#x, memory: %#x",
260 curTick
, inst_data
, data
);
265 // Assume the result was the same as the one passed in. This checker
266 // doesn't check if the SC should succeed or fail, it just checks the
268 if (res
&& unverifiedReq
->scResultValid())
269 *res
= unverifiedReq
->getExtraData();
275 #ifndef DOXYGEN_SHOULD_SKIP_THIS
278 CheckerCPU::write(uint64_t data
, Addr addr
, unsigned flags
, uint64_t *res
);
282 CheckerCPU::write(uint32_t data
, Addr addr
, unsigned flags
, uint64_t *res
);
286 CheckerCPU::write(uint16_t data
, Addr addr
, unsigned flags
, uint64_t *res
);
290 CheckerCPU::write(uint8_t data
, Addr addr
, unsigned flags
, uint64_t *res
);
292 #endif //DOXYGEN_SHOULD_SKIP_THIS
296 CheckerCPU::write(double data
, Addr addr
, unsigned flags
, uint64_t *res
)
298 return write(*(uint64_t*)&data
, addr
, flags
, res
);
303 CheckerCPU::write(float data
, Addr addr
, unsigned flags
, uint64_t *res
)
305 return write(*(uint32_t*)&data
, addr
, flags
, res
);
310 CheckerCPU::write(int32_t data
, Addr addr
, unsigned flags
, uint64_t *res
)
312 return write((uint32_t)data
, addr
, flags
, res
);
318 CheckerCPU::dbg_vtophys(Addr addr
)
320 return vtophys(tc
, addr
);
322 #endif // FULL_SYSTEM
325 CheckerCPU::checkFlags(Request
*req
)
327 // Remove any dynamic flags that don't have to do with the request itself.
328 unsigned flags
= unverifiedReq
->getFlags();
329 unsigned mask
= LOCKED
| PHYSICAL
| VPTE
| ALTMODE
| UNCACHEABLE
| PREFETCH
;
330 flags
= flags
& (mask
);
331 if (flags
== req
->getFlags()) {
339 CheckerCPU::dumpAndExit()
341 warn("%lli: Checker PC:%#x, next PC:%#x",
342 curTick
, thread
->readPC(), thread
->readNextPC());
343 panic("Checker found an error!");