simple_thread.cc revision 393
11060SN/A/*
27944SGiacomo.Gabrielli@arm.com * Copyright (c) 2003 The Regents of The University of Michigan
37944SGiacomo.Gabrielli@arm.com * All rights reserved.
47944SGiacomo.Gabrielli@arm.com *
57944SGiacomo.Gabrielli@arm.com * Redistribution and use in source and binary forms, with or without
67944SGiacomo.Gabrielli@arm.com * modification, are permitted provided that the following conditions are
77944SGiacomo.Gabrielli@arm.com * met: redistributions of source code must retain the above copyright
87944SGiacomo.Gabrielli@arm.com * notice, this list of conditions and the following disclaimer;
97944SGiacomo.Gabrielli@arm.com * redistributions in binary form must reproduce the above copyright
107944SGiacomo.Gabrielli@arm.com * notice, this list of conditions and the following disclaimer in the
117944SGiacomo.Gabrielli@arm.com * documentation and/or other materials provided with the distribution;
127944SGiacomo.Gabrielli@arm.com * neither the name of the copyright holders nor the names of its
137944SGiacomo.Gabrielli@arm.com * contributors may be used to endorse or promote products derived from
142702Sktlim@umich.edu * this software without specific prior written permission.
156973Stjones1@inf.ed.ac.uk *
161060SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171060SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181060SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241060SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261060SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271060SN/A */
281060SN/A
291060SN/A#include <string>
301060SN/A
311060SN/A#include "cpu/base_cpu.hh"
321060SN/A#include "cpu/exec_context.hh"
331060SN/A
341060SN/A#ifdef FULL_SYSTEM
351060SN/A#include "sim/system.hh"
361060SN/A#else
371060SN/A#include "sim/process.hh"
381060SN/A#endif
391060SN/A
402665Ssaidi@eecs.umich.eduusing namespace std;
412665Ssaidi@eecs.umich.edu
426973Stjones1@inf.ed.ac.uk// constructor
431060SN/A#ifdef FULL_SYSTEM
441060SN/AExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, System *_sys,
451464SN/A                         AlphaItb *_itb, AlphaDtb *_dtb,
461464SN/A                         FunctionalMemory *_mem)
471060SN/A    : _status(ExecContext::Unallocated),
482731Sktlim@umich.edu      kernelStats(this, _cpu), cpu(_cpu), thread_num(_thread_num),
492292SN/A      cpu_id(-1), mem(_mem), itb(_itb), dtb(_dtb), system(_sys),
501464SN/A      memCtrl(_sys->memCtrl), physmem(_sys->physmem),
518733Sgeoffrey.blake@arm.com#ifdef FS_MEASURE
521060SN/A      swCtx(NULL),
537720Sgblack@eecs.umich.edu#endif
541060SN/A      func_exe_insn(0), storeCondFailures(0)
556658Snate@binkert.org{
568887Sgeoffrey.blake@arm.com    memset(&regs, 0, sizeof(RegFile));
573770Sgblack@eecs.umich.edu}
581464SN/A#else
591464SN/AExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
602669Sktlim@umich.edu                         Process *_process, int _asid)
611060SN/A    : _status(ExecContext::Unallocated),
626973Stjones1@inf.ed.ac.uk      cpu(_cpu), thread_num(_thread_num), cpu_id(-1),
632669Sktlim@umich.edu      process(_process), mem(process->getMemory()), asid(_asid),
647678Sgblack@eecs.umich.edu      func_exe_insn(0), storeCondFailures(0)
658817Sgblack@eecs.umich.edu{
662292SN/A}
676023Snate@binkert.org
681060SN/AExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
691060SN/A                         FunctionalMemory *_mem, int _asid)
701060SN/A    : cpu(_cpu), thread_num(_thread_num), process(0), mem(_mem), asid(_asid),
711060SN/A      func_exe_insn(0), storeCondFailures(0)
721060SN/A{
731060SN/A}
741060SN/A#endif
759044SAli.Saidi@ARM.com
761060SN/A
771060SN/Avoid
781060SN/AExecContext::takeOverFrom(ExecContext *oldContext)
792733Sktlim@umich.edu{
802733Sktlim@umich.edu    // some things should already be set up
811060SN/A    assert(mem == oldContext->mem);
822292SN/A#ifdef FULL_SYSTEM
832107SN/A    assert(system == oldContext->system);
842690Sktlim@umich.edu#else
852107SN/A    assert(process == oldContext->process);
862690Sktlim@umich.edu#endif
872690Sktlim@umich.edu
881060SN/A    // copy over functional state
892292SN/A    _status = oldContext->_status;
902292SN/A#ifdef FULL_SYSTEM
918486Sgblack@eecs.umich.edu    kernelStats = oldContext->kernelStats;
922292SN/A#endif
932292SN/A    regs = oldContext->regs;
942292SN/A    cpu_id = oldContext->cpu_id;
952292SN/A    func_exe_insn = oldContext->func_exe_insn;
961060SN/A
975543Ssaidi@eecs.umich.edu    storeCondFailures = 0;
988902Sandreas.hansson@arm.com
991060SN/A    oldContext->_status = ExecContext::Unallocated;
1001060SN/A}
1012292SN/A
1022107SN/A
1038502Sgblack@eecs.umich.eduvoid
1041060SN/AExecContext::serialize(ostream &os)
1051060SN/A{
1061060SN/A    SERIALIZE_ENUM(_status);
1071060SN/A    regs.serialize(os);
1081060SN/A    // thread_num and cpu_id are deterministic from the config
1091060SN/A    SERIALIZE_SCALAR(func_exe_insn);
1102292SN/A}
1111060SN/A
1121060SN/A
1135358Sgblack@eecs.umich.eduvoid
1145358Sgblack@eecs.umich.eduExecContext::unserialize(Checkpoint *cp, const std::string &section)
1155358Sgblack@eecs.umich.edu{
1165358Sgblack@eecs.umich.edu    UNSERIALIZE_ENUM(_status);
1175358Sgblack@eecs.umich.edu    regs.unserialize(cp, section);
1185358Sgblack@eecs.umich.edu    // thread_num and cpu_id are deterministic from the config
1195358Sgblack@eecs.umich.edu    UNSERIALIZE_SCALAR(func_exe_insn);
1205358Sgblack@eecs.umich.edu}
1215358Sgblack@eecs.umich.edu
1225358Sgblack@eecs.umich.edu
1235358Sgblack@eecs.umich.eduvoid
1245358Sgblack@eecs.umich.eduExecContext::activate(int delay)
1255358Sgblack@eecs.umich.edu{
1268444Sgblack@eecs.umich.edu    if (status() == Active)
1277520Sgblack@eecs.umich.edu        return;
1288444Sgblack@eecs.umich.edu
1298444Sgblack@eecs.umich.edu    _status = Active;
1307520Sgblack@eecs.umich.edu    cpu->activateContext(thread_num, delay);
1316974Stjones1@inf.ed.ac.uk}
1326974Stjones1@inf.ed.ac.uk
1336974Stjones1@inf.ed.ac.ukvoid
1346974Stjones1@inf.ed.ac.ukExecContext::suspend()
1356973Stjones1@inf.ed.ac.uk{
1366974Stjones1@inf.ed.ac.uk    if (status() == Suspended)
1376974Stjones1@inf.ed.ac.uk        return;
1386973Stjones1@inf.ed.ac.uk
1396973Stjones1@inf.ed.ac.uk#ifdef FULL_SYSTEM
1406973Stjones1@inf.ed.ac.uk    // Don't change the status from active if there are pending interrupts
1416973Stjones1@inf.ed.ac.uk    if (cpu->check_interrupts()) {
1421060SN/A        assert(status() == Active);
1437944SGiacomo.Gabrielli@arm.com        return;
1447944SGiacomo.Gabrielli@arm.com    }
1457944SGiacomo.Gabrielli@arm.com#endif
1467944SGiacomo.Gabrielli@arm.com
1477944SGiacomo.Gabrielli@arm.com    _status = Suspended;
1487944SGiacomo.Gabrielli@arm.com    cpu->suspendContext(thread_num);
1498545Ssaidi@eecs.umich.edu}
1508545Ssaidi@eecs.umich.edu
1518545Ssaidi@eecs.umich.eduvoid
1528545Ssaidi@eecs.umich.eduExecContext::deallocate()
1538545Ssaidi@eecs.umich.edu{
1548545Ssaidi@eecs.umich.edu    if (status() == Unallocated)
1558545Ssaidi@eecs.umich.edu        return;
1568545Ssaidi@eecs.umich.edu
1578545Ssaidi@eecs.umich.edu    _status = Unallocated;
1588545Ssaidi@eecs.umich.edu    cpu->deallocateContext(thread_num);
1598545Ssaidi@eecs.umich.edu}
1608545Ssaidi@eecs.umich.edu
1618545Ssaidi@eecs.umich.eduvoid
1627944SGiacomo.Gabrielli@arm.comExecContext::halt()
1637944SGiacomo.Gabrielli@arm.com{
1647944SGiacomo.Gabrielli@arm.com    if (status() == Halted)
1657944SGiacomo.Gabrielli@arm.com        return;
1667944SGiacomo.Gabrielli@arm.com
1677944SGiacomo.Gabrielli@arm.com    _status = Halted;
1687944SGiacomo.Gabrielli@arm.com    cpu->haltContext(thread_num);
1697944SGiacomo.Gabrielli@arm.com}
1707944SGiacomo.Gabrielli@arm.com
1717944SGiacomo.Gabrielli@arm.com
1727944SGiacomo.Gabrielli@arm.comvoid
1737944SGiacomo.Gabrielli@arm.comExecContext::regStats(const string &name)
1747944SGiacomo.Gabrielli@arm.com{
1757944SGiacomo.Gabrielli@arm.com#ifdef FULL_SYSTEM
1767944SGiacomo.Gabrielli@arm.com    kernelStats.regStats(name + ".kern");
1777944SGiacomo.Gabrielli@arm.com#endif
1787944SGiacomo.Gabrielli@arm.com}
1798733Sgeoffrey.blake@arm.com