gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
misc.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 2012-2013, 2017-2018 ARM Limited
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met: redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer;
19  * redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution;
22  * neither the name of the copyright holders nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include "arch/arm/insts/misc.hh"
40 
41 #include "cpu/reg_class.hh"
42 
43 std::string
45 {
46  std::stringstream ss;
47  printMnemonic(ss);
48  printIntReg(ss, dest);
49  ss << ", ";
50  bool foundPsr = false;
51  for (unsigned i = 0; i < numSrcRegs(); i++) {
52  const RegId& reg = srcRegIdx(i);
53  if (!reg.isMiscReg()) {
54  continue;
55  }
56  if (reg.index() == MISCREG_CPSR) {
57  ss << "cpsr";
58  foundPsr = true;
59  break;
60  }
61  if (reg.index() == MISCREG_SPSR) {
62  ss << "spsr";
63  foundPsr = true;
64  break;
65  }
66  }
67  if (!foundPsr) {
68  ss << "????";
69  }
70  return ss.str();
71 }
72 
73 void
74 MsrBase::printMsrBase(std::ostream &os) const
75 {
76  printMnemonic(os);
77  bool apsr = false;
78  bool foundPsr = false;
79  for (unsigned i = 0; i < numDestRegs(); i++) {
80  const RegId& reg = destRegIdx(i);
81  if (!reg.isMiscReg()) {
82  continue;
83  }
84  if (reg.index() == MISCREG_CPSR) {
85  os << "cpsr_";
86  foundPsr = true;
87  break;
88  }
89  if (reg.index() == MISCREG_SPSR) {
90  if (bits(byteMask, 1, 0)) {
91  os << "spsr_";
92  } else {
93  os << "apsr_";
94  apsr = true;
95  }
96  foundPsr = true;
97  break;
98  }
99  }
100  if (!foundPsr) {
101  os << "????";
102  return;
103  }
104  if (bits(byteMask, 3)) {
105  if (apsr) {
106  os << "nzcvq";
107  } else {
108  os << "f";
109  }
110  }
111  if (bits(byteMask, 2)) {
112  if (apsr) {
113  os << "g";
114  } else {
115  os << "s";
116  }
117  }
118  if (bits(byteMask, 1)) {
119  os << "x";
120  }
121  if (bits(byteMask, 0)) {
122  os << "c";
123  }
124 }
125 
126 std::string
128 {
129  std::stringstream ss;
130  printMsrBase(ss);
131  ccprintf(ss, ", #%#x", imm);
132  return ss.str();
133 }
134 
135 std::string
137 {
138  std::stringstream ss;
139  printMsrBase(ss);
140  ss << ", ";
141  printIntReg(ss, op1);
142  return ss.str();
143 }
144 
145 std::string
147 {
148  std::stringstream ss;
149  printMnemonic(ss);
150  printIntReg(ss, dest);
151  ss << ", ";
152  printIntReg(ss, dest2);
153  ss << ", ";
154  printMiscReg(ss, op1);
155  return ss.str();
156 }
157 
158 std::string
160 {
161  std::stringstream ss;
162  printMnemonic(ss);
163  printMiscReg(ss, dest);
164  ss << ", ";
165  printIntReg(ss, op1);
166  ss << ", ";
167  printIntReg(ss, op2);
168  return ss.str();
169 }
170 
171 std::string
173 {
174  std::stringstream ss;
175  printMnemonic(ss);
176  ccprintf(ss, "#%d", imm);
177  return ss.str();
178 }
179 
180 std::string
182 {
183  std::stringstream ss;
184  printMnemonic(ss);
185  printIntReg(ss, dest);
186  ccprintf(ss, ", #%d", imm);
187  return ss.str();
188 }
189 
190 std::string
192 {
193  std::stringstream ss;
194  printMnemonic(ss);
195  printIntReg(ss, dest);
196  ss << ", ";
197  printIntReg(ss, op1);
198  return ss.str();
199 }
200 
201 std::string
203 {
204  std::stringstream ss;
205  printMnemonic(ss);
206  printIntReg(ss, dest);
207  return ss.str();
208 }
209 
210 std::string
212  Addr pc, const Loader::SymbolTable *symtab) const
213 {
214  std::stringstream ss;
215  printMnemonic(ss);
216  printIntReg(ss, dest);
217  ss << ", ";
218  printIntReg(ss, op1);
219  ss << ", ";
220  printIntReg(ss, op2);
221  ccprintf(ss, ", #%d", imm);
222  return ss.str();
223 }
224 
225 std::string
227  Addr pc, const Loader::SymbolTable *symtab) const
228 {
229  std::stringstream ss;
230  printMnemonic(ss);
231  printIntReg(ss, dest);
232  ss << ", ";
233  printIntReg(ss, op1);
234  ss << ", ";
235  printIntReg(ss, op2);
236  ss << ", ";
237  printIntReg(ss, op3);
238  return ss.str();
239 }
240 
241 std::string
243  Addr pc, const Loader::SymbolTable *symtab) const
244 {
245  std::stringstream ss;
246  printMnemonic(ss);
247  printIntReg(ss, dest);
248  ss << ", ";
249  printIntReg(ss, op1);
250  ss << ", ";
251  printIntReg(ss, op2);
252  return ss.str();
253 }
254 
255 std::string
257  Addr pc, const Loader::SymbolTable *symtab) const
258 {
259  std::stringstream ss;
260  printMnemonic(ss);
261  printIntReg(ss, dest);
262  ss << ", ";
263  printIntReg(ss, op1);
264  ccprintf(ss, ", #%d", imm);
265  return ss.str();
266 }
267 
268 std::string
270  Addr pc, const Loader::SymbolTable *symtab) const
271 {
272  std::stringstream ss;
273  printMnemonic(ss);
274  printMiscReg(ss, dest);
275  ss << ", ";
276  printIntReg(ss, op1);
277  return ss.str();
278 }
279 
280 std::string
282  Addr pc, const Loader::SymbolTable *symtab) const
283 {
284  std::stringstream ss;
285  printMnemonic(ss);
286  printIntReg(ss, dest);
287  ss << ", ";
288  printMiscReg(ss, op1);
289  return ss.str();
290 }
291 
292 std::string
294  Addr pc, const Loader::SymbolTable *symtab) const
295 {
296  std::stringstream ss;
297  printMnemonic(ss);
298  printIntReg(ss, dest);
299  ccprintf(ss, ", #%d, #%d", imm1, imm2);
300  return ss.str();
301 }
302 
303 std::string
305  Addr pc, const Loader::SymbolTable *symtab) const
306 {
307  std::stringstream ss;
308  printMnemonic(ss);
309  printIntReg(ss, dest);
310  ss << ", ";
311  printIntReg(ss, op1);
312  ccprintf(ss, ", #%d, #%d", imm1, imm2);
313  return ss.str();
314 }
315 
316 std::string
318  Addr pc, const Loader::SymbolTable *symtab) const
319 {
320  std::stringstream ss;
321  printMnemonic(ss);
322  printIntReg(ss, dest);
323  ccprintf(ss, ", #%d, ", imm);
324  printIntReg(ss, op1);
325  return ss.str();
326 }
327 
328 std::string
330  Addr pc, const Loader::SymbolTable *symtab) const
331 {
332  std::stringstream ss;
333  printMnemonic(ss);
334  printIntReg(ss, dest);
335  ccprintf(ss, ", #%d, ", imm);
336  printShiftOperand(ss, op1, true, shiftAmt, INTREG_ZERO, shiftType);
337  printIntReg(ss, op1);
338  return ss.str();
339 }
340 
341 std::string
343  Addr pc, const Loader::SymbolTable *symtab) const
344 {
345  return csprintf("%-10s (inst %#08x)", "unknown", encoding());
346 }
347 
348 McrMrcMiscInst::McrMrcMiscInst(const char *_mnemonic, ExtMachInst _machInst,
349  uint64_t _iss, MiscRegIndex _miscReg)
350  : ArmStaticInst(_mnemonic, _machInst, No_OpClass)
351 {
352  flags[IsNonSpeculative] = true;
353  iss = _iss;
354  miscReg = _miscReg;
355 }
356 
357 Fault
359 {
360  bool hypTrap = mcrMrc15TrapToHyp(miscReg, xc->tcBase(), iss);
361 
362  if (hypTrap) {
363  return std::make_shared<HypervisorTrap>(machInst, iss,
365  } else {
366  return NoFault;
367  }
368 }
369 
370 std::string
372  Addr pc, const Loader::SymbolTable *symtab) const
373 {
374  return csprintf("%-10s (pipe flush)", mnemonic);
375 }
376 
378  ExtMachInst _machInst, uint64_t _iss,
379  MiscRegIndex _miscReg)
380  : McrMrcMiscInst(_mnemonic, _machInst, _iss, _miscReg)
381 {}
382 
383 Fault
385 {
386  bool hypTrap = mcrMrc15TrapToHyp(miscReg, xc->tcBase(), iss);
387 
388  if (hypTrap) {
389  return std::make_shared<HypervisorTrap>(machInst, iss,
391  } else {
392  return std::make_shared<UndefinedInstruction>(machInst, false,
393  mnemonic);
394  }
395 }
396 
397 std::string
399  Addr pc, const Loader::SymbolTable *symtab) const
400 {
401  return csprintf("%-10s (implementation defined)", mnemonic);
402 }
bool mcrMrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc, uint32_t iss, ExceptionClass *ec)
Definition: utility.cc:530
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:202
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:211
void printMnemonic(std::ostream &os, const std::string &suffix="", bool withPred=true, bool withCond64=false, ConditionCode cond64=COND_UC) const
Definition: static_inst.cc:372
MiscRegIndex
Definition: miscregs.hh:56
int8_t numSrcRegs() const
Number of source registers.
Definition: static_inst.hh:135
Bitfield< 5, 3 > reg
Definition: types.hh:87
decltype(nullptr) constexpr NoFault
Definition: types.hh:243
bool isMiscReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:161
Bitfield< 7 > i
uint64_t iss
Definition: misc.hh:398
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:44
int8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:137
void printMsrBase(std::ostream &os) const
Definition: misc.cc:74
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:246
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th source reg.
Definition: static_inst.hh:222
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:293
Bitfield< 17 > os
Definition: misc.hh:803
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:342
IntRegIndex dest
Definition: misc.hh:46
const ExtMachInst machInst
The binary machine instruction.
Definition: static_inst.hh:231
std::bitset< Num_Flags > flags
Flag values for this instruction.
Definition: static_inst.hh:99
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition: exec_context.hh:70
Bitfield< 4 > pc
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
McrMrcImplDefined(const char *_mnemonic, ExtMachInst _machInst, uint64_t _iss, MiscRegIndex _miscReg)
Definition: misc.cc:377
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:159
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:181
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:304
void printIntReg(std::ostream &os, RegIndex reg_idx, uint8_t opWidth=0) const
Print a register name for disassembly given the unique dependence tag number (FP or int)...
Definition: static_inst.cc:294
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:242
void printShiftOperand(std::ostream &os, IntRegIndex rm, bool immShift, uint32_t shiftAmt, IntRegIndex rs, ArmShiftType type) const
Definition: static_inst.cc:493
Bitfield< 21 > ss
virtual ThreadContext * tcBase() const =0
Returns a pointer to the ThreadContext.
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:371
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
Bitfield< 7, 0 > imm
Definition: types.hh:140
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:136
void printMiscReg(std::ostream &os, RegIndex reg_idx) const
Definition: static_inst.cc:365
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:172
McrMrcMiscInst(const char *_mnemonic, ExtMachInst _machInst, uint64_t _iss, MiscRegIndex _miscReg)
Definition: misc.cc:348
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:281
Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const override
Definition: misc.cc:384
Certain mrc/mcr instructions act as nops or flush the pipe based on what register the instruction is ...
Definition: misc.hh:395
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:269
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:173
Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const override
Definition: misc.cc:358
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:146
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th destination reg.
Definition: static_inst.hh:218
TheISA::ExtMachInst ExtMachInst
Binary extended machine instruction type.
Definition: static_inst.hh:89
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
MiscRegIndex miscReg
Definition: misc.hh:399
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:256
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:398
T bits(T val, int first, int last)
Extract the bitfield from position &#39;first&#39; to &#39;last&#39; (inclusive) from &#39;val&#39; and right justify it...
Definition: bitfield.hh:71
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:317
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:191
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:226
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:329
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
MachInst encoding() const
Returns the real encoding of the instruction: the machInst field is in fact always 64 bit wide and co...
Definition: static_inst.hh:527
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:127

Generated on Mon Jun 8 2020 15:34:39 for gem5 by doxygen 1.8.13