gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
misc64.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2013,2017-2019 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Authors: Gabe Black
38  * Giacomo Travaglini
39  */
40 
41 #include "arch/arm/insts/misc64.hh"
42 #include "arch/arm/isa.hh"
43 
44 std::string
46 {
47  std::stringstream ss;
48  printMnemonic(ss, "", false);
49  ccprintf(ss, "#0x%x", imm);
50  return ss.str();
51 }
52 
53 std::string
55 {
56  std::stringstream ss;
57  printMnemonic(ss, "", false);
58  printIntReg(ss, dest);
59  ss << ", ";
60  printIntReg(ss, op1);
61  ccprintf(ss, ", #%d, #%d", imm1, imm2);
62  return ss.str();
63 }
64 
65 std::string
67  Addr pc, const SymbolTable *symtab) const
68 {
69  std::stringstream ss;
70  printMnemonic(ss, "", false);
71  printIntReg(ss, dest);
72  ss << ", ";
73  printIntReg(ss, op1);
74  ss << ", ";
75  printIntReg(ss, op2);
76  ccprintf(ss, ", #%d", imm);
77  return ss.str();
78 }
79 
80 std::string
82 {
83  return csprintf("%-10s (inst %#08x)", "unknown", encoding());
84 }
85 
86 Fault
88  ExceptionLevel el, uint32_t immediate) const
89 {
91 
92  // Check for traps to supervisor (FP/SIMD regs)
93  if (el <= EL1 && checkEL1Trap(tc, misc_reg, el, ec, immediate)) {
94  return std::make_shared<SupervisorTrap>(machInst, immediate, ec);
95  }
96 
97  // Check for traps to hypervisor
98  if ((ArmSystem::haveVirtualization(tc) && el <= EL2) &&
99  checkEL2Trap(tc, misc_reg, el, ec, immediate)) {
100  return std::make_shared<HypervisorTrap>(machInst, immediate, ec);
101  }
102 
103  // Check for traps to secure monitor
104  if ((ArmSystem::haveSecurity(tc) && el <= EL3) &&
105  checkEL3Trap(tc, misc_reg, el, ec, immediate)) {
106  return std::make_shared<SecureMonitorTrap>(machInst, immediate, ec);
107  }
108 
109  return NoFault;
110 }
111 
112 bool
115  uint32_t &immediate) const
116 {
117  const CPACR cpacr = tc->readMiscReg(MISCREG_CPACR_EL1);
118 
119  bool trap_to_sup = false;
120  switch (misc_reg) {
121  case MISCREG_FPCR:
122  case MISCREG_FPSR:
123  case MISCREG_FPEXC32_EL2:
124  if ((el == EL0 && cpacr.fpen != 0x3) ||
125  (el == EL1 && !(cpacr.fpen & 0x1))) {
126  trap_to_sup = true;
127  ec = EC_TRAPPED_SIMD_FP;
128  immediate = 0x1E00000;
129  }
130  break;
131  default:
132  break;
133  }
134  return trap_to_sup;
135 }
136 
137 bool
140  uint32_t &immediate) const
141 {
142  const CPTR cptr = tc->readMiscReg(MISCREG_CPTR_EL2);
143  const HCR hcr = tc->readMiscReg(MISCREG_HCR_EL2);
144  const SCR scr = tc->readMiscReg(MISCREG_SCR_EL3);
145  const CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
146 
147  bool trap_to_hyp = false;
148 
149  if (!inSecureState(scr, cpsr) && (el != EL2)) {
150  switch (misc_reg) {
151  // FP/SIMD regs
152  case MISCREG_FPCR:
153  case MISCREG_FPSR:
154  case MISCREG_FPEXC32_EL2:
155  trap_to_hyp = cptr.tfp;
156  ec = EC_TRAPPED_SIMD_FP;
157  immediate = 0x1E00000;
158  break;
159  // CPACR
160  case MISCREG_CPACR_EL1:
161  trap_to_hyp = cptr.tcpac && el == EL1;
162  break;
163  // Virtual memory control regs
164  case MISCREG_SCTLR_EL1:
165  case MISCREG_TTBR0_EL1:
166  case MISCREG_TTBR1_EL1:
167  case MISCREG_TCR_EL1:
168  case MISCREG_ESR_EL1:
169  case MISCREG_FAR_EL1:
170  case MISCREG_AFSR0_EL1:
171  case MISCREG_AFSR1_EL1:
172  case MISCREG_MAIR_EL1:
173  case MISCREG_AMAIR_EL1:
175  trap_to_hyp =
176  ((hcr.trvm && miscRead) || (hcr.tvm && !miscRead)) &&
177  el == EL1;
178  break;
179  // TLB maintenance instructions
192  trap_to_hyp = hcr.ttlb && el == EL1;
193  break;
194  // Cache maintenance instructions to the point of unification
195  case MISCREG_IC_IVAU_Xt:
196  case MISCREG_ICIALLU:
197  case MISCREG_ICIALLUIS:
198  case MISCREG_DC_CVAU_Xt:
199  trap_to_hyp = hcr.tpu && el <= EL1;
200  break;
201  // Data/Unified cache maintenance instructions to the
202  // point of coherency
203  case MISCREG_DC_IVAC_Xt:
204  case MISCREG_DC_CIVAC_Xt:
205  case MISCREG_DC_CVAC_Xt:
206  trap_to_hyp = hcr.tpc && el <= EL1;
207  break;
208  // Data/Unified cache maintenance instructions by set/way
209  case MISCREG_DC_ISW_Xt:
210  case MISCREG_DC_CSW_Xt:
211  case MISCREG_DC_CISW_Xt:
212  trap_to_hyp = hcr.tsw && el == EL1;
213  break;
214  // ACTLR
215  case MISCREG_ACTLR_EL1:
216  trap_to_hyp = hcr.tacr && el == EL1;
217  break;
218 
229  trap_to_hyp = el==EL1 && hcr.apk == 0;
230  break;
231  // @todo: Trap implementation-dependent functionality based on
232  // hcr.tidcp
233 
234  // ID regs, group 3
235  case MISCREG_ID_PFR0_EL1:
236  case MISCREG_ID_PFR1_EL1:
237  case MISCREG_ID_DFR0_EL1:
238  case MISCREG_ID_AFR0_EL1:
249  case MISCREG_MVFR0_EL1:
250  case MISCREG_MVFR1_EL1:
251  case MISCREG_MVFR2_EL1:
263  assert(miscRead);
264  trap_to_hyp = hcr.tid3 && el == EL1;
265  break;
266  // ID regs, group 2
267  case MISCREG_CTR_EL0:
268  case MISCREG_CCSIDR_EL1:
269  case MISCREG_CLIDR_EL1:
270  case MISCREG_CSSELR_EL1:
271  trap_to_hyp = hcr.tid2 && el <= EL1;
272  break;
273  // ID regs, group 1
274  case MISCREG_AIDR_EL1:
275  case MISCREG_REVIDR_EL1:
276  assert(miscRead);
277  trap_to_hyp = hcr.tid1 && el == EL1;
278  break;
280  trap_to_hyp = hcr.tidcp && el == EL1;
281  break;
282  // GICv3 regs
284  {
285  auto *isa = static_cast<ArmISA::ISA *>(tc->getIsaPtr());
286  if (isa->haveGICv3CpuIfc())
287  trap_to_hyp = hcr.fmo && el == EL1;
288  }
289  break;
292  {
293  auto *isa = static_cast<ArmISA::ISA *>(tc->getIsaPtr());
294  if (isa->haveGICv3CpuIfc())
295  trap_to_hyp = hcr.imo && el == EL1;
296  }
297  break;
298  default:
299  break;
300  }
301  }
302  return trap_to_hyp;
303 }
304 
305 bool
308  uint32_t &immediate) const
309 {
310  const CPTR cptr = tc->readMiscReg(MISCREG_CPTR_EL3);
311  const SCR scr = tc->readMiscReg(MISCREG_SCR_EL3);
312  bool trap_to_mon = false;
313 
314  switch (misc_reg) {
315  // FP/SIMD regs
316  case MISCREG_FPCR:
317  case MISCREG_FPSR:
318  case MISCREG_FPEXC32_EL2:
319  trap_to_mon = cptr.tfp;
320  ec = EC_TRAPPED_SIMD_FP;
321  immediate = 0x1E00000;
322  break;
323  // CPACR, CPTR
324  case MISCREG_CPACR_EL1:
325  if (el == EL1 || el == EL2) {
326  trap_to_mon = cptr.tcpac;
327  }
328  break;
329  case MISCREG_CPTR_EL2:
330  if (el == EL2) {
331  trap_to_mon = cptr.tcpac;
332  }
333  break;
344  trap_to_mon = (el==EL1 || el==EL2) && scr.apk==0 && ELIs64(tc, EL3);
345  break;
346  default:
347  break;
348  }
349  return trap_to_mon;
350 }
351 
352 RegVal
354 {
355  if (dest == MISCREG_SPSEL) {
356  return imm & 0x1;
357  } else if (dest == MISCREG_PAN) {
358  return (imm & 0x1) << 22;
359  } else {
360  panic("Not a valid PSTATE field register\n");
361  }
362 }
363 
364 std::string
366 {
367  std::stringstream ss;
368  printMnemonic(ss);
369  printMiscReg(ss, dest);
370  ss << ", ";
371  ccprintf(ss, "#0x%x", imm);
372  return ss.str();
373 }
374 
375 std::string
377  Addr pc, const SymbolTable *symtab) const
378 {
379  std::stringstream ss;
380  printMnemonic(ss);
381  printMiscReg(ss, dest);
382  ss << ", ";
383  printIntReg(ss, op1);
384  return ss.str();
385 }
386 
387 std::string
389  Addr pc, const SymbolTable *symtab) const
390 {
391  std::stringstream ss;
392  printMnemonic(ss);
393  printIntReg(ss, dest);
394  ss << ", ";
395  printMiscReg(ss, op1);
396  return ss.str();
397 }
398 
399 Fault
401  Trace::InstRecord *traceData) const
402 {
403  auto tc = xc->tcBase();
404  const CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
405  const ExceptionLevel el = (ExceptionLevel) (uint8_t) cpsr.el;
406 
407  Fault fault = trap(tc, miscReg, el, imm);
408 
409  if (fault != NoFault) {
410  return fault;
411 
412  } else if (warning) {
413  warn_once("\tinstruction '%s' unimplemented\n", fullMnemonic.c_str());
414  return NoFault;
415 
416  } else {
417  return std::make_shared<UndefinedInstruction>(machInst, false,
418  mnemonic);
419  }
420 }
421 
422 std::string
424  const SymbolTable *symtab) const
425 {
426  return csprintf("%-10s (implementation defined)", fullMnemonic.c_str());
427 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
void ccprintf(cp::Print &print)
Definition: cprintf.hh:131
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
decltype(nullptr) constexpr NoFault
Definition: types.hh:245
bool haveSecurity() const
Returns true if this system implements the Security Extensions.
Definition: system.hh:185
Fault trap(ThreadContext *tc, MiscRegIndex misc_reg, ExceptionLevel el, uint32_t immediate) const
Definition: misc64.cc:87
RegVal miscRegImm() const
Returns the "register view" of the immediate field.
Definition: misc64.cc:353
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc64.cc:66
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:244
uint64_t RegVal
Definition: types.hh:168
bool checkEL1Trap(ThreadContext *tc, const MiscRegIndex misc_reg, ExceptionLevel el, ExceptionClass &ec, uint32_t &immediate) const
Definition: misc64.cc:113
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc64.cc:45
ThreadContext is the external interface to all thread state for anything outside of the CPU...
bool checkEL3Trap(ThreadContext *tc, const MiscRegIndex misc_reg, ExceptionLevel el, ExceptionClass &ec, uint32_t &immediate) const
Definition: misc64.cc:306
ExceptionLevel
Definition: types.hh:585
bool ELIs64(ThreadContext *tc, ExceptionLevel el)
Definition: utility.cc:333
const ExtMachInst machInst
The binary machine instruction.
Definition: static_inst.hh:229
Bitfield< 3, 2 > el
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition: exec_context.hh:73
Bitfield< 4 > pc
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: misc64.cc:365
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
Bitfield< 21 > ss
Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const override
Definition: misc64.cc:400
bool haveVirtualization() const
Returns true if this system implements the virtualization Extensions.
Definition: system.hh:194
virtual BaseISA * getIsaPtr()=0
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
#define warn_once(...)
Definition: logging.hh:216
ExceptionClass
Definition: types.hh:612
void printMiscReg(std::ostream &os, RegIndex reg_idx) const
Definition: static_inst.cc:367
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc64.cc:376
uint64_t imm
Definition: misc64.hh:49
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc64.cc:388
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc64.cc:81
virtual ThreadContext * tcBase()=0
Returns a pointer to the ThreadContext.
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc64.cc:54
bool inSecureState(ThreadContext *tc)
Definition: utility.cc:195
std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const override
Internal function to generate disassembly string.
Definition: misc64.cc:423
virtual RegVal readMiscReg(RegIndex misc_reg)=0
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
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
bool checkEL2Trap(ThreadContext *tc, const MiscRegIndex misc_reg, ExceptionLevel el, ExceptionClass &ec, uint32_t &immediate) const
Definition: misc64.cc:138

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