gem5  v20.1.0.0
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 using namespace ArmISA;
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 
212 std::string
214  Addr pc, const Loader::SymbolTable *symtab) const
215 {
216  std::stringstream ss;
217  printMnemonic(ss);
218  printIntReg(ss, dest);
219  ss << ", ";
220  printIntReg(ss, op1);
221  ss << ", ";
222  printIntReg(ss, op2);
223  ccprintf(ss, ", #%d", imm);
224  return ss.str();
225 }
226 
227 std::string
229  Addr pc, const Loader::SymbolTable *symtab) const
230 {
231  std::stringstream ss;
232  printMnemonic(ss);
233  printIntReg(ss, dest);
234  ss << ", ";
235  printIntReg(ss, op1);
236  ss << ", ";
237  printIntReg(ss, op2);
238  ss << ", ";
239  printIntReg(ss, op3);
240  return ss.str();
241 }
242 
243 std::string
245  Addr pc, const Loader::SymbolTable *symtab) const
246 {
247  std::stringstream ss;
248  printMnemonic(ss);
249  printIntReg(ss, dest);
250  ss << ", ";
251  printIntReg(ss, op1);
252  ss << ", ";
253  printIntReg(ss, op2);
254  return ss.str();
255 }
256 
257 std::string
259  Addr pc, const Loader::SymbolTable *symtab) const
260 {
261  std::stringstream ss;
262  printMnemonic(ss);
263  printIntReg(ss, dest);
264  ss << ", ";
265  printIntReg(ss, op1);
266  ccprintf(ss, ", #%d", imm);
267  return ss.str();
268 }
269 
270 std::string
272  Addr pc, const Loader::SymbolTable *symtab) const
273 {
274  std::stringstream ss;
275  printMnemonic(ss);
276  printMiscReg(ss, dest);
277  ss << ", ";
278  printIntReg(ss, op1);
279  return ss.str();
280 }
281 
282 std::string
284  Addr pc, const Loader::SymbolTable *symtab) const
285 {
286  std::stringstream ss;
287  printMnemonic(ss);
288  printIntReg(ss, dest);
289  ss << ", ";
290  printMiscReg(ss, op1);
291  return ss.str();
292 }
293 
294 std::string
296  Addr pc, const Loader::SymbolTable *symtab) const
297 {
298  std::stringstream ss;
299  printMnemonic(ss);
300  printIntReg(ss, dest);
301  ccprintf(ss, ", #%d, #%d", imm1, imm2);
302  return ss.str();
303 }
304 
305 std::string
307  Addr pc, const Loader::SymbolTable *symtab) const
308 {
309  std::stringstream ss;
310  printMnemonic(ss);
311  printIntReg(ss, dest);
312  ss << ", ";
313  printIntReg(ss, op1);
314  ccprintf(ss, ", #%d, #%d", imm1, imm2);
315  return ss.str();
316 }
317 
318 std::string
320  Addr pc, const Loader::SymbolTable *symtab) const
321 {
322  std::stringstream ss;
323  printMnemonic(ss);
324  printIntReg(ss, dest);
325  ccprintf(ss, ", #%d, ", imm);
326  printIntReg(ss, op1);
327  return ss.str();
328 }
329 
330 std::string
332  Addr pc, const Loader::SymbolTable *symtab) const
333 {
334  std::stringstream ss;
335  printMnemonic(ss);
336  printIntReg(ss, dest);
337  ccprintf(ss, ", #%d, ", imm);
338  printShiftOperand(ss, op1, true, shiftAmt, INTREG_ZERO, shiftType);
339  printIntReg(ss, op1);
340  return ss.str();
341 }
342 
343 std::string
345  Addr pc, const Loader::SymbolTable *symtab) const
346 {
347  return csprintf("%-10s (inst %#08x)", "unknown", encoding());
348 }
349 
350 McrMrcMiscInst::McrMrcMiscInst(const char *_mnemonic, ExtMachInst _machInst,
351  uint64_t _iss, MiscRegIndex _miscReg)
352  : ArmStaticInst(_mnemonic, _machInst, No_OpClass)
353 {
354  flags[IsNonSpeculative] = true;
355  iss = _iss;
356  miscReg = _miscReg;
357 }
358 
359 Fault
361 {
362  bool hypTrap = mcrMrc15TrapToHyp(miscReg, xc->tcBase(), iss);
363 
364  if (hypTrap) {
365  return std::make_shared<HypervisorTrap>(machInst, iss,
367  } else {
368  return NoFault;
369  }
370 }
371 
372 std::string
374  Addr pc, const Loader::SymbolTable *symtab) const
375 {
376  return csprintf("%-10s (pipe flush)", mnemonic);
377 }
378 
380  ExtMachInst _machInst, uint64_t _iss,
381  MiscRegIndex _miscReg)
382  : McrMrcMiscInst(_mnemonic, _machInst, _iss, _miscReg)
383 {}
384 
385 Fault
387 {
388  bool hypTrap = mcrMrc15TrapToHyp(miscReg, xc->tcBase(), iss);
389 
390  if (hypTrap) {
391  return std::make_shared<HypervisorTrap>(machInst, iss,
393  } else {
394  return std::make_shared<UndefinedInstruction>(machInst, false,
395  mnemonic);
396  }
397 }
398 
399 std::string
401  Addr pc, const Loader::SymbolTable *symtab) const
402 {
403  return csprintf("%-10s (implementation defined)", mnemonic);
404 }
StaticInst::flags
std::bitset< Num_Flags > flags
Flag values for this instruction.
Definition: static_inst.hh:99
X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:803
misc.hh
RegOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:204
UnknownOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:344
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Loader::SymbolTable
Definition: symtab.hh:59
ArmISA::INTREG_ZERO
@ INTREG_ZERO
Definition: intregs.hh:112
Trace::InstRecord
Definition: insttracer.hh:55
MrrcOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:148
RegImmImmOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:295
McrrOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:161
RegRegRegRegOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:228
ArmISA::mcrMrc15TrapToHyp
bool mcrMrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc, uint32_t iss, ExceptionClass *ec)
Definition: utility.cc:607
ArmISA
Definition: ccregs.hh:41
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:87
MsrBase::printMsrBase
void printMsrBase(std::ostream &os) const
Definition: misc.cc:76
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
McrMrcImplDefined::McrMrcImplDefined
McrMrcImplDefined(const char *_mnemonic, ArmISA::ExtMachInst _machInst, uint64_t _iss, ArmISA::MiscRegIndex _miscReg)
Definition: misc.cc:379
ArmISA::ArmStaticInst
Definition: static_inst.hh:60
RegRegRegOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:244
MrsOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:46
RegRegImmImmOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:306
McrMrcMiscInst::iss
uint64_t iss
Definition: misc.hh:406
RegImmRegShiftOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:331
ArmISA::ss
Bitfield< 21 > ss
Definition: miscregs_types.hh:56
ArmISA::imm
Bitfield< 7, 0 > imm
Definition: types.hh:141
Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
McrMrcMiscInst::McrMrcMiscInst
McrMrcMiscInst(const char *_mnemonic, ArmISA::ExtMachInst _machInst, uint64_t _iss, ArmISA::MiscRegIndex _miscReg)
Definition: misc.cc:350
ExecContext
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition: exec_context.hh:70
StaticInst::mnemonic
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:258
StaticInst::ExtMachInst
TheISA::ExtMachInst ExtMachInst
Binary extended machine instruction type.
Definition: static_inst.hh:89
McrMrcImplDefined::execute
Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const override
Definition: misc.cc:386
NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:245
ArmISA::MISCREG_SPSR
@ MISCREG_SPSR
Definition: miscregs.hh:58
McrMrcMiscInst::execute
Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const override
Definition: misc.cc:360
McrMrcImplDefined::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:400
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
ImmOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:174
ArmISA::EC_TRAPPED_CP15_MCR_MRC
@ EC_TRAPPED_CP15_MCR_MRC
Definition: types.hh:652
McrMrcMiscInst
Certain mrc/mcr instructions act as nops or flush the pipe based on what register the instruction is ...
Definition: misc.hh:403
MiscRegRegImmOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:271
McrMrcMiscInst::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:373
ExecContext::tcBase
virtual ThreadContext * tcBase() const =0
Returns a pointer to the ThreadContext.
RegRegImmOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:258
ArmISA::MISCREG_CPSR
@ MISCREG_CPSR
Definition: miscregs.hh:57
MsrRegOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:138
StaticInst::machInst
const ExtMachInst machInst
The binary machine instruction.
Definition: static_inst.hh:243
RegRegOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:193
RegImmOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:183
McrMrcMiscInst::miscReg
ArmISA::MiscRegIndex miscReg
Definition: misc.hh:407
ArmISA::MiscRegIndex
MiscRegIndex
Definition: miscregs.hh:56
reg_class.hh
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
RegImmRegOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:319
ArmISA::encoding
Bitfield< 27, 25 > encoding
Definition: types.hh:99
RegMiscRegImmOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:283
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
MsrImmOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:129
RegRegRegImmOp::generateDisassembly
std::string generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc.cc:213
bits
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:75

Generated on Wed Sep 30 2020 14:02:00 for gem5 by doxygen 1.8.17