thread_state.hh revision 6331
12810Srdreslin@umich.edu/* 28702Sandreas.hansson@arm.com * Copyright (c) 2006 The Regents of The University of Michigan 38702Sandreas.hansson@arm.com * All rights reserved. 48702Sandreas.hansson@arm.com * 58702Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68702Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78702Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88702Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98702Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108702Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118702Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128702Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 138702Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 142810Srdreslin@umich.edu * this software without specific prior written permission. 152810Srdreslin@umich.edu * 162810Srdreslin@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172810Srdreslin@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182810Srdreslin@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192810Srdreslin@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202810Srdreslin@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212810Srdreslin@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222810Srdreslin@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232810Srdreslin@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242810Srdreslin@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252810Srdreslin@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262810Srdreslin@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272810Srdreslin@umich.edu * 282810Srdreslin@umich.edu * Authors: Kevin Lim 292810Srdreslin@umich.edu */ 302810Srdreslin@umich.edu 312810Srdreslin@umich.edu#ifndef __CPU_O3_THREAD_STATE_HH__ 322810Srdreslin@umich.edu#define __CPU_O3_THREAD_STATE_HH__ 332810Srdreslin@umich.edu 342810Srdreslin@umich.edu#include "base/callback.hh" 352810Srdreslin@umich.edu#include "base/output.hh" 362810Srdreslin@umich.edu#include "cpu/thread_context.hh" 372810Srdreslin@umich.edu#include "cpu/thread_state.hh" 382810Srdreslin@umich.edu#include "sim/sim_exit.hh" 392810Srdreslin@umich.edu 402810Srdreslin@umich.educlass Event; 412810Srdreslin@umich.educlass Process; 422810Srdreslin@umich.edu 434458Sstever@eecs.umich.edu#if FULL_SYSTEM 448856Sandreas.hansson@arm.comclass EndQuiesceEvent; 452810Srdreslin@umich.educlass FunctionProfile; 462810Srdreslin@umich.educlass ProfileNode; 472810Srdreslin@umich.edu#else 482810Srdreslin@umich.educlass FunctionalMemory; 492810Srdreslin@umich.educlass Process; 502810Srdreslin@umich.edu#endif 512810Srdreslin@umich.edu 522810Srdreslin@umich.edu/** 532810Srdreslin@umich.edu * Class that has various thread state, such as the status, the 542810Srdreslin@umich.edu * current instruction being processed, whether or not the thread has 552810Srdreslin@umich.edu * a trap pending or is being externally updated, the ThreadContext 565338Sstever@gmail.com * pointer, etc. It also handles anything related to a specific 575338Sstever@gmail.com * thread's process, such as syscalls and checking valid addresses. 585338Sstever@gmail.com */ 594458Sstever@eecs.umich.edutemplate <class Impl> 604458Sstever@eecs.umich.edustruct O3ThreadState : public ThreadState { 612813Srdreslin@umich.edu typedef ThreadContext::Status Status; 623861Sstever@eecs.umich.edu typedef typename Impl::O3CPU O3CPU; 632810Srdreslin@umich.edu 642810Srdreslin@umich.edu private: 652810Srdreslin@umich.edu /** Pointer to the CPU. */ 662810Srdreslin@umich.edu O3CPU *cpu; 674672Sstever@eecs.umich.edu public: 682810Srdreslin@umich.edu /** Whether or not the thread is currently in syscall mode, and 694672Sstever@eecs.umich.edu * thus able to be externally updated without squashing. 702810Srdreslin@umich.edu */ 712810Srdreslin@umich.edu bool inSyscall; 722810Srdreslin@umich.edu 732810Srdreslin@umich.edu /** Whether or not the thread is currently waiting on a trap, and 742810Srdreslin@umich.edu * thus able to be externally updated without squashing. 753860Sstever@eecs.umich.edu */ 763860Sstever@eecs.umich.edu bool trapPending; 772810Srdreslin@umich.edu 782810Srdreslin@umich.edu#if FULL_SYSTEM 792810Srdreslin@umich.edu O3ThreadState(O3CPU *_cpu, int _thread_num) 808856Sandreas.hansson@arm.com : ThreadState(_cpu, _thread_num), 818856Sandreas.hansson@arm.com cpu(_cpu), inSyscall(0), trapPending(0) 828856Sandreas.hansson@arm.com { 838856Sandreas.hansson@arm.com if (cpu->params()->profile) { 848856Sandreas.hansson@arm.com profile = new FunctionProfile(cpu->params()->system->kernelSymtab); 853738Sstever@eecs.umich.edu Callback *cb = 868856Sandreas.hansson@arm.com new MakeCallback<O3ThreadState, 873738Sstever@eecs.umich.edu &O3ThreadState::dumpFuncProfile>(this); 888856Sandreas.hansson@arm.com registerExitCallback(cb); 898856Sandreas.hansson@arm.com } 903738Sstever@eecs.umich.edu 918856Sandreas.hansson@arm.com // let's fill with a dummy node for now so we don't get a segfault 924478Sstever@eecs.umich.edu // on the first cycle when there's no node available. 938975Sandreas.hansson@arm.com static ProfileNode dummyNode; 948948Sandreas.hansson@arm.com profileNode = &dummyNode; 958975Sandreas.hansson@arm.com profilePC = 3; 963738Sstever@eecs.umich.edu } 973738Sstever@eecs.umich.edu#else 983738Sstever@eecs.umich.edu O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process) 993738Sstever@eecs.umich.edu : ThreadState(_cpu, _thread_num, _process), 1008856Sandreas.hansson@arm.com cpu(_cpu), inSyscall(0), trapPending(0) 1018856Sandreas.hansson@arm.com { } 1028856Sandreas.hansson@arm.com#endif 1038856Sandreas.hansson@arm.com 1048856Sandreas.hansson@arm.com /** Pointer to the ThreadContext of this thread. */ 1058856Sandreas.hansson@arm.com ThreadContext *tc; 1068856Sandreas.hansson@arm.com 1078856Sandreas.hansson@arm.com /** Returns a pointer to the TC of this thread. */ 1088856Sandreas.hansson@arm.com ThreadContext *getTC() { return tc; } 1098856Sandreas.hansson@arm.com 1108856Sandreas.hansson@arm.com#if !FULL_SYSTEM 1113738Sstever@eecs.umich.edu /** Handles the syscall. */ 1123738Sstever@eecs.umich.edu void syscall(int64_t callnum) { process->syscall(callnum, tc); } 1138856Sandreas.hansson@arm.com#endif 1148914Sandreas.hansson@arm.com 1158914Sandreas.hansson@arm.com#if FULL_SYSTEM 1168914Sandreas.hansson@arm.com void dumpFuncProfile() 1178914Sandreas.hansson@arm.com { 1188914Sandreas.hansson@arm.com std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name())); 1198975Sandreas.hansson@arm.com profile->dump(tc, *os); 1208914Sandreas.hansson@arm.com } 1218914Sandreas.hansson@arm.com#endif 1228914Sandreas.hansson@arm.com}; 1238914Sandreas.hansson@arm.com 1248914Sandreas.hansson@arm.com#endif // __CPU_O3_THREAD_STATE_HH__ 1258914Sandreas.hansson@arm.com