12239SN/A/*
25254Sksewell@umich.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan
35254Sksewell@umich.edu * All rights reserved.
42239SN/A *
55254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
65254Sksewell@umich.edu * modification, are permitted provided that the following conditions are
75254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
85254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
95254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
105254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
115254Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
125254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
135254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
145254Sksewell@umich.edu * this software without specific prior written permission.
152239SN/A *
165254Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175254Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185254Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195254Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205254Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215254Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225254Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235254Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245254Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255254Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265254Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
285254Sksewell@umich.edu * Authors: Ali Saidi
292239SN/A */
302239SN/A
312745Sksewell@umich.edu#ifndef __ARCH_MIPS_STACKTRACE_HH__
322745Sksewell@umich.edu#define __ARCH_MIPS_STACKTRACE_HH__
332239SN/A
342239SN/A#include "base/trace.hh"
352239SN/A#include "cpu/static_inst.hh"
368232Snate@binkert.org#include "debug/Stack.hh"
372239SN/A
382680Sktlim@umich.educlass ThreadContext;
392239SN/A
403580Sgblack@eecs.umich.edunamespace MipsISA
413580Sgblack@eecs.umich.edu{
423580Sgblack@eecs.umich.edu
432239SN/Aclass ProcessInfo
442239SN/A{
452239SN/A  private:
462680Sktlim@umich.edu    ThreadContext *tc;
472239SN/A
482239SN/A    int task_off;
492239SN/A    int pid_off;
502239SN/A    int name_off;
512239SN/A
522239SN/A  public:
532680Sktlim@umich.edu    ProcessInfo(ThreadContext *_tc);
542239SN/A
552239SN/A    Addr task(Addr ksp) const;
562239SN/A    int pid(Addr ksp) const;
572239SN/A    std::string name(Addr ksp) const;
582239SN/A};
592239SN/A
602239SN/Aclass StackTrace
612239SN/A{
622239SN/A  protected:
635567Snate@binkert.org    typedef MipsISA::MachInst MachInst;
642239SN/A  private:
652680Sktlim@umich.edu    ThreadContext *tc;
662239SN/A    std::vector<Addr> stack;
672239SN/A
682239SN/A  private:
692239SN/A    bool isEntry(Addr addr);
702239SN/A    bool decodePrologue(Addr sp, Addr callpc, Addr func, int &size, Addr &ra);
712239SN/A    bool decodeSave(MachInst inst, int &reg, int &disp);
722239SN/A    bool decodeStack(MachInst inst, int &disp);
732239SN/A
742680Sktlim@umich.edu    void trace(ThreadContext *tc, bool is_call);
752239SN/A
762239SN/A  public:
772239SN/A    StackTrace();
7810417Sandreas.hansson@arm.com    StackTrace(ThreadContext *tc, const StaticInstPtr &inst);
792239SN/A    ~StackTrace();
802239SN/A
812239SN/A    void clear()
822239SN/A    {
832680Sktlim@umich.edu        tc = 0;
842239SN/A        stack.clear();
852239SN/A    }
862239SN/A
872680Sktlim@umich.edu    bool valid() const { return tc != NULL; }
8810417Sandreas.hansson@arm.com    bool trace(ThreadContext *tc, const StaticInstPtr &inst);
892239SN/A
902239SN/A  public:
912239SN/A    const std::vector<Addr> &getstack() const { return stack; }
922239SN/A
932239SN/A    static const int user = 1;
942239SN/A    static const int console = 2;
952239SN/A    static const int unknown = 3;
962239SN/A
972239SN/A#if TRACING_ON
982239SN/A  private:
992239SN/A    void dump();
1002239SN/A
1012239SN/A  public:
1022239SN/A    void dprintf() { if (DTRACE(Stack)) dump(); }
1032239SN/A#else
1042239SN/A  public:
1052239SN/A    void dprintf() {}
1062239SN/A#endif
1072239SN/A};
1082239SN/A
1092239SN/Ainline bool
11010417Sandreas.hansson@arm.comStackTrace::trace(ThreadContext *tc, const StaticInstPtr &inst)
1112239SN/A{
1122239SN/A    if (!inst->isCall() && !inst->isReturn())
1132239SN/A        return false;
1142239SN/A
1152239SN/A    if (valid())
1162239SN/A        clear();
1172239SN/A
1182680Sktlim@umich.edu    trace(tc, !inst->isReturn());
1192239SN/A    return true;
1202239SN/A}
1212239SN/A
1223580Sgblack@eecs.umich.edu}
1233580Sgblack@eecs.umich.edu
1242745Sksewell@umich.edu#endif // __ARCH_MIPS_STACKTRACE_HH__
125