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 "cpu/exetrace.hh"
36 #include "cpu/simple/timing.hh"
37 #include "mem/packet.hh"
38 #include "mem/packet_access.hh"
39 #include "params/TimingSimpleCPU.hh"
40 #include "sim/system.hh"
43 using namespace TheISA
;
46 TimingSimpleCPU::getPort(const std::string
&if_name
, int idx
)
48 if (if_name
== "dcache_port")
50 else if (if_name
== "icache_port")
53 panic("No Such Port\n");
57 TimingSimpleCPU::init()
61 for (int i
= 0; i
< threadContexts
.size(); ++i
) {
62 ThreadContext
*tc
= threadContexts
[i
];
64 // initialize CPU, including PC
65 TheISA::initCPU(tc
, _cpuId
);
71 TimingSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt
)
73 panic("TimingSimpleCPU doesn't expect recvAtomic callback!");
78 TimingSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt
)
80 //No internal storage to update, jusst return
85 TimingSimpleCPU::CpuPort::recvStatusChange(Status status
)
87 if (status
== RangeChange
) {
88 if (!snoopRangeSent
) {
89 snoopRangeSent
= true;
90 sendStatusChange(Port::RangeChange
);
95 panic("TimingSimpleCPU doesn't expect recvStatusChange callback!");
100 TimingSimpleCPU::CpuPort::TickEvent::schedule(PacketPtr _pkt
, Tick t
)
103 cpu
->schedule(this, t
);
106 TimingSimpleCPU::TimingSimpleCPU(TimingSimpleCPUParams
*p
)
107 : BaseSimpleCPU(p
), fetchTranslation(this), icachePort(this, p
->clock
),
108 dcachePort(this, p
->clock
), fetchEvent(this)
112 icachePort
.snoopRangeSent
= false;
113 dcachePort
.snoopRangeSent
= false;
115 ifetch_pkt
= dcache_pkt
= NULL
;
118 changeState(SimObject::Running
);
122 TimingSimpleCPU::~TimingSimpleCPU()
127 TimingSimpleCPU::serialize(ostream
&os
)
129 SimObject::State so_state
= SimObject::getState();
130 SERIALIZE_ENUM(so_state
);
131 BaseSimpleCPU::serialize(os
);
135 TimingSimpleCPU::unserialize(Checkpoint
*cp
, const string
§ion
)
137 SimObject::State so_state
;
138 UNSERIALIZE_ENUM(so_state
);
139 BaseSimpleCPU::unserialize(cp
, section
);
143 TimingSimpleCPU::drain(Event
*drain_event
)
145 // TimingSimpleCPU is ready to drain if it's not waiting for
146 // an access to complete.
147 if (_status
== Idle
|| _status
== Running
|| _status
== SwitchedOut
) {
148 changeState(SimObject::Drained
);
151 changeState(SimObject::Draining
);
152 drainEvent
= drain_event
;
158 TimingSimpleCPU::resume()
160 DPRINTF(SimpleCPU
, "Resume\n");
161 if (_status
!= SwitchedOut
&& _status
!= Idle
) {
162 assert(system
->getMemoryMode() == Enums::timing
);
164 if (fetchEvent
.scheduled())
165 deschedule(fetchEvent
);
167 schedule(fetchEvent
, nextCycle());
170 changeState(SimObject::Running
);
174 TimingSimpleCPU::switchOut()
176 assert(_status
== Running
|| _status
== Idle
);
177 _status
= SwitchedOut
;
178 numCycles
+= tickToCycles(curTick
- previousTick
);
180 // If we've been scheduled to resume but are then told to switch out,
181 // we'll need to cancel it.
182 if (fetchEvent
.scheduled())
183 deschedule(fetchEvent
);
188 TimingSimpleCPU::takeOverFrom(BaseCPU
*oldCPU
)
190 BaseCPU::takeOverFrom(oldCPU
, &icachePort
, &dcachePort
);
192 // if any of this CPU's ThreadContexts are active, mark the CPU as
193 // running and schedule its tick event.
194 for (int i
= 0; i
< threadContexts
.size(); ++i
) {
195 ThreadContext
*tc
= threadContexts
[i
];
196 if (tc
->status() == ThreadContext::Active
&& _status
!= Running
) {
202 if (_status
!= Running
) {
205 assert(threadContexts
.size() == 1);
206 previousTick
= curTick
;
211 TimingSimpleCPU::activateContext(int thread_num
, int delay
)
213 DPRINTF(SimpleCPU
, "ActivateContext %d (%d cycles)\n", thread_num
, delay
);
215 assert(thread_num
== 0);
218 assert(_status
== Idle
);
223 // kick things off by initiating the fetch of the next instruction
224 schedule(fetchEvent
, nextCycle(curTick
+ ticks(delay
)));
229 TimingSimpleCPU::suspendContext(int thread_num
)
231 DPRINTF(SimpleCPU
, "SuspendContext %d\n", thread_num
);
233 assert(thread_num
== 0);
239 assert(_status
== Running
);
241 // just change status to Idle... if status != Running,
242 // completeInst() will not initiate fetch of next instruction.
249 TimingSimpleCPU::handleReadPacket(PacketPtr pkt
)
251 RequestPtr req
= pkt
->req
;
252 if (req
->isMmapedIpr()) {
254 delay
= TheISA::handleIprRead(thread
->getTC(), pkt
);
255 new IprEvent(pkt
, this, nextCycle(curTick
+ delay
));
256 _status
= DcacheWaitResponse
;
258 } else if (!dcachePort
.sendTiming(pkt
)) {
259 _status
= DcacheRetry
;
262 _status
= DcacheWaitResponse
;
263 // memory system takes ownership of packet
266 return dcache_pkt
== NULL
;
270 TimingSimpleCPU::sendData(Fault fault
, RequestPtr req
,
271 uint8_t *data
, uint64_t *res
, bool read
)
274 if (fault
!= NoFault
) {
278 translationFault(fault
);
282 buildPacket(pkt
, req
, read
);
283 pkt
->dataDynamic
<uint8_t>(data
);
284 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
287 completeDataAccess(pkt
);
289 handleReadPacket(pkt
);
291 bool do_access
= true; // flag to suppress cache access
294 do_access
= TheISA::handleLockedWrite(thread
, req
);
295 } else if (req
->isCondSwap()) {
297 req
->setExtraData(*res
);
304 _status
= DcacheWaitResponse
;
305 completeDataAccess(pkt
);
311 TimingSimpleCPU::sendSplitData(Fault fault1
, Fault fault2
,
312 RequestPtr req1
, RequestPtr req2
, RequestPtr req
,
313 uint8_t *data
, bool read
)
316 if (fault1
!= NoFault
|| fault2
!= NoFault
) {
320 if (fault1
!= NoFault
)
321 translationFault(fault1
);
322 else if (fault2
!= NoFault
)
323 translationFault(fault2
);
326 PacketPtr pkt1
, pkt2
;
327 buildSplitPacket(pkt1
, pkt2
, req1
, req2
, req
, data
, read
);
328 if (req
->getFlags().isSet(Request::NO_ACCESS
)) {
330 pkt1
->makeResponse();
331 completeDataAccess(pkt1
);
333 if (handleReadPacket(pkt1
)) {
334 SplitFragmentSenderState
* send_state
=
335 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
336 send_state
->clearFromParent();
337 if (handleReadPacket(pkt2
)) {
338 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
340 send_state
->clearFromParent();
345 if (handleWritePacket()) {
346 SplitFragmentSenderState
* send_state
=
347 dynamic_cast<SplitFragmentSenderState
*>(pkt1
->senderState
);
348 send_state
->clearFromParent();
350 if (handleWritePacket()) {
351 send_state
= dynamic_cast<SplitFragmentSenderState
*>(
353 send_state
->clearFromParent();
360 TimingSimpleCPU::translationFault(Fault fault
)
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
->isMmapedIpr() && !req2
->isMmapedIpr());
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
->dataDynamic
<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);
436 TimingSimpleCPU::read(Addr addr
, T
&data
, unsigned flags
)
440 const int thread_id
= 0;
441 const Addr pc
= thread
->readPC();
442 int block_size
= dcachePort
.peerBlockSize();
443 int data_size
= sizeof(T
);
445 RequestPtr req
= new Request(asid
, addr
, data_size
,
446 flags
, pc
, _cpuId
, thread_id
);
448 Addr split_addr
= roundDown(addr
+ data_size
- 1, block_size
);
449 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
452 _status
= DTBWaitResponse
;
453 if (split_addr
> addr
) {
454 RequestPtr req1
, req2
;
455 assert(!req
->isLLSC() && !req
->isSwap());
456 req
->splitOnVaddr(split_addr
, req1
, req2
);
458 typedef SplitDataTranslation::WholeTranslationState WholeState
;
459 WholeState
*state
= new WholeState(req1
, req2
, req
,
460 (uint8_t *)(new T
), BaseTLB::Read
);
461 thread
->dtb
->translateTiming(req1
, tc
,
462 new SplitDataTranslation(this, 0, state
), BaseTLB::Read
);
463 thread
->dtb
->translateTiming(req2
, tc
,
464 new SplitDataTranslation(this, 1, state
), BaseTLB::Read
);
466 DataTranslation
*translation
=
467 new DataTranslation(this, (uint8_t *)(new T
), NULL
, BaseTLB::Read
);
468 thread
->dtb
->translateTiming(req
, tc
, translation
, BaseTLB::Read
);
472 traceData
->setData(data
);
473 traceData
->setAddr(addr
);
476 // This will need a new way to tell if it has a dcache attached.
477 if (req
->isUncacheable())
478 recordEvent("Uncached Read");
483 #ifndef DOXYGEN_SHOULD_SKIP_THIS
487 TimingSimpleCPU::read(Addr addr
, Twin64_t
&data
, unsigned flags
);
491 TimingSimpleCPU::read(Addr addr
, Twin32_t
&data
, unsigned flags
);
495 TimingSimpleCPU::read(Addr addr
, uint64_t &data
, unsigned flags
);
499 TimingSimpleCPU::read(Addr addr
, uint32_t &data
, unsigned flags
);
503 TimingSimpleCPU::read(Addr addr
, uint16_t &data
, unsigned flags
);
507 TimingSimpleCPU::read(Addr addr
, uint8_t &data
, unsigned flags
);
509 #endif //DOXYGEN_SHOULD_SKIP_THIS
513 TimingSimpleCPU::read(Addr addr
, double &data
, unsigned flags
)
515 return read(addr
, *(uint64_t*)&data
, flags
);
520 TimingSimpleCPU::read(Addr addr
, float &data
, unsigned flags
)
522 return read(addr
, *(uint32_t*)&data
, flags
);
528 TimingSimpleCPU::read(Addr addr
, int32_t &data
, unsigned flags
)
530 return read(addr
, (uint32_t&)data
, flags
);
534 TimingSimpleCPU::handleWritePacket()
536 RequestPtr req
= dcache_pkt
->req
;
537 if (req
->isMmapedIpr()) {
539 delay
= TheISA::handleIprWrite(thread
->getTC(), dcache_pkt
);
540 new IprEvent(dcache_pkt
, this, nextCycle(curTick
+ delay
));
541 _status
= DcacheWaitResponse
;
543 } else if (!dcachePort
.sendTiming(dcache_pkt
)) {
544 _status
= DcacheRetry
;
546 _status
= DcacheWaitResponse
;
547 // memory system takes ownership of packet
550 return dcache_pkt
== NULL
;
555 TimingSimpleCPU::write(T data
, Addr addr
, unsigned flags
, uint64_t *res
)
558 const int thread_id
= 0;
559 const Addr pc
= thread
->readPC();
560 int block_size
= dcachePort
.peerBlockSize();
561 int data_size
= sizeof(T
);
563 RequestPtr req
= new Request(asid
, addr
, data_size
,
564 flags
, pc
, _cpuId
, thread_id
);
566 Addr split_addr
= roundDown(addr
+ data_size
- 1, block_size
);
567 assert(split_addr
<= addr
|| split_addr
- addr
< block_size
);
570 *dataP
= TheISA::htog(data
);
571 _status
= DTBWaitResponse
;
572 if (split_addr
> addr
) {
573 RequestPtr req1
, req2
;
574 assert(!req
->isLLSC() && !req
->isSwap());
575 req
->splitOnVaddr(split_addr
, req1
, req2
);
577 typedef SplitDataTranslation::WholeTranslationState WholeState
;
578 WholeState
*state
= new WholeState(req1
, req2
, req
,
579 (uint8_t *)dataP
, BaseTLB::Write
);
580 thread
->dtb
->translateTiming(req1
, tc
,
581 new SplitDataTranslation(this, 0, state
), BaseTLB::Write
);
582 thread
->dtb
->translateTiming(req2
, tc
,
583 new SplitDataTranslation(this, 1, state
), BaseTLB::Write
);
585 DataTranslation
*translation
=
586 new DataTranslation(this, (uint8_t *)dataP
, res
, BaseTLB::Write
);
587 thread
->dtb
->translateTiming(req
, tc
, translation
, BaseTLB::Write
);
591 traceData
->setAddr(req
->getVaddr());
592 traceData
->setData(data
);
595 // This will need a new way to tell if it's hooked up to a cache or not.
596 if (req
->isUncacheable())
597 recordEvent("Uncached Write");
599 // If the write needs to have a fault on the access, consider calling
600 // changeStatus() and changing it to "bad addr write" or something.
605 #ifndef DOXYGEN_SHOULD_SKIP_THIS
608 TimingSimpleCPU::write(Twin32_t data
, Addr addr
,
609 unsigned flags
, uint64_t *res
);
613 TimingSimpleCPU::write(Twin64_t data
, Addr addr
,
614 unsigned flags
, uint64_t *res
);
618 TimingSimpleCPU::write(uint64_t data
, Addr addr
,
619 unsigned flags
, uint64_t *res
);
623 TimingSimpleCPU::write(uint32_t data
, Addr addr
,
624 unsigned flags
, uint64_t *res
);
628 TimingSimpleCPU::write(uint16_t data
, Addr addr
,
629 unsigned flags
, uint64_t *res
);
633 TimingSimpleCPU::write(uint8_t data
, Addr addr
,
634 unsigned flags
, uint64_t *res
);
636 #endif //DOXYGEN_SHOULD_SKIP_THIS
640 TimingSimpleCPU::write(double data
, Addr addr
, unsigned flags
, uint64_t *res
)
642 return write(*(uint64_t*)&data
, addr
, flags
, res
);
647 TimingSimpleCPU::write(float data
, Addr addr
, unsigned flags
, uint64_t *res
)
649 return write(*(uint32_t*)&data
, addr
, flags
, res
);
655 TimingSimpleCPU::write(int32_t data
, Addr addr
, unsigned flags
, uint64_t *res
)
657 return write((uint32_t)data
, addr
, flags
, res
);
662 TimingSimpleCPU::fetch()
664 DPRINTF(SimpleCPU
, "Fetch\n");
666 if (!curStaticInst
|| !curStaticInst
->isDelayedCommit())
667 checkForInterrupts();
671 bool fromRom
= isRomMicroPC(thread
->readMicroPC());
673 if (!fromRom
&& !curMacroStaticInst
) {
674 Request
*ifetch_req
= new Request();
675 ifetch_req
->setThreadContext(_cpuId
, /* thread ID */ 0);
676 setupFetchRequest(ifetch_req
);
677 thread
->itb
->translateTiming(ifetch_req
, tc
, &fetchTranslation
,
680 _status
= IcacheWaitResponse
;
681 completeIfetch(NULL
);
683 numCycles
+= tickToCycles(curTick
- previousTick
);
684 previousTick
= curTick
;
690 TimingSimpleCPU::sendFetch(Fault fault
, RequestPtr req
, ThreadContext
*tc
)
692 if (fault
== NoFault
) {
693 ifetch_pkt
= new Packet(req
, MemCmd::ReadReq
, Packet::Broadcast
);
694 ifetch_pkt
->dataStatic(&inst
);
696 if (!icachePort
.sendTiming(ifetch_pkt
)) {
697 // Need to wait for retry
698 _status
= IcacheRetry
;
700 // Need to wait for cache to respond
701 _status
= IcacheWaitResponse
;
702 // ownership of packet transferred to memory system
707 // fetch fault: advance directly to next instruction (fault handler)
711 numCycles
+= tickToCycles(curTick
- previousTick
);
712 previousTick
= curTick
;
717 TimingSimpleCPU::advanceInst(Fault fault
)
719 if (fault
!= NoFault
|| !stayAtPC
)
722 if (_status
== Running
) {
723 // kick off fetch of next instruction... callback from icache
724 // response will cause that instruction to be executed,
725 // keeping the CPU running.
732 TimingSimpleCPU::completeIfetch(PacketPtr pkt
)
734 DPRINTF(SimpleCPU
, "Complete ICache Fetch\n");
736 // received a response from the icache: execute the received
739 assert(!pkt
|| !pkt
->isError());
740 assert(_status
== IcacheWaitResponse
);
744 numCycles
+= tickToCycles(curTick
- previousTick
);
745 previousTick
= curTick
;
747 if (getState() == SimObject::Draining
) {
759 curStaticInst
->isMemRef() && !curStaticInst
->isDataPrefetch()) {
760 // load or store: just send to dcache
761 Fault fault
= curStaticInst
->initiateAcc(this, traceData
);
762 if (_status
!= Running
) {
763 // instruction will complete in dcache response callback
764 assert(_status
== DcacheWaitResponse
||
765 _status
== DcacheRetry
|| DTBWaitResponse
);
766 assert(fault
== NoFault
);
768 if (fault
!= NoFault
&& traceData
) {
769 // If there was a fault, we shouldn't trace this instruction.
775 // @todo remove me after debugging with legion done
776 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
777 curStaticInst
->isFirstMicroop()))
781 } else if (curStaticInst
) {
782 // non-memory instruction: execute completely now
783 Fault fault
= curStaticInst
->execute(this, traceData
);
785 // keep an instruction count
786 if (fault
== NoFault
)
788 else if (traceData
) {
789 // If there was a fault, we shouldn't trace this instruction.
795 // @todo remove me after debugging with legion done
796 if (curStaticInst
&& (!curStaticInst
->isMicroop() ||
797 curStaticInst
->isFirstMicroop()))
801 advanceInst(NoFault
);
811 TimingSimpleCPU::IcachePort::ITickEvent::process()
813 cpu
->completeIfetch(pkt
);
817 TimingSimpleCPU::IcachePort::recvTiming(PacketPtr pkt
)
819 if (pkt
->isResponse() && !pkt
->wasNacked()) {
820 // delay processing of returned data until next CPU clock edge
821 Tick next_tick
= cpu
->nextCycle(curTick
);
823 if (next_tick
== curTick
)
824 cpu
->completeIfetch(pkt
);
826 tickEvent
.schedule(pkt
, next_tick
);
830 else if (pkt
->wasNacked()) {
831 assert(cpu
->_status
== IcacheWaitResponse
);
833 if (!sendTiming(pkt
)) {
834 cpu
->_status
= IcacheRetry
;
835 cpu
->ifetch_pkt
= pkt
;
838 //Snooping a Coherence Request, do nothing
843 TimingSimpleCPU::IcachePort::recvRetry()
845 // we shouldn't get a retry unless we have a packet that we're
846 // waiting to transmit
847 assert(cpu
->ifetch_pkt
!= NULL
);
848 assert(cpu
->_status
== IcacheRetry
);
849 PacketPtr tmp
= cpu
->ifetch_pkt
;
850 if (sendTiming(tmp
)) {
851 cpu
->_status
= IcacheWaitResponse
;
852 cpu
->ifetch_pkt
= NULL
;
857 TimingSimpleCPU::completeDataAccess(PacketPtr pkt
)
859 // received a response from the dcache: complete the load or store
861 assert(!pkt
->isError());
863 numCycles
+= tickToCycles(curTick
- previousTick
);
864 previousTick
= curTick
;
866 if (pkt
->senderState
) {
867 SplitFragmentSenderState
* send_state
=
868 dynamic_cast<SplitFragmentSenderState
*>(pkt
->senderState
);
872 PacketPtr big_pkt
= send_state
->bigPkt
;
875 SplitMainSenderState
* main_send_state
=
876 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
877 assert(main_send_state
);
878 // Record the fact that this packet is no longer outstanding.
879 assert(main_send_state
->outstanding
!= 0);
880 main_send_state
->outstanding
--;
882 if (main_send_state
->outstanding
) {
885 delete main_send_state
;
886 big_pkt
->senderState
= NULL
;
891 assert(_status
== DcacheWaitResponse
|| _status
== DTBWaitResponse
);
894 Fault fault
= curStaticInst
->completeAcc(pkt
, this, traceData
);
896 // keep an instruction count
897 if (fault
== NoFault
)
899 else if (traceData
) {
900 // If there was a fault, we shouldn't trace this instruction.
905 // the locked flag may be cleared on the response packet, so check
906 // pkt->req and not pkt to see if it was a load-locked
907 if (pkt
->isRead() && pkt
->req
->isLLSC()) {
908 TheISA::handleLockedRead(thread
, pkt
->req
);
916 if (getState() == SimObject::Draining
) {
928 TimingSimpleCPU::completeDrain()
930 DPRINTF(Config
, "Done draining\n");
931 changeState(SimObject::Drained
);
932 drainEvent
->process();
936 TimingSimpleCPU::DcachePort::setPeer(Port
*port
)
941 // Update the ThreadContext's memory ports (Functional/Virtual
943 cpu
->tcBase()->connectMemPorts(cpu
->tcBase());
948 TimingSimpleCPU::DcachePort::recvTiming(PacketPtr pkt
)
950 if (pkt
->isResponse() && !pkt
->wasNacked()) {
951 // delay processing of returned data until next CPU clock edge
952 Tick next_tick
= cpu
->nextCycle(curTick
);
954 if (next_tick
== curTick
) {
955 cpu
->completeDataAccess(pkt
);
957 tickEvent
.schedule(pkt
, next_tick
);
962 else if (pkt
->wasNacked()) {
963 assert(cpu
->_status
== DcacheWaitResponse
);
965 if (!sendTiming(pkt
)) {
966 cpu
->_status
= DcacheRetry
;
967 cpu
->dcache_pkt
= pkt
;
970 //Snooping a Coherence Request, do nothing
975 TimingSimpleCPU::DcachePort::DTickEvent::process()
977 cpu
->completeDataAccess(pkt
);
981 TimingSimpleCPU::DcachePort::recvRetry()
983 // we shouldn't get a retry unless we have a packet that we're
984 // waiting to transmit
985 assert(cpu
->dcache_pkt
!= NULL
);
986 assert(cpu
->_status
== DcacheRetry
);
987 PacketPtr tmp
= cpu
->dcache_pkt
;
988 if (tmp
->senderState
) {
989 // This is a packet from a split access.
990 SplitFragmentSenderState
* send_state
=
991 dynamic_cast<SplitFragmentSenderState
*>(tmp
->senderState
);
993 PacketPtr big_pkt
= send_state
->bigPkt
;
995 SplitMainSenderState
* main_send_state
=
996 dynamic_cast<SplitMainSenderState
*>(big_pkt
->senderState
);
997 assert(main_send_state
);
999 if (sendTiming(tmp
)) {
1000 // If we were able to send without retrying, record that fact
1001 // and try sending the other fragment.
1002 send_state
->clearFromParent();
1003 int other_index
= main_send_state
->getPendingFragment();
1004 if (other_index
> 0) {
1005 tmp
= main_send_state
->fragments
[other_index
];
1006 cpu
->dcache_pkt
= tmp
;
1007 if ((big_pkt
->isRead() && cpu
->handleReadPacket(tmp
)) ||
1008 (big_pkt
->isWrite() && cpu
->handleWritePacket())) {
1009 main_send_state
->fragments
[other_index
] = NULL
;
1012 cpu
->_status
= DcacheWaitResponse
;
1013 // memory system takes ownership of packet
1014 cpu
->dcache_pkt
= NULL
;
1017 } else if (sendTiming(tmp
)) {
1018 cpu
->_status
= DcacheWaitResponse
;
1019 // memory system takes ownership of packet
1020 cpu
->dcache_pkt
= NULL
;
1024 TimingSimpleCPU::IprEvent::IprEvent(Packet
*_pkt
, TimingSimpleCPU
*_cpu
,
1026 : pkt(_pkt
), cpu(_cpu
)
1028 cpu
->schedule(this, t
);
1032 TimingSimpleCPU::IprEvent::process()
1034 cpu
->completeDataAccess(pkt
);
1038 TimingSimpleCPU::IprEvent::description() const
1040 return "Timing Simple CPU Delay IPR event";
1045 TimingSimpleCPU::printAddr(Addr a
)
1047 dcachePort
.printAddr(a
);
1051 ////////////////////////////////////////////////////////////////////////
1053 // TimingSimpleCPU Simulation Object
1056 TimingSimpleCPUParams::create()
1060 if (workload
.size() != 1)
1061 panic("only one workload allowed");
1063 return new TimingSimpleCPU(this);