gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
isa.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 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  * Ali Saidi
39  */
40 
41 #include "arch/arm/isa.hh"
42 
43 #include "arch/arm/faults.hh"
44 #include "arch/arm/interrupts.hh"
45 #include "arch/arm/pmu.hh"
46 #include "arch/arm/system.hh"
47 #include "arch/arm/tlb.hh"
48 #include "arch/arm/tlbi_op.hh"
49 #include "cpu/base.hh"
50 #include "cpu/checker/cpu.hh"
51 #include "debug/Arm.hh"
52 #include "debug/MiscRegs.hh"
53 #include "dev/arm/generic_timer.hh"
54 #include "dev/arm/gic_v3.hh"
56 #include "params/ArmISA.hh"
57 #include "sim/faults.hh"
58 #include "sim/stat_control.hh"
59 #include "sim/system.hh"
60 
61 namespace ArmISA
62 {
63 
64 ISA::ISA(Params *p) : BaseISA(p), system(NULL),
65  _decoderFlavour(p->decoderFlavour), _vecRegRenameMode(Enums::Full),
66  pmu(p->pmu), haveGICv3CPUInterface(false), impdefAsNop(p->impdef_nop),
67  afterStartup(false)
68 {
70 
71  // Hook up a dummy device if we haven't been configured with a
72  // real PMU. By using a dummy device, we don't need to check that
73  // the PMU exist every time we try to access a PMU register.
74  if (!pmu)
75  pmu = &dummyDevice;
76 
77  // Give all ISA devices a pointer to this ISA
78  pmu->setISA(this);
79 
80  system = dynamic_cast<ArmSystem *>(p->system);
81 
82  // Cache system-level properties
83  if (FullSystem && system) {
91  haveSVE = system->haveSVE();
92  havePAN = system->havePAN();
93  sveVL = system->sveVL();
94  haveLSE = system->haveLSE();
95  } else {
96  highestELIs64 = true; // ArmSystem::highestELIs64 does the same
98  haveCrypto = true;
99  haveLargeAsid64 = false;
100  physAddrRange = 32; // dummy value
101  haveSVE = true;
102  havePAN = false;
103  sveVL = p->sve_vl_se;
104  haveLSE = true;
105  }
106 
107  // Initial rename mode depends on highestEL
108  const_cast<Enums::VecRegRenameMode&>(_vecRegRenameMode) =
109  highestELIs64 ? Enums::Full : Enums::Elem;
110 
113 
114  clear();
115 }
116 
118 
119 const ArmISAParams *
120 ISA::params() const
121 {
122  return dynamic_cast<const Params *>(_params);
123 }
124 
125 void
127 {
128  const Params *p(params());
129 
130  SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
131  memset(miscRegs, 0, sizeof(miscRegs));
132 
133  initID32(p);
134 
135  // We always initialize AArch64 ID registers even
136  // if we are in AArch32. This is done since if we
137  // are in SE mode we don't know if our ArmProcess is
138  // AArch32 or AArch64
139  initID64(p);
140 
141  // Start with an event in the mailbox
143 
144  // Separate Instruction and Data TLBs
145  miscRegs[MISCREG_TLBTR] = 1;
146 
147  MVFR0 mvfr0 = 0;
148  mvfr0.advSimdRegisters = 2;
149  mvfr0.singlePrecision = 2;
150  mvfr0.doublePrecision = 2;
151  mvfr0.vfpExceptionTrapping = 0;
152  mvfr0.divide = 1;
153  mvfr0.squareRoot = 1;
154  mvfr0.shortVectors = 1;
155  mvfr0.roundingModes = 1;
156  miscRegs[MISCREG_MVFR0] = mvfr0;
157 
158  MVFR1 mvfr1 = 0;
159  mvfr1.flushToZero = 1;
160  mvfr1.defaultNaN = 1;
161  mvfr1.advSimdLoadStore = 1;
162  mvfr1.advSimdInteger = 1;
163  mvfr1.advSimdSinglePrecision = 1;
164  mvfr1.advSimdHalfPrecision = 1;
165  mvfr1.vfpHalfPrecision = 1;
166  miscRegs[MISCREG_MVFR1] = mvfr1;
167 
168  // Reset values of PRRR and NMRR are implementation dependent
169 
170  // @todo: PRRR and NMRR in secure state?
172  (1 << 19) | // 19
173  (0 << 18) | // 18
174  (0 << 17) | // 17
175  (1 << 16) | // 16
176  (2 << 14) | // 15:14
177  (0 << 12) | // 13:12
178  (2 << 10) | // 11:10
179  (2 << 8) | // 9:8
180  (2 << 6) | // 7:6
181  (2 << 4) | // 5:4
182  (1 << 2) | // 3:2
183  0; // 1:0
184 
186  (1 << 30) | // 31:30
187  (0 << 26) | // 27:26
188  (0 << 24) | // 25:24
189  (3 << 22) | // 23:22
190  (2 << 20) | // 21:20
191  (0 << 18) | // 19:18
192  (0 << 16) | // 17:16
193  (1 << 14) | // 15:14
194  (0 << 12) | // 13:12
195  (2 << 10) | // 11:10
196  (0 << 8) | // 9:8
197  (3 << 6) | // 7:6
198  (2 << 4) | // 5:4
199  (0 << 2) | // 3:2
200  0; // 1:0
201 
202  if (FullSystem && system->highestELIs64()) {
203  // Initialize AArch64 state
204  clear64(p);
205  return;
206  }
207 
208  // Initialize AArch32 state...
209  clear32(p, sctlr_rst);
210 }
211 
212 void
213 ISA::clear32(const ArmISAParams *p, const SCTLR &sctlr_rst)
214 {
215  CPSR cpsr = 0;
216  cpsr.mode = MODE_USER;
217 
218  if (FullSystem) {
220  }
221 
222  miscRegs[MISCREG_CPSR] = cpsr;
223  updateRegMap(cpsr);
224 
225  SCTLR sctlr = 0;
226  sctlr.te = (bool) sctlr_rst.te;
227  sctlr.nmfi = (bool) sctlr_rst.nmfi;
228  sctlr.v = (bool) sctlr_rst.v;
229  sctlr.u = 1;
230  sctlr.xp = 1;
231  sctlr.rao2 = 1;
232  sctlr.rao3 = 1;
233  sctlr.rao4 = 0xf; // SCTLR[6:3]
234  sctlr.uci = 1;
235  sctlr.dze = 1;
236  miscRegs[MISCREG_SCTLR_NS] = sctlr;
237  miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
238  miscRegs[MISCREG_HCPTR] = 0;
239 
240  miscRegs[MISCREG_CPACR] = 0;
241 
242  miscRegs[MISCREG_FPSID] = p->fpsid;
243 
244  if (haveLPAE) {
245  TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS];
246  ttbcr.eae = 0;
247  miscRegs[MISCREG_TTBCR_NS] = ttbcr;
248  // Enforce consistency with system-level settings
250  }
251 
252  if (haveSecurity) {
253  miscRegs[MISCREG_SCTLR_S] = sctlr;
254  miscRegs[MISCREG_SCR] = 0;
256  } else {
257  // we're always non-secure
258  miscRegs[MISCREG_SCR] = 1;
259  }
260 
261  //XXX We need to initialize the rest of the state.
262 }
263 
264 void
265 ISA::clear64(const ArmISAParams *p)
266 {
267  CPSR cpsr = 0;
268  Addr rvbar = system->resetAddr();
269  switch (system->highestEL()) {
270  // Set initial EL to highest implemented EL using associated stack
271  // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset
272  // value
273  case EL3:
274  cpsr.mode = MODE_EL3H;
275  miscRegs[MISCREG_RVBAR_EL3] = rvbar;
276  break;
277  case EL2:
278  cpsr.mode = MODE_EL2H;
279  miscRegs[MISCREG_RVBAR_EL2] = rvbar;
280  break;
281  case EL1:
282  cpsr.mode = MODE_EL1H;
283  miscRegs[MISCREG_RVBAR_EL1] = rvbar;
284  break;
285  default:
286  panic("Invalid highest implemented exception level");
287  break;
288  }
289 
290  // Initialize rest of CPSR
291  cpsr.daif = 0xf; // Mask all interrupts
292  cpsr.ss = 0;
293  cpsr.il = 0;
294  miscRegs[MISCREG_CPSR] = cpsr;
295  updateRegMap(cpsr);
296 
297  // Initialize other control registers
298  miscRegs[MISCREG_MPIDR_EL1] = 0x80000000;
299  if (haveSecurity) {
300  miscRegs[MISCREG_SCTLR_EL3] = 0x30c50830;
301  miscRegs[MISCREG_SCR_EL3] = 0x00000030; // RES1 fields
302  } else if (haveVirtualization) {
303  // also MISCREG_SCTLR_EL2 (by mapping)
304  miscRegs[MISCREG_HSCTLR] = 0x30c50830;
305  } else {
306  // also MISCREG_SCTLR_EL1 (by mapping)
307  miscRegs[MISCREG_SCTLR_NS] = 0x30d00800 | 0x00050030; // RES1 | init
308  // Always non-secure
310  }
311 }
312 
313 void
314 ISA::initID32(const ArmISAParams *p)
315 {
316  // Initialize configurable default values
317 
318  uint32_t midr;
319  if (p->midr != 0x0)
320  midr = p->midr;
321  else if (highestELIs64)
322  // Cortex-A57 TRM r0p0 MIDR
323  midr = 0x410fd070;
324  else
325  // Cortex-A15 TRM r0p0 MIDR
326  midr = 0x410fc0f0;
327 
328  miscRegs[MISCREG_MIDR] = midr;
329  miscRegs[MISCREG_MIDR_EL1] = midr;
330  miscRegs[MISCREG_VPIDR] = midr;
331 
332  miscRegs[MISCREG_ID_ISAR0] = p->id_isar0;
333  miscRegs[MISCREG_ID_ISAR1] = p->id_isar1;
334  miscRegs[MISCREG_ID_ISAR2] = p->id_isar2;
335  miscRegs[MISCREG_ID_ISAR3] = p->id_isar3;
336  miscRegs[MISCREG_ID_ISAR4] = p->id_isar4;
337  miscRegs[MISCREG_ID_ISAR5] = p->id_isar5;
338 
339  miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0;
340  miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1;
341  miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2;
342  miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3;
343 
345  miscRegs[MISCREG_ID_ISAR5], 19, 4,
346  haveCrypto ? 0x1112 : 0x0);
347 }
348 
349 void
350 ISA::initID64(const ArmISAParams *p)
351 {
352  // Initialize configurable id registers
353  miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1;
354  miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1;
356  (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) |
357  (p->pmu ? 0x0000000000000100ULL : 0); // Enable PMUv3
358 
359  miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1;
360  miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1;
361  miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1;
362  miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1;
363  miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1;
364  miscRegs[MISCREG_ID_AA64MMFR2_EL1] = p->id_aa64mmfr2_el1;
365 
367  (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3
368 
370 
371  // SVE
372  miscRegs[MISCREG_ID_AA64ZFR0_EL1] = 0; // SVEver 0
373  if (haveSecurity) {
375  } else if (haveVirtualization) {
377  } else {
379  }
380 
381  // Enforce consistency with system-level settings...
382 
383  // EL3
386  haveSecurity ? 0x2 : 0x0);
387  // EL2
389  miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8,
390  haveVirtualization ? 0x2 : 0x0);
391  // SVE
393  miscRegs[MISCREG_ID_AA64PFR0_EL1], 35, 32,
394  haveSVE ? 0x1 : 0x0);
395  // Large ASID support
398  haveLargeAsid64 ? 0x2 : 0x0);
399  // Physical address size
401  miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0,
403  // Crypto
406  haveCrypto ? 0x1112 : 0x0);
407  // LSE
409  miscRegs[MISCREG_ID_AA64ISAR0_EL1], 23, 20,
410  haveLSE ? 0x2 : 0x0);
411  // PAN
414  havePAN ? 0x1 : 0x0);
415 }
416 
417 void
419 {
420  pmu->setThreadContext(tc);
421 
422  if (system) {
423  Gicv3 *gicv3 = dynamic_cast<Gicv3 *>(system->getGIC());
424  if (gicv3) {
425  haveGICv3CPUInterface = true;
426  gicv3CpuInterface.reset(gicv3->getCPUInterface(tc->contextId()));
427  gicv3CpuInterface->setISA(this);
428  gicv3CpuInterface->setThreadContext(tc);
429  }
430  }
431 
432  afterStartup = true;
433 }
434 
435 
436 RegVal
437 ISA::readMiscRegNoEffect(int misc_reg) const
438 {
439  assert(misc_reg < NumMiscRegs);
440 
441  const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
442  const auto &map = getMiscIndices(misc_reg);
443  int lower = map.first, upper = map.second;
444  // NB!: apply architectural masks according to desired register,
445  // despite possibly getting value from different (mapped) register.
446  auto val = !upper ? miscRegs[lower] : ((miscRegs[lower] & mask(32))
447  |(miscRegs[upper] << 32));
448  if (val & reg.res0()) {
449  DPRINTF(MiscRegs, "Reading MiscReg %s with set res0 bits: %#x\n",
450  miscRegName[misc_reg], val & reg.res0());
451  }
452  if ((val & reg.res1()) != reg.res1()) {
453  DPRINTF(MiscRegs, "Reading MiscReg %s with clear res1 bits: %#x\n",
454  miscRegName[misc_reg], (val & reg.res1()) ^ reg.res1());
455  }
456  return (val & ~reg.raz()) | reg.rao(); // enforce raz/rao
457 }
458 
459 
460 RegVal
461 ISA::readMiscReg(int misc_reg, ThreadContext *tc)
462 {
463  CPSR cpsr = 0;
464  PCState pc = 0;
465  SCR scr = 0;
466 
467  if (misc_reg == MISCREG_CPSR) {
468  cpsr = miscRegs[misc_reg];
469  pc = tc->pcState();
470  cpsr.j = pc.jazelle() ? 1 : 0;
471  cpsr.t = pc.thumb() ? 1 : 0;
472  return cpsr;
473  }
474 
475 #ifndef NDEBUG
476  if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
477  if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
478  warn("Unimplemented system register %s read.\n",
479  miscRegName[misc_reg]);
480  else
481  panic("Unimplemented system register %s read.\n",
482  miscRegName[misc_reg]);
483  }
484 #endif
485 
486  switch (unflattenMiscReg(misc_reg)) {
487  case MISCREG_HCR:
488  case MISCREG_HCR2:
489  if (!haveVirtualization)
490  return 0;
491  break;
492  case MISCREG_CPACR:
493  {
494  const uint32_t ones = (uint32_t)(-1);
495  CPACR cpacrMask = 0;
496  // Only cp10, cp11, and ase are implemented, nothing else should
497  // be readable? (straight copy from the write code)
498  cpacrMask.cp10 = ones;
499  cpacrMask.cp11 = ones;
500  cpacrMask.asedis = ones;
501 
502  // Security Extensions may limit the readability of CPACR
503  if (haveSecurity) {
506  if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) {
507  NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
508  // NB: Skipping the full loop, here
509  if (!nsacr.cp10) cpacrMask.cp10 = 0;
510  if (!nsacr.cp11) cpacrMask.cp11 = 0;
511  }
512  }
514  val &= cpacrMask;
515  DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n",
516  miscRegName[misc_reg], val);
517  return val;
518  }
519  case MISCREG_MPIDR:
520  case MISCREG_MPIDR_EL1:
521  return readMPIDR(system, tc);
522  case MISCREG_VMPIDR:
523  case MISCREG_VMPIDR_EL2:
524  // top bit defined as RES1
525  return readMiscRegNoEffect(misc_reg) | 0x80000000;
526  case MISCREG_ID_AFR0: // not implemented, so alias MIDR
527  case MISCREG_REVIDR: // not implemented, so alias MIDR
528  case MISCREG_MIDR:
531  if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
532  return readMiscRegNoEffect(misc_reg);
533  } else {
535  }
536  break;
537  case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI
538  case MISCREG_JMCR: // Jazelle trivial implementation, RAZ/WI
539  case MISCREG_JIDR: // Jazelle trivial implementation, RAZ/WI
540  case MISCREG_AIDR: // AUX ID set to 0
541  case MISCREG_TCMTR: // No TCM's
542  return 0;
543 
544  case MISCREG_CLIDR:
545  warn_once("The clidr register always reports 0 caches.\n");
546  warn_once("clidr LoUIS field of 0b001 to match current "
547  "ARM implementations.\n");
548  return 0x00200000;
549  case MISCREG_CCSIDR:
550  warn_once("The ccsidr register isn't implemented and "
551  "always reads as 0.\n");
552  break;
553  case MISCREG_CTR: // AArch32, ARMv7, top bit set
554  case MISCREG_CTR_EL0: // AArch64
555  {
556  //all caches have the same line size in gem5
557  //4 byte words in ARM
558  unsigned lineSizeWords =
559  tc->getSystemPtr()->cacheLineSize() / 4;
560  unsigned log2LineSizeWords = 0;
561 
562  while (lineSizeWords >>= 1) {
563  ++log2LineSizeWords;
564  }
565 
566  CTR ctr = 0;
567  //log2 of minimun i-cache line size (words)
568  ctr.iCacheLineSize = log2LineSizeWords;
569  //b11 - gem5 uses pipt
570  ctr.l1IndexPolicy = 0x3;
571  //log2 of minimum d-cache line size (words)
572  ctr.dCacheLineSize = log2LineSizeWords;
573  //log2 of max reservation size (words)
574  ctr.erg = log2LineSizeWords;
575  //log2 of max writeback size (words)
576  ctr.cwg = log2LineSizeWords;
577  //b100 - gem5 format is ARMv7
578  ctr.format = 0x4;
579 
580  return ctr;
581  }
582  case MISCREG_ACTLR:
583  warn("Not doing anything for miscreg ACTLR\n");
584  break;
585 
590  return pmu->readMiscReg(misc_reg);
591 
592  case MISCREG_CPSR_Q:
593  panic("shouldn't be reading this register seperately\n");
594  case MISCREG_FPSCR_QC:
596  case MISCREG_FPSCR_EXC:
598  case MISCREG_FPSR:
599  {
600  const uint32_t ones = (uint32_t)(-1);
601  FPSCR fpscrMask = 0;
602  fpscrMask.ioc = ones;
603  fpscrMask.dzc = ones;
604  fpscrMask.ofc = ones;
605  fpscrMask.ufc = ones;
606  fpscrMask.ixc = ones;
607  fpscrMask.idc = ones;
608  fpscrMask.qc = ones;
609  fpscrMask.v = ones;
610  fpscrMask.c = ones;
611  fpscrMask.z = ones;
612  fpscrMask.n = ones;
613  return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
614  }
615  case MISCREG_FPCR:
616  {
617  const uint32_t ones = (uint32_t)(-1);
618  FPSCR fpscrMask = 0;
619  fpscrMask.len = ones;
620  fpscrMask.fz16 = ones;
621  fpscrMask.stride = ones;
622  fpscrMask.rMode = ones;
623  fpscrMask.fz = ones;
624  fpscrMask.dn = ones;
625  fpscrMask.ahp = ones;
626  return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
627  }
628  case MISCREG_NZCV:
629  {
630  CPSR cpsr = 0;
631  cpsr.nz = tc->readCCReg(CCREG_NZ);
632  cpsr.c = tc->readCCReg(CCREG_C);
633  cpsr.v = tc->readCCReg(CCREG_V);
634  return cpsr;
635  }
636  case MISCREG_DAIF:
637  {
638  CPSR cpsr = 0;
639  cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif;
640  return cpsr;
641  }
642  case MISCREG_SP_EL0:
643  {
644  return tc->readIntReg(INTREG_SP0);
645  }
646  case MISCREG_SP_EL1:
647  {
648  return tc->readIntReg(INTREG_SP1);
649  }
650  case MISCREG_SP_EL2:
651  {
652  return tc->readIntReg(INTREG_SP2);
653  }
654  case MISCREG_SPSEL:
655  {
656  return miscRegs[MISCREG_CPSR] & 0x1;
657  }
658  case MISCREG_CURRENTEL:
659  {
660  return miscRegs[MISCREG_CPSR] & 0xc;
661  }
662  case MISCREG_PAN:
663  {
664  return miscRegs[MISCREG_CPSR] & 0x400000;
665  }
666  case MISCREG_L2CTLR:
667  {
668  // mostly unimplemented, just set NumCPUs field from sim and return
669  L2CTLR l2ctlr = 0;
670  // b00:1CPU to b11:4CPUs
671  l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1;
672  return l2ctlr;
673  }
674  case MISCREG_DBGDIDR:
675  /* For now just implement the version number.
676  * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5)
677  */
678  return 0x5 << 16;
679  case MISCREG_DBGDSCRint:
680  return 0;
681  case MISCREG_ISR:
682  {
683  auto ic = dynamic_cast<ArmISA::Interrupts *>(
685  return ic->getISR(
689  }
690  case MISCREG_ISR_EL1:
691  {
692  auto ic = dynamic_cast<ArmISA::Interrupts *>(
694  return ic->getISR(
698  }
699  case MISCREG_DCZID_EL0:
700  return 0x04; // DC ZVA clear 64-byte chunks
701  case MISCREG_HCPTR:
702  {
703  RegVal val = readMiscRegNoEffect(misc_reg);
704  // The trap bit associated with CP14 is defined as RAZ
705  val &= ~(1 << 14);
706  // If a CP bit in NSACR is 0 then the corresponding bit in
707  // HCPTR is RAO/WI
708  bool secure_lookup = haveSecurity &&
711  if (!secure_lookup) {
713  val |= (mask ^ 0x7FFF) & 0xBFFF;
714  }
715  // Set the bits for unimplemented coprocessors to RAO/WI
716  val |= 0x33FF;
717  return (val);
718  }
719  case MISCREG_HDFAR: // alias for secure DFAR
721  case MISCREG_HIFAR: // alias for secure IFAR
723 
724  case MISCREG_ID_PFR0:
725  // !ThumbEE | !Jazelle | Thumb | ARM
726  return 0x00000031;
727  case MISCREG_ID_PFR1:
728  { // Timer | Virti | !M Profile | TrustZone | ARMv4
729  bool haveTimer = (system->getGenericTimer() != NULL);
730  return 0x00000001
731  | (haveSecurity ? 0x00000010 : 0x0)
732  | (haveVirtualization ? 0x00001000 : 0x0)
733  | (haveTimer ? 0x00010000 : 0x0);
734  }
736  return 0x0000000000000002 | // AArch{64,32} supported at EL0
737  0x0000000000000020 | // EL1
738  (haveVirtualization ? 0x0000000000000200 : 0) | // EL2
739  (haveSecurity ? 0x0000000000002000 : 0) | // EL3
740  (haveSVE ? 0x0000000100000000 : 0) | // SVE
741  (haveGICv3CPUInterface ? 0x0000000001000000 : 0);
743  return 0; // bits [63:0] RES0 (reserved for future use)
744 
745  // Generic Timer registers
753  return getGenericTimer(tc).readMiscReg(misc_reg);
754 
758  return getGICv3CPUInterface(tc).readMiscReg(misc_reg);
759 
760  default:
761  break;
762 
763  }
764  return readMiscRegNoEffect(misc_reg);
765 }
766 
767 void
769 {
770  assert(misc_reg < NumMiscRegs);
771 
772  const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
773  const auto &map = getMiscIndices(misc_reg);
774  int lower = map.first, upper = map.second;
775 
776  auto v = (val & ~reg.wi()) | reg.rao();
777  if (upper > 0) {
778  miscRegs[lower] = bits(v, 31, 0);
779  miscRegs[upper] = bits(v, 63, 32);
780  DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n",
781  misc_reg, lower, upper, v);
782  } else {
783  miscRegs[lower] = v;
784  DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n",
785  misc_reg, lower, v);
786  }
787 }
788 
789 void
791 {
792 
793  RegVal newVal = val;
794  bool secure_lookup;
795  SCR scr;
796 
797  if (misc_reg == MISCREG_CPSR) {
798  updateRegMap(val);
799 
800 
801  CPSR old_cpsr = miscRegs[MISCREG_CPSR];
802  int old_mode = old_cpsr.mode;
803  CPSR cpsr = val;
804  if (old_mode != cpsr.mode || cpsr.il != old_cpsr.il) {
807  }
808 
809  if (cpsr.pan != old_cpsr.pan) {
811  }
812 
813  DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
814  miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
815  PCState pc = tc->pcState();
816  pc.nextThumb(cpsr.t);
817  pc.nextJazelle(cpsr.j);
818  pc.illegalExec(cpsr.il == 1);
819 
820  tc->getDecoderPtr()->setSveLen((getCurSveVecLenInBits(tc) >> 7) - 1);
821 
822  // Follow slightly different semantics if a CheckerCPU object
823  // is connected
824  CheckerCPU *checker = tc->getCheckerCpuPtr();
825  if (checker) {
826  tc->pcStateNoRecord(pc);
827  } else {
828  tc->pcState(pc);
829  }
830  } else {
831 #ifndef NDEBUG
832  if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
833  if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
834  warn("Unimplemented system register %s write with %#x.\n",
835  miscRegName[misc_reg], val);
836  else
837  panic("Unimplemented system register %s write with %#x.\n",
838  miscRegName[misc_reg], val);
839  }
840 #endif
841  switch (unflattenMiscReg(misc_reg)) {
842  case MISCREG_CPACR:
843  {
844 
845  const uint32_t ones = (uint32_t)(-1);
846  CPACR cpacrMask = 0;
847  // Only cp10, cp11, and ase are implemented, nothing else should
848  // be writable
849  cpacrMask.cp10 = ones;
850  cpacrMask.cp11 = ones;
851  cpacrMask.asedis = ones;
852 
853  // Security Extensions may limit the writability of CPACR
854  if (haveSecurity) {
856  CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR);
857  if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) {
858  NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
859  // NB: Skipping the full loop, here
860  if (!nsacr.cp10) cpacrMask.cp10 = 0;
861  if (!nsacr.cp11) cpacrMask.cp11 = 0;
862  }
863  }
864 
866  newVal &= cpacrMask;
867  newVal |= old_val & ~cpacrMask;
868  DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
869  miscRegName[misc_reg], newVal);
870  }
871  break;
872  case MISCREG_CPACR_EL1:
873  {
874  const uint32_t ones = (uint32_t)(-1);
875  CPACR cpacrMask = 0;
876  cpacrMask.tta = ones;
877  cpacrMask.fpen = ones;
878  if (haveSVE) {
879  cpacrMask.zen = ones;
880  }
881  newVal &= cpacrMask;
882  DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
883  miscRegName[misc_reg], newVal);
884  }
885  break;
886  case MISCREG_CPTR_EL2:
887  {
888  const uint32_t ones = (uint32_t)(-1);
889  CPTR cptrMask = 0;
890  cptrMask.tcpac = ones;
891  cptrMask.tta = ones;
892  cptrMask.tfp = ones;
893  if (haveSVE) {
894  cptrMask.tz = ones;
895  }
896  newVal &= cptrMask;
897  cptrMask = 0;
898  cptrMask.res1_13_12_el2 = ones;
899  cptrMask.res1_7_0_el2 = ones;
900  if (!haveSVE) {
901  cptrMask.res1_8_el2 = ones;
902  }
903  cptrMask.res1_9_el2 = ones;
904  newVal |= cptrMask;
905  DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
906  miscRegName[misc_reg], newVal);
907  }
908  break;
909  case MISCREG_CPTR_EL3:
910  {
911  const uint32_t ones = (uint32_t)(-1);
912  CPTR cptrMask = 0;
913  cptrMask.tcpac = ones;
914  cptrMask.tta = ones;
915  cptrMask.tfp = ones;
916  if (haveSVE) {
917  cptrMask.ez = ones;
918  }
919  newVal &= cptrMask;
920  DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
921  miscRegName[misc_reg], newVal);
922  }
923  break;
924  case MISCREG_CSSELR:
925  warn_once("The csselr register isn't implemented.\n");
926  return;
927 
928  case MISCREG_DC_ZVA_Xt:
929  warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n");
930  return;
931 
932  case MISCREG_FPSCR:
933  {
934  const uint32_t ones = (uint32_t)(-1);
935  FPSCR fpscrMask = 0;
936  fpscrMask.ioc = ones;
937  fpscrMask.dzc = ones;
938  fpscrMask.ofc = ones;
939  fpscrMask.ufc = ones;
940  fpscrMask.ixc = ones;
941  fpscrMask.idc = ones;
942  fpscrMask.ioe = ones;
943  fpscrMask.dze = ones;
944  fpscrMask.ofe = ones;
945  fpscrMask.ufe = ones;
946  fpscrMask.ixe = ones;
947  fpscrMask.ide = ones;
948  fpscrMask.len = ones;
949  fpscrMask.fz16 = ones;
950  fpscrMask.stride = ones;
951  fpscrMask.rMode = ones;
952  fpscrMask.fz = ones;
953  fpscrMask.dn = ones;
954  fpscrMask.ahp = ones;
955  fpscrMask.qc = ones;
956  fpscrMask.v = ones;
957  fpscrMask.c = ones;
958  fpscrMask.z = ones;
959  fpscrMask.n = ones;
960  newVal = (newVal & (uint32_t)fpscrMask) |
962  ~(uint32_t)fpscrMask);
963  tc->getDecoderPtr()->setContext(newVal);
964  }
965  break;
966  case MISCREG_FPSR:
967  {
968  const uint32_t ones = (uint32_t)(-1);
969  FPSCR fpscrMask = 0;
970  fpscrMask.ioc = ones;
971  fpscrMask.dzc = ones;
972  fpscrMask.ofc = ones;
973  fpscrMask.ufc = ones;
974  fpscrMask.ixc = ones;
975  fpscrMask.idc = ones;
976  fpscrMask.qc = ones;
977  fpscrMask.v = ones;
978  fpscrMask.c = ones;
979  fpscrMask.z = ones;
980  fpscrMask.n = ones;
981  newVal = (newVal & (uint32_t)fpscrMask) |
983  ~(uint32_t)fpscrMask);
984  misc_reg = MISCREG_FPSCR;
985  }
986  break;
987  case MISCREG_FPCR:
988  {
989  const uint32_t ones = (uint32_t)(-1);
990  FPSCR fpscrMask = 0;
991  fpscrMask.len = ones;
992  fpscrMask.fz16 = ones;
993  fpscrMask.stride = ones;
994  fpscrMask.rMode = ones;
995  fpscrMask.fz = ones;
996  fpscrMask.dn = ones;
997  fpscrMask.ahp = ones;
998  newVal = (newVal & (uint32_t)fpscrMask) |
1000  ~(uint32_t)fpscrMask);
1001  misc_reg = MISCREG_FPSCR;
1002  }
1003  break;
1004  case MISCREG_CPSR_Q:
1005  {
1006  assert(!(newVal & ~CpsrMaskQ));
1007  newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal;
1008  misc_reg = MISCREG_CPSR;
1009  }
1010  break;
1011  case MISCREG_FPSCR_QC:
1012  {
1014  (newVal & FpscrQcMask);
1015  misc_reg = MISCREG_FPSCR;
1016  }
1017  break;
1018  case MISCREG_FPSCR_EXC:
1019  {
1021  (newVal & FpscrExcMask);
1022  misc_reg = MISCREG_FPSCR;
1023  }
1024  break;
1025  case MISCREG_FPEXC:
1026  {
1027  // vfpv3 architecture, section B.6.1 of DDI04068
1028  // bit 29 - valid only if fpexc[31] is 0
1029  const uint32_t fpexcMask = 0x60000000;
1030  newVal = (newVal & fpexcMask) |
1031  (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask);
1032  }
1033  break;
1034  case MISCREG_HCR:
1035  case MISCREG_HCR2:
1036  if (!haveVirtualization)
1037  return;
1038  break;
1039  case MISCREG_IFSR:
1040  {
1041  // ARM ARM (ARM DDI 0406C.b) B4.1.96
1042  const uint32_t ifsrMask =
1043  mask(31, 13) | mask(11, 11) | mask(8, 6);
1044  newVal = newVal & ~ifsrMask;
1045  }
1046  break;
1047  case MISCREG_DFSR:
1048  {
1049  // ARM ARM (ARM DDI 0406C.b) B4.1.52
1050  const uint32_t dfsrMask = mask(31, 14) | mask(8, 8);
1051  newVal = newVal & ~dfsrMask;
1052  }
1053  break;
1054  case MISCREG_AMAIR0:
1055  case MISCREG_AMAIR1:
1056  {
1057  // ARM ARM (ARM DDI 0406C.b) B4.1.5
1058  // Valid only with LPAE
1059  if (!haveLPAE)
1060  return;
1061  DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal);
1062  }
1063  break;
1064  case MISCREG_SCR:
1067  break;
1068  case MISCREG_SCTLR:
1069  {
1070  DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
1072 
1073  MiscRegIndex sctlr_idx;
1074  if (haveSecurity && !highestELIs64 && !scr.ns) {
1075  sctlr_idx = MISCREG_SCTLR_S;
1076  } else {
1077  sctlr_idx = MISCREG_SCTLR_NS;
1078  }
1079 
1080  SCTLR sctlr = miscRegs[sctlr_idx];
1081  SCTLR new_sctlr = newVal;
1082  new_sctlr.nmfi = ((bool)sctlr.nmfi) && !haveVirtualization;
1083  miscRegs[sctlr_idx] = (RegVal)new_sctlr;
1086  }
1087  case MISCREG_MIDR:
1088  case MISCREG_ID_PFR0:
1089  case MISCREG_ID_PFR1:
1090  case MISCREG_ID_DFR0:
1091  case MISCREG_ID_MMFR0:
1092  case MISCREG_ID_MMFR1:
1093  case MISCREG_ID_MMFR2:
1094  case MISCREG_ID_MMFR3:
1095  case MISCREG_ID_ISAR0:
1096  case MISCREG_ID_ISAR1:
1097  case MISCREG_ID_ISAR2:
1098  case MISCREG_ID_ISAR3:
1099  case MISCREG_ID_ISAR4:
1100  case MISCREG_ID_ISAR5:
1101 
1102  case MISCREG_MPIDR:
1103  case MISCREG_FPSID:
1104  case MISCREG_TLBTR:
1105  case MISCREG_MVFR0:
1106  case MISCREG_MVFR1:
1107 
1119  // ID registers are constants.
1120  return;
1121 
1122  // TLB Invalidate All
1123  case MISCREG_TLBIALL: // TLBI all entries, EL0&1,
1124  {
1125  assert32(tc);
1126  scr = readMiscReg(MISCREG_SCR, tc);
1127 
1128  TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
1129  tlbiOp(tc);
1130  return;
1131  }
1132  // TLB Invalidate All, Inner Shareable
1133  case MISCREG_TLBIALLIS:
1134  {
1135  assert32(tc);
1136  scr = readMiscReg(MISCREG_SCR, tc);
1137 
1138  TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
1139  tlbiOp.broadcast(tc);
1140  return;
1141  }
1142  // Instruction TLB Invalidate All
1143  case MISCREG_ITLBIALL:
1144  {
1145  assert32(tc);
1146  scr = readMiscReg(MISCREG_SCR, tc);
1147 
1148  ITLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
1149  tlbiOp(tc);
1150  return;
1151  }
1152  // Data TLB Invalidate All
1153  case MISCREG_DTLBIALL:
1154  {
1155  assert32(tc);
1156  scr = readMiscReg(MISCREG_SCR, tc);
1157 
1158  DTLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
1159  tlbiOp(tc);
1160  return;
1161  }
1162  // TLB Invalidate by VA
1163  // mcr tlbimval(is) is invalidating all matching entries
1164  // regardless of the level of lookup, since in gem5 we cache
1165  // in the tlb the last level of lookup only.
1166  case MISCREG_TLBIMVA:
1167  case MISCREG_TLBIMVAL:
1168  {
1169  assert32(tc);
1170  scr = readMiscReg(MISCREG_SCR, tc);
1171 
1172  TLBIMVA tlbiOp(EL1,
1173  haveSecurity && !scr.ns,
1174  mbits(newVal, 31, 12),
1175  bits(newVal, 7,0));
1176 
1177  tlbiOp(tc);
1178  return;
1179  }
1180  // TLB Invalidate by VA, Inner Shareable
1181  case MISCREG_TLBIMVAIS:
1182  case MISCREG_TLBIMVALIS:
1183  {
1184  assert32(tc);
1185  scr = readMiscReg(MISCREG_SCR, tc);
1186 
1187  TLBIMVA tlbiOp(EL1,
1188  haveSecurity && !scr.ns,
1189  mbits(newVal, 31, 12),
1190  bits(newVal, 7,0));
1191 
1192  tlbiOp.broadcast(tc);
1193  return;
1194  }
1195  // TLB Invalidate by ASID match
1196  case MISCREG_TLBIASID:
1197  {
1198  assert32(tc);
1199  scr = readMiscReg(MISCREG_SCR, tc);
1200 
1201  TLBIASID tlbiOp(EL1,
1202  haveSecurity && !scr.ns,
1203  bits(newVal, 7,0));
1204 
1205  tlbiOp(tc);
1206  return;
1207  }
1208  // TLB Invalidate by ASID match, Inner Shareable
1209  case MISCREG_TLBIASIDIS:
1210  {
1211  assert32(tc);
1212  scr = readMiscReg(MISCREG_SCR, tc);
1213 
1214  TLBIASID tlbiOp(EL1,
1215  haveSecurity && !scr.ns,
1216  bits(newVal, 7,0));
1217 
1218  tlbiOp.broadcast(tc);
1219  return;
1220  }
1221  // mcr tlbimvaal(is) is invalidating all matching entries
1222  // regardless of the level of lookup, since in gem5 we cache
1223  // in the tlb the last level of lookup only.
1224  // TLB Invalidate by VA, All ASID
1225  case MISCREG_TLBIMVAA:
1226  case MISCREG_TLBIMVAAL:
1227  {
1228  assert32(tc);
1229  scr = readMiscReg(MISCREG_SCR, tc);
1230 
1231  TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
1232  mbits(newVal, 31,12));
1233 
1234  tlbiOp(tc);
1235  return;
1236  }
1237  // TLB Invalidate by VA, All ASID, Inner Shareable
1238  case MISCREG_TLBIMVAAIS:
1239  case MISCREG_TLBIMVAALIS:
1240  {
1241  assert32(tc);
1242  scr = readMiscReg(MISCREG_SCR, tc);
1243 
1244  TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
1245  mbits(newVal, 31,12));
1246 
1247  tlbiOp.broadcast(tc);
1248  return;
1249  }
1250  // mcr tlbimvalh(is) is invalidating all matching entries
1251  // regardless of the level of lookup, since in gem5 we cache
1252  // in the tlb the last level of lookup only.
1253  // TLB Invalidate by VA, Hyp mode
1254  case MISCREG_TLBIMVAH:
1255  case MISCREG_TLBIMVALH:
1256  {
1257  assert32(tc);
1258  scr = readMiscReg(MISCREG_SCR, tc);
1259 
1260  TLBIMVAA tlbiOp(EL2, haveSecurity && !scr.ns,
1261  mbits(newVal, 31,12));
1262 
1263  tlbiOp(tc);
1264  return;
1265  }
1266  // TLB Invalidate by VA, Hyp mode, Inner Shareable
1267  case MISCREG_TLBIMVAHIS:
1268  case MISCREG_TLBIMVALHIS:
1269  {
1270  assert32(tc);
1271  scr = readMiscReg(MISCREG_SCR, tc);
1272 
1273  TLBIMVAA tlbiOp(EL2, haveSecurity && !scr.ns,
1274  mbits(newVal, 31,12));
1275 
1276  tlbiOp.broadcast(tc);
1277  return;
1278  }
1279  // mcr tlbiipas2l(is) is invalidating all matching entries
1280  // regardless of the level of lookup, since in gem5 we cache
1281  // in the tlb the last level of lookup only.
1282  // TLB Invalidate by Intermediate Physical Address, Stage 2
1283  case MISCREG_TLBIIPAS2:
1284  case MISCREG_TLBIIPAS2L:
1285  {
1286  assert32(tc);
1287  scr = readMiscReg(MISCREG_SCR, tc);
1288 
1289  TLBIIPA tlbiOp(EL1,
1290  haveSecurity && !scr.ns,
1291  static_cast<Addr>(bits(newVal, 35, 0)) << 12);
1292 
1293  tlbiOp(tc);
1294  return;
1295  }
1296  // TLB Invalidate by Intermediate Physical Address, Stage 2,
1297  // Inner Shareable
1298  case MISCREG_TLBIIPAS2IS:
1299  case MISCREG_TLBIIPAS2LIS:
1300  {
1301  assert32(tc);
1302  scr = readMiscReg(MISCREG_SCR, tc);
1303 
1304  TLBIIPA tlbiOp(EL1,
1305  haveSecurity && !scr.ns,
1306  static_cast<Addr>(bits(newVal, 35, 0)) << 12);
1307 
1308  tlbiOp.broadcast(tc);
1309  return;
1310  }
1311  // Instruction TLB Invalidate by VA
1312  case MISCREG_ITLBIMVA:
1313  {
1314  assert32(tc);
1315  scr = readMiscReg(MISCREG_SCR, tc);
1316 
1317  ITLBIMVA tlbiOp(EL1,
1318  haveSecurity && !scr.ns,
1319  mbits(newVal, 31, 12),
1320  bits(newVal, 7,0));
1321 
1322  tlbiOp(tc);
1323  return;
1324  }
1325  // Data TLB Invalidate by VA
1326  case MISCREG_DTLBIMVA:
1327  {
1328  assert32(tc);
1329  scr = readMiscReg(MISCREG_SCR, tc);
1330 
1331  DTLBIMVA tlbiOp(EL1,
1332  haveSecurity && !scr.ns,
1333  mbits(newVal, 31, 12),
1334  bits(newVal, 7,0));
1335 
1336  tlbiOp(tc);
1337  return;
1338  }
1339  // Instruction TLB Invalidate by ASID match
1340  case MISCREG_ITLBIASID:
1341  {
1342  assert32(tc);
1343  scr = readMiscReg(MISCREG_SCR, tc);
1344 
1345  ITLBIASID tlbiOp(EL1,
1346  haveSecurity && !scr.ns,
1347  bits(newVal, 7,0));
1348 
1349  tlbiOp(tc);
1350  return;
1351  }
1352  // Data TLB Invalidate by ASID match
1353  case MISCREG_DTLBIASID:
1354  {
1355  assert32(tc);
1356  scr = readMiscReg(MISCREG_SCR, tc);
1357 
1358  DTLBIASID tlbiOp(EL1,
1359  haveSecurity && !scr.ns,
1360  bits(newVal, 7,0));
1361 
1362  tlbiOp(tc);
1363  return;
1364  }
1365  // TLB Invalidate All, Non-Secure Non-Hyp
1366  case MISCREG_TLBIALLNSNH:
1367  {
1368  assert32(tc);
1369 
1370  TLBIALLN tlbiOp(EL1);
1371  tlbiOp(tc);
1372  return;
1373  }
1374  // TLB Invalidate All, Non-Secure Non-Hyp, Inner Shareable
1375  case MISCREG_TLBIALLNSNHIS:
1376  {
1377  assert32(tc);
1378 
1379  TLBIALLN tlbiOp(EL1);
1380  tlbiOp.broadcast(tc);
1381  return;
1382  }
1383  // TLB Invalidate All, Hyp mode
1384  case MISCREG_TLBIALLH:
1385  {
1386  assert32(tc);
1387 
1388  TLBIALLN tlbiOp(EL2);
1389  tlbiOp(tc);
1390  return;
1391  }
1392  // TLB Invalidate All, Hyp mode, Inner Shareable
1393  case MISCREG_TLBIALLHIS:
1394  {
1395  assert32(tc);
1396 
1397  TLBIALLN tlbiOp(EL2);
1398  tlbiOp.broadcast(tc);
1399  return;
1400  }
1401  // AArch64 TLB Invalidate All, EL3
1402  case MISCREG_TLBI_ALLE3:
1403  {
1404  assert64(tc);
1405 
1406  TLBIALL tlbiOp(EL3, true);
1407  tlbiOp(tc);
1408  return;
1409  }
1410  // AArch64 TLB Invalidate All, EL3, Inner Shareable
1411  case MISCREG_TLBI_ALLE3IS:
1412  {
1413  assert64(tc);
1414 
1415  TLBIALL tlbiOp(EL3, true);
1416  tlbiOp.broadcast(tc);
1417  return;
1418  }
1419  // AArch64 TLB Invalidate All, EL2, Inner Shareable
1420  case MISCREG_TLBI_ALLE2:
1421  case MISCREG_TLBI_ALLE2IS:
1422  {
1423  assert64(tc);
1424  scr = readMiscReg(MISCREG_SCR, tc);
1425 
1426  TLBIALL tlbiOp(EL2, haveSecurity && !scr.ns);
1427  tlbiOp(tc);
1428  return;
1429  }
1430  // AArch64 TLB Invalidate All, EL1
1431  case MISCREG_TLBI_ALLE1:
1432  case MISCREG_TLBI_VMALLE1:
1434  // @todo: handle VMID and stage 2 to enable Virtualization
1435  {
1436  assert64(tc);
1437  scr = readMiscReg(MISCREG_SCR, tc);
1438 
1439  TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
1440  tlbiOp(tc);
1441  return;
1442  }
1443  // AArch64 TLB Invalidate All, EL1, Inner Shareable
1444  case MISCREG_TLBI_ALLE1IS:
1447  // @todo: handle VMID and stage 2 to enable Virtualization
1448  {
1449  assert64(tc);
1450  scr = readMiscReg(MISCREG_SCR, tc);
1451 
1452  TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
1453  tlbiOp.broadcast(tc);
1454  return;
1455  }
1456  // VAEx(IS) and VALEx(IS) are the same because TLBs
1457  // only store entries
1458  // from the last level of translation table walks
1459  // @todo: handle VMID to enable Virtualization
1460  // AArch64 TLB Invalidate by VA, EL3
1461  case MISCREG_TLBI_VAE3_Xt:
1462  case MISCREG_TLBI_VALE3_Xt:
1463  {
1464  assert64(tc);
1465 
1466  TLBIMVA tlbiOp(EL3, true,
1467  static_cast<Addr>(bits(newVal, 43, 0)) << 12,
1468  0xbeef);
1469  tlbiOp(tc);
1470  return;
1471  }
1472  // AArch64 TLB Invalidate by VA, EL3, Inner Shareable
1475  {
1476  assert64(tc);
1477 
1478  TLBIMVA tlbiOp(EL3, true,
1479  static_cast<Addr>(bits(newVal, 43, 0)) << 12,
1480  0xbeef);
1481 
1482  tlbiOp.broadcast(tc);
1483  return;
1484  }
1485  // AArch64 TLB Invalidate by VA, EL2
1486  case MISCREG_TLBI_VAE2_Xt:
1487  case MISCREG_TLBI_VALE2_Xt:
1488  {
1489  assert64(tc);
1490  scr = readMiscReg(MISCREG_SCR, tc);
1491 
1492  TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns,
1493  static_cast<Addr>(bits(newVal, 43, 0)) << 12,
1494  0xbeef);
1495  tlbiOp(tc);
1496  return;
1497  }
1498  // AArch64 TLB Invalidate by VA, EL2, Inner Shareable
1501  {
1502  assert64(tc);
1503  scr = readMiscReg(MISCREG_SCR, tc);
1504 
1505  TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns,
1506  static_cast<Addr>(bits(newVal, 43, 0)) << 12,
1507  0xbeef);
1508 
1509  tlbiOp.broadcast(tc);
1510  return;
1511  }
1512  // AArch64 TLB Invalidate by VA, EL1
1513  case MISCREG_TLBI_VAE1_Xt:
1514  case MISCREG_TLBI_VALE1_Xt:
1515  {
1516  assert64(tc);
1517  scr = readMiscReg(MISCREG_SCR, tc);
1518  auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
1519  bits(newVal, 55, 48);
1520 
1521  TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns,
1522  static_cast<Addr>(bits(newVal, 43, 0)) << 12,
1523  asid);
1524 
1525  tlbiOp(tc);
1526  return;
1527  }
1528  // AArch64 TLB Invalidate by VA, EL1, Inner Shareable
1531  {
1532  assert64(tc);
1533  scr = readMiscReg(MISCREG_SCR, tc);
1534  auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
1535  bits(newVal, 55, 48);
1536 
1537  TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns,
1538  static_cast<Addr>(bits(newVal, 43, 0)) << 12,
1539  asid);
1540 
1541  tlbiOp.broadcast(tc);
1542  return;
1543  }
1544  // AArch64 TLB Invalidate by ASID, EL1
1545  // @todo: handle VMID to enable Virtualization
1547  {
1548  assert64(tc);
1549  scr = readMiscReg(MISCREG_SCR, tc);
1550  auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
1551  bits(newVal, 55, 48);
1552 
1553  TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid);
1554  tlbiOp(tc);
1555  return;
1556  }
1557  // AArch64 TLB Invalidate by ASID, EL1, Inner Shareable
1559  {
1560  assert64(tc);
1561  scr = readMiscReg(MISCREG_SCR, tc);
1562  auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
1563  bits(newVal, 55, 48);
1564 
1565  TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid);
1566  tlbiOp.broadcast(tc);
1567  return;
1568  }
1569  // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store
1570  // entries from the last level of translation table walks
1571  // AArch64 TLB Invalidate by VA, All ASID, EL1
1572  case MISCREG_TLBI_VAAE1_Xt:
1574  {
1575  assert64(tc);
1576  scr = readMiscReg(MISCREG_SCR, tc);
1577 
1578  TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
1579  static_cast<Addr>(bits(newVal, 43, 0)) << 12);
1580 
1581  tlbiOp(tc);
1582  return;
1583  }
1584  // AArch64 TLB Invalidate by VA, All ASID, EL1, Inner Shareable
1587  {
1588  assert64(tc);
1589  scr = readMiscReg(MISCREG_SCR, tc);
1590 
1591  TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
1592  static_cast<Addr>(bits(newVal, 43, 0)) << 12);
1593 
1594  tlbiOp.broadcast(tc);
1595  return;
1596  }
1597  // AArch64 TLB Invalidate by Intermediate Physical Address,
1598  // Stage 2, EL1
1601  {
1602  assert64(tc);
1603  scr = readMiscReg(MISCREG_SCR, tc);
1604 
1605  TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns,
1606  static_cast<Addr>(bits(newVal, 35, 0)) << 12);
1607 
1608  tlbiOp(tc);
1609  return;
1610  }
1611  // AArch64 TLB Invalidate by Intermediate Physical Address,
1612  // Stage 2, EL1, Inner Shareable
1615  {
1616  assert64(tc);
1617  scr = readMiscReg(MISCREG_SCR, tc);
1618 
1619  TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns,
1620  static_cast<Addr>(bits(newVal, 35, 0)) << 12);
1621 
1622  tlbiOp.broadcast(tc);
1623  return;
1624  }
1625  case MISCREG_ACTLR:
1626  warn("Not doing anything for write of miscreg ACTLR\n");
1627  break;
1628 
1632  case MISCREG_PMCR ... MISCREG_PMOVSSET:
1633  pmu->setMiscReg(misc_reg, newVal);
1634  break;
1635 
1636 
1637  case MISCREG_HSTR: // TJDBX, now redifined to be RES0
1638  {
1639  HSTR hstrMask = 0;
1640  hstrMask.tjdbx = 1;
1641  newVal &= ~((uint32_t) hstrMask);
1642  break;
1643  }
1644  case MISCREG_HCPTR:
1645  {
1646  // If a CP bit in NSACR is 0 then the corresponding bit in
1647  // HCPTR is RAO/WI. Same applies to NSASEDIS
1648  secure_lookup = haveSecurity &&
1651  if (!secure_lookup) {
1653  RegVal mask =
1654  (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF;
1655  newVal = (newVal & ~mask) | (oldValue & mask);
1656  }
1657  break;
1658  }
1659  case MISCREG_HDFAR: // alias for secure DFAR
1660  misc_reg = MISCREG_DFAR_S;
1661  break;
1662  case MISCREG_HIFAR: // alias for secure IFAR
1663  misc_reg = MISCREG_IFAR_S;
1664  break;
1665  case MISCREG_ATS1CPR:
1666  case MISCREG_ATS1CPW:
1667  case MISCREG_ATS1CUR:
1668  case MISCREG_ATS1CUW:
1669  case MISCREG_ATS12NSOPR:
1670  case MISCREG_ATS12NSOPW:
1671  case MISCREG_ATS12NSOUR:
1672  case MISCREG_ATS12NSOUW:
1673  case MISCREG_ATS1HR:
1674  case MISCREG_ATS1HW:
1675  {
1676  Request::Flags flags = 0;
1679  Fault fault;
1680  switch(misc_reg) {
1681  case MISCREG_ATS1CPR:
1682  flags = TLB::MustBeOne;
1683  tranType = TLB::S1CTran;
1684  mode = BaseTLB::Read;
1685  break;
1686  case MISCREG_ATS1CPW:
1687  flags = TLB::MustBeOne;
1688  tranType = TLB::S1CTran;
1689  mode = BaseTLB::Write;
1690  break;
1691  case MISCREG_ATS1CUR:
1692  flags = TLB::MustBeOne | TLB::UserMode;
1693  tranType = TLB::S1CTran;
1694  mode = BaseTLB::Read;
1695  break;
1696  case MISCREG_ATS1CUW:
1697  flags = TLB::MustBeOne | TLB::UserMode;
1698  tranType = TLB::S1CTran;
1699  mode = BaseTLB::Write;
1700  break;
1701  case MISCREG_ATS12NSOPR:
1702  if (!haveSecurity)
1703  panic("Security Extensions required for ATS12NSOPR");
1704  flags = TLB::MustBeOne;
1705  tranType = TLB::S1S2NsTran;
1706  mode = BaseTLB::Read;
1707  break;
1708  case MISCREG_ATS12NSOPW:
1709  if (!haveSecurity)
1710  panic("Security Extensions required for ATS12NSOPW");
1711  flags = TLB::MustBeOne;
1712  tranType = TLB::S1S2NsTran;
1713  mode = BaseTLB::Write;
1714  break;
1715  case MISCREG_ATS12NSOUR:
1716  if (!haveSecurity)
1717  panic("Security Extensions required for ATS12NSOUR");
1718  flags = TLB::MustBeOne | TLB::UserMode;
1719  tranType = TLB::S1S2NsTran;
1720  mode = BaseTLB::Read;
1721  break;
1722  case MISCREG_ATS12NSOUW:
1723  if (!haveSecurity)
1724  panic("Security Extensions required for ATS12NSOUW");
1725  flags = TLB::MustBeOne | TLB::UserMode;
1726  tranType = TLB::S1S2NsTran;
1727  mode = BaseTLB::Write;
1728  break;
1729  case MISCREG_ATS1HR: // only really useful from secure mode.
1730  flags = TLB::MustBeOne;
1731  tranType = TLB::HypMode;
1732  mode = BaseTLB::Read;
1733  break;
1734  case MISCREG_ATS1HW:
1735  flags = TLB::MustBeOne;
1736  tranType = TLB::HypMode;
1737  mode = BaseTLB::Write;
1738  break;
1739  }
1740  // If we're in timing mode then doing the translation in
1741  // functional mode then we're slightly distorting performance
1742  // results obtained from simulations. The translation should be
1743  // done in the same mode the core is running in. NOTE: This
1744  // can't be an atomic translation because that causes problems
1745  // with unexpected atomic snoop requests.
1746  warn("Translating via %s in functional mode! Fix Me!\n",
1747  miscRegName[misc_reg]);
1748 
1749  auto req = std::make_shared<Request>(
1750  0, val, 0, flags, Request::funcMasterId,
1751  tc->pcState().pc(), tc->contextId());
1752 
1753  fault = getDTBPtr(tc)->translateFunctional(
1754  req, tc, mode, tranType);
1755 
1756  TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1757  HCR hcr = readMiscRegNoEffect(MISCREG_HCR);
1758 
1759  RegVal newVal;
1760  if (fault == NoFault) {
1761  Addr paddr = req->getPaddr();
1762  if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode ||
1763  ((tranType & TLB::S1S2NsTran) && hcr.vm) )) {
1764  newVal = (paddr & mask(39, 12)) |
1765  (getDTBPtr(tc)->getAttr());
1766  } else {
1767  newVal = (paddr & 0xfffff000) |
1768  (getDTBPtr(tc)->getAttr());
1769  }
1770  DPRINTF(MiscRegs,
1771  "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
1772  val, newVal);
1773  } else {
1774  ArmFault *armFault = static_cast<ArmFault *>(fault.get());
1775  armFault->update(tc);
1776  // Set fault bit and FSR
1777  FSR fsr = armFault->getFsr(tc);
1778 
1779  newVal = ((fsr >> 9) & 1) << 11;
1780  if (newVal) {
1781  // LPAE - rearange fault status
1782  newVal |= ((fsr >> 0) & 0x3f) << 1;
1783  } else {
1784  // VMSA - rearange fault status
1785  newVal |= ((fsr >> 0) & 0xf) << 1;
1786  newVal |= ((fsr >> 10) & 0x1) << 5;
1787  newVal |= ((fsr >> 12) & 0x1) << 6;
1788  }
1789  newVal |= 0x1; // F bit
1790  newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
1791  newVal |= armFault->isStage2() ? 0x200 : 0;
1792  DPRINTF(MiscRegs,
1793  "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n",
1794  val, fsr, newVal);
1795  }
1797  return;
1798  }
1799  case MISCREG_TTBCR:
1800  {
1801  TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1802  const uint32_t ones = (uint32_t)(-1);
1803  TTBCR ttbcrMask = 0;
1804  TTBCR ttbcrNew = newVal;
1805 
1806  // ARM DDI 0406C.b, ARMv7-32
1807  ttbcrMask.n = ones; // T0SZ
1808  if (haveSecurity) {
1809  ttbcrMask.pd0 = ones;
1810  ttbcrMask.pd1 = ones;
1811  }
1812  ttbcrMask.epd0 = ones;
1813  ttbcrMask.irgn0 = ones;
1814  ttbcrMask.orgn0 = ones;
1815  ttbcrMask.sh0 = ones;
1816  ttbcrMask.ps = ones; // T1SZ
1817  ttbcrMask.a1 = ones;
1818  ttbcrMask.epd1 = ones;
1819  ttbcrMask.irgn1 = ones;
1820  ttbcrMask.orgn1 = ones;
1821  ttbcrMask.sh1 = ones;
1822  if (haveLPAE)
1823  ttbcrMask.eae = ones;
1824 
1825  if (haveLPAE && ttbcrNew.eae) {
1826  newVal = newVal & ttbcrMask;
1827  } else {
1828  newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask));
1829  }
1830  // Invalidate TLB MiscReg
1833  break;
1834  }
1835  case MISCREG_TTBR0:
1836  case MISCREG_TTBR1:
1837  {
1838  TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1839  if (haveLPAE) {
1840  if (ttbcr.eae) {
1841  // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP
1842  // ARMv8 AArch32 bit 63-56 only
1843  uint64_t ttbrMask = mask(63,56) | mask(47,40);
1844  newVal = (newVal & (~ttbrMask));
1845  }
1846  }
1847  // Invalidate TLB MiscReg
1850  break;
1851  }
1852  case MISCREG_SCTLR_EL1:
1853  case MISCREG_CONTEXTIDR:
1854  case MISCREG_PRRR:
1855  case MISCREG_NMRR:
1856  case MISCREG_MAIR0:
1857  case MISCREG_MAIR1:
1858  case MISCREG_DACR:
1859  case MISCREG_VTTBR:
1860  case MISCREG_SCR_EL3:
1861  case MISCREG_HCR_EL2:
1862  case MISCREG_TCR_EL1:
1863  case MISCREG_TCR_EL2:
1864  case MISCREG_TCR_EL3:
1865  case MISCREG_SCTLR_EL2:
1866  case MISCREG_SCTLR_EL3:
1867  case MISCREG_HSCTLR:
1868  case MISCREG_TTBR0_EL1:
1869  case MISCREG_TTBR1_EL1:
1870  case MISCREG_TTBR0_EL2:
1871  case MISCREG_TTBR1_EL2:
1872  case MISCREG_TTBR0_EL3:
1875  break;
1876  case MISCREG_NZCV:
1877  {
1878  CPSR cpsr = val;
1879 
1880  tc->setCCReg(CCREG_NZ, cpsr.nz);
1881  tc->setCCReg(CCREG_C, cpsr.c);
1882  tc->setCCReg(CCREG_V, cpsr.v);
1883  }
1884  break;
1885  case MISCREG_DAIF:
1886  {
1887  CPSR cpsr = miscRegs[MISCREG_CPSR];
1888  cpsr.daif = (uint8_t) ((CPSR) newVal).daif;
1889  newVal = cpsr;
1890  misc_reg = MISCREG_CPSR;
1891  }
1892  break;
1893  case MISCREG_SP_EL0:
1894  tc->setIntReg(INTREG_SP0, newVal);
1895  break;
1896  case MISCREG_SP_EL1:
1897  tc->setIntReg(INTREG_SP1, newVal);
1898  break;
1899  case MISCREG_SP_EL2:
1900  tc->setIntReg(INTREG_SP2, newVal);
1901  break;
1902  case MISCREG_SPSEL:
1903  {
1904  CPSR cpsr = miscRegs[MISCREG_CPSR];
1905  cpsr.sp = (uint8_t) ((CPSR) newVal).sp;
1906  newVal = cpsr;
1907  misc_reg = MISCREG_CPSR;
1908  }
1909  break;
1910  case MISCREG_CURRENTEL:
1911  {
1912  CPSR cpsr = miscRegs[MISCREG_CPSR];
1913  cpsr.el = (uint8_t) ((CPSR) newVal).el;
1914  newVal = cpsr;
1915  misc_reg = MISCREG_CPSR;
1916  }
1917  break;
1918  case MISCREG_PAN:
1919  {
1920  // PAN is affecting data accesses
1922 
1923  CPSR cpsr = miscRegs[MISCREG_CPSR];
1924  cpsr.pan = (uint8_t) ((CPSR) newVal).pan;
1925  newVal = cpsr;
1926  misc_reg = MISCREG_CPSR;
1927  }
1928  break;
1929  case MISCREG_AT_S1E1R_Xt:
1930  case MISCREG_AT_S1E1W_Xt:
1931  case MISCREG_AT_S1E0R_Xt:
1932  case MISCREG_AT_S1E0W_Xt:
1933  case MISCREG_AT_S1E2R_Xt:
1934  case MISCREG_AT_S1E2W_Xt:
1935  case MISCREG_AT_S12E1R_Xt:
1936  case MISCREG_AT_S12E1W_Xt:
1937  case MISCREG_AT_S12E0R_Xt:
1938  case MISCREG_AT_S12E0W_Xt:
1939  case MISCREG_AT_S1E3R_Xt:
1940  case MISCREG_AT_S1E3W_Xt:
1941  {
1942  RequestPtr req = std::make_shared<Request>();
1943  Request::Flags flags = 0;
1946  Fault fault;
1947  switch(misc_reg) {
1948  case MISCREG_AT_S1E1R_Xt:
1949  flags = TLB::MustBeOne;
1950  tranType = TLB::S1E1Tran;
1951  mode = BaseTLB::Read;
1952  break;
1953  case MISCREG_AT_S1E1W_Xt:
1954  flags = TLB::MustBeOne;
1955  tranType = TLB::S1E1Tran;
1956  mode = BaseTLB::Write;
1957  break;
1958  case MISCREG_AT_S1E0R_Xt:
1959  flags = TLB::MustBeOne | TLB::UserMode;
1960  tranType = TLB::S1E0Tran;
1961  mode = BaseTLB::Read;
1962  break;
1963  case MISCREG_AT_S1E0W_Xt:
1964  flags = TLB::MustBeOne | TLB::UserMode;
1965  tranType = TLB::S1E0Tran;
1966  mode = BaseTLB::Write;
1967  break;
1968  case MISCREG_AT_S1E2R_Xt:
1969  flags = TLB::MustBeOne;
1970  tranType = TLB::S1E2Tran;
1971  mode = BaseTLB::Read;
1972  break;
1973  case MISCREG_AT_S1E2W_Xt:
1974  flags = TLB::MustBeOne;
1975  tranType = TLB::S1E2Tran;
1976  mode = BaseTLB::Write;
1977  break;
1978  case MISCREG_AT_S12E0R_Xt:
1979  flags = TLB::MustBeOne | TLB::UserMode;
1980  tranType = TLB::S12E0Tran;
1981  mode = BaseTLB::Read;
1982  break;
1983  case MISCREG_AT_S12E0W_Xt:
1984  flags = TLB::MustBeOne | TLB::UserMode;
1985  tranType = TLB::S12E0Tran;
1986  mode = BaseTLB::Write;
1987  break;
1988  case MISCREG_AT_S12E1R_Xt:
1989  flags = TLB::MustBeOne;
1990  tranType = TLB::S12E1Tran;
1991  mode = BaseTLB::Read;
1992  break;
1993  case MISCREG_AT_S12E1W_Xt:
1994  flags = TLB::MustBeOne;
1995  tranType = TLB::S12E1Tran;
1996  mode = BaseTLB::Write;
1997  break;
1998  case MISCREG_AT_S1E3R_Xt:
1999  flags = TLB::MustBeOne;
2000  tranType = TLB::S1E3Tran;
2001  mode = BaseTLB::Read;
2002  break;
2003  case MISCREG_AT_S1E3W_Xt:
2004  flags = TLB::MustBeOne;
2005  tranType = TLB::S1E3Tran;
2006  mode = BaseTLB::Write;
2007  break;
2008  }
2009  // If we're in timing mode then doing the translation in
2010  // functional mode then we're slightly distorting performance
2011  // results obtained from simulations. The translation should be
2012  // done in the same mode the core is running in. NOTE: This
2013  // can't be an atomic translation because that causes problems
2014  // with unexpected atomic snoop requests.
2015  warn("Translating via %s in functional mode! Fix Me!\n",
2016  miscRegName[misc_reg]);
2017 
2018  req->setVirt(0, val, 0, flags, Request::funcMasterId,
2019  tc->pcState().pc());
2020  req->setContext(tc->contextId());
2021  fault = getDTBPtr(tc)->translateFunctional(req, tc, mode,
2022  tranType);
2023 
2024  RegVal newVal;
2025  if (fault == NoFault) {
2026  Addr paddr = req->getPaddr();
2027  uint64_t attr = getDTBPtr(tc)->getAttr();
2028  uint64_t attr1 = attr >> 56;
2029  if (!attr1 || attr1 ==0x44) {
2030  attr |= 0x100;
2031  attr &= ~ uint64_t(0x80);
2032  }
2033  newVal = (paddr & mask(47, 12)) | attr;
2034  DPRINTF(MiscRegs,
2035  "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n",
2036  val, newVal);
2037  } else {
2038  ArmFault *armFault = static_cast<ArmFault *>(fault.get());
2039  armFault->update(tc);
2040  // Set fault bit and FSR
2041  FSR fsr = armFault->getFsr(tc);
2042 
2043  CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
2044  if (cpsr.width) { // AArch32
2045  newVal = ((fsr >> 9) & 1) << 11;
2046  // rearrange fault status
2047  newVal |= ((fsr >> 0) & 0x3f) << 1;
2048  newVal |= 0x1; // F bit
2049  newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
2050  newVal |= armFault->isStage2() ? 0x200 : 0;
2051  } else { // AArch64
2052  newVal = 1; // F bit
2053  newVal |= fsr << 1; // FST
2054  // TODO: DDI 0487A.f D7-2083, AbortFault's s1ptw bit.
2055  newVal |= armFault->isStage2() ? 1 << 8 : 0; // PTW
2056  newVal |= armFault->isStage2() ? 1 << 9 : 0; // S
2057  newVal |= 1 << 11; // RES1
2058  }
2059  DPRINTF(MiscRegs,
2060  "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n",
2061  val, fsr, newVal);
2062  }
2064  return;
2065  }
2066  case MISCREG_SPSR_EL3:
2067  case MISCREG_SPSR_EL2:
2068  case MISCREG_SPSR_EL1:
2069  {
2070  RegVal spsr_mask = havePAN ?
2071  ~(0x5 << 21) : ~(0x7 << 21);
2072 
2073  newVal = val & spsr_mask;
2074  break;
2075  }
2076  case MISCREG_L2CTLR:
2077  warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
2078  miscRegName[misc_reg], uint32_t(val));
2079  break;
2080 
2081  // Generic Timer registers
2082  case MISCREG_CNTHV_CTL_EL2:
2089  getGenericTimer(tc).setMiscReg(misc_reg, newVal);
2090  break;
2094  getGICv3CPUInterface(tc).setMiscReg(misc_reg, newVal);
2095  return;
2096  case MISCREG_ZCR_EL3:
2097  case MISCREG_ZCR_EL2:
2098  case MISCREG_ZCR_EL1:
2099  tc->getDecoderPtr()->setSveLen(
2100  (getCurSveVecLenInBits(tc) >> 7) - 1);
2101  break;
2102  }
2103  }
2104  setMiscRegNoEffect(misc_reg, newVal);
2105 }
2106 
2107 BaseISADevice &
2109 {
2110  // We only need to create an ISA interface the first time we try
2111  // to access the timer.
2112  if (timer)
2113  return *timer.get();
2114 
2115  assert(system);
2116  GenericTimer *generic_timer(system->getGenericTimer());
2117  if (!generic_timer) {
2118  panic("Trying to get a generic timer from a system that hasn't "
2119  "been configured to use a generic timer.\n");
2120  }
2121 
2122  timer.reset(new GenericTimerISA(*generic_timer, tc->contextId()));
2123  timer->setThreadContext(tc);
2124 
2125  return *timer.get();
2126 }
2127 
2128 BaseISADevice &
2130 {
2131  panic_if(!gicv3CpuInterface, "GICV3 cpu interface is not registered!");
2132  return *gicv3CpuInterface.get();
2133 }
2134 
2135 unsigned
2137 {
2138  if (!FullSystem) {
2139  return sveVL * 128;
2140  }
2141 
2142  panic_if(!tc,
2143  "A ThreadContext is needed to determine the SVE vector length "
2144  "in full-system mode");
2145 
2146  CPSR cpsr = miscRegs[MISCREG_CPSR];
2147  ExceptionLevel el = (ExceptionLevel) (uint8_t) cpsr.el;
2148 
2149  unsigned len = 0;
2150 
2151  if (el == EL1 || (el == EL0 && !ELIsInHost(tc, el))) {
2152  len = static_cast<ZCR>(miscRegs[MISCREG_ZCR_EL1]).len;
2153  }
2154 
2155  if (el == EL2 || (el == EL0 && ELIsInHost(tc, el))) {
2156  len = static_cast<ZCR>(miscRegs[MISCREG_ZCR_EL2]).len;
2157  } else if (haveVirtualization && !inSecureState(tc) &&
2158  (el == EL0 || el == EL1)) {
2159  len = std::min(
2160  len,
2161  static_cast<unsigned>(
2162  static_cast<ZCR>(miscRegs[MISCREG_ZCR_EL2]).len));
2163  }
2164 
2165  if (el == EL3) {
2166  len = static_cast<ZCR>(miscRegs[MISCREG_ZCR_EL3]).len;
2167  } else if (haveSecurity) {
2168  len = std::min(
2169  len,
2170  static_cast<unsigned>(
2171  static_cast<ZCR>(miscRegs[MISCREG_ZCR_EL3]).len));
2172  }
2173 
2174  len = std::min(len, sveVL - 1);
2175 
2176  return (len + 1) * 128;
2177 }
2178 
2179 void
2181 {
2182  auto vv = vc.as<uint64_t>();
2183  for (int i = 2; i < eCount; ++i) {
2184  vv[i] = 0;
2185  }
2186 }
2187 
2190 {
2191  switch (FullSystem ? sys->highestEL() : EL1) {
2192  case EL0:
2193  case EL1: priv(); break;
2194  case EL2: hyp(); break;
2195  case EL3: mon(); break;
2196  }
2197  return *this;
2198 }
2199 
2200 } // namespace ArmISA
2201 
2202 ArmISA::ISA *
2203 ArmISAParams::create()
2204 {
2205  return new ArmISA::ISA(this);
2206 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
#define DPRINTF(x,...)
Definition: trace.hh:229
bool haveLPAE
Definition: isa.hh:92
virtual System * getSystemPtr()=0
MiscRegIndex
Definition: miscregs.hh:57
unsigned sveVL
SVE vector length in quadwords.
Definition: isa.hh:103
bitset< NUM_MISCREG_INFOS > miscRegInfo[NUM_MISCREGS]
Definition: miscregs.cc:2888
BaseISADevice & getGenericTimer(ThreadContext *tc)
Definition: isa.cc:2108
Bitfield< 5, 3 > reg
Definition: types.hh:89
Bitfield< 28 > v
decltype(nullptr) constexpr NoFault
Definition: types.hh:245
Definition: gic_v3.hh:54
bool haveGICv3CPUInterface
Definition: isa.hh:96
virtual void setISA(ISA *isa)
Definition: isa_device.cc:53
virtual TheISA::Decoder * getDecoderPtr()=0
The file contains the definition of a set of TLB Invalidate Instructions.
ArmSystem * system
Definition: isa.hh:71
CheckerCPU class.
Definition: cpu.hh:87
Instruction TLB Invalidate All.
Definition: tlbi_op.hh:97
Bitfield< 7 > i
This module implements the global system counter and the local per-CPU architected timers as specifie...
bool haveSecurity() const
Returns true if this system implements the Security Extensions.
Definition: system.hh:185
void clear32(const ArmISAParams *p, const SCTLR &sctlr_rst)
Definition: isa.cc:213
VecRegT< VecElem, NumElems, true > as() const
View interposers.
Definition: vec_reg.hh:385
Vector Register Abstraction This generic class is the model in a particularization of MVC...
Definition: vec_reg.hh:160
virtual TheISA::PCState pcState() const =0
virtual RegVal readIntReg(RegIndex reg_idx) const =0
virtual RegVal readMiscReg(int misc_reg)=0
Read a system register belonging to this device.
RegVal readMiscRegNoEffect(int misc_reg) const
Definition: isa.cc:437
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
TLB * getDTBPtr(T *tc)
Definition: tlb.hh:480
bool havePAN() const
Returns true if Priviledge Access Never is implemented.
Definition: system.hh:250
Instruction TLB Invalidate by VA.
Definition: tlbi_op.hh:211
Bitfield< 0 > sp
bool highestELIs64() const
Returns true if the register width of the highest implemented exception level is 64 bits (ARMv8) ...
Definition: system.hh:221
Base class for devices that use the MiscReg interfaces.
Definition: isa_device.hh:60
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:136
uint64_t getAttr() const
Definition: tlb.hh:350
bool haveSecurity
Definition: isa.hh:91
uint64_t RegVal
Definition: types.hh:168
void preUnflattenMiscReg()
Definition: miscregs.cc:1099
virtual BaseCPU * getCpuPtr()=0
Definition: ccregs.hh:42
uint8_t physAddrRange
Definition: isa.hh:97
static std::vector< struct MiscRegLUTEntry > lookUpMiscReg
Metadata table accessible via the value of the register.
Definition: isa.hh:136
virtual FSR getFsr(ThreadContext *tc) const
Definition: faults.hh:241
const char *const miscRegName[]
Definition: miscregs.hh:1021
Bitfield< 4, 0 > mode
virtual RegVal readCCReg(RegIndex reg_idx) const =0
void clear64(const ArmISAParams *p)
Definition: isa.cc:265
const int NumMiscRegs
Definition: registers.hh:87
RegVal readMPIDR(ArmSystem *arm_sys, ThreadContext *tc)
This helper function is either returing the value of MPIDR_EL1 (by calling getMPIDR), or it is issuing a read to VMPIDR_EL2 (as it happens in virtualized systems)
Definition: utility.cc:225
TLB Invalidate by VA, All ASID.
Definition: tlbi_op.hh:180
ThreadContext is the external interface to all thread state for anything outside of the CPU...
unsigned getCurSveVecLenInBits(ThreadContext *tc) const
Definition: isa.cc:2136
virtual void setThreadContext(ThreadContext *tc)
Definition: isa_device.hh:67
STL vector class.
Definition: stl.hh:40
bool havePAN
Definition: isa.hh:100
TLB Invalidate by VA.
Definition: tlbi_op.hh:195
Bitfield< 63 > val
Definition: misc.hh:771
ExceptionLevel
Definition: types.hh:585
bool haveSVE() const
Returns true if SVE is implemented (ARMv8)
Definition: system.hh:241
void setMiscRegNoEffect(int misc_reg, RegVal val)
Definition: isa.cc:768
ISA(Params *p)
Definition: isa.cc:64
Data TLB Invalidate by ASID match.
Definition: tlbi_op.hh:153
Instruction TLB Invalidate by ASID match.
Definition: tlbi_op.hh:137
uint8_t encodePhysAddrRange64(int pa_size)
Returns the encoding corresponding to the specified n.
Definition: utility.cc:921
Bitfield< 3, 2 > el
Bitfield< 4 > pc
int unflattenMiscReg(int reg)
Definition: miscregs.cc:1115
void initializeMiscRegMetadata()
Definition: miscregs.cc:2891
const Enums::VecRegRenameMode _vecRegRenameMode
Definition: isa.hh:75
virtual void pcStateNoRecord(const TheISA::PCState &val)=0
RegVal miscRegs[NumMiscRegs]
Definition: isa.hh:411
void initID64(const ArmISAParams *p)
Definition: isa.cc:350
unsigned sveVL() const
Returns the SVE vector length at reset, in quadwords.
Definition: system.hh:244
BaseGic * getGIC() const
Get a pointer to the system&#39;s GIC.
Definition: system.hh:217
chain highest(ArmSystem *const sys) const
Definition: isa.cc:2189
bool haveVirtualization
Definition: isa.hh:93
Bitfield< 18, 16 > len
std::pair< int, int > getMiscIndices(int misc_reg) const
Definition: isa.hh:702
bool ELIs32(ThreadContext *tc, ExceptionLevel el)
Definition: utility.cc:339
BaseISADevice & getGICv3CPUInterface(ThreadContext *tc)
Definition: isa.cc:2129
unsigned numContexts() const
Definition: system.hh:206
static const uint32_t CpsrMaskQ
Definition: miscregs.hh:1904
T insertBits(T val, int first, int last, B bit_val)
Returns val with bits first to last set to the LSBs of bit_val.
Definition: bitfield.hh:132
virtual void setMiscReg(int misc_reg, RegVal val)=0
Write to a system register belonging to this device.
bool haveCrypto
Definition: isa.hh:94
std::unique_ptr< BaseISADevice > timer
Definition: isa.hh:84
std::unique_ptr< BaseISADevice > gicv3CpuInterface
Definition: isa.hh:87
bool highestELIs64
Definition: isa.hh:90
bool translateFunctional(ThreadContext *tc, Addr vaddr, Addr &paddr)
Do a functional lookup on the TLB (for debugging) and don&#39;t modify any internal state.
Definition: tlb.cc:117
virtual void setCCReg(RegIndex reg_idx, RegVal val)=0
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
bool haveVirtualization() const
Returns true if this system implements the virtualization Extensions.
Definition: system.hh:194
ArmTranslationType
Definition: tlb.hh:125
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
#define ULL(N)
uint64_t constant
Definition: types.hh:50
Gicv3CPUInterface * getCPUInterface(int cpu_id) const
Definition: gic_v3.hh:136
#define warn_once(...)
Definition: logging.hh:216
This master id is used for functional requests that don&#39;t come from a particular device.
Definition: request.hh:212
bool haveCrypto() const
Returns true if this system implements the Crypto Extension.
Definition: system.hh:199
Data TLB Invalidate All.
Definition: tlbi_op.hh:110
bool haveLSE
Definition: isa.hh:99
Bitfield< 15 > system
Definition: misc.hh:999
void initID32(const ArmISAParams *p)
Definition: isa.cc:314
Mode
Definition: tlb.hh:59
virtual bool isStage2() const
Definition: faults.hh:240
TLB Invalidate by ASID match.
Definition: tlbi_op.hh:123
void assert32(ThreadContext *tc)
Definition: isa.hh:457
const Params * params() const
Definition: isa.cc:120
virtual uint32_t iss() const =0
DummyISADevice dummyDevice
Dummy device for to handle non-existing ISA devices.
Definition: isa.hh:78
TLB Invalidate All, Non-Secure.
Definition: tlbi_op.hh:169
virtual CheckerCPU * getCheckerCpuPtr()=0
void clear()
Definition: isa.cc:126
bool haveLargeAsid64
Definition: isa.hh:95
Bitfield< 9, 6 > daif
uint8_t physAddrRange() const
Returns the supported physical address range in bits.
Definition: system.hh:257
ExceptionLevel highestEL() const
Returns the highest implemented exception level.
Definition: system.hh:224
bool afterStartup
Definition: isa.hh:111
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
virtual int threadId() const =0
TLB Invalidate All.
Definition: tlbi_op.hh:86
void setMiscReg(int misc_reg, RegVal val, ThreadContext *tc)
Definition: isa.cc:790
Bitfield< 22 > pan
void broadcast(ThreadContext *tc)
Broadcast the TLB Invalidate operation to all TLBs in the Arm system.
Definition: tlbi_op.hh:71
bool haveSVE
Definition: isa.hh:98
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
virtual ContextID contextId() const =0
BaseInterrupts * getInterruptController(ThreadID tid)
Definition: base.hh:226
Bitfield< 2 > priv
Definition: miscregs.hh:129
bool haveLSE() const
Returns true if LSE is implemented (ARMv8.1)
Definition: system.hh:247
GenericTimer * getGenericTimer() const
Get a pointer to the system&#39;s generic timer model.
Definition: system.hh:214
BaseISADevice * pmu
Definition: isa.hh:81
void assert64(ThreadContext *tc)
Definition: isa.hh:462
Bitfield< 3, 0 > mask
Definition: types.hh:64
Definition: isa.hh:35
static const uint32_t FpscrExcMask
Definition: miscregs.hh:1921
void update(ThreadContext *tc)
Definition: faults.cc:424
#define warn(...)
Definition: logging.hh:212
ArmISAParams Params
Definition: isa.hh:769
void invalidateMiscReg()
Definition: tlb.hh:449
RegVal readMiscReg(int misc_reg, ThreadContext *tc)
Definition: isa.cc:461
bool inSecureState(ThreadContext *tc)
Definition: utility.cc:195
bool ELIsInHost(ThreadContext *tc, ExceptionLevel el)
Returns true if the current exception level el is executing a Host OS or an application of a Host OS ...
Definition: utility.cc:348
T mbits(T val, int first, int last)
Mask off the given bits in place like bits() but without shifting.
Definition: bitfield.hh:96
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
bool haveLargeAsid64() const
Returns true if ASID is 16 bits in AArch64 (ARMv8)
Definition: system.hh:238
Bitfield< 0 > p
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:185
Addr resetAddr() const
Returns the reset address if the highest implemented exception level is 64 bits (ARMv8) ...
Definition: system.hh:235
virtual RegVal readMiscReg(RegIndex misc_reg)=0
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
void updateRegMap(CPSR cpsr)
Definition: isa.hh:415
TLB Invalidate by Intermediate Physical Address.
Definition: tlbi_op.hh:247
Data TLB Invalidate by VA.
Definition: tlbi_op.hh:229
static void zeroSveVecRegUpperPart(VecRegContainer &vc, unsigned eCount)
Definition: isa.cc:2180
bool ic(TxDesc *d)
static const uint32_t FpscrQcMask
Definition: miscregs.hh:1923
TLB * getITBPtr(T *tc)
Definition: tlb.hh:471
bool haveLPAE() const
Returns true if this system implements the Large Physical Address Extension.
Definition: system.hh:189
unsigned int cacheLineSize() const
Get the cache line size of the system.
Definition: system.hh:188
virtual void startup()
startup() is the final initialization call before simulation.
Definition: sim_object.cc:99

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