simple_thread.cc revision 1858
110152Satgutier@umich.edu/*
210152Satgutier@umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan
310152Satgutier@umich.edu * All rights reserved.
410152Satgutier@umich.edu *
510234Syasuko.eckert@amd.com * Redistribution and use in source and binary forms, with or without
610152Satgutier@umich.edu * modification, are permitted provided that the following conditions are
710152Satgutier@umich.edu * met: redistributions of source code must retain the above copyright
810152Satgutier@umich.edu * notice, this list of conditions and the following disclaimer;
910152Satgutier@umich.edu * redistributions in binary form must reproduce the above copyright
1010152Satgutier@umich.edu * notice, this list of conditions and the following disclaimer in the
1110152Satgutier@umich.edu * documentation and/or other materials provided with the distribution;
1210152Satgutier@umich.edu * neither the name of the copyright holders nor the names of its
1310152Satgutier@umich.edu * contributors may be used to endorse or promote products derived from
1410152Satgutier@umich.edu * this software without specific prior written permission.
1510152Satgutier@umich.edu *
1610152Satgutier@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1710152Satgutier@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1810152Satgutier@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1910152Satgutier@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2010152Satgutier@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2110152Satgutier@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2210152Satgutier@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2310152Satgutier@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410152Satgutier@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2510152Satgutier@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2610152Satgutier@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2710152Satgutier@umich.edu */
2810152Satgutier@umich.edu
2910234Syasuko.eckert@amd.com#include <string>
3010152Satgutier@umich.edu
3110152Satgutier@umich.edu#include "cpu/base.hh"
3210152Satgutier@umich.edu#include "cpu/exec_context.hh"
3310152Satgutier@umich.edu
3410152Satgutier@umich.edu#if FULL_SYSTEM
3510152Satgutier@umich.edu#include "base/cprintf.hh"
3610152Satgutier@umich.edu#include "kern/kernel_stats.hh"
3710152Satgutier@umich.edu#include "sim/serialize.hh"
3810152Satgutier@umich.edu#include "sim/system.hh"
3910152Satgutier@umich.edu#else
4010234Syasuko.eckert@amd.com#include "sim/process.hh"
4110234Syasuko.eckert@amd.com#endif
4210234Syasuko.eckert@amd.com
4310234Syasuko.eckert@amd.comusing namespace std;
4410234Syasuko.eckert@amd.com
4510234Syasuko.eckert@amd.com// constructor
4610234Syasuko.eckert@amd.com#if FULL_SYSTEM
4710234Syasuko.eckert@amd.comExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, System *_sys,
4810234Syasuko.eckert@amd.com                         AlphaITB *_itb, AlphaDTB *_dtb,
4910234Syasuko.eckert@amd.com                         FunctionalMemory *_mem)
5010234Syasuko.eckert@amd.com    : _status(ExecContext::Unallocated), cpu(_cpu), thread_num(_thread_num),
5110234Syasuko.eckert@amd.com      cpu_id(-1), mem(_mem), itb(_itb), dtb(_dtb), system(_sys),
5210234Syasuko.eckert@amd.com      memctrl(_sys->memctrl), physmem(_sys->physmem),
5310152Satgutier@umich.edu      kernelBinning(system->kernelBinning), bin(kernelBinning->bin),
5410152Satgutier@umich.edu      fnbin(kernelBinning->fnbin), func_exe_inst(0), storeCondFailures(0)
5510234Syasuko.eckert@amd.com{
5610152Satgutier@umich.edu    kernelStats = new Kernel::Statistics(this);
5710152Satgutier@umich.edu    memset(&regs, 0, sizeof(RegFile));
5810152Satgutier@umich.edu}
5910234Syasuko.eckert@amd.com#else
6010234Syasuko.eckert@amd.comExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
6110234Syasuko.eckert@amd.com                         Process *_process, int _asid)
6210234Syasuko.eckert@amd.com    : _status(ExecContext::Unallocated),
6310234Syasuko.eckert@amd.com      cpu(_cpu), thread_num(_thread_num), cpu_id(-1),
6410234Syasuko.eckert@amd.com      process(_process), mem(process->getMemory()), asid(_asid),
6510152Satgutier@umich.edu      func_exe_inst(0), storeCondFailures(0)
6610152Satgutier@umich.edu{
6710152Satgutier@umich.edu    memset(&regs, 0, sizeof(RegFile));
6810152Satgutier@umich.edu}
6910234Syasuko.eckert@amd.com
7010234Syasuko.eckert@amd.comExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
7110234Syasuko.eckert@amd.com                         FunctionalMemory *_mem, int _asid)
7210152Satgutier@umich.edu    : cpu(_cpu), thread_num(_thread_num), process(0), mem(_mem), asid(_asid),
7310152Satgutier@umich.edu      func_exe_inst(0), storeCondFailures(0)
7410152Satgutier@umich.edu{
7510152Satgutier@umich.edu    memset(&regs, 0, sizeof(RegFile));
7610152Satgutier@umich.edu}
7710234Syasuko.eckert@amd.com#endif
7810234Syasuko.eckert@amd.com
7910234Syasuko.eckert@amd.comExecContext::~ExecContext()
8010152Satgutier@umich.edu{
8110152Satgutier@umich.edu#if FULL_SYSTEM
8210152Satgutier@umich.edu    delete kernelStats;
8310152Satgutier@umich.edu#endif
8410234Syasuko.eckert@amd.com}
8510234Syasuko.eckert@amd.com
8610234Syasuko.eckert@amd.com
8710234Syasuko.eckert@amd.comvoid
8810152Satgutier@umich.eduExecContext::takeOverFrom(ExecContext *oldContext)
8910152Satgutier@umich.edu{
9010152Satgutier@umich.edu    // some things should already be set up
9110152Satgutier@umich.edu    assert(mem == oldContext->mem);
9210234Syasuko.eckert@amd.com#if FULL_SYSTEM
9310234Syasuko.eckert@amd.com    assert(system == oldContext->system);
9410234Syasuko.eckert@amd.com#else
9510234Syasuko.eckert@amd.com    assert(process == oldContext->process);
9610234Syasuko.eckert@amd.com#endif
9710234Syasuko.eckert@amd.com
9810234Syasuko.eckert@amd.com    // copy over functional state
9910234Syasuko.eckert@amd.com    _status = oldContext->_status;
10010234Syasuko.eckert@amd.com    regs = oldContext->regs;
10110234Syasuko.eckert@amd.com    cpu_id = oldContext->cpu_id;
10210234Syasuko.eckert@amd.com    func_exe_inst = oldContext->func_exe_inst;
10310234Syasuko.eckert@amd.com
10410234Syasuko.eckert@amd.com    storeCondFailures = 0;
10510234Syasuko.eckert@amd.com
10610234Syasuko.eckert@amd.com    oldContext->_status = ExecContext::Unallocated;
10710234Syasuko.eckert@amd.com}
10810234Syasuko.eckert@amd.com
10910234Syasuko.eckert@amd.com#if FULL_SYSTEM
11010234Syasuko.eckert@amd.comvoid
11110234Syasuko.eckert@amd.comExecContext::execute(const StaticInstBase *inst)
11210152Satgutier@umich.edu{
11310152Satgutier@umich.edu    assert(kernelStats);
11410152Satgutier@umich.edu    system->kernelBinning->execute(this, inst);
11510152Satgutier@umich.edu}
11610234Syasuko.eckert@amd.com#endif
11710234Syasuko.eckert@amd.com
11810234Syasuko.eckert@amd.comvoid
11910152Satgutier@umich.eduExecContext::serialize(ostream &os)
12010152Satgutier@umich.edu{
12110152Satgutier@umich.edu    SERIALIZE_ENUM(_status);
12210152Satgutier@umich.edu    regs.serialize(os);
12310234Syasuko.eckert@amd.com    // thread_num and cpu_id are deterministic from the config
12410234Syasuko.eckert@amd.com    SERIALIZE_SCALAR(func_exe_inst);
12510234Syasuko.eckert@amd.com    SERIALIZE_SCALAR(inst);
12610234Syasuko.eckert@amd.com
12710152Satgutier@umich.edu#if FULL_SYSTEM
12810152Satgutier@umich.edu    kernelStats->serialize(os);
12910152Satgutier@umich.edu#endif
13010152Satgutier@umich.edu}
13110234Syasuko.eckert@amd.com
13210234Syasuko.eckert@amd.com
13310152Satgutier@umich.eduvoid
13410152Satgutier@umich.eduExecContext::unserialize(Checkpoint *cp, const std::string &section)
13510152Satgutier@umich.edu{
13610234Syasuko.eckert@amd.com    UNSERIALIZE_ENUM(_status);
13710234Syasuko.eckert@amd.com    regs.unserialize(cp, section);
13810234Syasuko.eckert@amd.com    // thread_num and cpu_id are deterministic from the config
13910234Syasuko.eckert@amd.com    UNSERIALIZE_SCALAR(func_exe_inst);
14010234Syasuko.eckert@amd.com    UNSERIALIZE_SCALAR(inst);
14110152Satgutier@umich.edu
14210152Satgutier@umich.edu#if FULL_SYSTEM
14310152Satgutier@umich.edu    kernelStats->unserialize(cp, section);
144#endif
145}
146
147
148void
149ExecContext::activate(int delay)
150{
151    if (status() == Active)
152        return;
153
154    _status = Active;
155    cpu->activateContext(thread_num, delay);
156}
157
158void
159ExecContext::suspend()
160{
161    if (status() == Suspended)
162        return;
163
164#if FULL_SYSTEM
165    // Don't change the status from active if there are pending interrupts
166    if (cpu->check_interrupts()) {
167        assert(status() == Active);
168        return;
169    }
170#endif
171
172    _status = Suspended;
173    cpu->suspendContext(thread_num);
174}
175
176void
177ExecContext::deallocate()
178{
179    if (status() == Unallocated)
180        return;
181
182    _status = Unallocated;
183    cpu->deallocateContext(thread_num);
184}
185
186void
187ExecContext::halt()
188{
189    if (status() == Halted)
190        return;
191
192    _status = Halted;
193    cpu->haltContext(thread_num);
194}
195
196
197void
198ExecContext::regStats(const string &name)
199{
200#if FULL_SYSTEM
201    kernelStats->regStats(name + ".kern");
202#endif
203}
204
205void
206ExecContext::trap(Fault fault)
207{
208    //TheISA::trap(fault);    //One possible way to do it...
209
210    /** @todo: Going to hack it for now.  Do a true fixup later. */
211#if FULL_SYSTEM
212    ev5_trap(fault);
213#else
214    fatal("fault (%d) detected @ PC 0x%08p", fault, readPC());
215#endif
216}
217