e479fce55ae1015c7e85418365ddc1f856491d81
[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 <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
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 regs theregs;
70 regs oldregs;
71 fpu thefpregs;
72 fpu oldfpregs;
73 uint64_t locals[8];
74 uint64_t oldLocals[8];
75 uint64_t inputs[8];
76 uint64_t oldInputs[8];
77 bool regDiffSinceUpdate[numregs];
78
79 //This calculates where the pc might go after the current instruction.
80 //while this equals npc for most instructions, it doesn't for all of
81 //them. The return value is the number of actual potential targets.
82 int getTargets(uint32_t inst, uint64_t pc, uint64_t npc,
83 uint64_t &target1, uint64_t &target2);
84
85 protected:
86 bool update(int pid);
87
88 public:
89 SparcTraceChild();
90
91 bool sendState(int socket);
92
93 int64_t getRegVal(int num);
94
95 int64_t getOldRegVal(int num);
96
97 bool step();
98
99 uint64_t
100 getPC()
101 {
102 return getRegVal(PC);
103 }
104
105 uint64_t
106 getSP()
107 {
108 return getRegVal(O6);
109 }
110
111 std::ostream & outputStartState(std::ostream & os);
112 };
113
114 #endif