gem5  v19.0.0.0
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  * Authors: Gabe Black
39  */
40 
41 #include "arch/arm/insts/misc.hh"
42 
43 #include "cpu/reg_class.hh"
44 
45 std::string
47 {
48  std::stringstream ss;
49  printMnemonic(ss);
50  printIntReg(ss, dest);
51  ss << ", ";
52  bool foundPsr = false;
53  for (unsigned i = 0; i < numSrcRegs(); i++) {
54  const RegId& reg = srcRegIdx(i);
55  if (!reg.isMiscReg()) {
56  continue;
57  }
58  if (reg.index() == MISCREG_CPSR) {
59  ss << "cpsr";
60  foundPsr = true;
61  break;
62  }
63  if (reg.index() == MISCREG_SPSR) {
64  ss << "spsr";
65  foundPsr = true;
66  break;
67  }
68  }
69  if (!foundPsr) {
70  ss << "????";
71  }
72  return ss.str();
73 }
74 
75 void
76 MsrBase::printMsrBase(std::ostream &os) const
77 {
78  printMnemonic(os);
79  bool apsr = false;
80  bool foundPsr = false;
81  for (unsigned i = 0; i < numDestRegs(); i++) {
82  const RegId& reg = destRegIdx(i);
83  if (!reg.isMiscReg()) {
84  continue;
85  }
86  if (reg.index() == MISCREG_CPSR) {
87  os << "cpsr_";
88  foundPsr = true;
89  break;
90  }
91  if (reg.index() == MISCREG_SPSR) {
92  if (bits(byteMask, 1, 0)) {
93  os << "spsr_";
94  } else {
95  os << "apsr_";
96  apsr = true;
97  }
98  foundPsr = true;
99  break;
100  }
101  }
102  if (!foundPsr) {
103  os << "????";
104  return;
105  }
106  if (bits(byteMask, 3)) {
107  if (apsr) {
108  os << "nzcvq";
109  } else {
110  os << "f";
111  }
112  }
113  if (bits(byteMask, 2)) {
114  if (apsr) {
115  os << "g";
116  } else {
117  os << "s";
118  }
119  }
120  if (bits(byteMask, 1)) {
121  os << "x";
122  }
123  if (bits(byteMask, 0)) {
124  os << "c";
125  }
126 }
127 
128 std::string
130 {
131  std::stringstream ss;
132  printMsrBase(ss);
133  ccprintf(ss, ", #%#x", imm);
134  return ss.str();
135 }
136 
137 std::string
139 {
140  std::stringstream ss;
141  printMsrBase(ss);
142  ss << ", ";
143  printIntReg(ss, op1);
144  return ss.str();
145 }
146 
147 std::string
149 {
150  std::stringstream ss;
151  printMnemonic(ss);
152  printIntReg(ss, dest);
153  ss << ", ";
154  printIntReg(ss, dest2);
155  ss << ", ";
156  printMiscReg(ss, op1);
157  return ss.str();
158 }
159 
160 std::string
162 {
163  std::stringstream ss;
164  printMnemonic(ss);
165  printMiscReg(ss, dest);
166  ss << ", ";
167  printIntReg(ss, op1);
168  ss << ", ";
169  printIntReg(ss, op2);
170  return ss.str();
171 }
172 
173 std::string
175 {
176  std::stringstream ss;
177  printMnemonic(ss);
178  ccprintf(ss, "#%d", imm);
179  return ss.str();
180 }
181 
182 std::string
184 {
185  std::stringstream ss;
186  printMnemonic(ss);
187  printIntReg(ss, dest);
188  ccprintf(ss, ", #%d", imm);
189  return ss.str();
190 }
191 
192 std::string
194 {
195  std::stringstream ss;
196  printMnemonic(ss);
197  printIntReg(ss, dest);
198  ss << ", ";
199  printIntReg(ss, op1);
200  return ss.str();
201 }
202 
203 std::string
205 {
206  std::stringstream ss;
207  printMnemonic(ss);
208  printIntReg(ss, dest);
209  return ss.str();
210 }
211 std::string
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 {
228  std::stringstream ss;
229  printMnemonic(ss);
230  printIntReg(ss, dest);
231  ss << ", ";
232  printIntReg(ss, op1);
233  ss << ", ";
234  printIntReg(ss, op2);
235  ss << ", ";
236  printIntReg(ss, op3);
237  return ss.str();
238 }
239 
240 std::string
242 {
243  std::stringstream ss;
244  printMnemonic(ss);
245  printIntReg(ss, dest);
246  ss << ", ";
247  printIntReg(ss, op1);
248  ss << ", ";
249  printIntReg(ss, op2);
250  return ss.str();
251 }
252 
253 std::string
255 {
256  std::stringstream ss;
257  printMnemonic(ss);
258  printIntReg(ss, dest);
259  ss << ", ";
260  printIntReg(ss, op1);
261  ccprintf(ss, ", #%d", imm);
262  return ss.str();
263 }
264 
265 std::string
267 {
268  std::stringstream ss;
269  printMnemonic(ss);
270  printMiscReg(ss, dest);
271  ss << ", ";
272  printIntReg(ss, op1);
273  return ss.str();
274 }
275 
276 std::string
278 {
279  std::stringstream ss;
280  printMnemonic(ss);
281  printIntReg(ss, dest);
282  ss << ", ";
283  printMiscReg(ss, op1);
284  return ss.str();
285 }
286 
287 std::string
289 {
290  std::stringstream ss;
291  printMnemonic(ss);
292  printIntReg(ss, dest);
293  ccprintf(ss, ", #%d, #%d", imm1, imm2);
294  return ss.str();
295 }
296 
297 std::string
299 {
300  std::stringstream ss;
301  printMnemonic(ss);
302  printIntReg(ss, dest);
303  ss << ", ";
304  printIntReg(ss, op1);
305  ccprintf(ss, ", #%d, #%d", imm1, imm2);
306  return ss.str();
307 }
308 
309 std::string
311 {
312  std::stringstream ss;
313  printMnemonic(ss);
314  printIntReg(ss, dest);
315  ccprintf(ss, ", #%d, ", imm);
316  printIntReg(ss, op1);
317  return ss.str();
318 }
319 
320 std::string
322 {
323  std::stringstream ss;
324  printMnemonic(ss);
325  printIntReg(ss, dest);
326  ccprintf(ss, ", #%d, ", imm);
327  printShiftOperand(ss, op1, true, shiftAmt, INTREG_ZERO, shiftType);
328  printIntReg(ss, op1);
329  return ss.str();
330 }
331 
332 std::string
334 {
335  return csprintf("%-10s (inst %#08x)", "unknown", encoding());
336 }
337 
338 McrMrcMiscInst::McrMrcMiscInst(const char *_mnemonic, ExtMachInst _machInst,
339  uint64_t _iss, MiscRegIndex _miscReg)
340  : ArmStaticInst(_mnemonic, _machInst, No_OpClass)
341 {
342  flags[IsNonSpeculative] = true;
343  iss = _iss;
344  miscReg = _miscReg;
345 }
346 
347 Fault
349 {
350  bool hypTrap = mcrMrc15TrapToHyp(miscReg, xc->tcBase(), iss);
351 
352  if (hypTrap) {
353  return std::make_shared<HypervisorTrap>(machInst, iss,
355  } else {
356  return NoFault;
357  }
358 }
359 
360 std::string
362 {
363  return csprintf("%-10s (pipe flush)", mnemonic);
364 }
365 
367  ExtMachInst _machInst, uint64_t _iss,
368  MiscRegIndex _miscReg)
369  : McrMrcMiscInst(_mnemonic, _machInst, _iss, _miscReg)
370 {}
371 
372 Fault
374 {
375  bool hypTrap = mcrMrc15TrapToHyp(miscReg, xc->tcBase(), iss);
376 
377  if (hypTrap) {
378  return std::make_shared<HypervisorTrap>(machInst, iss,
380  } else {
381  return std::make_shared<UndefinedInstruction>(machInst, false,
382  mnemonic);
383  }
384 }
385 
386 std::string
388  const SymbolTable *symtab) const
389 {
390  return csprintf("%-10s (implementation defined)", mnemonic);
391 }
void ccprintf(cp::Print &print)
Definition: cprintf.hh:131
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:138
void printMnemonic(std::ostream &os, const std::string &suffix="", bool withPred=true, bool withCond64=false, ConditionCode cond64=COND_UC) const
Definition: static_inst.cc:374
MiscRegIndex
Definition: miscregs.hh:57
int8_t numSrcRegs() const
Number of source registers.
Definition: static_inst.hh:133
Bitfield< 5, 3 > reg
Definition: types.hh:89
decltype(nullptr) constexpr NoFault
Definition: types.hh:245
bool isMiscReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:167
Bitfield< 7 > i
uint64_t iss
Definition: misc.hh:400
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:298
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:212
int8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:135
void printMsrBase(std::ostream &os) const
Definition: misc.cc:76
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:244
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th source reg.
Definition: static_inst.hh:220
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:361
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:387
Bitfield< 17 > os
Definition: misc.hh:805
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:174
IntRegIndex dest
Definition: misc.hh:48
const ExtMachInst machInst
The binary machine instruction.
Definition: static_inst.hh:229
std::bitset< Num_Flags > flags
Flag values for this instruction.
Definition: static_inst.hh:97
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:277
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition: exec_context.hh:73
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:226
Bitfield< 4 > pc
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:266
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:162
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:241
McrMrcImplDefined(const char *_mnemonic, ExtMachInst _machInst, uint64_t _iss, MiscRegIndex _miscReg)
Definition: misc.cc:366
bool mcrMrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc, uint32_t iss)
Definition: utility.cc:517
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:193
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:296
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:148
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:129
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
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:183
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Bitfield< 7, 0 > imm
Definition: types.hh:142
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:321
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:254
void printMiscReg(std::ostream &os, RegIndex reg_idx) const
Definition: static_inst.cc:367
McrMrcMiscInst(const char *_mnemonic, ExtMachInst _machInst, uint64_t _iss, MiscRegIndex _miscReg)
Definition: misc.cc:338
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:46
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:161
Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const override
Definition: misc.cc:373
Certain mrc/mcr instructions act as nops or flush the pipe based on what register the instruction is ...
Definition: misc.hh:397
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:179
virtual ThreadContext * tcBase()=0
Returns a pointer to the ThreadContext.
Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const override
Definition: misc.cc:348
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th destination reg.
Definition: static_inst.hh:216
TheISA::ExtMachInst ExtMachInst
Binary extended machine instruction type.
Definition: static_inst.hh:87
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:288
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:79
MiscRegIndex miscReg
Definition: misc.hh:401
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:72
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:333
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:204
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:310
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:533

Generated on Fri Feb 28 2020 16:26:57 for gem5 by doxygen 1.8.13