simple_thread.cc revision 217
1/* 2 * Copyright (c) 2003 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <string> 30 31#include "cpu/base_cpu.hh" 32#include "cpu/exec_context.hh" 33 34#ifdef FULL_SYSTEM 35#include "sim/system.hh" 36#else 37#include "sim/prog.hh" 38#endif 39 40using namespace std; 41 42// constructor 43#ifdef FULL_SYSTEM 44ExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, System *_sys, 45 AlphaItb *_itb, AlphaDtb *_dtb, 46 FunctionalMemory *_mem) 47 : _status(ExecContext::Unallocated), 48 kernelStats(this, _cpu), cpu(_cpu), thread_num(_thread_num), 49 cpu_id(-1), mem(_mem), itb(_itb), dtb(_dtb), system(_sys), 50 memCtrl(_sys->memCtrl), physmem(_sys->physmem), 51 func_exe_insn(0), storeCondFailures(0) 52{ 53 memset(®s, 0, sizeof(RegFile)); 54} 55#else 56ExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, 57 Process *_process, int _asid) 58 : _status(ExecContext::Unallocated), 59 cpu(_cpu), thread_num(_thread_num), cpu_id(-1), 60 process(_process), mem(process->getMemory()), asid(_asid), 61 func_exe_insn(0), storeCondFailures(0) 62{ 63} 64 65ExecContext::ExecContext(BaseCPU *_cpu, int _thread_num, 66 FunctionalMemory *_mem, int _asid) 67 : cpu(_cpu), thread_num(_thread_num), process(0), mem(_mem), asid(_asid), 68 func_exe_insn(0), storeCondFailures(0) 69{ 70} 71#endif 72 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_ARRAY(regs.intRegFile, NumIntRegs); 104 SERIALIZE_ARRAY(regs.floatRegFile.q, NumFloatRegs); 105} 106 107 108void 109ExecContext::unserialize(IniFile &db, const std::string §ion) 110{ 111 UNSERIALIZE_ARRAY(regs.intRegFile, NumIntRegs); 112 UNSERIALIZE_ARRAY(regs.floatRegFile.q, NumFloatRegs); 113} 114 115 116void 117ExecContext::setStatus(Status new_status) 118{ 119#ifdef FULL_SYSTEM 120 if (status() == new_status) 121 return; 122 123 // Don't change the status from active if there are pending interrupts 124 if (new_status == Suspended && cpu->check_interrupts()) { 125 assert(status() == Active); 126 return; 127 } 128#endif 129 130 _status = new_status; 131 cpu->execCtxStatusChg(thread_num); 132} 133 134void 135ExecContext::regStats(const string &name) 136{ 137#ifdef FULL_SYSTEM 138 kernelStats.regStats(name + ".kern"); 139#endif 140} 141