2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
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.
32 #include "arch/sparc/intregfile.hh"
33 #include "base/trace.hh"
34 #include "base/misc.hh"
35 #include "sim/serialize.hh"
39 using namespace SparcISA
;
44 string
SparcISA::getIntRegName(RegIndex index
)
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
];
54 int IntRegFile::flattenIndex(int reg
)
56 int flatIndex
= offset
[reg
>> FrameOffsetBits
]
57 | (reg
& FrameOffsetMask
);
58 DPRINTF(Sparc
, "Flattened index %d into %d.\n", reg
, flatIndex
);
62 void IntRegFile::clear()
65 for (x
= 0; x
< MaxGL
; x
++)
66 memset(regGlobals
[x
], 0, sizeof(IntReg
) * RegsPerFrame
);
67 for(int x
= 0; x
< 2 * NWindows
; x
++)
68 memset(regSegments
[x
], 0, sizeof(IntReg
) * RegsPerFrame
);
69 memset(regs
, 0, sizeof(IntReg
) * NumIntRegs
);
72 IntRegFile::IntRegFile()
75 regView
[Globals
] = regGlobals
[0];
80 IntReg
IntRegFile::readReg(int intReg
)
82 DPRINTF(Sparc
, "Read register %d = 0x%x\n", intReg
, regs
[intReg
]);
85 if(intReg
< NumIntArchRegs
)
86 val
= regView
[intReg
>> FrameOffsetBits
][intReg
& FrameOffsetMask
];
87 else if((intReg
-= NumIntArchRegs
) < NumMicroIntRegs
)
88 val
= microRegs
[intReg
];
90 panic("Tried to read non-existant integer register %d, %d\n",
91 NumIntArchRegs
+ NumMicroIntRegs
+ intReg
, intReg
);
93 DPRINTF(Sparc
, "Read register %d = 0x%x\n", intReg
, val
);
97 void IntRegFile::setReg(int intReg
, const IntReg
&val
)
101 DPRINTF(Sparc
, "Wrote register %d = 0x%x\n", intReg
, val
);
107 DPRINTF(Sparc
, "Wrote register %d = 0x%x\n", intReg
, val
);
108 if(intReg
< NumIntArchRegs
)
109 regView
[intReg
>> FrameOffsetBits
][intReg
& FrameOffsetMask
] = val
;
110 else if((intReg
-= NumIntArchRegs
) < NumMicroIntRegs
)
111 microRegs
[intReg
] = val
;
113 panic("Tried to set non-existant integer register\n");
117 //This doesn't effect the actual CWP register.
118 //It's purpose is to adjust the view of the register file
119 //to what it would be if CWP = cwp.
120 void IntRegFile::setCWP(int cwp
)
122 int index
= ((NWindows
- cwp
) % NWindows
) * 2;
123 offset
[Outputs
] = FrameOffset
+ (index
* RegsPerFrame
);
124 offset
[Locals
] = FrameOffset
+ ((index
+1) * RegsPerFrame
);
125 offset
[Inputs
] = FrameOffset
+
126 (((index
+2) % (NWindows
* 2)) * RegsPerFrame
);
127 regView
[Outputs
] = regSegments
[index
];
128 regView
[Locals
] = regSegments
[index
+1];
129 regView
[Inputs
] = regSegments
[(index
+2) % (NWindows
* 2)];
131 DPRINTF(Sparc
, "Changed the CWP value to %d\n", cwp
);
134 void IntRegFile::setGlobals(int gl
)
136 DPRINTF(Sparc
, "Now using %d globals\n", gl
);
138 regView
[Globals
] = regGlobals
[gl
];
139 offset
[Globals
] = RegGlobalOffset
+ gl
* RegsPerFrame
;
142 void IntRegFile::serialize(std::ostream
&os
)
145 for(x
= 0; x
< MaxGL
; x
++)
146 SERIALIZE_ARRAY(regGlobals
[x
], RegsPerFrame
);
147 for(x
= 0; x
< 2 * NWindows
; x
++)
148 SERIALIZE_ARRAY(regSegments
[x
], RegsPerFrame
);
149 SERIALIZE_ARRAY(microRegs
, NumMicroIntRegs
);
152 void IntRegFile::unserialize(Checkpoint
*cp
, const std::string
§ion
)
155 for(x
= 0; x
< MaxGL
; x
++)
156 UNSERIALIZE_ARRAY(regGlobals
[x
], RegsPerFrame
);
157 for(unsigned int x
= 0; x
< 2 * NWindows
; x
++)
158 UNSERIALIZE_ARRAY(regSegments
[x
], RegsPerFrame
);
159 UNSERIALIZE_ARRAY(microRegs
, NumMicroIntRegs
);