tracechild.hh revision 3115
112855Sgabeblack@google.com/*
212855Sgabeblack@google.com * Copyright (c) 2006 The Regents of The University of Michigan
312855Sgabeblack@google.com * All rights reserved.
412855Sgabeblack@google.com *
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 <assert.h>
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{
48public:
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, F1, F2, F3, F4, F5, F6, F7,
61                F8, F9, F10, F11, F12, F13, F14, F15,
62                F16, F17, F18, F19, F20, F21, F22, F23,
63                F24, F25, F26, F27, F28, F29, F30, F31,
64                //Miscelaneous
65                FSR, FPRS, PC, NPC, Y, CWP, PSTATE, ASI, CCR,
66                numregs
67        };
68private:
69        char printBuffer[256];
70        static std::string regNames[numregs];
71        regs theregs;
72        regs oldregs;
73        fpu thefpregs;
74        fpu oldfpregs;
75        int64_t locals[8];
76        int64_t oldLocals[8];
77        int64_t inputs[8];
78        int64_t oldInputs[8];
79        bool regDiffSinceUpdate[numregs];
80
81protected:
82        bool update(int pid);
83
84public:
85        SparcTraceChild();
86
87        int getNumRegs()
88        {
89                return numregs;
90        }
91
92        bool diffSinceUpdate(int num)
93        {
94                assert(num < numregs && num >= 0);
95                return regDiffSinceUpdate[num];
96        }
97
98        std::string getRegName(int num)
99        {
100                assert(num < numregs && num >= 0);
101                return regNames[num];
102        }
103
104        int64_t getRegVal(int num);
105
106        int64_t getOldRegVal(int num);
107
108        bool step();
109
110        uint64_t getPC()
111        {
112                return getRegVal(PC);
113        }
114
115        uint64_t getSP()
116        {
117                return getRegVal(O6);
118        }
119
120        char * printReg(int num);
121
122        std::ostream & outputStartState(std::ostream & os);
123};
124
125#endif
126