gem5 v24.0.0.0
Loading...
Searching...
No Matches
static_inst.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006-2007 The Regents of The University of Michigan
3 * All rights reserved
4 * Copyright 2017 Google Inc.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
31
32#include "arch/sparc/pcstate.hh"
35#include "base/bitunion.hh"
36
37namespace gem5
38{
39
40namespace SparcISA
41{
42
43const char *CondTestAbbrev[] =
44{
45 [Never] = "nev",
46 [Equal] = "e",
47 [LessOrEqual] = "le",
48 [Less] = "l",
49 [LessOrEqualUnsigned] = "leu",
50 [CarrySet] = "c",
51 [Negative] = "n",
52 [OverflowSet] = "o",
53 [Always] = "a",
54 [NotEqual] = "ne",
55 [Greater] = "g",
56 [GreaterOrEqual] = "ge",
57 [GreaterUnsigned] = "gu",
58 [CarryClear] = "cc",
59 [Positive] = "p",
60 [OverflowClear] = "oc"
61};
62
63void
64SparcStaticInst::printMnemonic(std::ostream &os, const char *mnemonic)
65{
66 ccprintf(os, "\t%s ", mnemonic);
67}
68
69void
70SparcStaticInst::printRegArray(std::ostream &os, const RegId *indexArray,
71 int num) const
72{
73 if (num <= 0)
74 return;
75 printReg(os, indexArray[0]);
76 for (int x = 1; x < num; x++) {
77 os << ", ";
78 printReg(os, indexArray[x]);
79 }
80}
81
82void
84{
85 pcState.as<PCState>().advance();
86}
87
88void
90{
91 PCState pc = tc->pcState().as<PCState>();
92 pc.advance();
93 tc->pcState(pc);
94}
95
96void
97SparcStaticInst::printSrcReg(std::ostream &os, int reg) const
98{
99 if (_numSrcRegs > reg)
101}
102
103void
104SparcStaticInst::printDestReg(std::ostream &os, int reg) const
105{
106 if (_numDestRegs > reg)
108}
109
110void
112{
113 const int MaxGlobal = 8;
114 const int MaxOutput = 16;
115 const int MaxLocal = 24;
116 const int MaxInput = 32;
117 const int MaxMicroReg = 40;
118 RegIndex reg_idx = reg.index();
119 if (reg.is(IntRegClass)) {
120 // If we used a register from the next or previous window,
121 // take out the offset.
122 while (reg_idx >= MaxMicroReg)
123 reg_idx -= MaxMicroReg;
124 if (reg_idx == FramePointerReg)
125 ccprintf(os, "%%fp");
126 else if (reg_idx == StackPointerReg)
127 ccprintf(os, "%%sp");
128 else if (reg_idx < MaxGlobal)
129 ccprintf(os, "%%g%d", reg_idx);
130 else if (reg_idx < MaxOutput)
131 ccprintf(os, "%%o%d", reg_idx - MaxGlobal);
132 else if (reg_idx < MaxLocal)
133 ccprintf(os, "%%l%d", reg_idx - MaxOutput);
134 else if (reg_idx < MaxInput)
135 ccprintf(os, "%%i%d", reg_idx - MaxLocal);
136 else if (reg_idx < MaxMicroReg)
137 ccprintf(os, "%%u%d", reg_idx - MaxInput);
138 // The fake int regs that are really control regs
139 else {
140 switch (reg_idx - MaxMicroReg) {
141 case 1:
142 ccprintf(os, "%%y");
143 break;
144 case 2:
145 ccprintf(os, "%%ccr");
146 break;
147 case 3:
148 ccprintf(os, "%%cansave");
149 break;
150 case 4:
151 ccprintf(os, "%%canrestore");
152 break;
153 case 5:
154 ccprintf(os, "%%cleanwin");
155 break;
156 case 6:
157 ccprintf(os, "%%otherwin");
158 break;
159 case 7:
160 ccprintf(os, "%%wstate");
161 break;
162 }
163 }
164 } else if (reg.is(FloatRegClass)) {
165 ccprintf(os, "%%f%d", reg_idx);
166 } else {
167 switch (reg_idx) {
168 case MISCREG_ASI:
169 ccprintf(os, "%%asi");
170 break;
171 case MISCREG_FPRS:
172 ccprintf(os, "%%fprs");
173 break;
174 case MISCREG_PCR:
175 ccprintf(os, "%%pcr");
176 break;
177 case MISCREG_PIC:
178 ccprintf(os, "%%pic");
179 break;
180 case MISCREG_GSR:
181 ccprintf(os, "%%gsr");
182 break;
183 case MISCREG_SOFTINT:
184 ccprintf(os, "%%softint");
185 break;
187 ccprintf(os, "%%softint_set");
188 break;
190 ccprintf(os, "%%softint_clr");
191 break;
193 ccprintf(os, "%%tick_cmpr");
194 break;
195 case MISCREG_STICK:
196 ccprintf(os, "%%stick");
197 break;
199 ccprintf(os, "%%stick_cmpr");
200 break;
201 case MISCREG_TPC:
202 ccprintf(os, "%%tpc");
203 break;
204 case MISCREG_TNPC:
205 ccprintf(os, "%%tnpc");
206 break;
207 case MISCREG_TSTATE:
208 ccprintf(os, "%%tstate");
209 break;
210 case MISCREG_TT:
211 ccprintf(os, "%%tt");
212 break;
213 case MISCREG_TICK:
214 ccprintf(os, "%%tick");
215 break;
216 case MISCREG_TBA:
217 ccprintf(os, "%%tba");
218 break;
219 case MISCREG_PSTATE:
220 ccprintf(os, "%%pstate");
221 break;
222 case MISCREG_TL:
223 ccprintf(os, "%%tl");
224 break;
225 case MISCREG_PIL:
226 ccprintf(os, "%%pil");
227 break;
228 case MISCREG_CWP:
229 ccprintf(os, "%%cwp");
230 break;
231 case MISCREG_GL:
232 ccprintf(os, "%%gl");
233 break;
234 case MISCREG_HPSTATE:
235 ccprintf(os, "%%hpstate");
236 break;
237 case MISCREG_HTSTATE:
238 ccprintf(os, "%%htstate");
239 break;
240 case MISCREG_HINTP:
241 ccprintf(os, "%%hintp");
242 break;
243 case MISCREG_HTBA:
244 ccprintf(os, "%%htba");
245 break;
247 ccprintf(os, "%%hstick_cmpr");
248 break;
249 case MISCREG_HVER:
250 ccprintf(os, "%%hver");
251 break;
253 ccprintf(os, "%%strand_sts_reg");
254 break;
255 case MISCREG_FSR:
256 ccprintf(os, "%%fsr");
257 break;
258 default:
259 ccprintf(os, "%%ctrl%d", reg_idx);
260 }
261 }
262}
263
264std::string
266 Addr pc, const loader::SymbolTable *symtab) const
267{
268 std::stringstream ss;
269
271
272 // just print the first two source regs... if there's
273 // a third one, it's a read-modify-write dest (Rc),
274 // e.g. for CMOVxx
275 if (_numSrcRegs > 0)
276 printReg(ss, srcRegIdx(0));
277 if (_numSrcRegs > 1) {
278 ss << ",";
279 printReg(ss, srcRegIdx(1));
280 }
281
282 // just print the first dest... if there's a second one,
283 // it's generally implicit
284 if (_numDestRegs > 0) {
285 if (_numSrcRegs > 0)
286 ss << ",";
288 }
289
290 return ss.str();
291}
292
293bool
294SparcStaticInst::passesFpCondition(uint32_t fcc, uint32_t condition)
295{
296 bool u = (fcc == 3);
297 bool g = (fcc == 2);
298 bool l = (fcc == 1);
299 bool e = (fcc == 0);
300
301 switch (condition) {
302 case FAlways:
303 return 1;
304 case FNever:
305 return 0;
306 case FUnordered:
307 return u;
308 case FGreater:
309 return g;
311 return u || g;
312 case FLess:
313 return l;
314 case FUnorderedOrLess:
315 return u || l;
316 case FLessOrGreater:
317 return l || g;
318 case FNotEqual:
319 return l || g || u;
320 case FEqual:
321 return e;
323 return u || e;
324 case FGreaterOrEqual:
325 return g || e;
327 return u || g || e;
328 case FLessOrEqual:
329 return l || e;
331 return u || l || e;
332 case FOrdered:
333 return e || l || g;
334 }
335 panic("Tried testing condition nonexistant condition code %d", condition);
336}
337
338bool
339SparcStaticInst::passesCondition(uint32_t codes, uint32_t condition)
340{
341 BitUnion32(CondCodes)
342 Bitfield<0> c;
343 Bitfield<1> v;
344 Bitfield<2> z;
345 Bitfield<3> n;
346 EndBitUnion(CondCodes)
347 CondCodes condCodes = codes;
348
349 switch (condition) {
350 case Always:
351 return true;
352 case Never:
353 return false;
354 case NotEqual:
355 return !condCodes.z;
356 case Equal:
357 return condCodes.z;
358 case Greater:
359 return !(condCodes.z | (condCodes.n ^ condCodes.v));
360 case LessOrEqual:
361 return condCodes.z | (condCodes.n ^ condCodes.v);
362 case GreaterOrEqual:
363 return !(condCodes.n ^ condCodes.v);
364 case Less:
365 return (condCodes.n ^ condCodes.v);
366 case GreaterUnsigned:
367 return !(condCodes.c | condCodes.z);
369 return (condCodes.c | condCodes.z);
370 case CarryClear:
371 return !condCodes.c;
372 case CarrySet:
373 return condCodes.c;
374 case Positive:
375 return !condCodes.n;
376 case Negative:
377 return condCodes.n;
378 case OverflowClear:
379 return !condCodes.v;
380 case OverflowSet:
381 return condCodes.v;
382 }
383 panic("Tried testing condition nonexistant "
384 "condition code %d", condition);
385}
386
387} // namespace SparcISA
388} // namespace gem5
#define BitUnion32(name)
Definition bitunion.hh:495
Target & as()
Definition pcstate.hh:73
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
void printRegArray(std::ostream &os, const RegId *indexArray, int num) const
static bool passesCondition(uint32_t codes, uint32_t condition)
static void printReg(std::ostream &os, RegId reg)
static void printMnemonic(std::ostream &os, const char *mnemonic)
void advancePC(PCStateBase &pcState) const override
void printDestReg(std::ostream &os, int reg) const
static bool passesFpCondition(uint32_t fcc, uint32_t condition)
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
void printSrcReg(std::ostream &os, int reg) const
uint8_t _numSrcRegs
See numSrcRegs().
uint8_t _numDestRegs
See numDestRegs().
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
const char * mnemonic
Base mnemonic (e.g., "add").
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual const PCStateBase & pcState() const =0
#define EndBitUnion(name)
This closes off the class and union started by the above macro.
Definition bitunion.hh:428
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 9 > e
Definition misc_types.hh:65
Bitfield< 22 > u
Bitfield< 21 > ss
Definition misc_types.hh:60
Bitfield< 4 > pc
Bitfield< 5 > l
Bitfield< 4 > g
Bitfield< 3 > x
Definition pagetable.hh:73
Bitfield< 6 > z
Definition misc.hh:144
@ MISCREG_SOFTINT_CLR
Definition misc.hh:54
@ MISCREG_HPSTATE
Hyper privileged registers.
Definition misc.hh:79
@ MISCREG_PSTATE
Definition misc.hh:67
@ MISCREG_STICK_CMPR
Definition misc.hh:58
@ MISCREG_TICK_CMPR
Definition misc.hh:56
@ MISCREG_HTSTATE
Definition misc.hh:80
@ MISCREG_TSTATE
Definition misc.hh:63
@ MISCREG_ASI
Ancillary State Registers.
Definition misc.hh:47
@ MISCREG_HINTP
Definition misc.hh:81
@ MISCREG_HSTICK_CMPR
Definition misc.hh:85
@ MISCREG_SOFTINT_SET
Definition misc.hh:53
@ MISCREG_STRAND_STS_REG
Definition misc.hh:84
@ MISCREG_FSR
Floating Point Status Register.
Definition misc.hh:88
@ MISCREG_SOFTINT
Definition misc.hh:55
@ MISCREG_STICK
Definition misc.hh:57
@ MISCREG_TPC
Privilged Registers.
Definition misc.hh:61
constexpr auto & StackPointerReg
Definition int.hh:170
Bitfield< 4 > c
Definition misc.hh:146
Bitfield< 7 > n
Definition misc.hh:142
constexpr auto & FramePointerReg
Definition int.hh:171
Bitfield< 5 > v
Definition misc.hh:145
const char * CondTestAbbrev[]
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 17 > os
Definition misc.hh:838
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint16_t RegIndex
Definition types.hh:176
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
@ FloatRegClass
Floating-point register.
Definition reg_class.hh:62
@ IntRegClass
Integer register.
Definition reg_class.hh:61
void ccprintf(cp::Print &print)
Definition cprintf.hh:130

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0