thread_state.hh revision 8793
110428Sandreas.hansson@arm.com/*
210428Sandreas.hansson@arm.com * Copyright (c) 2006 The Regents of The University of Michigan
310428Sandreas.hansson@arm.com * All rights reserved.
410428Sandreas.hansson@arm.com *
510428Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
610428Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
710428Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
810428Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
910428Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
1010428Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
1110428Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
1210428Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
1310428Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from
1410428Sandreas.hansson@arm.com * this software without specific prior written permission.
1510428Sandreas.hansson@arm.com *
1610428Sandreas.hansson@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1710428Sandreas.hansson@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1810428Sandreas.hansson@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1910428Sandreas.hansson@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2010428Sandreas.hansson@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2110428Sandreas.hansson@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2210428Sandreas.hansson@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2310428Sandreas.hansson@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410428Sandreas.hansson@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2510428Sandreas.hansson@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2610428Sandreas.hansson@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2710428Sandreas.hansson@arm.com *
2810428Sandreas.hansson@arm.com * Authors: Kevin Lim
2910428Sandreas.hansson@arm.com */
3010428Sandreas.hansson@arm.com
3110428Sandreas.hansson@arm.com#ifndef __CPU_O3_THREAD_STATE_HH__
3210428Sandreas.hansson@arm.com#define __CPU_O3_THREAD_STATE_HH__
3310428Sandreas.hansson@arm.com
3410428Sandreas.hansson@arm.com#include "base/callback.hh"
3510428Sandreas.hansson@arm.com#include "base/output.hh"
3610428Sandreas.hansson@arm.com#include "cpu/thread_context.hh"
3710428Sandreas.hansson@arm.com#include "cpu/thread_state.hh"
3810428Sandreas.hansson@arm.com#include "sim/full_system.hh"
3910428Sandreas.hansson@arm.com#include "sim/sim_exit.hh"
4010428Sandreas.hansson@arm.com
4110428Sandreas.hansson@arm.comclass EndQuiesceEvent;
4210428Sandreas.hansson@arm.comclass Event;
4310428Sandreas.hansson@arm.comclass FunctionalMemory;
4410428Sandreas.hansson@arm.comclass FunctionProfile;
4510428Sandreas.hansson@arm.comclass Process;
4610428Sandreas.hansson@arm.comclass ProfileNode;
4710428Sandreas.hansson@arm.com
4810428Sandreas.hansson@arm.com/**
4910428Sandreas.hansson@arm.com * Class that has various thread state, such as the status, the
5010428Sandreas.hansson@arm.com * current instruction being processed, whether or not the thread has
5110428Sandreas.hansson@arm.com * a trap pending or is being externally updated, the ThreadContext
5210428Sandreas.hansson@arm.com * pointer, etc.  It also handles anything related to a specific
5310428Sandreas.hansson@arm.com * thread's process, such as syscalls and checking valid addresses.
5410428Sandreas.hansson@arm.com */
5510428Sandreas.hansson@arm.comtemplate <class Impl>
5610428Sandreas.hansson@arm.comstruct O3ThreadState : public ThreadState {
5710428Sandreas.hansson@arm.com    typedef ThreadContext::Status Status;
5810428Sandreas.hansson@arm.com    typedef typename Impl::O3CPU O3CPU;
5910428Sandreas.hansson@arm.com
6010428Sandreas.hansson@arm.com  private:
6110428Sandreas.hansson@arm.com    /** Pointer to the CPU. */
6210428Sandreas.hansson@arm.com    O3CPU *cpu;
6310428Sandreas.hansson@arm.com  public:
6410428Sandreas.hansson@arm.com    /** Whether or not the thread is currently in syscall mode, and
6510428Sandreas.hansson@arm.com     * thus able to be externally updated without squashing.
6610428Sandreas.hansson@arm.com     */
6710428Sandreas.hansson@arm.com    bool inSyscall;
6810428Sandreas.hansson@arm.com
6910428Sandreas.hansson@arm.com    /** Whether or not the thread is currently waiting on a trap, and
7010428Sandreas.hansson@arm.com     * thus able to be externally updated without squashing.
7110428Sandreas.hansson@arm.com     */
7210428Sandreas.hansson@arm.com    bool trapPending;
7310428Sandreas.hansson@arm.com
7410428Sandreas.hansson@arm.com    O3ThreadState(O3CPU *_cpu, int _thread_num, Process *_process)
7510428Sandreas.hansson@arm.com        : ThreadState(_cpu, _thread_num, _process),
7610428Sandreas.hansson@arm.com          cpu(_cpu), inSyscall(0), trapPending(0)
7710428Sandreas.hansson@arm.com    {
7810428Sandreas.hansson@arm.com        if (FullSystem) {
7910428Sandreas.hansson@arm.com            if (cpu->params()->profile) {
8010428Sandreas.hansson@arm.com                profile = new FunctionProfile(
8110428Sandreas.hansson@arm.com                        cpu->params()->system->kernelSymtab);
8210428Sandreas.hansson@arm.com                Callback *cb =
8310428Sandreas.hansson@arm.com                    new MakeCallback<O3ThreadState,
8410428Sandreas.hansson@arm.com                    &O3ThreadState::dumpFuncProfile>(this);
8510428Sandreas.hansson@arm.com                registerExitCallback(cb);
8610428Sandreas.hansson@arm.com            }
8710428Sandreas.hansson@arm.com
8810428Sandreas.hansson@arm.com            // let's fill with a dummy node for now so we don't get a segfault
8910428Sandreas.hansson@arm.com            // on the first cycle when there's no node available.
9010428Sandreas.hansson@arm.com            static ProfileNode dummyNode;
9110428Sandreas.hansson@arm.com            profileNode = &dummyNode;
9210428Sandreas.hansson@arm.com            profilePC = 3;
9310428Sandreas.hansson@arm.com        }
9410428Sandreas.hansson@arm.com    }
9510428Sandreas.hansson@arm.com
9610428Sandreas.hansson@arm.com    /** Pointer to the ThreadContext of this thread. */
9710428Sandreas.hansson@arm.com    ThreadContext *tc;
9810428Sandreas.hansson@arm.com
9910428Sandreas.hansson@arm.com    /** Returns a pointer to the TC of this thread. */
10010428Sandreas.hansson@arm.com    ThreadContext *getTC() { return tc; }
10110428Sandreas.hansson@arm.com
10210428Sandreas.hansson@arm.com    /** Handles the syscall. */
10310428Sandreas.hansson@arm.com    void syscall(int64_t callnum) { process->syscall(callnum, tc); }
10410428Sandreas.hansson@arm.com
10510428Sandreas.hansson@arm.com    void dumpFuncProfile()
10610428Sandreas.hansson@arm.com    {
10710428Sandreas.hansson@arm.com        std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name()));
10810428Sandreas.hansson@arm.com        profile->dump(tc, *os);
10910428Sandreas.hansson@arm.com    }
11010428Sandreas.hansson@arm.com};
11110428Sandreas.hansson@arm.com
11210428Sandreas.hansson@arm.com#endif // __CPU_O3_THREAD_STATE_HH__
11310428Sandreas.hansson@arm.com