Fixing statetrace to work with 32 bit SPARC processes, as well as rewritting it's...
[gem5.git] / util / statetrace / arch / tracechild_sparc.hh
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 <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
44 struct regs;
45
46 class 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 int64_t locals[8];
76 int64_t oldLocals[8];
77 int64_t inputs[8];
78 int64_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 int getNumRegs()
94 {
95 return numregs;
96 }
97
98 bool diffSinceUpdate(int num)
99 {
100 assert(num < numregs && num >= 0);
101 return regDiffSinceUpdate[num];
102 }
103
104 std::string getRegName(int num)
105 {
106 assert(num < numregs && num >= 0);
107 return regNames[num];
108 }
109
110 int64_t getRegVal(int num);
111
112 int64_t getOldRegVal(int num);
113
114 bool step();
115
116 uint64_t getPC()
117 {
118 return getRegVal(PC);
119 }
120
121 uint64_t getSP()
122 {
123 return getRegVal(O6);
124 }
125
126 char * printReg(int num);
127
128 std::ostream & outputStartState(std::ostream & os);
129 };
130
131 #endif