2 * Copyright (c) 2010 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) 2002-2005 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.
40 * Authors: Steve Reinhardt
43 #include "arch/locked_mem.hh"
44 #include "arch/mmapped_ipr.hh"
45 #include "arch/utility.hh"
46 #include "base/bigint.hh"
47 #include "config/the_isa.hh"
48 #include "cpu/simple/timing.hh"
49 #include "cpu/exetrace.hh"
50 #include "debug/Config.hh"
51 #include "debug/ExecFaulting.hh"
52 #include "debug/SimpleCPU.hh"
53 #include "mem/packet.hh"
54 #include "mem/packet_access.hh"
55 #include "params/TimingSimpleCPU.hh"
56 #include "sim/faults.hh"
57 #include "sim/system.hh"
60 using namespace TheISA
;
63 TimingSimpleCPU::getPort(const std::string
&if_name
, int idx
)
65 if (if_name
== "dcache_port")
67 else if (if_name
== "icache_port")
70 panic("No Such Port\n");
74 TimingSimpleCPU::init()
78 for (int i
= 0; i
< threadContexts
.size(); ++i
) {
79 ThreadContext
*tc
= threadContexts
[i
];
81 // initialize CPU, including PC
82 TheISA::initCPU(tc
, _cpuId
);
88 TimingSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt
)
90 panic("TimingSimpleCPU doesn't expect recvAtomic callback!");
95 TimingSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt
)
97 //No internal storage to update, jusst return
102 TimingSimpleCPU::CpuPort::recvStatusChange(Status status
)
104 if (status
== RangeChange
) {
105 if (!snoopRangeSent
) {
106 snoopRangeSent
= true;
107 sendStatusChange(Port::RangeChange
);
112 panic("TimingSimpleCPU doesn't expect recvStatusChange callback!");
117 TimingSimpleCPU::CpuPort::TickEvent::schedule(PacketPtr _pkt
, Tick t
)
120 cpu
->schedule(this, t
);
123 TimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams
*p
)
124 : BaseSimpleCPU(p
), fetchTranslation(this), icachePort(this, p
->clock
),
125 dcachePort(this, p
->clock
), fetchEvent(this)
129 icachePort
.snoopRangeSent
= false;
130 dcachePort
.snoopRangeSent
= false;
132 ifetch_pkt
= dcache_pkt
= NULL
;
135 changeState(SimObject::Running
);
136 system
->totalNumInsts
= 0;
140 TimingSimpleCPU::~TimingSimpleCPU()
145 TimingSimpleCPU::serialize(ostream
&os
)
147 SimObject::State so_state
= SimObject::getState();
148 SERIALIZE_ENUM(so_state
);
149 BaseSimpleCPU::serialize(os
);
153 TimingSimpleCPU::unserialize(Checkpoint
*cp
, const string
§ion
)
155 SimObject::State so_state
;
156 UNSERIALIZE_ENUM(so_state
);
157 BaseSimpleCPU::unserialize(cp
, section
);
161 TimingSimpleCPU::drain(Event
*drain_event
)
163 // TimingSimpleCPU is ready to drain if it's not waiting for
164 // an access to complete.
165 if (_status
== Idle
|| _status
== Running
|| _status
== SwitchedOut
) {
166 changeState(SimObject::Drained
);
169 changeState(SimObject::Draining
);
170 drainEvent
= drain_event
;
176 TimingSimpleCPU::resume()
178 DPRINTF(SimpleCPU
, "Resume\n");
179 if (_status
!= SwitchedOut
&& _status
!= Idle
) {
180 assert(system
->getMemoryMode() == Enums::timing
);
182 if (fetchEvent
.scheduled())
183 deschedule(fetchEvent
);
185 schedule(fetchEvent
, nextCycle());
188 changeState(SimObject::Running
);
192 TimingSimpleCPU::switchOut()
194 assert(_status
== Running
|| _status
== Idle
);
195 _status
= SwitchedOut
;
196 numCycles
+= tickToCycles(curTick() - previousTick
);
198 // If we've been scheduled to resume but are then told to switch out,
199 // we'll need to cancel it.
200 if (fetchEvent
.scheduled())
201 deschedule(fetchEvent
);
206 TimingSimpleCPU::takeOverFrom(BaseCPU
*oldCPU
)
208 BaseCPU::takeOverFrom(oldCPU
, &icachePort
, &dcachePort
);
210 // if any of this CPU's ThreadContexts are active, mark the CPU as
211 // running and schedule its tick event.
212 for (int i
= 0; i
< threadContexts
.size(); ++i
) {
213 ThreadContext
*tc
= threadContexts
[i
];
214 if (tc
->status() == ThreadContext::Active
&& _status
!= Running
) {
220 if (_status
!= Running
) {
223 assert(threadContexts
.size() == 1);
224 previousTick
= curTick();
229 TimingSimpleCPU::activateContext(int thread_num
, int delay
)
231 DPRINTF(SimpleCPU
, "ActivateContext %d (%d cycles)\n", thread_num
, delay
);
233 assert(thread_num
== 0);
236 assert(_status
== Idle
);
241 // kick things off by initiating the fetch of the next instruction
242 schedule(fetchEvent
, nextCycle(curTick() + ticks(delay
)));
247 TimingSimpleCPU::suspendContext(int thread_num
)
249 DPRINTF(SimpleCPU
, "SuspendContext %d\n", thread_num
);
251 assert(thread_num
== 0);
257 assert(_status
== Running
);
259 // just change status to Idle... if status != Running,
260 // completeInst() will not initiate fetch of next instruction.
267 TimingSimpleCPU::handleReadPacket(PacketPtr pkt
)
269 RequestPtr req
= pkt
->req
;
270 if (req
->isMmappedIpr()) {
272 delay
= TheISA::handleIprRead(thread
->getTC(), pkt
);
273 new IprEvent(pkt
, this, nextCycle(curTick() + delay
));
274 _status
= DcacheWaitResponse
;
276 } else if (!dcachePort
.sendTiming(pkt
)) {
277 _status
= DcacheRetry
;
280 _status
= DcacheWaitResponse
;
281 // memory system takes ownership of packet
284 return dcache_pkt
== NULL
;
288 TimingSimpleCPU::sendData(RequestPtr req
, uint8_t *data
, uint64_t *res
,
292 buildPacket(pkt
, req
, read
);
293 pkt
->dataDynamicArray
<uint8_t>(data
);
294 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
297 completeDataAccess(pkt
);
299 handleReadPacket(pkt
);
301 bool do_access
= true; // flag to suppress cache access
304 do_access
= TheISA::handleLockedWrite(thread
, req
);
305 } else if (req
->isCondSwap()) {
307 req
->setExtraData(*res
);
314 _status
= DcacheWaitResponse
;
315 completeDataAccess(pkt
);
321 TimingSimpleCPU::sendSplitData(RequestPtr req1
, RequestPtr req2
,
322 RequestPtr req
, uint8_t *data
, bool read
)
324 PacketPtr pkt1
, pkt2
;
325 buildSplitPacket(pkt1
, pkt2
, req1
, req2
, req
, data
, read
);
326 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
328 pkt1
->makeResponse();
329 completeDataAccess(pkt1
);
331 SplitFragmentSenderState
* send_state
=
332 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
333 if (handleReadPacket(pkt1
)) {
334 send_state
->clearFromParent();
335 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
337 if (handleReadPacket(pkt2
)) {
338 send_state
->clearFromParent();
343 SplitFragmentSenderState
* send_state
=
344 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
345 if (handleWritePacket()) {
346 send_state
->clearFromParent();
348 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
350 if (handleWritePacket()) {
351 send_state
->clearFromParent();
358 TimingSimpleCPU::translationFault(Fault fault
)
360 // fault may be NoFault in cases where a fault is suppressed,
361 // for instance prefetches.
362 numCycles
+= tickToCycles(curTick() - previousTick
);
363 previousTick
= curTick();
366 // Since there was a fault, we shouldn't trace this instruction.
373 if (getState() == SimObject::Draining
) {
382 TimingSimpleCPU::buildPacket(PacketPtr
&pkt
, RequestPtr req
, bool read
)
386 cmd
= MemCmd::ReadReq
;
388 cmd
= MemCmd::LoadLockedReq
;
390 cmd
= MemCmd::WriteReq
;
392 cmd
= MemCmd::StoreCondReq
;
393 } else if (req
->isSwap()) {
394 cmd
= MemCmd::SwapReq
;
397 pkt
= new Packet(req
, cmd
, Packet::Broadcast
);
401 TimingSimpleCPU::buildSplitPacket(PacketPtr
&pkt1
, PacketPtr
&pkt2
,
402 RequestPtr req1
, RequestPtr req2
, RequestPtr req
,
403 uint8_t *data
, bool read
)
407 assert(!req1
->isMmappedIpr() && !req2
->isMmappedIpr());
409 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
410 buildPacket(pkt1
, req
, read
);
414 buildPacket(pkt1
, req1
, read
);
415 buildPacket(pkt2
, req2
, read
);
417 req
->setPhys(req1
->getPaddr(), req
->getSize(), req1
->getFlags());
418 PacketPtr pkt
= new Packet(req
, pkt1
->cmd
.responseCommand(),
421 pkt
->dataDynamicArray
<uint8_t>(data
);
422 pkt1
->dataStatic
<uint8_t>(data
);
423 pkt2
->dataStatic
<uint8_t>(data
+ req1
->getSize());
425 SplitMainSenderState
* main_send_state
= new SplitMainSenderState
;
426 pkt
->senderState
= main_send_state
;
427 main_send_state
->fragments
[0] = pkt1
;
428 main_send_state
->fragments
[1] = pkt2
;
429 main_send_state
->outstanding
= 2;
430 pkt1
->senderState
= new SplitFragmentSenderState(pkt
, 0);
431 pkt2
->senderState
= new SplitFragmentSenderState(pkt
, 1);
435 TimingSimpleCPU::readBytes(Addr addr
, uint8_t *data
,
436 unsigned size
, unsigned flags
)
440 const ThreadID tid
= 0;
441 const Addr pc
= thread
->instAddr();
442 unsigned block_size
= dcachePort
.peerBlockSize();
443 BaseTLB::Mode mode
= BaseTLB::Read
;
446 traceData
->setAddr(addr
);
449 RequestPtr req
= new Request(asid
, addr
, size
,
450 flags
, pc
, _cpuId
, tid
);
452 Addr split_addr
= roundDown(addr
+ size
- 1, block_size
);
453 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
455 _status
= DTBWaitResponse
;
456 if (split_addr
> addr
) {
457 RequestPtr req1
, req2
;
458 assert(!req
->isLLSC() && !req
->isSwap());
459 req
->splitOnVaddr(split_addr
, req1
, req2
);
461 WholeTranslationState
*state
=
462 new WholeTranslationState(req
, req1
, req2
, new uint8_t[size
],
464 DataTranslation
<TimingSimpleCPU
> *trans1
=
465 new DataTranslation
<TimingSimpleCPU
>(this, state
, 0);
466 DataTranslation
<TimingSimpleCPU
> *trans2
=
467 new DataTranslation
<TimingSimpleCPU
>(this, state
, 1);
469 thread
->dtb
->translateTiming(req1
, tc
, trans1
, mode
);
470 thread
->dtb
->translateTiming(req2
, tc
, trans2
, mode
);
472 WholeTranslationState
*state
=
473 new WholeTranslationState(req
, new uint8_t[size
], NULL
, mode
);
474 DataTranslation
<TimingSimpleCPU
> *translation
475 = new DataTranslation
<TimingSimpleCPU
>(this, state
);
476 thread
->dtb
->translateTiming(req
, tc
, translation
, mode
);
484 TimingSimpleCPU::read(Addr addr
, T
&data
, unsigned flags
)
486 return readBytes(addr
, (uint8_t *)&data
, sizeof(T
), flags
);
489 #ifndef DOXYGEN_SHOULD_SKIP_THIS
493 TimingSimpleCPU::read(Addr addr
, Twin64_t
&data
, unsigned flags
);
497 TimingSimpleCPU::read(Addr addr
, Twin32_t
&data
, unsigned flags
);
501 TimingSimpleCPU::read(Addr addr
, uint64_t &data
, unsigned flags
);
505 TimingSimpleCPU::read(Addr addr
, uint32_t &data
, unsigned flags
);
509 TimingSimpleCPU::read(Addr addr
, uint16_t &data
, unsigned flags
);
513 TimingSimpleCPU::read(Addr addr
, uint8_t &data
, unsigned flags
);
515 #endif //DOXYGEN_SHOULD_SKIP_THIS
519 TimingSimpleCPU::read(Addr addr
, double &data
, unsigned flags
)
521 return read(addr
, *(uint64_t*)&data
, flags
);
526 TimingSimpleCPU::read(Addr addr
, float &data
, unsigned flags
)
528 return read(addr
, *(uint32_t*)&data
, flags
);
533 TimingSimpleCPU::read(Addr addr
, int32_t &data
, unsigned flags
)
535 return read(addr
, (uint32_t&)data
, flags
);
539 TimingSimpleCPU::handleWritePacket()
541 RequestPtr req
= dcache_pkt
->req
;
542 if (req
->isMmappedIpr()) {
544 delay
= TheISA::handleIprWrite(thread
->getTC(), dcache_pkt
);
545 new IprEvent(dcache_pkt
, this, nextCycle(curTick() + delay
));
546 _status
= DcacheWaitResponse
;
548 } else if (!dcachePort
.sendTiming(dcache_pkt
)) {
549 _status
= DcacheRetry
;
551 _status
= DcacheWaitResponse
;
552 // memory system takes ownership of packet
555 return dcache_pkt
== NULL
;
559 TimingSimpleCPU::writeTheseBytes(uint8_t *data
, unsigned size
,
560 Addr addr
, unsigned flags
, uint64_t *res
)
563 const ThreadID tid
= 0;
564 const Addr pc
= thread
->instAddr();
565 unsigned block_size
= dcachePort
.peerBlockSize();
566 BaseTLB::Mode mode
= BaseTLB::Write
;
569 traceData
->setAddr(addr
);
572 RequestPtr req
= new Request(asid
, addr
, size
,
573 flags
, pc
, _cpuId
, tid
);
575 Addr split_addr
= roundDown(addr
+ size
- 1, block_size
);
576 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
578 _status
= DTBWaitResponse
;
579 if (split_addr
> addr
) {
580 RequestPtr req1
, req2
;
581 assert(!req
->isLLSC() && !req
->isSwap());
582 req
->splitOnVaddr(split_addr
, req1
, req2
);
584 WholeTranslationState
*state
=
585 new WholeTranslationState(req
, req1
, req2
, data
, res
, mode
);
586 DataTranslation
<TimingSimpleCPU
> *trans1
=
587 new DataTranslation
<TimingSimpleCPU
>(this, state
, 0);
588 DataTranslation
<TimingSimpleCPU
> *trans2
=
589 new DataTranslation
<TimingSimpleCPU
>(this, state
, 1);
591 thread
->dtb
->translateTiming(req1
, tc
, trans1
, mode
);
592 thread
->dtb
->translateTiming(req2
, tc
, trans2
, mode
);
594 WholeTranslationState
*state
=
595 new WholeTranslationState(req
, data
, res
, mode
);
596 DataTranslation
<TimingSimpleCPU
> *translation
=
597 new DataTranslation
<TimingSimpleCPU
>(this, state
);
598 thread
->dtb
->translateTiming(req
, tc
, translation
, mode
);
601 // Translation faults will be returned via finishTranslation()
606 TimingSimpleCPU::writeBytes(uint8_t *data
, unsigned size
,
607 Addr addr
, unsigned flags
, uint64_t *res
)
609 uint8_t *newData
= new uint8_t[size
];
610 memcpy(newData
, data
, size
);
611 return writeTheseBytes(newData
, size
, addr
, flags
, res
);
616 TimingSimpleCPU::write(T data
, Addr addr
, unsigned flags
, uint64_t *res
)
619 traceData
->setData(data
);
621 T
*dataP
= (T
*) new uint8_t[sizeof(T
)];
622 *dataP
= TheISA::htog(data
);
624 return writeTheseBytes((uint8_t *)dataP
, sizeof(T
), addr
, flags
, res
);
628 #ifndef DOXYGEN_SHOULD_SKIP_THIS
631 TimingSimpleCPU::write(Twin32_t data
, Addr addr
,
632 unsigned flags
, uint64_t *res
);
636 TimingSimpleCPU::write(Twin64_t data
, Addr addr
,
637 unsigned flags
, uint64_t *res
);
641 TimingSimpleCPU::write(uint64_t data
, Addr addr
,
642 unsigned flags
, uint64_t *res
);
646 TimingSimpleCPU::write(uint32_t data
, Addr addr
,
647 unsigned flags
, uint64_t *res
);
651 TimingSimpleCPU::write(uint16_t data
, Addr addr
,
652 unsigned flags
, uint64_t *res
);
656 TimingSimpleCPU::write(uint8_t data
, Addr addr
,
657 unsigned flags
, uint64_t *res
);
659 #endif //DOXYGEN_SHOULD_SKIP_THIS
663 TimingSimpleCPU::write(double data
, Addr addr
, unsigned flags
, uint64_t *res
)
665 return write(*(uint64_t*)&data
, addr
, flags
, res
);
670 TimingSimpleCPU::write(float data
, Addr addr
, unsigned flags
, uint64_t *res
)
672 return write(*(uint32_t*)&data
, addr
, flags
, res
);
678 TimingSimpleCPU::write(int32_t data
, Addr addr
, unsigned flags
, uint64_t *res
)
680 return write((uint32_t)data
, addr
, flags
, res
);
685 TimingSimpleCPU::finishTranslation(WholeTranslationState
*state
)
689 if (state
->getFault() != NoFault
) {
690 if (state
->isPrefetch()) {
693 delete [] state
->data
;
695 translationFault(state
->getFault());
697 if (!state
->isSplit
) {
698 sendData(state
->mainReq
, state
->data
, state
->res
,
699 state
->mode
== BaseTLB::Read
);
701 sendSplitData(state
->sreqLow
, state
->sreqHigh
, state
->mainReq
,
702 state
->data
, state
->mode
== BaseTLB::Read
);
711 TimingSimpleCPU::fetch()
713 DPRINTF(SimpleCPU
, "Fetch\n");
715 if (!curStaticInst
|| !curStaticInst
->isDelayedCommit())
716 checkForInterrupts();
720 // We must have just got suspended by a PC event
724 TheISA::PCState pcState
= thread
->pcState();
725 bool needToFetch
= !isRomMicroPC(pcState
.microPC()) && !curMacroStaticInst
;
728 Request
*ifetch_req
= new Request();
729 ifetch_req
->setThreadContext(_cpuId
, /* thread ID */ 0);
730 setupFetchRequest(ifetch_req
);
731 thread
->itb
->translateTiming(ifetch_req
, tc
, &fetchTranslation
,
734 _status
= IcacheWaitResponse
;
735 completeIfetch(NULL
);
737 numCycles
+= tickToCycles(curTick() - previousTick
);
738 previousTick
= curTick();
744 TimingSimpleCPU::sendFetch(Fault fault
, RequestPtr req
, ThreadContext
*tc
)
746 if (fault
== NoFault
) {
747 ifetch_pkt
= new Packet(req
, MemCmd::ReadReq
, Packet::Broadcast
);
748 ifetch_pkt
->dataStatic(&inst
);
750 if (!icachePort
.sendTiming(ifetch_pkt
)) {
751 // Need to wait for retry
752 _status
= IcacheRetry
;
754 // Need to wait for cache to respond
755 _status
= IcacheWaitResponse
;
756 // ownership of packet transferred to memory system
761 // fetch fault: advance directly to next instruction (fault handler)
766 numCycles
+= tickToCycles(curTick() - previousTick
);
767 previousTick
= curTick();
772 TimingSimpleCPU::advanceInst(Fault fault
)
774 if (fault
!= NoFault
|| !stayAtPC
)
777 if (_status
== Running
) {
778 // kick off fetch of next instruction... callback from icache
779 // response will cause that instruction to be executed,
780 // keeping the CPU running.
787 TimingSimpleCPU::completeIfetch(PacketPtr pkt
)
789 DPRINTF(SimpleCPU
, "Complete ICache Fetch\n");
791 // received a response from the icache: execute the received
794 assert(!pkt
|| !pkt
->isError());
795 assert(_status
== IcacheWaitResponse
);
799 numCycles
+= tickToCycles(curTick() - previousTick
);
800 previousTick
= curTick();
802 if (getState() == SimObject::Draining
) {
813 if (curStaticInst
&& curStaticInst
->isMemRef()) {
814 // load or store: just send to dcache
815 Fault fault
= curStaticInst
->initiateAcc(this, traceData
);
817 // If we're not running now the instruction will complete in a dcache
818 // response callback or the instruction faulted and has started an
820 if (_status
== Running
) {
821 if (fault
!= NoFault
&& traceData
) {
822 // If there was a fault, we shouldn't trace this instruction.
828 // @todo remove me after debugging with legion done
829 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
830 curStaticInst
->isFirstMicroop()))
834 } else if (curStaticInst
) {
835 // non-memory instruction: execute completely now
836 Fault fault
= curStaticInst
->execute(this, traceData
);
838 // keep an instruction count
839 if (fault
== NoFault
)
841 else if (traceData
&& !DTRACE(ExecFaulting
)) {
847 // @todo remove me after debugging with legion done
848 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
849 curStaticInst
->isFirstMicroop()))
853 advanceInst(NoFault
);
863 TimingSimpleCPU::IcachePort::ITickEvent::process()
865 cpu
->completeIfetch(pkt
);
869 TimingSimpleCPU::IcachePort::recvTiming(PacketPtr pkt
)
871 if (pkt
->isResponse() && !pkt
->wasNacked()) {
872 // delay processing of returned data until next CPU clock edge
873 Tick next_tick
= cpu
->nextCycle(curTick());
875 if (next_tick
== curTick())
876 cpu
->completeIfetch(pkt
);
878 tickEvent
.schedule(pkt
, next_tick
);
882 else if (pkt
->wasNacked()) {
883 assert(cpu
->_status
== IcacheWaitResponse
);
885 if (!sendTiming(pkt
)) {
886 cpu
->_status
= IcacheRetry
;
887 cpu
->ifetch_pkt
= pkt
;
890 //Snooping a Coherence Request, do nothing
895 TimingSimpleCPU::IcachePort::recvRetry()
897 // we shouldn't get a retry unless we have a packet that we're
898 // waiting to transmit
899 assert(cpu
->ifetch_pkt
!= NULL
);
900 assert(cpu
->_status
== IcacheRetry
);
901 PacketPtr tmp
= cpu
->ifetch_pkt
;
902 if (sendTiming(tmp
)) {
903 cpu
->_status
= IcacheWaitResponse
;
904 cpu
->ifetch_pkt
= NULL
;
909 TimingSimpleCPU::completeDataAccess(PacketPtr pkt
)
911 // received a response from the dcache: complete the load or store
913 assert(!pkt
->isError());
914 assert(_status
== DcacheWaitResponse
|| _status
== DTBWaitResponse
||
915 pkt
->req
->getFlags().isSet(Request::NO_ACCESS
));
917 numCycles
+= tickToCycles(curTick() - previousTick
);
918 previousTick
= curTick();
920 if (pkt
->senderState
) {
921 SplitFragmentSenderState
* send_state
=
922 dynamic_cast<SplitFragmentSenderState
*>(pkt
->senderState
);
926 PacketPtr big_pkt
= send_state
->bigPkt
;
929 SplitMainSenderState
* main_send_state
=
930 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
931 assert(main_send_state
);
932 // Record the fact that this packet is no longer outstanding.
933 assert(main_send_state
->outstanding
!= 0);
934 main_send_state
->outstanding
--;
936 if (main_send_state
->outstanding
) {
939 delete main_send_state
;
940 big_pkt
->senderState
= NULL
;
947 Fault fault
= curStaticInst
->completeAcc(pkt
, this, traceData
);
949 // keep an instruction count
950 if (fault
== NoFault
)
952 else if (traceData
) {
953 // If there was a fault, we shouldn't trace this instruction.
958 // the locked flag may be cleared on the response packet, so check
959 // pkt->req and not pkt to see if it was a load-locked
960 if (pkt
->isRead() && pkt
->req
->isLLSC()) {
961 TheISA::handleLockedRead(thread
, pkt
->req
);
969 if (getState() == SimObject::Draining
) {
981 TimingSimpleCPU::completeDrain()
983 DPRINTF(Config
, "Done draining\n");
984 changeState(SimObject::Drained
);
985 drainEvent
->process();
989 TimingSimpleCPU::DcachePort::setPeer(Port
*port
)
994 // Update the ThreadContext's memory ports (Functional/Virtual
996 cpu
->tcBase()->connectMemPorts(cpu
->tcBase());
1001 TimingSimpleCPU::DcachePort::recvTiming(PacketPtr pkt
)
1003 if (pkt
->isResponse() && !pkt
->wasNacked()) {
1004 // delay processing of returned data until next CPU clock edge
1005 Tick next_tick
= cpu
->nextCycle(curTick());
1007 if (next_tick
== curTick()) {
1008 cpu
->completeDataAccess(pkt
);
1010 if (!tickEvent
.scheduled()) {
1011 tickEvent
.schedule(pkt
, next_tick
);
1013 // In the case of a split transaction and a cache that is
1014 // faster than a CPU we could get two responses before
1015 // next_tick expires
1016 if (!retryEvent
.scheduled())
1017 schedule(retryEvent
, next_tick
);
1024 else if (pkt
->wasNacked()) {
1025 assert(cpu
->_status
== DcacheWaitResponse
);
1026 pkt
->reinitNacked();
1027 if (!sendTiming(pkt
)) {
1028 cpu
->_status
= DcacheRetry
;
1029 cpu
->dcache_pkt
= pkt
;
1032 //Snooping a Coherence Request, do nothing
1037 TimingSimpleCPU::DcachePort::DTickEvent::process()
1039 cpu
->completeDataAccess(pkt
);
1043 TimingSimpleCPU::DcachePort::recvRetry()
1045 // we shouldn't get a retry unless we have a packet that we're
1046 // waiting to transmit
1047 assert(cpu
->dcache_pkt
!= NULL
);
1048 assert(cpu
->_status
== DcacheRetry
);
1049 PacketPtr tmp
= cpu
->dcache_pkt
;
1050 if (tmp
->senderState
) {
1051 // This is a packet from a split access.
1052 SplitFragmentSenderState
* send_state
=
1053 dynamic_cast<SplitFragmentSenderState
*>(tmp
->senderState
);
1055 PacketPtr big_pkt
= send_state
->bigPkt
;
1057 SplitMainSenderState
* main_send_state
=
1058 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
1059 assert(main_send_state
);
1061 if (sendTiming(tmp
)) {
1062 // If we were able to send without retrying, record that fact
1063 // and try sending the other fragment.
1064 send_state
->clearFromParent();
1065 int other_index
= main_send_state
->getPendingFragment();
1066 if (other_index
> 0) {
1067 tmp
= main_send_state
->fragments
[other_index
];
1068 cpu
->dcache_pkt
= tmp
;
1069 if ((big_pkt
->isRead() && cpu
->handleReadPacket(tmp
)) ||
1070 (big_pkt
->isWrite() && cpu
->handleWritePacket())) {
1071 main_send_state
->fragments
[other_index
] = NULL
;
1074 cpu
->_status
= DcacheWaitResponse
;
1075 // memory system takes ownership of packet
1076 cpu
->dcache_pkt
= NULL
;
1079 } else if (sendTiming(tmp
)) {
1080 cpu
->_status
= DcacheWaitResponse
;
1081 // memory system takes ownership of packet
1082 cpu
->dcache_pkt
= NULL
;
1086 TimingSimpleCPU::IprEvent::IprEvent(Packet
*_pkt
, TimingSimpleCPU
*_cpu
,
1088 : pkt(_pkt
), cpu(_cpu
)
1090 cpu
->schedule(this, t
);
1094 TimingSimpleCPU::IprEvent::process()
1096 cpu
->completeDataAccess(pkt
);
1100 TimingSimpleCPU::IprEvent::description() const
1102 return "Timing Simple CPU Delay IPR event";
1107 TimingSimpleCPU::printAddr(Addr a
)
1109 dcachePort
.printAddr(a
);
1113 ////////////////////////////////////////////////////////////////////////
1115 // TimingSimpleCPU Simulation Object
1118 TimingSimpleCPUParams::create()
1122 if (workload
.size() != 1)
1123 panic("only one workload allowed");
1125 return new TimingSimpleCPU(this);