2 * Copyright (c) 2002-2005 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.
28 * Authors: Steve Reinhardt
31 #include "arch/locked_mem.hh"
32 #include "arch/mmaped_ipr.hh"
33 #include "arch/utility.hh"
34 #include "base/bigint.hh"
35 #include "config/the_isa.hh"
36 #include "cpu/exetrace.hh"
37 #include "cpu/simple/timing.hh"
38 #include "mem/packet.hh"
39 #include "mem/packet_access.hh"
40 #include "params/TimingSimpleCPU.hh"
41 #include "sim/system.hh"
44 using namespace TheISA
;
47 TimingSimpleCPU::getPort(const std::string
&if_name
, int idx
)
49 if (if_name
== "dcache_port")
51 else if (if_name
== "icache_port")
54 panic("No Such Port\n");
58 TimingSimpleCPU::init()
62 for (int i
= 0; i
< threadContexts
.size(); ++i
) {
63 ThreadContext
*tc
= threadContexts
[i
];
65 // initialize CPU, including PC
66 TheISA::initCPU(tc
, _cpuId
);
72 TimingSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt
)
74 panic("TimingSimpleCPU doesn't expect recvAtomic callback!");
79 TimingSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt
)
81 //No internal storage to update, jusst return
86 TimingSimpleCPU::CpuPort::recvStatusChange(Status status
)
88 if (status
== RangeChange
) {
89 if (!snoopRangeSent
) {
90 snoopRangeSent
= true;
91 sendStatusChange(Port::RangeChange
);
96 panic("TimingSimpleCPU doesn't expect recvStatusChange callback!");
101 TimingSimpleCPU::CpuPort::TickEvent::schedule(PacketPtr _pkt
, Tick t
)
104 cpu
->schedule(this, t
);
107 TimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams
*p
)
108 : BaseSimpleCPU(p
), fetchTranslation(this), icachePort(this, p
->clock
),
109 dcachePort(this, p
->clock
), fetchEvent(this)
113 icachePort
.snoopRangeSent
= false;
114 dcachePort
.snoopRangeSent
= false;
116 ifetch_pkt
= dcache_pkt
= NULL
;
119 changeState(SimObject::Running
);
123 TimingSimpleCPU::~TimingSimpleCPU()
128 TimingSimpleCPU::serialize(ostream
&os
)
130 SimObject::State so_state
= SimObject::getState();
131 SERIALIZE_ENUM(so_state
);
132 BaseSimpleCPU::serialize(os
);
136 TimingSimpleCPU::unserialize(Checkpoint
*cp
, const string
§ion
)
138 SimObject::State so_state
;
139 UNSERIALIZE_ENUM(so_state
);
140 BaseSimpleCPU::unserialize(cp
, section
);
144 TimingSimpleCPU::drain(Event
*drain_event
)
146 // TimingSimpleCPU is ready to drain if it's not waiting for
147 // an access to complete.
148 if (_status
== Idle
|| _status
== Running
|| _status
== SwitchedOut
) {
149 changeState(SimObject::Drained
);
152 changeState(SimObject::Draining
);
153 drainEvent
= drain_event
;
159 TimingSimpleCPU::resume()
161 DPRINTF(SimpleCPU
, "Resume\n");
162 if (_status
!= SwitchedOut
&& _status
!= Idle
) {
163 assert(system
->getMemoryMode() == Enums::timing
);
165 if (fetchEvent
.scheduled())
166 deschedule(fetchEvent
);
168 schedule(fetchEvent
, nextCycle());
171 changeState(SimObject::Running
);
175 TimingSimpleCPU::switchOut()
177 assert(_status
== Running
|| _status
== Idle
);
178 _status
= SwitchedOut
;
179 numCycles
+= tickToCycles(curTick
- previousTick
);
181 // If we've been scheduled to resume but are then told to switch out,
182 // we'll need to cancel it.
183 if (fetchEvent
.scheduled())
184 deschedule(fetchEvent
);
189 TimingSimpleCPU::takeOverFrom(BaseCPU
*oldCPU
)
191 BaseCPU::takeOverFrom(oldCPU
, &icachePort
, &dcachePort
);
193 // if any of this CPU's ThreadContexts are active, mark the CPU as
194 // running and schedule its tick event.
195 for (int i
= 0; i
< threadContexts
.size(); ++i
) {
196 ThreadContext
*tc
= threadContexts
[i
];
197 if (tc
->status() == ThreadContext::Active
&& _status
!= Running
) {
203 if (_status
!= Running
) {
206 assert(threadContexts
.size() == 1);
207 previousTick
= curTick
;
212 TimingSimpleCPU::activateContext(int thread_num
, int delay
)
214 DPRINTF(SimpleCPU
, "ActivateContext %d (%d cycles)\n", thread_num
, delay
);
216 assert(thread_num
== 0);
219 assert(_status
== Idle
);
224 // kick things off by initiating the fetch of the next instruction
225 schedule(fetchEvent
, nextCycle(curTick
+ ticks(delay
)));
230 TimingSimpleCPU::suspendContext(int thread_num
)
232 DPRINTF(SimpleCPU
, "SuspendContext %d\n", thread_num
);
234 assert(thread_num
== 0);
240 assert(_status
== Running
);
242 // just change status to Idle... if status != Running,
243 // completeInst() will not initiate fetch of next instruction.
250 TimingSimpleCPU::handleReadPacket(PacketPtr pkt
)
252 RequestPtr req
= pkt
->req
;
253 if (req
->isMmapedIpr()) {
255 delay
= TheISA::handleIprRead(thread
->getTC(), pkt
);
256 new IprEvent(pkt
, this, nextCycle(curTick
+ delay
));
257 _status
= DcacheWaitResponse
;
259 } else if (!dcachePort
.sendTiming(pkt
)) {
260 _status
= DcacheRetry
;
263 _status
= DcacheWaitResponse
;
264 // memory system takes ownership of packet
267 return dcache_pkt
== NULL
;
271 TimingSimpleCPU::sendData(RequestPtr req
, uint8_t *data
, uint64_t *res
,
275 buildPacket(pkt
, req
, read
);
276 pkt
->dataDynamic
<uint8_t>(data
);
277 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
280 completeDataAccess(pkt
);
282 handleReadPacket(pkt
);
284 bool do_access
= true; // flag to suppress cache access
287 do_access
= TheISA::handleLockedWrite(thread
, req
);
288 } else if (req
->isCondSwap()) {
290 req
->setExtraData(*res
);
297 _status
= DcacheWaitResponse
;
298 completeDataAccess(pkt
);
304 TimingSimpleCPU::sendSplitData(RequestPtr req1
, RequestPtr req2
,
305 RequestPtr req
, uint8_t *data
, bool read
)
307 PacketPtr pkt1
, pkt2
;
308 buildSplitPacket(pkt1
, pkt2
, req1
, req2
, req
, data
, read
);
309 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
311 pkt1
->makeResponse();
312 completeDataAccess(pkt1
);
314 if (handleReadPacket(pkt1
)) {
315 SplitFragmentSenderState
* send_state
=
316 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
317 send_state
->clearFromParent();
318 if (handleReadPacket(pkt2
)) {
319 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
321 send_state
->clearFromParent();
326 if (handleWritePacket()) {
327 SplitFragmentSenderState
* send_state
=
328 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
329 send_state
->clearFromParent();
331 if (handleWritePacket()) {
332 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
334 send_state
->clearFromParent();
341 TimingSimpleCPU::translationFault(Fault fault
)
343 // fault may be NoFault in cases where a fault is suppressed,
344 // for instance prefetches.
345 numCycles
+= tickToCycles(curTick
- previousTick
);
346 previousTick
= curTick
;
349 // Since there was a fault, we shouldn't trace this instruction.
356 if (getState() == SimObject::Draining
) {
365 TimingSimpleCPU::buildPacket(PacketPtr
&pkt
, RequestPtr req
, bool read
)
369 cmd
= MemCmd::ReadReq
;
371 cmd
= MemCmd::LoadLockedReq
;
373 cmd
= MemCmd::WriteReq
;
375 cmd
= MemCmd::StoreCondReq
;
376 } else if (req
->isSwap()) {
377 cmd
= MemCmd::SwapReq
;
380 pkt
= new Packet(req
, cmd
, Packet::Broadcast
);
384 TimingSimpleCPU::buildSplitPacket(PacketPtr
&pkt1
, PacketPtr
&pkt2
,
385 RequestPtr req1
, RequestPtr req2
, RequestPtr req
,
386 uint8_t *data
, bool read
)
390 assert(!req1
->isMmapedIpr() && !req2
->isMmapedIpr());
392 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
393 buildPacket(pkt1
, req
, read
);
397 buildPacket(pkt1
, req1
, read
);
398 buildPacket(pkt2
, req2
, read
);
400 req
->setPhys(req1
->getPaddr(), req
->getSize(), req1
->getFlags());
401 PacketPtr pkt
= new Packet(req
, pkt1
->cmd
.responseCommand(),
404 pkt
->dataDynamic
<uint8_t>(data
);
405 pkt1
->dataStatic
<uint8_t>(data
);
406 pkt2
->dataStatic
<uint8_t>(data
+ req1
->getSize());
408 SplitMainSenderState
* main_send_state
= new SplitMainSenderState
;
409 pkt
->senderState
= main_send_state
;
410 main_send_state
->fragments
[0] = pkt1
;
411 main_send_state
->fragments
[1] = pkt2
;
412 main_send_state
->outstanding
= 2;
413 pkt1
->senderState
= new SplitFragmentSenderState(pkt
, 0);
414 pkt2
->senderState
= new SplitFragmentSenderState(pkt
, 1);
419 TimingSimpleCPU::read(Addr addr
, T
&data
, unsigned flags
)
423 const ThreadID tid
= 0;
424 const Addr pc
= thread
->readPC();
425 unsigned block_size
= dcachePort
.peerBlockSize();
426 int data_size
= sizeof(T
);
427 BaseTLB::Mode mode
= BaseTLB::Read
;
430 traceData
->setAddr(addr
);
433 RequestPtr req
= new Request(asid
, addr
, data_size
,
434 flags
, pc
, _cpuId
, tid
);
436 Addr split_addr
= roundDown(addr
+ data_size
- 1, block_size
);
437 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
439 _status
= DTBWaitResponse
;
440 if (split_addr
> addr
) {
441 RequestPtr req1
, req2
;
442 assert(!req
->isLLSC() && !req
->isSwap());
443 req
->splitOnVaddr(split_addr
, req1
, req2
);
445 WholeTranslationState
*state
=
446 new WholeTranslationState(req
, req1
, req2
, (uint8_t *)(new T
),
448 DataTranslation
<TimingSimpleCPU
> *trans1
=
449 new DataTranslation
<TimingSimpleCPU
>(this, state
, 0);
450 DataTranslation
<TimingSimpleCPU
> *trans2
=
451 new DataTranslation
<TimingSimpleCPU
>(this, state
, 1);
453 thread
->dtb
->translateTiming(req1
, tc
, trans1
, mode
);
454 thread
->dtb
->translateTiming(req2
, tc
, trans2
, mode
);
456 WholeTranslationState
*state
=
457 new WholeTranslationState(req
, (uint8_t *)(new T
), NULL
, mode
);
458 DataTranslation
<TimingSimpleCPU
> *translation
459 = new DataTranslation
<TimingSimpleCPU
>(this, state
);
460 thread
->dtb
->translateTiming(req
, tc
, translation
, mode
);
466 #ifndef DOXYGEN_SHOULD_SKIP_THIS
470 TimingSimpleCPU::read(Addr addr
, Twin64_t
&data
, unsigned flags
);
474 TimingSimpleCPU::read(Addr addr
, Twin32_t
&data
, unsigned flags
);
478 TimingSimpleCPU::read(Addr addr
, uint64_t &data
, unsigned flags
);
482 TimingSimpleCPU::read(Addr addr
, uint32_t &data
, unsigned flags
);
486 TimingSimpleCPU::read(Addr addr
, uint16_t &data
, unsigned flags
);
490 TimingSimpleCPU::read(Addr addr
, uint8_t &data
, unsigned flags
);
492 #endif //DOXYGEN_SHOULD_SKIP_THIS
496 TimingSimpleCPU::read(Addr addr
, double &data
, unsigned flags
)
498 return read(addr
, *(uint64_t*)&data
, flags
);
503 TimingSimpleCPU::read(Addr addr
, float &data
, unsigned flags
)
505 return read(addr
, *(uint32_t*)&data
, flags
);
510 TimingSimpleCPU::read(Addr addr
, int32_t &data
, unsigned flags
)
512 return read(addr
, (uint32_t&)data
, flags
);
516 TimingSimpleCPU::handleWritePacket()
518 RequestPtr req
= dcache_pkt
->req
;
519 if (req
->isMmapedIpr()) {
521 delay
= TheISA::handleIprWrite(thread
->getTC(), dcache_pkt
);
522 new IprEvent(dcache_pkt
, this, nextCycle(curTick
+ delay
));
523 _status
= DcacheWaitResponse
;
525 } else if (!dcachePort
.sendTiming(dcache_pkt
)) {
526 _status
= DcacheRetry
;
528 _status
= DcacheWaitResponse
;
529 // memory system takes ownership of packet
532 return dcache_pkt
== NULL
;
537 TimingSimpleCPU::write(T data
, Addr addr
, unsigned flags
, uint64_t *res
)
540 const ThreadID tid
= 0;
541 const Addr pc
= thread
->readPC();
542 unsigned block_size
= dcachePort
.peerBlockSize();
543 int data_size
= sizeof(T
);
544 BaseTLB::Mode mode
= BaseTLB::Write
;
547 traceData
->setAddr(addr
);
548 traceData
->setData(data
);
551 RequestPtr req
= new Request(asid
, addr
, data_size
,
552 flags
, pc
, _cpuId
, tid
);
554 Addr split_addr
= roundDown(addr
+ data_size
- 1, block_size
);
555 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
558 *dataP
= TheISA::htog(data
);
559 _status
= DTBWaitResponse
;
560 if (split_addr
> addr
) {
561 RequestPtr req1
, req2
;
562 assert(!req
->isLLSC() && !req
->isSwap());
563 req
->splitOnVaddr(split_addr
, req1
, req2
);
565 WholeTranslationState
*state
=
566 new WholeTranslationState(req
, req1
, req2
, (uint8_t *)dataP
,
568 DataTranslation
<TimingSimpleCPU
> *trans1
=
569 new DataTranslation
<TimingSimpleCPU
>(this, state
, 0);
570 DataTranslation
<TimingSimpleCPU
> *trans2
=
571 new DataTranslation
<TimingSimpleCPU
>(this, state
, 1);
573 thread
->dtb
->translateTiming(req1
, tc
, trans1
, mode
);
574 thread
->dtb
->translateTiming(req2
, tc
, trans2
, mode
);
576 WholeTranslationState
*state
=
577 new WholeTranslationState(req
, (uint8_t *)dataP
, res
, mode
);
578 DataTranslation
<TimingSimpleCPU
> *translation
=
579 new DataTranslation
<TimingSimpleCPU
>(this, state
);
580 thread
->dtb
->translateTiming(req
, tc
, translation
, mode
);
583 // Translation faults will be returned via finishTranslation()
588 #ifndef DOXYGEN_SHOULD_SKIP_THIS
591 TimingSimpleCPU::write(Twin32_t data
, Addr addr
,
592 unsigned flags
, uint64_t *res
);
596 TimingSimpleCPU::write(Twin64_t data
, Addr addr
,
597 unsigned flags
, uint64_t *res
);
601 TimingSimpleCPU::write(uint64_t data
, Addr addr
,
602 unsigned flags
, uint64_t *res
);
606 TimingSimpleCPU::write(uint32_t data
, Addr addr
,
607 unsigned flags
, uint64_t *res
);
611 TimingSimpleCPU::write(uint16_t data
, Addr addr
,
612 unsigned flags
, uint64_t *res
);
616 TimingSimpleCPU::write(uint8_t data
, Addr addr
,
617 unsigned flags
, uint64_t *res
);
619 #endif //DOXYGEN_SHOULD_SKIP_THIS
623 TimingSimpleCPU::write(double data
, Addr addr
, unsigned flags
, uint64_t *res
)
625 return write(*(uint64_t*)&data
, addr
, flags
, res
);
630 TimingSimpleCPU::write(float data
, Addr addr
, unsigned flags
, uint64_t *res
)
632 return write(*(uint32_t*)&data
, addr
, flags
, res
);
638 TimingSimpleCPU::write(int32_t data
, Addr addr
, unsigned flags
, uint64_t *res
)
640 return write((uint32_t)data
, addr
, flags
, res
);
645 TimingSimpleCPU::finishTranslation(WholeTranslationState
*state
)
649 if (state
->getFault() != NoFault
) {
650 if (state
->isPrefetch()) {
655 translationFault(state
->getFault());
657 if (!state
->isSplit
) {
658 sendData(state
->mainReq
, state
->data
, state
->res
,
659 state
->mode
== BaseTLB::Read
);
661 sendSplitData(state
->sreqLow
, state
->sreqHigh
, state
->mainReq
,
662 state
->data
, state
->mode
== BaseTLB::Read
);
671 TimingSimpleCPU::fetch()
673 DPRINTF(SimpleCPU
, "Fetch\n");
675 if (!curStaticInst
|| !curStaticInst
->isDelayedCommit())
676 checkForInterrupts();
680 bool fromRom
= isRomMicroPC(thread
->readMicroPC());
682 if (!fromRom
&& !curMacroStaticInst
) {
683 Request
*ifetch_req
= new Request();
684 ifetch_req
->setThreadContext(_cpuId
, /* thread ID */ 0);
685 setupFetchRequest(ifetch_req
);
686 thread
->itb
->translateTiming(ifetch_req
, tc
, &fetchTranslation
,
689 _status
= IcacheWaitResponse
;
690 completeIfetch(NULL
);
692 numCycles
+= tickToCycles(curTick
- previousTick
);
693 previousTick
= curTick
;
699 TimingSimpleCPU::sendFetch(Fault fault
, RequestPtr req
, ThreadContext
*tc
)
701 if (fault
== NoFault
) {
702 ifetch_pkt
= new Packet(req
, MemCmd::ReadReq
, Packet::Broadcast
);
703 ifetch_pkt
->dataStatic(&inst
);
705 if (!icachePort
.sendTiming(ifetch_pkt
)) {
706 // Need to wait for retry
707 _status
= IcacheRetry
;
709 // Need to wait for cache to respond
710 _status
= IcacheWaitResponse
;
711 // ownership of packet transferred to memory system
716 // fetch fault: advance directly to next instruction (fault handler)
720 numCycles
+= tickToCycles(curTick
- previousTick
);
721 previousTick
= curTick
;
726 TimingSimpleCPU::advanceInst(Fault fault
)
728 if (fault
!= NoFault
|| !stayAtPC
)
731 if (_status
== Running
) {
732 // kick off fetch of next instruction... callback from icache
733 // response will cause that instruction to be executed,
734 // keeping the CPU running.
741 TimingSimpleCPU::completeIfetch(PacketPtr pkt
)
743 DPRINTF(SimpleCPU
, "Complete ICache Fetch\n");
745 // received a response from the icache: execute the received
748 assert(!pkt
|| !pkt
->isError());
749 assert(_status
== IcacheWaitResponse
);
753 numCycles
+= tickToCycles(curTick
- previousTick
);
754 previousTick
= curTick
;
756 if (getState() == SimObject::Draining
) {
768 curStaticInst
->isMemRef() && !curStaticInst
->isDataPrefetch()) {
769 // load or store: just send to dcache
770 Fault fault
= curStaticInst
->initiateAcc(this, traceData
);
771 if (_status
!= Running
) {
772 // instruction will complete in dcache response callback
773 assert(_status
== DcacheWaitResponse
||
774 _status
== DcacheRetry
|| DTBWaitResponse
);
775 assert(fault
== NoFault
);
777 if (fault
!= NoFault
&& traceData
) {
778 // If there was a fault, we shouldn't trace this instruction.
784 // @todo remove me after debugging with legion done
785 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
786 curStaticInst
->isFirstMicroop()))
790 } else if (curStaticInst
) {
791 // non-memory instruction: execute completely now
792 Fault fault
= curStaticInst
->execute(this, traceData
);
794 // keep an instruction count
795 if (fault
== NoFault
)
797 else if (traceData
) {
798 // If there was a fault, we shouldn't trace this instruction.
804 // @todo remove me after debugging with legion done
805 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
806 curStaticInst
->isFirstMicroop()))
810 advanceInst(NoFault
);
820 TimingSimpleCPU::IcachePort::ITickEvent::process()
822 cpu
->completeIfetch(pkt
);
826 TimingSimpleCPU::IcachePort::recvTiming(PacketPtr pkt
)
828 if (pkt
->isResponse() && !pkt
->wasNacked()) {
829 // delay processing of returned data until next CPU clock edge
830 Tick next_tick
= cpu
->nextCycle(curTick
);
832 if (next_tick
== curTick
)
833 cpu
->completeIfetch(pkt
);
835 tickEvent
.schedule(pkt
, next_tick
);
839 else if (pkt
->wasNacked()) {
840 assert(cpu
->_status
== IcacheWaitResponse
);
842 if (!sendTiming(pkt
)) {
843 cpu
->_status
= IcacheRetry
;
844 cpu
->ifetch_pkt
= pkt
;
847 //Snooping a Coherence Request, do nothing
852 TimingSimpleCPU::IcachePort::recvRetry()
854 // we shouldn't get a retry unless we have a packet that we're
855 // waiting to transmit
856 assert(cpu
->ifetch_pkt
!= NULL
);
857 assert(cpu
->_status
== IcacheRetry
);
858 PacketPtr tmp
= cpu
->ifetch_pkt
;
859 if (sendTiming(tmp
)) {
860 cpu
->_status
= IcacheWaitResponse
;
861 cpu
->ifetch_pkt
= NULL
;
866 TimingSimpleCPU::completeDataAccess(PacketPtr pkt
)
868 // received a response from the dcache: complete the load or store
870 assert(!pkt
->isError());
871 assert(_status
== DcacheWaitResponse
|| _status
== DTBWaitResponse
||
872 pkt
->req
->getFlags().isSet(Request::NO_ACCESS
));
874 numCycles
+= tickToCycles(curTick
- previousTick
);
875 previousTick
= curTick
;
877 if (pkt
->senderState
) {
878 SplitFragmentSenderState
* send_state
=
879 dynamic_cast<SplitFragmentSenderState
*>(pkt
->senderState
);
883 PacketPtr big_pkt
= send_state
->bigPkt
;
886 SplitMainSenderState
* main_send_state
=
887 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
888 assert(main_send_state
);
889 // Record the fact that this packet is no longer outstanding.
890 assert(main_send_state
->outstanding
!= 0);
891 main_send_state
->outstanding
--;
893 if (main_send_state
->outstanding
) {
896 delete main_send_state
;
897 big_pkt
->senderState
= NULL
;
904 Fault fault
= curStaticInst
->completeAcc(pkt
, this, traceData
);
906 // keep an instruction count
907 if (fault
== NoFault
)
909 else if (traceData
) {
910 // If there was a fault, we shouldn't trace this instruction.
915 // the locked flag may be cleared on the response packet, so check
916 // pkt->req and not pkt to see if it was a load-locked
917 if (pkt
->isRead() && pkt
->req
->isLLSC()) {
918 TheISA::handleLockedRead(thread
, pkt
->req
);
926 if (getState() == SimObject::Draining
) {
938 TimingSimpleCPU::completeDrain()
940 DPRINTF(Config
, "Done draining\n");
941 changeState(SimObject::Drained
);
942 drainEvent
->process();
946 TimingSimpleCPU::DcachePort::setPeer(Port
*port
)
951 // Update the ThreadContext's memory ports (Functional/Virtual
953 cpu
->tcBase()->connectMemPorts(cpu
->tcBase());
958 TimingSimpleCPU::DcachePort::recvTiming(PacketPtr pkt
)
960 if (pkt
->isResponse() && !pkt
->wasNacked()) {
961 // delay processing of returned data until next CPU clock edge
962 Tick next_tick
= cpu
->nextCycle(curTick
);
964 if (next_tick
== curTick
) {
965 cpu
->completeDataAccess(pkt
);
967 tickEvent
.schedule(pkt
, next_tick
);
972 else if (pkt
->wasNacked()) {
973 assert(cpu
->_status
== DcacheWaitResponse
);
975 if (!sendTiming(pkt
)) {
976 cpu
->_status
= DcacheRetry
;
977 cpu
->dcache_pkt
= pkt
;
980 //Snooping a Coherence Request, do nothing
985 TimingSimpleCPU::DcachePort::DTickEvent::process()
987 cpu
->completeDataAccess(pkt
);
991 TimingSimpleCPU::DcachePort::recvRetry()
993 // we shouldn't get a retry unless we have a packet that we're
994 // waiting to transmit
995 assert(cpu
->dcache_pkt
!= NULL
);
996 assert(cpu
->_status
== DcacheRetry
);
997 PacketPtr tmp
= cpu
->dcache_pkt
;
998 if (tmp
->senderState
) {
999 // This is a packet from a split access.
1000 SplitFragmentSenderState
* send_state
=
1001 dynamic_cast<SplitFragmentSenderState
*>(tmp
->senderState
);
1003 PacketPtr big_pkt
= send_state
->bigPkt
;
1005 SplitMainSenderState
* main_send_state
=
1006 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
1007 assert(main_send_state
);
1009 if (sendTiming(tmp
)) {
1010 // If we were able to send without retrying, record that fact
1011 // and try sending the other fragment.
1012 send_state
->clearFromParent();
1013 int other_index
= main_send_state
->getPendingFragment();
1014 if (other_index
> 0) {
1015 tmp
= main_send_state
->fragments
[other_index
];
1016 cpu
->dcache_pkt
= tmp
;
1017 if ((big_pkt
->isRead() && cpu
->handleReadPacket(tmp
)) ||
1018 (big_pkt
->isWrite() && cpu
->handleWritePacket())) {
1019 main_send_state
->fragments
[other_index
] = NULL
;
1022 cpu
->_status
= DcacheWaitResponse
;
1023 // memory system takes ownership of packet
1024 cpu
->dcache_pkt
= NULL
;
1027 } else if (sendTiming(tmp
)) {
1028 cpu
->_status
= DcacheWaitResponse
;
1029 // memory system takes ownership of packet
1030 cpu
->dcache_pkt
= NULL
;
1034 TimingSimpleCPU::IprEvent::IprEvent(Packet
*_pkt
, TimingSimpleCPU
*_cpu
,
1036 : pkt(_pkt
), cpu(_cpu
)
1038 cpu
->schedule(this, t
);
1042 TimingSimpleCPU::IprEvent::process()
1044 cpu
->completeDataAccess(pkt
);
1048 TimingSimpleCPU::IprEvent::description() const
1050 return "Timing Simple CPU Delay IPR event";
1055 TimingSimpleCPU::printAddr(Addr a
)
1057 dcachePort
.printAddr(a
);
1061 ////////////////////////////////////////////////////////////////////////
1063 // TimingSimpleCPU Simulation Object
1066 TimingSimpleCPUParams::create()
1070 if (workload
.size() != 1)
1071 panic("only one workload allowed");
1073 return new TimingSimpleCPU(this);