tracechild.hh revision 8108
1/*
2 * Copyright (c) 2006-2007 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 * Authors: Gabe Black
29 */
30
31#ifndef TRACECHILD_SPARC_HH
32#define TRACECHILD_SPARC_HH
33
34#include <asm-sparc64/reg.h>
35#include <cassert>
36#include <ostream>
37#include <stdint.h>
38#include <string>
39#include <sys/ptrace.h>
40#include <sys/types.h>
41
42#include "tracechild.hh"
43
44struct regs;
45
46class SparcTraceChild : public TraceChild
47{
48  public:
49    enum RegNum
50    {
51        //Global registers
52        G0, G1, G2, G3, G4, G5, G6, G7,
53        //Output registers
54        O0, O1, O2, O3, O4, O5, O6, O7,
55        //Local registers
56        L0, L1, L2, L3, L4, L5, L6, L7,
57        //Input registers
58        I0, I1, I2, I3, I4, I5, I6, I7,
59        //Floating point
60        F0, F2, F4, F6, F8, F10, F12, F14,
61        F16, F18, F20, F22, F24, F26, F28, F30,
62        F32, F34, F36, F38, F40, F42, F44, F46,
63        F48, F50, F52, F54, F56, F58, F60, F62,
64        //Miscelaneous
65        FSR, FPRS, PC, NPC, Y, CWP, PSTATE, ASI, CCR,
66        numregs
67    };
68  private:
69    char printBuffer[256];
70    static std::string regNames[numregs];
71    regs theregs;
72    regs oldregs;
73    fpu thefpregs;
74    fpu oldfpregs;
75    uint64_t locals[8];
76    uint64_t oldLocals[8];
77    uint64_t inputs[8];
78    uint64_t oldInputs[8];
79    bool regDiffSinceUpdate[numregs];
80
81    //This calculates where the pc might go after the current instruction.
82    //while this equals npc for most instructions, it doesn't for all of
83    //them. The return value is the number of actual potential targets.
84    int getTargets(uint32_t inst, uint64_t pc, uint64_t npc,
85            uint64_t &target1, uint64_t &target2);
86
87  protected:
88    bool update(int pid);
89
90  public:
91    SparcTraceChild();
92
93    bool sendState(int socket);
94
95    int
96    getNumRegs()
97    {
98        return numregs;
99    }
100
101    bool
102    diffSinceUpdate(int num)
103    {
104        assert(num < numregs && num >= 0);
105        return regDiffSinceUpdate[num];
106    }
107
108    std::string
109    getRegName(int num)
110    {
111        assert(num < numregs && num >= 0);
112        return regNames[num];
113    }
114
115    int64_t getRegVal(int num);
116
117    int64_t getOldRegVal(int num);
118
119    bool step();
120
121    uint64_t
122    getPC()
123    {
124        return getRegVal(PC);
125    }
126
127    uint64_t
128    getSP()
129    {
130        return getRegVal(O6);
131    }
132
133    char * printReg(int num);
134
135    std::ostream & outputStartState(std::ostream & os);
136};
137
138#endif
139