Merge zizzer:/bk/newmem
[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 "sim/serialize.hh"
35
36 using namespace SparcISA;
37 using namespace std;
38
39 class Checkpoint;
40
41 string SparcISA::getIntRegName(RegIndex index)
42 {
43 static std::string intRegName[NumIntRegs] =
44 {"g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
45 "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
46 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
47 "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7"};
48 return intRegName[index];
49 }
50
51 int IntRegFile::flattenIndex(int reg)
52 {
53 int flatIndex = offset[reg >> FrameOffsetBits]
54 | (reg & FrameOffsetMask);
55 DPRINTF(Sparc, "Flattened index %d into %d.\n", reg, flatIndex);
56 return flatIndex;
57 }
58
59 void IntRegFile::clear()
60 {
61 int x;
62 for (x = 0; x < MaxGL; x++)
63 memset(regGlobals[x], 0, sizeof(IntReg) * RegsPerFrame);
64 for(int x = 0; x < 2 * NWindows; x++)
65 bzero(regSegments[x], sizeof(IntReg) * RegsPerFrame);
66 }
67
68 IntRegFile::IntRegFile()
69 {
70 offset[Globals] = 0;
71 regView[Globals] = regGlobals[0];
72 setCWP(0);
73 clear();
74 }
75
76 IntReg IntRegFile::readReg(int intReg)
77 {
78 IntReg val;
79 if(intReg < NumRegularIntRegs)
80 val = regView[intReg >> FrameOffsetBits][intReg & FrameOffsetMask];
81 else if((intReg -= NumRegularIntRegs) < NumMicroIntRegs)
82 val = microRegs[intReg];
83 else
84 panic("Tried to read non-existant integer register\n");
85
86 DPRINTF(Sparc, "Read register %d = 0x%x\n", intReg, val);
87 return val;
88 }
89
90 Fault IntRegFile::setReg(int intReg, const IntReg &val)
91 {
92 if(intReg)
93 {
94 DPRINTF(Sparc, "Wrote register %d = 0x%x\n", intReg, val);
95 if(intReg < NumRegularIntRegs)
96 regView[intReg >> FrameOffsetBits][intReg & FrameOffsetMask] = val;
97 else if((intReg -= NumRegularIntRegs) < NumMicroIntRegs)
98 microRegs[intReg] = val;
99 else
100 panic("Tried to set non-existant integer register\n");
101 }
102 return NoFault;
103 }
104
105 //This doesn't effect the actual CWP register.
106 //It's purpose is to adjust the view of the register file
107 //to what it would be if CWP = cwp.
108 void IntRegFile::setCWP(int cwp)
109 {
110 int index = ((NWindows - cwp) % NWindows) * 2;
111 offset[Outputs] = FrameOffset + (index * RegsPerFrame);
112 offset[Locals] = FrameOffset + ((index+1) * RegsPerFrame);
113 offset[Inputs] = FrameOffset +
114 (((index+2) % (NWindows * 2)) * RegsPerFrame);
115 regView[Outputs] = regSegments[index];
116 regView[Locals] = regSegments[index+1];
117 regView[Inputs] = regSegments[(index+2) % (NWindows * 2)];
118
119 DPRINTF(Sparc, "Changed the CWP value to %d\n", cwp);
120 }
121
122 void IntRegFile::setGlobals(int gl)
123 {
124 DPRINTF(Sparc, "Now using %d globals", gl);
125
126 regView[Globals] = regGlobals[gl];
127 offset[Globals] = RegGlobalOffset + gl * RegsPerFrame;
128 }
129
130 void IntRegFile::serialize(std::ostream &os)
131 {
132 unsigned int x;
133 for(x = 0; x < MaxGL; x++)
134 SERIALIZE_ARRAY(regGlobals[x], RegsPerFrame);
135 for(x = 0; x < 2 * NWindows; x++)
136 SERIALIZE_ARRAY(regSegments[x], RegsPerFrame);
137 SERIALIZE_ARRAY(microRegs, NumMicroIntRegs);
138 }
139
140 void IntRegFile::unserialize(Checkpoint *cp, const std::string &section)
141 {
142 unsigned int x;
143 for(x = 0; x < MaxGL; x++)
144 UNSERIALIZE_ARRAY(regGlobals[x], RegsPerFrame);
145 for(unsigned int x = 0; x < 2 * NWindows; x++)
146 UNSERIALIZE_ARRAY(regSegments[x], RegsPerFrame);
147 UNSERIALIZE_ARRAY(microRegs, NumMicroIntRegs);
148 }