simple_thread.cc revision 217
11388SN/A/*
211359Sandreas@sandberg.pp.se * Copyright (c) 2003 The Regents of The University of Michigan
311359Sandreas@sandberg.pp.se * All rights reserved.
411359Sandreas@sandberg.pp.se *
511359Sandreas@sandberg.pp.se * Redistribution and use in source and binary forms, with or without
611359Sandreas@sandberg.pp.se * modification, are permitted provided that the following conditions are
711359Sandreas@sandberg.pp.se * met: redistributions of source code must retain the above copyright
811359Sandreas@sandberg.pp.se * notice, this list of conditions and the following disclaimer;
911359Sandreas@sandberg.pp.se * redistributions in binary form must reproduce the above copyright
1011359Sandreas@sandberg.pp.se * notice, this list of conditions and the following disclaimer in the
1111359Sandreas@sandberg.pp.se * documentation and/or other materials provided with the distribution;
1211359Sandreas@sandberg.pp.se * neither the name of the copyright holders nor the names of its
1311359Sandreas@sandberg.pp.se * contributors may be used to endorse or promote products derived from
1411359Sandreas@sandberg.pp.se * this software without specific prior written permission.
151388SN/A *
161388SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171388SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181388SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191388SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201388SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211388SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221388SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231388SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241388SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251388SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261388SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271388SN/A */
281388SN/A
291388SN/A#include <string>
301388SN/A
311388SN/A#include "cpu/base_cpu.hh"
321388SN/A#include "cpu/exec_context.hh"
331388SN/A
341388SN/A#ifdef FULL_SYSTEM
351388SN/A#include "sim/system.hh"
361388SN/A#else
371388SN/A#include "sim/prog.hh"
381388SN/A#endif
391388SN/A
402665Ssaidi@eecs.umich.eduusing namespace std;
412665Ssaidi@eecs.umich.edu
428634Schris.emmons@arm.com// constructor
4311359Sandreas@sandberg.pp.se#ifdef FULL_SYSTEM
4411359Sandreas@sandberg.pp.seExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, System *_sys,
451388SN/A                         AlphaItb *_itb, AlphaDtb *_dtb,
461388SN/A                         FunctionalMemory *_mem)
471388SN/A    : _status(ExecContext::Unallocated),
481388SN/A      kernelStats(this, _cpu), cpu(_cpu), thread_num(_thread_num),
498634Schris.emmons@arm.com      cpu_id(-1), mem(_mem), itb(_itb), dtb(_dtb), system(_sys),
5010810Sbr@bsdpad.com      memCtrl(_sys->memCtrl), physmem(_sys->physmem),
511388SN/A      func_exe_insn(0), storeCondFailures(0)
528634Schris.emmons@arm.com{
538229Snate@binkert.org    memset(&regs, 0, sizeof(RegFile));
548229Snate@binkert.org}
558229Snate@binkert.org#else
561388SN/AExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
571388SN/A                         Process *_process, int _asid)
5811293Sandreas.hansson@arm.com    : _status(ExecContext::Unallocated),
595749Scws3k@cs.virginia.edu      cpu(_cpu), thread_num(_thread_num), cpu_id(-1),
601388SN/A      process(_process), mem(process->getMemory()), asid(_asid),
611388SN/A      func_exe_insn(0), storeCondFailures(0)
621388SN/A{
631388SN/A}
641388SN/A
651388SN/AExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
661388SN/A                         FunctionalMemory *_mem, int _asid)
6711359Sandreas@sandberg.pp.se    : cpu(_cpu), thread_num(_thread_num), process(0), mem(_mem), asid(_asid),
6811359Sandreas@sandberg.pp.se      func_exe_insn(0), storeCondFailures(0)
6911359Sandreas@sandberg.pp.se{
7011359Sandreas@sandberg.pp.se}
7111359Sandreas@sandberg.pp.se#endif
7211359Sandreas@sandberg.pp.se
7311359Sandreas@sandberg.pp.se
7411359Sandreas@sandberg.pp.sevoid
7511359Sandreas@sandberg.pp.seExecContext::takeOverFrom(ExecContext *oldContext)
7611359Sandreas@sandberg.pp.se{
7711359Sandreas@sandberg.pp.se    // some things should already be set up
7811359Sandreas@sandberg.pp.se    assert(mem == oldContext->mem);
7911359Sandreas@sandberg.pp.se#ifdef FULL_SYSTEM
8011359Sandreas@sandberg.pp.se    assert(system == oldContext->system);
8111359Sandreas@sandberg.pp.se#else
8211359Sandreas@sandberg.pp.se    assert(process == oldContext->process);
8311359Sandreas@sandberg.pp.se#endif
8411359Sandreas@sandberg.pp.se
8511359Sandreas@sandberg.pp.se    // copy over functional state
8611359Sandreas@sandberg.pp.se    _status = oldContext->_status;
8711359Sandreas@sandberg.pp.se#ifdef FULL_SYSTEM
8811359Sandreas@sandberg.pp.se    kernelStats = oldContext->kernelStats;
8911359Sandreas@sandberg.pp.se#endif
9011359Sandreas@sandberg.pp.se    regs = oldContext->regs;
9111359Sandreas@sandberg.pp.se    cpu_id = oldContext->cpu_id;
9211359Sandreas@sandberg.pp.se    func_exe_insn = oldContext->func_exe_insn;
9311359Sandreas@sandberg.pp.se
9411359Sandreas@sandberg.pp.se    storeCondFailures = 0;
9511359Sandreas@sandberg.pp.se
9611359Sandreas@sandberg.pp.se    oldContext->_status = ExecContext::Unallocated;
9711359Sandreas@sandberg.pp.se}
9811359Sandreas@sandberg.pp.se
9911359Sandreas@sandberg.pp.se
10011359Sandreas@sandberg.pp.sevoid
10111359Sandreas@sandberg.pp.seExecContext::serialize(ostream &os)
10211359Sandreas@sandberg.pp.se{
10311359Sandreas@sandberg.pp.se    SERIALIZE_ARRAY(regs.intRegFile, NumIntRegs);
10411359Sandreas@sandberg.pp.se    SERIALIZE_ARRAY(regs.floatRegFile.q, NumFloatRegs);
10511359Sandreas@sandberg.pp.se}
10611359Sandreas@sandberg.pp.se
10711359Sandreas@sandberg.pp.se
10811359Sandreas@sandberg.pp.sevoid
10911359Sandreas@sandberg.pp.seExecContext::unserialize(IniFile &db, const std::string &section)
11011359Sandreas@sandberg.pp.se{
11111359Sandreas@sandberg.pp.se    UNSERIALIZE_ARRAY(regs.intRegFile, NumIntRegs);
11211359Sandreas@sandberg.pp.se    UNSERIALIZE_ARRAY(regs.floatRegFile.q, NumFloatRegs);
11311359Sandreas@sandberg.pp.se}
11411359Sandreas@sandberg.pp.se
11511359Sandreas@sandberg.pp.se
1161388SN/Avoid
1178634Schris.emmons@arm.comExecContext::setStatus(Status new_status)
1181388SN/A{
1191388SN/A#ifdef FULL_SYSTEM
1201388SN/A    if (status() == new_status)
1211388SN/A        return;
12211359Sandreas@sandberg.pp.se
12311359Sandreas@sandberg.pp.se    // Don't change the status from active if there are pending interrupts
12411359Sandreas@sandberg.pp.se    if (new_status == Suspended && cpu->check_interrupts()) {
12511359Sandreas@sandberg.pp.se        assert(status() == Active);
12611359Sandreas@sandberg.pp.se        return;
1271388SN/A    }
1285749Scws3k@cs.virginia.edu#endif
12911359Sandreas@sandberg.pp.se
13011359Sandreas@sandberg.pp.se    _status = new_status;
13111359Sandreas@sandberg.pp.se    cpu->execCtxStatusChg(thread_num);
1325749Scws3k@cs.virginia.edu}
1335749Scws3k@cs.virginia.edu
1345749Scws3k@cs.virginia.eduvoid
13511359Sandreas@sandberg.pp.seExecContext::regStats(const string &name)
13611359Sandreas@sandberg.pp.se{
1375749Scws3k@cs.virginia.edu#ifdef FULL_SYSTEM
1385749Scws3k@cs.virginia.edu    kernelStats.regStats(name + ".kern");
13911359Sandreas@sandberg.pp.se#endif
1405749Scws3k@cs.virginia.edu}
1415749Scws3k@cs.virginia.edu