gem5  v22.1.0.0
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"
33 #include "arch/sparc/regs/int.hh"
34 #include "arch/sparc/regs/misc.hh"
35 #include "base/bitunion.hh"
36 
37 namespace gem5
38 {
39 
40 namespace SparcISA
41 {
42 
43 const 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 
63 void
64 SparcStaticInst::printMnemonic(std::ostream &os, const char *mnemonic)
65 {
66  ccprintf(os, "\t%s ", mnemonic);
67 }
68 
69 void
70 SparcStaticInst::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 
82 void
84 {
85  pcState.as<PCState>().advance();
86 }
87 
88 void
90 {
91  PCState pc = tc->pcState().as<PCState>();
92  pc.advance();
93  tc->pcState(pc);
94 }
95 
96 void
97 SparcStaticInst::printSrcReg(std::ostream &os, int reg) const
98 {
99  if (_numSrcRegs > reg)
101 }
102 
103 void
104 SparcStaticInst::printDestReg(std::ostream &os, int reg) const
105 {
106  if (_numDestRegs > reg)
108 }
109 
110 void
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;
186  case MISCREG_SOFTINT_SET:
187  ccprintf(os, "%%softint_set");
188  break;
189  case MISCREG_SOFTINT_CLR:
190  ccprintf(os, "%%softint_clr");
191  break;
192  case MISCREG_TICK_CMPR:
193  ccprintf(os, "%%tick_cmpr");
194  break;
195  case MISCREG_STICK:
196  ccprintf(os, "%%stick");
197  break;
198  case MISCREG_STICK_CMPR:
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;
246  case MISCREG_HSTICK_CMPR:
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 
264 std::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 << ",";
287  printReg(ss, destRegIdx(0));
288  }
289 
290  return ss.str();
291 }
292 
293 bool
294 SparcStaticInst::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;
310  case FUnorderedOrGreater:
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;
322  case FUnorderedOrEqual:
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 
338 bool
339 SparcStaticInst::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);
368  case LessOrEqualUnsigned:
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:72
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
void printRegArray(std::ostream &os, const RegId *indexArray, int num) const
Definition: static_inst.cc:70
static bool passesCondition(uint32_t codes, uint32_t condition)
Definition: static_inst.cc:339
static void printReg(std::ostream &os, RegId reg)
Definition: static_inst.cc:111
static void printMnemonic(std::ostream &os, const char *mnemonic)
Definition: static_inst.cc:64
void advancePC(PCStateBase &pcState) const override
Definition: static_inst.cc:83
void printDestReg(std::ostream &os, int reg) const
Definition: static_inst.cc:104
static bool passesFpCondition(uint32_t fcc, uint32_t condition)
Definition: static_inst.cc:294
std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: static_inst.cc:265
void printSrcReg(std::ostream &os, int reg) const
Definition: static_inst.cc:97
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:225
uint8_t _numSrcRegs
See numSrcRegs().
Definition: static_inst.hh:109
uint8_t _numDestRegs
See numDestRegs().
Definition: static_inst.hh:112
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:259
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:215
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual const PCStateBase & pcState() const =0
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 9 > e
Definition: misc_types.hh:65
Bitfield< 22 > u
Definition: misc_types.hh:359
Bitfield< 4 > pc
Bitfield< 4 > g
Definition: dt_constants.hh:86
Bitfield< 6 > z
Definition: misc.hh:144
@ MISCREG_SOFTINT_CLR
Definition: misc.hh:54
@ MISCREG_HTBA
Definition: misc.hh:82
@ MISCREG_CWP
Definition: misc.hh:70
@ MISCREG_HPSTATE
Hyper privileged registers.
Definition: misc.hh:79
@ MISCREG_PIC
Definition: misc.hh:51
@ MISCREG_PSTATE
Definition: misc.hh:67
@ MISCREG_FPRS
Definition: misc.hh:49
@ MISCREG_PCR
Definition: misc.hh:50
@ MISCREG_TT
Definition: misc.hh:64
@ MISCREG_TICK
Definition: misc.hh:48
@ MISCREG_STICK_CMPR
Definition: misc.hh:58
@ MISCREG_TICK_CMPR
Definition: misc.hh:56
@ MISCREG_PIL
Definition: misc.hh:69
@ 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_TL
Definition: misc.hh:68
@ MISCREG_HSTICK_CMPR
Definition: misc.hh:85
@ MISCREG_SOFTINT_SET
Definition: misc.hh:53
@ MISCREG_GL
Definition: misc.hh:76
@ MISCREG_TNPC
Definition: misc.hh:62
@ MISCREG_STRAND_STS_REG
Definition: misc.hh:84
@ MISCREG_TBA
Definition: misc.hh:66
@ MISCREG_FSR
Floating Point Status Register.
Definition: misc.hh:88
@ MISCREG_SOFTINT
Definition: misc.hh:55
@ MISCREG_GSR
Definition: misc.hh:52
@ MISCREG_HVER
Definition: misc.hh:83
@ 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
@ FUnorderedOrGreaterOrEqual
Definition: static_inst.hh:84
EndBitUnion(HPSTATE) BitUnion16(PSTATE) Bitfield< 1 > ie
const char * CondTestAbbrev[]
Definition: static_inst.cc:43
Bitfield< 4 > x
Definition: pagetable.hh:61
Bitfield< 55 > l
Definition: pagetable.hh:54
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 17 > os
Definition: misc.hh:810
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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:61
@ IntRegClass
Integer register.
Definition: reg_class.hh:60
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
std::stringstream ss
Definition: trace.test.cc:45

Generated on Wed Dec 21 2022 10:22:26 for gem5 by doxygen 1.9.1