simple_thread.cc revision 223
112854Sgabeblack@google.com/*
212854Sgabeblack@google.com * Copyright (c) 2003 The Regents of The University of Michigan
312854Sgabeblack@google.com * All rights reserved.
412854Sgabeblack@google.com *
512854Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612854Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712854Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812854Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912854Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012854Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112854Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212854Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312854Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412854Sgabeblack@google.com * this software without specific prior written permission.
1512854Sgabeblack@google.com *
1612854Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712854Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812854Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912854Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012854Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112854Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212854Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312854Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412854Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512854Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612854Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712854Sgabeblack@google.com */
2812854Sgabeblack@google.com
2912854Sgabeblack@google.com#include <string>
3012854Sgabeblack@google.com
3112854Sgabeblack@google.com#include "cpu/base_cpu.hh"
3212854Sgabeblack@google.com#include "cpu/exec_context.hh"
3312854Sgabeblack@google.com
3412854Sgabeblack@google.com#ifdef FULL_SYSTEM
3512854Sgabeblack@google.com#include "sim/system.hh"
3612854Sgabeblack@google.com#else
3712854Sgabeblack@google.com#include "sim/prog.hh"
3812854Sgabeblack@google.com#endif
3912854Sgabeblack@google.com
4012854Sgabeblack@google.comusing namespace std;
4112854Sgabeblack@google.com
4212854Sgabeblack@google.com// constructor
4312854Sgabeblack@google.com#ifdef FULL_SYSTEM
4412854Sgabeblack@google.comExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, System *_sys,
4512854Sgabeblack@google.com                         AlphaItb *_itb, AlphaDtb *_dtb,
4612854Sgabeblack@google.com                         FunctionalMemory *_mem)
4712854Sgabeblack@google.com    : _status(ExecContext::Unallocated),
4812854Sgabeblack@google.com      kernelStats(this, _cpu), cpu(_cpu), thread_num(_thread_num),
4912854Sgabeblack@google.com      cpu_id(-1), mem(_mem), itb(_itb), dtb(_dtb), system(_sys),
5012854Sgabeblack@google.com      memCtrl(_sys->memCtrl), physmem(_sys->physmem),
5112854Sgabeblack@google.com      func_exe_insn(0), storeCondFailures(0)
5212854Sgabeblack@google.com{
5312854Sgabeblack@google.com    memset(&regs, 0, sizeof(RegFile));
5412854Sgabeblack@google.com}
5512854Sgabeblack@google.com#else
5612854Sgabeblack@google.comExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
5712854Sgabeblack@google.com                         Process *_process, int _asid)
5812854Sgabeblack@google.com    : _status(ExecContext::Unallocated),
5912854Sgabeblack@google.com      cpu(_cpu), thread_num(_thread_num), cpu_id(-1),
6012854Sgabeblack@google.com      process(_process), mem(process->getMemory()), asid(_asid),
6112854Sgabeblack@google.com      func_exe_insn(0), storeCondFailures(0)
6212854Sgabeblack@google.com{
6312854Sgabeblack@google.com}
6412854Sgabeblack@google.com
6512854Sgabeblack@google.comExecContext::ExecContext(BaseCPU *_cpu, int _thread_num,
6612854Sgabeblack@google.com                         FunctionalMemory *_mem, int _asid)
6712854Sgabeblack@google.com    : cpu(_cpu), thread_num(_thread_num), process(0), mem(_mem), asid(_asid),
6812854Sgabeblack@google.com      func_exe_insn(0), storeCondFailures(0)
6912854Sgabeblack@google.com{
7012854Sgabeblack@google.com}
7112854Sgabeblack@google.com#endif
7212854Sgabeblack@google.com
73
74void
75ExecContext::takeOverFrom(ExecContext *oldContext)
76{
77    // some things should already be set up
78    assert(mem == oldContext->mem);
79#ifdef FULL_SYSTEM
80    assert(system == oldContext->system);
81#else
82    assert(process == oldContext->process);
83#endif
84
85    // copy over functional state
86    _status = oldContext->_status;
87#ifdef FULL_SYSTEM
88    kernelStats = oldContext->kernelStats;
89#endif
90    regs = oldContext->regs;
91    cpu_id = oldContext->cpu_id;
92    func_exe_insn = oldContext->func_exe_insn;
93
94    storeCondFailures = 0;
95
96    oldContext->_status = ExecContext::Unallocated;
97}
98
99
100void
101ExecContext::serialize(ostream &os)
102{
103    SERIALIZE_ENUM(_status);
104    regs.serialize(os);
105    // thread_num and cpu_id are deterministic from the config
106    SERIALIZE_SCALAR(func_exe_insn);
107}
108
109
110void
111ExecContext::unserialize(const IniFile *db, const std::string &section)
112{
113    UNSERIALIZE_ENUM(_status);
114    regs.unserialize(db, section);
115    // thread_num and cpu_id are deterministic from the config
116    UNSERIALIZE_SCALAR(func_exe_insn);
117}
118
119
120void
121ExecContext::setStatus(Status new_status)
122{
123#ifdef FULL_SYSTEM
124    if (status() == new_status)
125        return;
126
127    // Don't change the status from active if there are pending interrupts
128    if (new_status == Suspended && cpu->check_interrupts()) {
129        assert(status() == Active);
130        return;
131    }
132#endif
133
134    _status = new_status;
135    cpu->execCtxStatusChg(thread_num);
136}
137
138void
139ExecContext::regStats(const string &name)
140{
141#ifdef FULL_SYSTEM
142    kernelStats.regStats(name + ".kern");
143#endif
144}
145