simple_thread.cc revision 1917
12SN/A/* 212276Sanouk.vanlaer@arm.com * Copyright (c) 2001-2005 The Regents of The University of Michigan 38707Sandreas.hansson@arm.com * All rights reserved. 48707Sandreas.hansson@arm.com * 58707Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68707Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78707Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98707Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118707Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128707Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 138707Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 141762SN/A * this software without specific prior written permission. 157897Shestness@cs.utexas.edu * 169983Sstever@gmail.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 179983Sstever@gmail.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272SN/A */ 282SN/A 292SN/A#include <string> 302SN/A 312SN/A#include "cpu/base.hh" 322SN/A#include "cpu/exec_context.hh" 332SN/A 342SN/A#if FULL_SYSTEM 352SN/A#include "base/callback.hh" 362SN/A#include "base/cprintf.hh" 372SN/A#include "base/output.hh" 382SN/A#include "cpu/profile.hh" 392SN/A#include "kern/kernel_stats.hh" 402SN/A#include "sim/serialize.hh" 412SN/A#include "sim/sim_exit.hh" 422665Ssaidi@eecs.umich.edu#include "sim/system.hh" 432665Ssaidi@eecs.umich.edu#include "targetarch/stacktrace.hh" 442665Ssaidi@eecs.umich.edu#else 457897Shestness@cs.utexas.edu#include "sim/process.hh" 462SN/A#endif 472SN/A 4811793Sbrandon.potter@amd.comusing namespace std; 4911793Sbrandon.potter@amd.com 501388SN/A// constructor 518229Snate@binkert.org#if FULL_SYSTEM 522SN/AExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, System *_sys, 532SN/A AlphaITB *_itb, AlphaDTB *_dtb, 5412406Sgabeblack@google.com FunctionalMemory *_mem) 5511793Sbrandon.potter@amd.com : _status(ExecContext::Unallocated), cpu(_cpu), thread_num(_thread_num), 568229Snate@binkert.org cpu_id(-1), mem(_mem), itb(_itb), dtb(_dtb), system(_sys), 5712334Sgabeblack@google.com memctrl(_sys->memctrl), physmem(_sys->physmem), 581388SN/A kernelBinning(system->kernelBinning), bin(kernelBinning->bin), 595529Snate@binkert.org fnbin(kernelBinning->fnbin), profile(NULL), 6010529Smorr@cs.wisc.edu func_exe_inst(0), storeCondFailures(0) 612651Ssaidi@eecs.umich.edu{ 628229Snate@binkert.org kernelStats = new Kernel::Statistics(this); 632680Sktlim@umich.edu memset(®s, 0, sizeof(RegFile)); 6410529Smorr@cs.wisc.edu 658232Snate@binkert.org if (cpu->params->profile) { 6610529Smorr@cs.wisc.edu profile = new FunctionProfile(system->allSymtab); 675529Snate@binkert.org Callback *cb = 6811526Sdavid.guillen@arm.com new MakeCallback<ExecContext, &ExecContext::dumpFuncProfile>(this); 698779Sgblack@eecs.umich.edu registerExitCallback(cb); 702190SN/A } 7156SN/A 728229Snate@binkert.org // let's fill with a dummy node for now so we don't get a segfault 732190SN/A // on the first cycle when there's no node available. 742SN/A static ProfileNode dummyNode; 752359SN/A profileNode = &dummyNode; 762359SN/A profilePC = 3; 772359SN/A} 782SN/A#else 792SN/AExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, 802SN/A Process *_process, int _asid) 812SN/A : _status(ExecContext::Unallocated), 822SN/A cpu(_cpu), thread_num(_thread_num), cpu_id(-1), 832SN/A process(_process), mem(process->getMemory()), asid(_asid), 842SN/A func_exe_inst(0), storeCondFailures(0) 852SN/A{ 862SN/A memset(®s, 0, sizeof(RegFile)); 875606Snate@binkert.org} 886144Sksewell@umich.edu 896144Sksewell@umich.eduExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, 903126Sktlim@umich.edu FunctionalMemory *_mem, int _asid) 916144Sksewell@umich.edu : cpu(_cpu), thread_num(_thread_num), process(0), mem(_mem), asid(_asid), 927823Ssteve.reinhardt@amd.com func_exe_inst(0), storeCondFailures(0) 933126Sktlim@umich.edu{ 943126Sktlim@umich.edu memset(®s, 0, sizeof(RegFile)); 952356SN/A} 962356SN/A#endif 972356SN/A 988834Satgutier@umich.eduExecContext::~ExecContext() 9910786Smalek.musleh@gmail.com{ 10010786Smalek.musleh@gmail.com#if FULL_SYSTEM 10110786Smalek.musleh@gmail.com delete kernelStats; 10210786Smalek.musleh@gmail.com#endif 10311321Ssteve.reinhardt@amd.com} 10410786Smalek.musleh@gmail.com 10510786Smalek.musleh@gmail.com#if FULL_SYSTEM 10610786Smalek.musleh@gmail.comvoid 1072356SN/AExecContext::dumpFuncProfile() 1089179Sandreas.hansson@arm.com{ 1092367SN/A std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name())); 1106144Sksewell@umich.edu profile->dump(this, *os); 1116144Sksewell@umich.edu} 1126144Sksewell@umich.edu#endif 1132356SN/A 1142367SN/Avoid 1156144Sksewell@umich.eduExecContext::takeOverFrom(ExecContext *oldContext) 1167823Ssteve.reinhardt@amd.com{ 1176144Sksewell@umich.edu // some things should already be set up 1182367SN/A assert(mem == oldContext->mem); 1192356SN/A#if FULL_SYSTEM 1202356SN/A assert(system == oldContext->system); 1212356SN/A#else 1222356SN/A assert(process == oldContext->process); 1235336Shines@cs.fsu.edu#endif 1242356SN/A 1254873Sstever@eecs.umich.edu // copy over functional state 1262356SN/A _status = oldContext->_status; 1272356SN/A regs = oldContext->regs; 1288876Sandreas.hansson@arm.com cpu_id = oldContext->cpu_id; 12910190Sakash.bagdia@arm.com func_exe_inst = oldContext->func_exe_inst; 13012680Sgiacomo.travaglini@arm.com 13112680Sgiacomo.travaglini@arm.com storeCondFailures = 0; 13211050Sandreas.hansson@arm.com 1339814Sandreas.hansson@arm.com oldContext->_status = ExecContext::Unallocated; 1349220Shestness@cs.wisc.edu} 13510529Smorr@cs.wisc.edu 13612284Sjose.marinho@arm.comvoid 13710537Sandreas.hansson@arm.comExecContext::serialize(ostream &os) 13810537Sandreas.hansson@arm.com{ 13911877Sbrandon.potter@amd.com SERIALIZE_ENUM(_status); 14012276Sanouk.vanlaer@arm.com regs.serialize(os); 14112276Sanouk.vanlaer@arm.com // thread_num and cpu_id are deterministic from the config 14212277Sjose.marinho@arm.com SERIALIZE_SCALAR(func_exe_inst); 14312276Sanouk.vanlaer@arm.com SERIALIZE_SCALAR(inst); 1442SN/A 1455712Shsul@eecs.umich.edu#if FULL_SYSTEM 1465712Shsul@eecs.umich.edu kernelStats->serialize(os); 1475712Shsul@eecs.umich.edu#endif 1485712Shsul@eecs.umich.edu} 1495712Shsul@eecs.umich.edu 1502SN/A 1512SN/Avoid 1522SN/AExecContext::unserialize(Checkpoint *cp, const std::string §ion) 15310190Sakash.bagdia@arm.com{ 15410190Sakash.bagdia@arm.com UNSERIALIZE_ENUM(_status); 1555712Shsul@eecs.umich.edu regs.unserialize(cp, section); 1566221Snate@binkert.org // thread_num and cpu_id are deterministic from the config 1576221Snate@binkert.org UNSERIALIZE_SCALAR(func_exe_inst); 1582SN/A UNSERIALIZE_SCALAR(inst); 1592SN/A 1606221Snate@binkert.org#if FULL_SYSTEM 1616221Snate@binkert.org kernelStats->unserialize(cp, section); 1626221Snate@binkert.org#endif 1636221Snate@binkert.org} 1642SN/A 1652SN/A 1662SN/Avoid 1672SN/AExecContext::activate(int delay) 1685606Snate@binkert.org{ 1695606Snate@binkert.org if (status() == Active) 1709749Sandreas@sandberg.pp.se return; 1719749Sandreas@sandberg.pp.se 1725606Snate@binkert.org _status = Active; 1732SN/A cpu->activateContext(thread_num, delay); 1749647Sdam.sunwoo@arm.com} 1759647Sdam.sunwoo@arm.com 1769647Sdam.sunwoo@arm.comvoid 1779647Sdam.sunwoo@arm.comExecContext::suspend() 1789647Sdam.sunwoo@arm.com{ 1799647Sdam.sunwoo@arm.com if (status() == Suspended) 1809749Sandreas@sandberg.pp.se return; 1819749Sandreas@sandberg.pp.se 1829647Sdam.sunwoo@arm.com#if FULL_SYSTEM 1839647Sdam.sunwoo@arm.com // Don't change the status from active if there are pending interrupts 1841400SN/A if (cpu->check_interrupts()) { 1855606Snate@binkert.org assert(status() == Active); 1865606Snate@binkert.org return; 1872SN/A } 1882SN/A#endif 1892SN/A 1902SN/A _status = Suspended; 1916221Snate@binkert.org cpu->suspendContext(thread_num); 1926221Snate@binkert.org} 1935606Snate@binkert.org 1946670Shsul@eecs.umich.eduvoid 1955606Snate@binkert.orgExecContext::deallocate() 1962SN/A{ 1972SN/A if (status() == Unallocated) 198124SN/A return; 1996221Snate@binkert.org 2006221Snate@binkert.org _status = Unallocated; 2016221Snate@binkert.org cpu->deallocateContext(thread_num); 202124SN/A} 203124SN/A 204124SN/Avoid 205124SN/AExecContext::halt() 2065606Snate@binkert.org{ 2075606Snate@binkert.org if (status() == Halted) 2089749Sandreas@sandberg.pp.se return; 2099749Sandreas@sandberg.pp.se 2105606Snate@binkert.org _status = Halted; 211124SN/A cpu->haltContext(thread_num); 2121400SN/A} 2135606Snate@binkert.org 214124SN/A 215124SN/Avoid 216124SN/AExecContext::regStats(const string &name) 217124SN/A{ 2186221Snate@binkert.org#if FULL_SYSTEM 2196221Snate@binkert.org kernelStats->regStats(name + ".kern"); 2205606Snate@binkert.org#endif 2216221Snate@binkert.org} 2225606Snate@binkert.org 223124SN/Avoid 224124SN/AExecContext::trap(Fault fault) 2251191SN/A{ 2265529Snate@binkert.org //TheISA::trap(fault); //One possible way to do it... 2278634Schris.emmons@arm.com 22811359Sandreas@sandberg.pp.se /** @todo: Going to hack it for now. Do a true fixup later. */ 2298634Schris.emmons@arm.com#if FULL_SYSTEM 2301191SN/A ev5_trap(fault); 2315529Snate@binkert.org#else 2321191SN/A fatal("fault (%d) detected @ PC 0x%08p", fault, readPC()); 2335529Snate@binkert.org#endif 2341191SN/A} 2351191SN/A