ISA: Set up common trace flags for tracing registers.
[gem5.git] / src / arch / sparc / intregfile.cc
1 /*
2 * Copyright (c) 2003-2005 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 * Ali Saidi
30 */
31
32 #include "arch/sparc/intregfile.hh"
33 #include "base/trace.hh"
34 #include "base/misc.hh"
35 #include "sim/serialize.hh"
36
37 #include <string.h>
38
39 using namespace SparcISA;
40 using namespace std;
41
42 class Checkpoint;
43
44 string SparcISA::getIntRegName(RegIndex index)
45 {
46 static std::string intRegName[NumIntArchRegs] =
47 {"g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
48 "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
49 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
50 "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7"};
51 return intRegName[index];
52 }
53
54 void IntRegFile::clear()
55 {
56 int x;
57 for (x = 0; x < MaxGL; x++)
58 memset(regGlobals[x], 0, sizeof(IntReg) * RegsPerFrame);
59 for(int x = 0; x < 2 * NWindows; x++)
60 memset(regSegments[x], 0, sizeof(IntReg) * RegsPerFrame);
61 memset(regs, 0, sizeof(IntReg) * NumIntRegs);
62 }
63
64 IntRegFile::IntRegFile()
65 {
66 offset[Globals] = 0;
67 regView[Globals] = regGlobals[0];
68 clear();
69 }
70
71 IntReg IntRegFile::readReg(int intReg)
72 {
73 DPRINTF(IntRegs, "Read register %d = 0x%x\n", intReg, regs[intReg]);
74 return regs[intReg];
75 /* XXX Currently not used. When used again regView/offset need to be
76 * serialized!
77 IntReg val;
78 if(intReg < NumIntArchRegs)
79 val = regView[intReg >> FrameOffsetBits][intReg & FrameOffsetMask];
80 else if((intReg -= NumIntArchRegs) < NumMicroIntRegs)
81 val = microRegs[intReg];
82 else
83 panic("Tried to read non-existant integer register %d, %d\n",
84 NumIntArchRegs + NumMicroIntRegs + intReg, intReg);
85
86 DPRINTF(IntRegs, "Read register %d = 0x%x\n", intReg, val);
87 return val;
88 */
89 }
90
91 void IntRegFile::setReg(int intReg, const IntReg &val)
92 {
93 if(intReg)
94 {
95 DPRINTF(IntRegs, "Wrote register %d = 0x%x\n", intReg, val);
96 regs[intReg] = val;
97 }
98 return;
99 /* XXX Currently not used. When used again regView/offset need to be
100 * serialized!
101 if(intReg)
102 {
103 DPRINTF(IntRegs, "Wrote register %d = 0x%x\n", intReg, val);
104 if(intReg < NumIntArchRegs)
105 regView[intReg >> FrameOffsetBits][intReg & FrameOffsetMask] = val;
106 else if((intReg -= NumIntArchRegs) < NumMicroIntRegs)
107 microRegs[intReg] = val;
108 else
109 panic("Tried to set non-existant integer register\n");
110 } */
111 }
112
113 void IntRegFile::serialize(std::ostream &os)
114 {
115 SERIALIZE_ARRAY(regs, NumIntRegs);
116 SERIALIZE_ARRAY(microRegs, NumMicroIntRegs);
117
118 /* the below doesn't seem needed unless gabe makes regview work*/
119 unsigned int x;
120 for(x = 0; x < MaxGL; x++)
121 SERIALIZE_ARRAY(regGlobals[x], RegsPerFrame);
122 for(x = 0; x < 2 * NWindows; x++)
123 SERIALIZE_ARRAY(regSegments[x], RegsPerFrame);
124 }
125
126 void IntRegFile::unserialize(Checkpoint *cp, const std::string &section)
127 {
128 UNSERIALIZE_ARRAY(regs, NumIntRegs);
129 UNSERIALIZE_ARRAY(microRegs, NumMicroIntRegs);
130
131 /* the below doesn't seem needed unless gabe makes regview work*/
132 unsigned int x;
133 for(x = 0; x < MaxGL; x++)
134 UNSERIALIZE_ARRAY(regGlobals[x], RegsPerFrame);
135 for(unsigned int x = 0; x < 2 * NWindows; x++)
136 UNSERIALIZE_ARRAY(regSegments[x], RegsPerFrame);
137 }