simple_thread.cc revision 360
19883Sandreas@sandberg.pp.se/*
29883Sandreas@sandberg.pp.se * Copyright (c) 2003 The Regents of The University of Michigan
39883Sandreas@sandberg.pp.se * All rights reserved.
49883Sandreas@sandberg.pp.se *
59883Sandreas@sandberg.pp.se * Redistribution and use in source and binary forms, with or without
69883Sandreas@sandberg.pp.se * modification, are permitted provided that the following conditions are
79883Sandreas@sandberg.pp.se * met: redistributions of source code must retain the above copyright
89883Sandreas@sandberg.pp.se * notice, this list of conditions and the following disclaimer;
99883Sandreas@sandberg.pp.se * redistributions in binary form must reproduce the above copyright
109883Sandreas@sandberg.pp.se * notice, this list of conditions and the following disclaimer in the
119883Sandreas@sandberg.pp.se * documentation and/or other materials provided with the distribution;
129883Sandreas@sandberg.pp.se * neither the name of the copyright holders nor the names of its
139883Sandreas@sandberg.pp.se * contributors may be used to endorse or promote products derived from
149883Sandreas@sandberg.pp.se * this software without specific prior written permission.
159883Sandreas@sandberg.pp.se *
169883Sandreas@sandberg.pp.se * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
179883Sandreas@sandberg.pp.se * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
189883Sandreas@sandberg.pp.se * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
199883Sandreas@sandberg.pp.se * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
209883Sandreas@sandberg.pp.se * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
219883Sandreas@sandberg.pp.se * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
229883Sandreas@sandberg.pp.se * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
239883Sandreas@sandberg.pp.se * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
249883Sandreas@sandberg.pp.se * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
259883Sandreas@sandberg.pp.se * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
269883Sandreas@sandberg.pp.se * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
279883Sandreas@sandberg.pp.se */
289883Sandreas@sandberg.pp.se
299883Sandreas@sandberg.pp.se#include <string>
309883Sandreas@sandberg.pp.se
3111793Sbrandon.potter@amd.com#include "cpu/base_cpu.hh"
3211793Sbrandon.potter@amd.com#include "cpu/exec_context.hh"
339883Sandreas@sandberg.pp.se
349883Sandreas@sandberg.pp.se#ifdef FULL_SYSTEM
359883Sandreas@sandberg.pp.se#include "sim/system.hh"
369883Sandreas@sandberg.pp.se#else
379883Sandreas@sandberg.pp.se#include "sim/process.hh"
389883Sandreas@sandberg.pp.se#endif
3911793Sbrandon.potter@amd.com
4011793Sbrandon.potter@amd.comusing namespace std;
419883Sandreas@sandberg.pp.se
429883Sandreas@sandberg.pp.se// constructor
439883Sandreas@sandberg.pp.se#ifdef FULL_SYSTEM
449883Sandreas@sandberg.pp.seExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, System *_sys,
459883Sandreas@sandberg.pp.se                         AlphaItb *_itb, AlphaDtb *_dtb,
469883Sandreas@sandberg.pp.se                         FunctionalMemory *_mem)
479883Sandreas@sandberg.pp.se    : _status(ExecContext::Unallocated),
489883Sandreas@sandberg.pp.se      kernelStats(this, _cpu), cpu(_cpu), thread_num(_thread_num),
499883Sandreas@sandberg.pp.se      cpu_id(-1), mem(_mem), itb(_itb), dtb(_dtb), system(_sys),
509883Sandreas@sandberg.pp.se      memCtrl(_sys->memCtrl), physmem(_sys->physmem),
519883Sandreas@sandberg.pp.se#ifdef FS_MEASURE
529883Sandreas@sandberg.pp.se      swCtx(NULL),
539883Sandreas@sandberg.pp.se#endif
549883Sandreas@sandberg.pp.se      func_exe_insn(0), storeCondFailures(0)
559883Sandreas@sandberg.pp.se{
569883Sandreas@sandberg.pp.se    memset(&regs, 0, sizeof(RegFile));
579886Sandreas@sandberg.pp.se}
589886Sandreas@sandberg.pp.se#else
599886Sandreas@sandberg.pp.seExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
609886Sandreas@sandberg.pp.se                         Process *_process, int _asid)
619886Sandreas@sandberg.pp.se    : _status(ExecContext::Unallocated),
629886Sandreas@sandberg.pp.se      cpu(_cpu), thread_num(_thread_num), cpu_id(-1),
639886Sandreas@sandberg.pp.se      process(_process), mem(process->getMemory()), asid(_asid),
649886Sandreas@sandberg.pp.se      func_exe_insn(0), storeCondFailures(0)
659886Sandreas@sandberg.pp.se{
669886Sandreas@sandberg.pp.se}
679886Sandreas@sandberg.pp.se
689886Sandreas@sandberg.pp.seExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
699886Sandreas@sandberg.pp.se                         FunctionalMemory *_mem, int _asid)
709886Sandreas@sandberg.pp.se    : cpu(_cpu), thread_num(_thread_num), process(0), mem(_mem), asid(_asid),
719890Sandreas@sandberg.pp.se      func_exe_insn(0), storeCondFailures(0)
729890Sandreas@sandberg.pp.se{
739890Sandreas@sandberg.pp.se}
749890Sandreas@sandberg.pp.se#endif
759890Sandreas@sandberg.pp.se
769890Sandreas@sandberg.pp.se
779890Sandreas@sandberg.pp.sevoid
789890Sandreas@sandberg.pp.seExecContext::takeOverFrom(ExecContext *oldContext)
799890Sandreas@sandberg.pp.se{
809890Sandreas@sandberg.pp.se    // some things should already be set up
819890Sandreas@sandberg.pp.se    assert(mem == oldContext->mem);
829890Sandreas@sandberg.pp.se#ifdef FULL_SYSTEM
839890Sandreas@sandberg.pp.se    assert(system == oldContext->system);
849890Sandreas@sandberg.pp.se#else
859890Sandreas@sandberg.pp.se    assert(process == oldContext->process);
869890Sandreas@sandberg.pp.se#endif
879890Sandreas@sandberg.pp.se
889890Sandreas@sandberg.pp.se    // copy over functional state
899890Sandreas@sandberg.pp.se    _status = oldContext->_status;
909890Sandreas@sandberg.pp.se#ifdef FULL_SYSTEM
919890Sandreas@sandberg.pp.se    kernelStats = oldContext->kernelStats;
929890Sandreas@sandberg.pp.se#endif
939890Sandreas@sandberg.pp.se    regs = oldContext->regs;
949890Sandreas@sandberg.pp.se    cpu_id = oldContext->cpu_id;
959890Sandreas@sandberg.pp.se    func_exe_insn = oldContext->func_exe_insn;
969890Sandreas@sandberg.pp.se
979890Sandreas@sandberg.pp.se    storeCondFailures = 0;
989890Sandreas@sandberg.pp.se
999890Sandreas@sandberg.pp.se    oldContext->_status = ExecContext::Unallocated;
1009890Sandreas@sandberg.pp.se}
1019890Sandreas@sandberg.pp.se
1029890Sandreas@sandberg.pp.se
1039886Sandreas@sandberg.pp.sevoid
1049883Sandreas@sandberg.pp.seExecContext::serialize(ostream &os)
1059883Sandreas@sandberg.pp.se{
1069883Sandreas@sandberg.pp.se    SERIALIZE_ENUM(_status);
1079883Sandreas@sandberg.pp.se    regs.serialize(os);
1089883Sandreas@sandberg.pp.se    // thread_num and cpu_id are deterministic from the config
1099883Sandreas@sandberg.pp.se    SERIALIZE_SCALAR(func_exe_insn);
1109883Sandreas@sandberg.pp.se}
1119883Sandreas@sandberg.pp.se
1129883Sandreas@sandberg.pp.se
1139883Sandreas@sandberg.pp.sevoid
1149883Sandreas@sandberg.pp.seExecContext::unserialize(Checkpoint *cp, const std::string &section)
1159883Sandreas@sandberg.pp.se{
1169883Sandreas@sandberg.pp.se    UNSERIALIZE_ENUM(_status);
1179883Sandreas@sandberg.pp.se    regs.unserialize(cp, section);
1189883Sandreas@sandberg.pp.se    // thread_num and cpu_id are deterministic from the config
1199883Sandreas@sandberg.pp.se    UNSERIALIZE_SCALAR(func_exe_insn);
1209883Sandreas@sandberg.pp.se}
1219883Sandreas@sandberg.pp.se
12211321Ssteve.reinhardt@amd.com
1239883Sandreas@sandberg.pp.sevoid
1249883Sandreas@sandberg.pp.seExecContext::setStatus(Status new_status)
1259883Sandreas@sandberg.pp.se{
1269883Sandreas@sandberg.pp.se#ifdef FULL_SYSTEM
1279883Sandreas@sandberg.pp.se    if (status() == new_status)
1289883Sandreas@sandberg.pp.se        return;
1299883Sandreas@sandberg.pp.se
1309883Sandreas@sandberg.pp.se    // Don't change the status from active if there are pending interrupts
1319883Sandreas@sandberg.pp.se    if (new_status == Suspended && cpu->check_interrupts()) {
1329883Sandreas@sandberg.pp.se        assert(status() == Active);
13311321Ssteve.reinhardt@amd.com        return;
1349883Sandreas@sandberg.pp.se    }
1359883Sandreas@sandberg.pp.se#endif
1369883Sandreas@sandberg.pp.se
1379883Sandreas@sandberg.pp.se    _status = new_status;
1389883Sandreas@sandberg.pp.se    cpu->execCtxStatusChg(thread_num);
1399883Sandreas@sandberg.pp.se}
1409883Sandreas@sandberg.pp.se
1419883Sandreas@sandberg.pp.sevoid
1429883Sandreas@sandberg.pp.seExecContext::regStats(const string &name)
14311321Ssteve.reinhardt@amd.com{
1449883Sandreas@sandberg.pp.se#ifdef FULL_SYSTEM
1459883Sandreas@sandberg.pp.se    kernelStats.regStats(name + ".kern");
1469883Sandreas@sandberg.pp.se#endif
1479883Sandreas@sandberg.pp.se}
1489883Sandreas@sandberg.pp.se