X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcpu%2Fthread_state.cc;h=c62a7a3beba1957f6b9ada599f861b903674dfa4;hb=d85cd08113e61817fdf1df978f2713ba8b094996;hp=6a96560f194e63cf3238be1a56d59f099c43dcf5;hpb=4ed184eadefb16627f2807cb3dc7886bb1b920d1;p=gem5.git diff --git a/src/cpu/thread_state.cc b/src/cpu/thread_state.cc index 6a96560f1..c62a7a3be 100644 --- a/src/cpu/thread_state.cc +++ b/src/cpu/thread_state.cc @@ -29,30 +29,44 @@ */ #include "base/output.hh" +#include "cpu/base.hh" #include "cpu/profile.hh" #include "cpu/thread_state.hh" +#include "mem/port.hh" +#include "mem/translating_port.hh" #include "sim/serialize.hh" #if FULL_SYSTEM +#include "arch/kernel_stats.hh" #include "cpu/quiesce_event.hh" -#include "kern/kernel_stats.hh" +#include "mem/vport.hh" #endif #if FULL_SYSTEM -ThreadState::ThreadState(int _cpuId, int _tid) - : cpuId(_cpuId), tid(_tid), lastActivate(0), lastSuspend(0), +ThreadState::ThreadState(BaseCPU *cpu, ThreadID _tid) +#else +ThreadState::ThreadState(BaseCPU *cpu, ThreadID _tid, Process *_process) +#endif + : numInst(0), numLoad(0), _status(ThreadContext::Halted), + baseCpu(cpu), _threadId(_tid), lastActivate(0), lastSuspend(0), +#if FULL_SYSTEM profile(NULL), profileNode(NULL), profilePC(0), quiesceEvent(NULL), - funcExeInst(0), storeCondFailures(0) + kernelStats(NULL), physPort(NULL), virtPort(NULL), #else -ThreadState::ThreadState(int _cpuId, int _tid, Process *_process, - short _asid, MemObject *mem) - : cpuId(_cpuId), tid(_tid), lastActivate(0), lastSuspend(0), - process(_process), asid(_asid), - funcExeInst(0), storeCondFailures(0) + port(NULL), process(_process), #endif + funcExeInst(0), storeCondFailures(0) +{ +} + +ThreadState::~ThreadState() { - numInst = 0; - numLoad = 0; +#if !FULL_SYSTEM + if (port) { + delete port->getPeer(); + delete port; + } +#endif } void @@ -86,13 +100,47 @@ ThreadState::unserialize(Checkpoint *cp, const std::string §ion) Tick quiesceEndTick; UNSERIALIZE_SCALAR(quiesceEndTick); if (quiesceEndTick) - quiesceEvent->schedule(quiesceEndTick); + baseCpu->schedule(quiesceEvent, quiesceEndTick); if (kernelStats) kernelStats->unserialize(cp, section); #endif } #if FULL_SYSTEM +void +ThreadState::connectMemPorts(ThreadContext *tc) +{ + connectPhysPort(); + connectVirtPort(tc); +} + +void +ThreadState::connectPhysPort() +{ + // @todo: For now this disregards any older port that may have + // already existed. Fix this memory leak once the bus port IDs + // for functional ports is resolved. + if (physPort) + physPort->removeConn(); + else + physPort = new FunctionalPort(csprintf("%s-%d-funcport", + baseCpu->name(), _threadId)); + connectToMemFunc(physPort); +} + +void +ThreadState::connectVirtPort(ThreadContext *tc) +{ + // @todo: For now this disregards any older port that may have + // already existed. Fix this memory leak once the bus port IDs + // for functional ports is resolved. + if (virtPort) + virtPort->removeConn(); + else + virtPort = new VirtualPort(csprintf("%s-%d-vport", + baseCpu->name(), _threadId), tc); + connectToMemFunc(virtPort); +} void ThreadState::profileClear() @@ -108,4 +156,37 @@ ThreadState::profileSample() profile->sample(profileNode, profilePC); } +#else +TranslatingPort * +ThreadState::getMemPort() +{ + if (port != NULL) + return port; + + /* Use this port to for syscall emulation writes to memory. */ + port = new TranslatingPort(csprintf("%s-%d-funcport", baseCpu->name(), _threadId), + process, TranslatingPort::NextPage); + + connectToMemFunc(port); + + return port; +} #endif + +void +ThreadState::connectToMemFunc(Port *port) +{ + Port *dcache_port, *func_mem_port; + + dcache_port = baseCpu->getPort("dcache_port"); + assert(dcache_port != NULL); + + MemObject *mem_object = dcache_port->getPeer()->getOwner(); + assert(mem_object != NULL); + + func_mem_port = mem_object->getPort("functional"); + assert(func_mem_port != NULL); + + func_mem_port->setPeer(port); + port->setPeer(func_mem_port); +}