gem5  v22.1.0.0
self_debug.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Arm Limited
3  * Copyright (c) 2019 Metempsy Technology LSC
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/self_debug.hh"
40 
41 #include "arch/arm/faults.hh"
43 #include "base/bitfield.hh"
44 
45 namespace gem5
46 {
47 
48 using namespace ArmISA;
49 
50 Fault
53 {
54  Fault fault = NoFault;
55 
56  if (mode == BaseMMU::Execute) {
57  const bool d_step = softStep->advanceSS(tc);
58  if (!d_step) {
59  fault = testVectorCatch(tc, req->getVaddr(), nullptr);
60  if (fault == NoFault)
61  fault = testBreakPoints(tc, req->getVaddr());
62  }
63  } else if (!req->isCacheMaintenance() ||
64  (req->isCacheInvalidate() && !req->isCacheClean())) {
65  bool md = mode == BaseMMU::Write ? true: false;
66  fault = testWatchPoints(tc, req->getVaddr(), md,
67  req->isAtomic(),
68  req->getSize(),
69  req->isCacheMaintenance());
70  }
71 
72  return fault;
73 }
74 
75 Fault
77 {
78  if (!mde)
79  return NoFault;
80 
81  setAArch32(tc);
82 
83  to32 = targetAArch32(tc);
84 
85  if (!isDebugEnabled(tc))
86  return NoFault;
87 
89  for (auto &p: arBrkPoints){
90  PCState pcst = tc->pcState().as<PCState>();
91  Addr pc = vaddr;
92  if (pcst.itstate() != 0x0)
93  pc = pcst.pc();
94  if (p.enable && p.isActive(pc) &&(!to32 || !p.onUse)) {
95  const DBGBCR ctr = p.getControlReg(tc);
96  if (p.isEnabled(tc, el, ctr.hmc, ctr.ssc, ctr.pmc)) {
97  if (p.test(tc, pc, el, ctr, false)) {
98  if (to32)
99  p.onUse = true;
100  return triggerException(tc, pc);
101  }
102  }
103  }
104  }
105  return NoFault;
106 }
107 
108 
109 Fault
111 {
112  if (to32) {
113  return std::make_shared<PrefetchAbort>(vaddr,
114  ArmFault::DebugEvent, false,
117  } else {
118  return std::make_shared<HardwareBreakpoint>(vaddr, 0x22);
119  }
120 }
121 
122 Fault
124  bool atomic, unsigned size, bool cm)
125 {
126  setAArch32(tc);
127  to32 = targetAArch32(tc);
128  if (!isDebugEnabled(tc) || !mde)
129  return NoFault;
130 
132  int idxtmp = -1;
133  for (auto &p: arWatchPoints){
134  idxtmp ++;
135  if (p.enable) {
136  if (p.test(tc, vaddr, el, write, atomic, size)) {
137  return triggerWatchpointException(tc, vaddr, write, cm);
138  }
139  }
140  }
141  return NoFault;
142 }
143 
144 Fault
146  bool write, bool cm)
147 {
148  if (to32) {
151  return std::make_shared<DataAbort>(vaddr,
153  write, ArmFault::DebugEvent, cm,
155  } else {
156  return std::make_shared<Watchpoint>(0, vaddr, write, cm);
157  }
158 }
159 
160 bool
162  bool secure, bool mask)
163 {
164  bool route_to_el2 = ArmSystem::haveEL(tc, EL2) &&
165  (!secure || HaveExt(tc, ArmExtension::FEAT_SEL2)) &&
166  enableTdeTge;
167 
168  ExceptionLevel target_el = route_to_el2 ? EL2 : EL1;
169  if (oslk || (sdd && secure && ArmSystem::haveEL(tc, EL3))) {
170  return false;
171  }
172 
173  if (el == target_el) {
174  return kde && !mask;
175  } else {
176  return target_el > el;
177  }
178 }
179 
180 bool
182  bool secure, bool mask)
183 {
184  if (el == EL0 && !ELStateUsingAArch32(tc, EL1, secure)) {
185  return isDebugEnabledForEL64(tc, el, secure, mask);
186  }
187 
188  if (oslk) {
189  return false;
190  }
191 
192  bool enabled;
193  if (secure && ArmSystem::haveEL(tc, EL3)) {
194  // We ignore the check for invasive External debug checking SPIDEN
195  // and DBGEN signals. They are not implemented
196  bool spd32 = bits(tc->readMiscReg(MISCREG_MDCR_EL3), 14);
197  enabled = spd32;
198 
199  bool suiden = bits(tc->readMiscReg(MISCREG_SDER), 0);
200  enabled = el == EL0 ? (enabled || suiden) : enabled;
201  } else {
202  enabled = el != EL2;
203  }
204  return enabled;
205 }
206 
207 bool
209 {
210  const DBGBCR ctr = getControlReg(tc);
211  return ((ctr.bt & 0x1) && enable) && test(tc, vaddr, el, ctr, true);
212 }
213 
214 bool
216  bool from_link)
217 {
218  bool v = false;
219  switch (ctr.bt) {
220  case 0x0:
221  v = testAddrMatch(tc, pc, ctr.bas);
222  break;
223 
224  case 0x1:
225  v = testAddrMatch(tc, pc, ctr.bas); // linked
226  if (v) {
227  v = (conf->getBrkPoint(ctr.lbn))->testLinkedBk(tc, pc, el);
228  }
229  break;
230 
231  case 0x2:
232  {
233  bool host = ELIsInHost(tc, el);
234  v = testContextMatch(tc, !host, true);
235  }
236  break;
237 
238  case 0x3:
239  if (from_link){
240  bool host = ELIsInHost(tc, el);
241  v = testContextMatch(tc, !host, true);
242  }
243  break;
244 
245  case 0x4:
246  v = testAddrMissMatch(tc, pc, ctr.bas);
247  break;
248 
249  case 0x5:
250  v = testAddrMissMatch(tc, pc, ctr.bas); // linked
251  if (v && !from_link)
252  v = v && (conf->getBrkPoint(ctr.lbn))->testLinkedBk(tc, pc, el);
253  break;
254 
255  case 0x6:
256  if (HaveExt(tc, ArmExtension::FEAT_VHE) && !ELIsInHost(tc, el))
257  v = testContextMatch(tc, true);
258  break;
259 
260  case 0x7:
261  if (HaveExt(tc, ArmExtension::FEAT_VHE) && !ELIsInHost(tc, el) &&
262  from_link)
263  v = testContextMatch(tc, true);
264  break;
265 
266  case 0x8:
267  if (EL2Enabled(tc) && !ELIsInHost(tc, el)) {
268  v = testVMIDMatch(tc);
269  }
270  break;
271 
272  case 0x9:
273  if (from_link && EL2Enabled(tc) && !ELIsInHost(tc, el)) {
274  v = testVMIDMatch(tc);
275  }
276  break;
277 
278  case 0xa:
279  if (EL2Enabled(tc) && !ELIsInHost(tc, el)) {
280  v = testContextMatch(tc, true);
281  if (v && !from_link)
282  v = v && testVMIDMatch(tc);
283  }
284  break;
285  case 0xb:
286  if (from_link && EL2Enabled(tc) && !ELIsInHost(tc, el)) {
287  v = testContextMatch(tc, true);
288  v = v && testVMIDMatch(tc);
289  }
290  break;
291 
292  case 0xc:
293  if (HaveExt(tc, ArmExtension::FEAT_VHE) &&
294  (!isSecure(tc)|| HaveExt(tc, ArmExtension::FEAT_SEL2)))
295  v = testContextMatch(tc, false);
296  break;
297 
298  case 0xd:
299  if (HaveExt(tc, ArmExtension::FEAT_VHE) && from_link &&
300  (!isSecure(tc)|| HaveExt(tc, ArmExtension::FEAT_SEL2))) {
301  v = testContextMatch(tc, false);
302  }
303  break;
304 
305  case 0xe:
306  if (HaveExt(tc, ArmExtension::FEAT_VHE) && !ELIsInHost(tc, el) &&
307  (!isSecure(tc)|| HaveExt(tc, ArmExtension::FEAT_SEL2))) {
308  v = testContextMatch(tc, true); // CONTEXTIDR_EL1
309  v = v && testContextMatch(tc, false); // CONTEXTIDR_EL2
310  }
311  break;
312  case 0xf:
313  if (HaveExt(tc, ArmExtension::FEAT_VHE) && !ELIsInHost(tc, el) &&
314  from_link &&
315  (!isSecure(tc)|| HaveExt(tc, ArmExtension::FEAT_SEL2))) {
316  v = testContextMatch(tc, true); // CONTEXTIDR_EL1
317  v = v && testContextMatch(tc, false); // CONTEXTIDR_EL2
318  }
319  break;
320  default:
321  break;
322  }
323  return v;
324 }
325 
326 void
328 {
329  CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
330  aarch32 = cpsr.width == 1;
331 
332  const AA64DFR0 dfr = tc->readMiscReg(MISCREG_ID_AA64DFR0_EL1);
333  const AA64MMFR2 mm_fr2 = tc->readMiscReg(MISCREG_ID_AA64MMFR2_EL1);
334  const AA64MMFR1 mm_fr1 = tc->readMiscReg(MISCREG_ID_AA64MMFR1_EL1);
335 
336  for (int i = 0; i <= dfr.brps; i++) {
337  const bool isctxaw = i >= (dfr.brps - dfr.ctx_cmps);
338 
341  this, isctxaw, (bool)mm_fr2.varange,
342  mm_fr1.vmidbits, aarch32);
343  const DBGBCR ctr = tc->readMiscReg(MISCREG_DBGBCR0_EL1 + i);
344 
345  bkp.updateControl(ctr);
346  arBrkPoints.push_back(bkp);
347  }
348 
349  for (int i = 0; i <= dfr.wrps; i++) {
352  this, (bool)mm_fr2.varange, aarch32);
353  const DBGWCR ctr = tc->readMiscReg(MISCREG_DBGWCR0_EL1 + i);
354 
355  wtp.updateControl(ctr);
356  arWatchPoints.push_back(wtp);
357  }
358 
359  RegVal oslar_el1 = tc->readMiscReg(MISCREG_OSLAR_EL1);
360  updateOSLock(oslar_el1);
361  // Initialize preloaded control booleans
362  uint64_t mdscr_el1 = tc->readMiscReg(MISCREG_MDSCR_EL1);
363  setMDSCRvals(mdscr_el1);
364 
365  const uint64_t mdcr_el3 = tc->readMiscReg(MISCREG_MDCR_EL3);
366  setbSDD(mdcr_el3);
367 
368  const HCR hcr = tc->readMiscReg(MISCREG_HCR_EL2);
369  const HDCR mdcr = tc->readMiscRegNoEffect(MISCREG_MDCR_EL2);
370  setenableTDETGE(hcr, mdcr);
371 
372  // Enable Vector Catch Exceptions
373  const DEVID dvid = tc->readMiscReg(MISCREG_DBGDEVID0);
374  vcExcpt = new VectorCatch(dvid.vectorcatch==0x0, this);
375 }
376 
377 bool
379 {
380  Addr pc_tocmp = getAddrfromReg(tc);
381  Addr pc = bits(in_pc, maxAddrSize, 2);
382 
383  bool prs = true;
384  CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
385  bool thumb = cpsr.t;
386 
387  if (thumb) {
388  if (bas == 0xc)
389  prs = bits(in_pc, 1, 0) == 0x2;
390  else if (bas == 0x3)
391  prs = bits(in_pc, 1, 0) == 0x0;
392  }
393  return (pc == pc_tocmp) && prs;
394 }
395 
396 bool
398 {
399  if (bas == 0x0)
400  return true;
401  Addr pc_tocmp = getAddrfromReg(tc);
402  Addr pc = bits(in_pc, maxAddrSize, 2);
403  bool prs = false;
404  CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
405  bool thumb = cpsr.t;
406 
407  if (thumb) {
408  if (bas == 0xc)
409  prs = bits(in_pc, 1, 0) == 0x2;
410  else if (bas == 0x3)
411  prs = bits(in_pc, 1, 0) == 0x0;
412  }
413  return (pc != pc_tocmp) && !prs;
414 }
415 
416 bool
418 {
419  return testContextMatch(tc, ctx1, ctx1);
420 }
421 
422 bool
423 BrkPoint::testContextMatch(ThreadContext *tc, bool ctx1, bool low_ctx)
424 {
425  if (!isCntxtAware)
426  return false;
427  MiscRegIndex miscridx;
428  ExceptionLevel el = currEL(tc);
429  bool a32 = conf->isAArch32();
430 
431  if (ctx1) {
432  miscridx = a32? MISCREG_CONTEXTIDR : MISCREG_CONTEXTIDR_EL1;
433  if ((el == EL3 && !a32) || el == EL2)
434  return false;
435  } else {
436  miscridx = MISCREG_CONTEXTIDR_EL2;
437  if (el == EL2 && a32)
438  return false;
439  }
440 
441  RegVal ctxid = bits(tc->readMiscReg(miscridx), 31, 0);
442  RegVal v = getContextfromReg(tc, low_ctx);
443  return (v == ctxid);
444 }
445 
446 bool
448 {
449  const bool vs = ((VTCR_t)(tc->readMiscReg(MISCREG_VTCR_EL2))).vs;
450 
451  uint32_t vmid_index = 55;
452  if (VMID16enabled && vs)
453  vmid_index = 63;
454  ExceptionLevel el = currEL(tc);
455  if (el == EL2)
456  return false;
457 
458  vmid_t vmid = bits(tc->readMiscReg(MISCREG_VTTBR_EL2), vmid_index, 48);
459  vmid_t v = getVMIDfromReg(tc, vs);
460 
461  return (v == vmid);
462 }
463 
464 
465 bool
467  uint8_t hmc, uint8_t ssc, uint8_t pmc)
468 {
469  bool v;
470  bool aarch32 = conf->isAArch32();
471  bool no_el2 = !ArmSystem::haveEL(tc, EL2);
472  bool no_el3 = !ArmSystem::haveEL(tc, EL3);
473 
474  if (no_el3 && !no_el2 && (ssc == 0x1 || ssc == 0x2) &&
475  !(hmc && ssc == 0x1 && pmc == 0x0)) {
476  return false;
477  } else if (no_el3 && no_el2 && (hmc != 0x0 || ssc != 0x0) &&
478  !(!aarch32 && ((hmc && ssc == 0x1 && pmc == 0x0) || ssc == 0x3))) {
479  return false;
480  } else if (no_el2 && hmc && ssc == 0x3 && pmc == 0x0) {
481  return false;
482  } else if (ssc == 0x11 && pmc == 0x1 &&
483  !(!aarch32 && hmc && ssc == 0x3 && pmc == 0x0)) {
484  // AND secureEL2 not implemented
485  return false;
486  } else if (hmc && ssc == 0x1 && pmc == 0x0) {
487  //AND secureEL2 not implemented
488  return false;
489  }
490  switch (el) {
491  case EL0:
492  v = (pmc == 0x3) || (pmc == 0x2 && hmc == 0x0);
493  if (aarch32)
494  v = v || (pmc == 0x0 && ssc != 0x3 && hmc == 0x0);
495  if (v && ssc == 0x3)
496  panic("Unexpected EL in SelfDebug::isDebugEnabled.\n");
497  break;
498  case EL1:
499  v = (pmc == 0x3) || (pmc == 0x1);
500  if (aarch32)
501  v = v || (pmc == 0x0 && hmc == 0x0 && ssc !=0x3);
502  break;
503  case EL2:
504  v = (ssc == 0x3) ||
505  ((hmc == 0x1) && !((ssc == 0x2) && (pmc == 0x0)));
506  if (v && pmc == 0x2)
507  panic("Unexpected EL in SelfDebug::isDebugEnabled.\n");
508  break;
509  case EL3:
510  if (ssc == 0x1)
511  panic("Unexpected EL in SelfDebug::isDebugEnabled.\n");
512  v = (hmc == 0x1) & (ssc != 0x3);
513  break;
514  default:
515  panic("Unexpected EL %d in BrkPoint::isEnabled.\n", el);
516  }
517  return v && SelfDebug::securityStateMatch(tc, ssc, hmc || !aarch32);
518 }
519 
520 vmid_t
522 {
523  uint32_t vmid_index = 39;
524  if (VMID16enabled && vs)
525  vmid_index = 47;
526  return bits(tc->readMiscReg(valRegIndex), vmid_index, 32);
527 }
528 
529 
530 bool
532  bool hmc, uint8_t ssc, uint8_t pac)
533 {
534 
535  bool v;
536  bool aarch32 = conf->isAArch32();
537  bool no_el2 = !ArmSystem::haveEL(tc, EL2);
538  bool no_el3 = !ArmSystem::haveEL(tc, EL3);
539 
540  if (aarch32) {
541  // WatchPoint PL2 using aarch32 is disabled except for
542  // debug state. Check G2-5395 table G2-15.
543  if (el == EL2)
544  return false;
545  if (no_el3) {
546  if (ssc == 0x01 || ssc == 0x02 ){
547  return false;
548  } else if (no_el2 &&
549  ((!hmc && ssc == 0x3) || (hmc && ssc == 0x0))) {
550  return false;
551  }
552  }
553  if (no_el2 && hmc && ssc == 0x03 && pac == 0)
554  return false;
555  }
556  switch (el) {
557  case EL0:
558  v = (pac == 0x3 || (pac == 0x2 && !hmc && ssc != 0x3));
559  break;
560  case EL1:
561  v = (pac == 0x1 || pac == 0x3);
562  break;
563  case EL2:
564  v = (hmc && (ssc != 0x2 || pac != 0x0));
565  break;
566  case EL3:
567  v = (hmc && (ssc == 0x2 ||
568  (ssc == 0x1 && (pac == 0x1 || pac == 0x3))));
569  break;
570  default:
571  panic("Unexpected EL in WatchPoint::isEnabled.\n");
572  }
573  return v && SelfDebug::securityStateMatch(tc, ssc, hmc);
574 }
575 
576 bool
578  bool atomic, unsigned size)
579 {
580 
581  bool v = false;
582  const DBGWCR ctr = tc->readMiscReg(ctrlRegIndex);
583  if (isEnabled(tc, el, ctr.hmc, ctr.ssc, ctr.pac) &&
584  ((wrt && (ctr.lsv & 0x2)) || (!wrt && (ctr.lsv & 0x1)) || atomic)) {
585  v = compareAddress(tc, addr, ctr.bas, ctr.mask, size);
586  if (ctr.wt) {
587  v = v && (conf->getBrkPoint(ctr.lbn))->testLinkedBk(tc, addr, el);
588  }
589  }
590  if (atomic && (ctr.lsv & 0x1)) {
591  wrt = false;
592  }
593  return v;
594 }
595 
596 bool
598  uint8_t mask, unsigned size)
599 {
600  Addr addr_tocmp = getAddrfromReg(tc);
601  int maxbits = isDoubleAligned(addr_tocmp) ? 4: 8;
602  int bottom = isDoubleAligned(addr_tocmp) ? 2: 3;
603  Addr addr = bits(in_addr, maxAddrSize, 0);
604 
605  if (bas == 0x0)
606  return false;
607 
608  if (mask == 0x0) {
609  for (int i = 0; i < maxbits; i++) {
610  uint8_t bas_m = 0x1 << i;
611  uint8_t masked_bas = bas & bas_m;
612  if (masked_bas == bas_m) {
613  uint8_t off = log2(masked_bas);
614  Addr cmpaddr = addr_tocmp | off;
615  for (int j = 0; j < size; j++) {
616  if ((addr + j) == cmpaddr) {
617  return true;
618  }
619  }
620  }
621  }
622  return false;
623  } else {
624  bool v = false;
625  for (int j = 0; j < size; j++) {
626  Addr compaddr;
627  if (mask > bottom) {
628  addr = bits((in_addr+j), maxAddrSize, mask);
629  compaddr = bits(addr_tocmp, maxAddrSize, mask);
630  } else {
631  addr = bits((in_addr+j), maxAddrSize, bottom);
632  compaddr = bits(addr_tocmp, maxAddrSize, bottom);
633  }
634  v = v || (addr == compaddr);
635  }
636  return v;
637  }
638 }
639 
640 bool
642  ExceptionLevel dest)
643 {
644  bool SS_bit = false;
645  bool enabled_src = false;
646  if (bSS) {
647  enabled_src = conf->isDebugEnabled(tc);
648 
649  bool enabled_dst = false;
650  bool secure = isSecureBelowEL3(tc) || dest == EL3;
651  if (spsr.width) {
652  enabled_dst = conf->isDebugEnabledForEL32(tc, dest, secure,
653  spsr.d == 1);
654  } else {
655  enabled_dst = conf->isDebugEnabledForEL64(tc, dest, secure,
656  spsr.d == 1);
657  }
658  ExceptionLevel ELd = debugTargetFrom(tc, secure);
659 
660  if (!ELIs32(tc, ELd) && !enabled_src && enabled_dst) {
661  SS_bit = spsr.ss;
662  if (SS_bit == 0x0) {
664  } else {
666  }
667  }
668  }
669  return SS_bit;
670 }
671 
672 bool
674 {
675  PCState pc = tc->pcState().as<PCState>();
676  bool res = false;
677  switch (stateSS) {
678  case INACTIVE_STATE:
679  pc.debugStep(false);
680  break;
681 
683  pc.debugStep(false);
684  if (cpsrD == 1 || !bSS) {
686  } else {
687  pc.stepped(true);
689  tc->pcState(pc);
690  }
691  break;
692 
694  if (!cpsrD && bSS) {
695  pc.debugStep(true);
696  res = true;
697  tc->pcState(pc);
698  }
700  clearLdx();
701  break;
702 
703  default:
704  break;
705  }
706  return res;
707 }
708 
709 Fault
711  ArmFault *fault)
712 {
713 
714  setAArch32(tc);
715  to32 = targetAArch32(tc);
716  if (!isDebugEnabled(tc) || !mde || !aarch32)
717  return NoFault;
718 
720  bool do_debug;
721  if (fault == nullptr)
722  do_debug = vcExcpt->addressMatching(tc, addr, el);
723  else
724  do_debug = vcExcpt->exceptionTrapping(tc, el, fault);
725  if (do_debug) {
726  if (enableTdeTge) {
727  return std::make_shared<HypervisorTrap>(0, 0x22,
729  } else {
730  return std::make_shared<PrefetchAbort>(addr,
731  ArmFault::DebugEvent, false,
734  }
735  }
736 
737  return NoFault;
738 }
739 
740 bool
742 {
743  // Each bit position in this string corresponds to a bit in DBGVCR
744  // and an exception vector.
745  bool enabled;
746  if (conf->isAArch32() && ELIs32(tc, EL1) &&
747  (addr & 0x3) == 0 && el != EL2 ) {
748 
749  DBGVCR match_word = 0x0;
750 
751  Addr vbase = getVectorBase(tc, false);
752  Addr vaddress = addr & ~ 0x1f;
753  Addr low_addr = bits(addr, 5, 2);
754  if (vaddress == vbase) {
755  if (ArmSystem::haveEL(tc, EL3) && !isSecure(tc)) {
756  uint32_t bmask = 1UL << (low_addr + 24);
757  match_word = match_word | (DBGVCR) bmask;
758  // Non-secure vectors
759  } else {
760  uint32_t bmask = 1UL << (low_addr);
761  match_word = match_word | (DBGVCR) bmask;
762  // Secure vectors (or no EL3)
763  }
764  }
765  uint32_t mvbase = getVectorBase(tc, true);
766  if (ArmSystem::haveEL(tc, EL3) && ELIs32(tc, EL3) &&
767  isSecure(tc) && (vaddress == mvbase)) {
768  uint32_t bmask = 1UL << (low_addr + 8);
769  match_word = match_word | (DBGVCR) bmask;
770  // Monitor vectors
771  }
772 
773  DBGVCR mask;
774 
775  // Mask out bits not corresponding to vectors.
776  if (!ArmSystem::haveEL(tc, EL3)) {
777  mask = (DBGVCR) 0xDE;
778  } else if (!ELIs32(tc, EL3)) {
779  mask = (DBGVCR) 0xDE0000DE;
780  } else {
781  mask = (DBGVCR) 0xDE00DEDE;
782  }
783  DBGVCR dbgvcr = tc->readMiscReg(MISCREG_DBGVCR);
784  match_word = match_word & dbgvcr & mask;
785  enabled = match_word != 0x0;
786  // Check for UNPREDICTABLE case - match on Prefetch Abort and
787  // Data Abort vectors
788  ExceptionLevel ELd = debugTargetFrom(tc, isSecure(tc));
789  if (((match_word & 0x18001818) != 0x0) && ELd == el) {
790  enabled = false;
791  }
792  } else {
793  enabled = false;
794  }
795  return enabled;
796 }
797 
798 bool
800  ArmFault* fault)
801 {
802  if (conf->isAArch32() && ELIs32(tc, EL1) && el != EL2) {
803 
804  DBGVCR dbgvcr = tc->readMiscReg(MISCREG_DBGVCR);
805  DBGVCR match_type = fault->vectorCatchFlag();
806  DBGVCR mask;
807 
808  if (!ArmSystem::haveEL(tc, EL3)) {
809  mask = (DBGVCR) 0xDE;
810  } else if (ELIs32(tc, EL3) && fault->getToMode() == MODE_MON) {
811  mask = (DBGVCR) 0x0000DE00;
812  } else {
813  if (isSecure(tc))
814  mask = (DBGVCR) 0x000000DE;
815  else
816  mask = (DBGVCR) 0xDE000000;
817  }
818  match_type = match_type & mask & dbgvcr;
819 
820  if (match_type != 0x0) {
821  return true;
822  }
823  }
824  return false;
825 }
826 
827 } // namespace gem5
virtual uint32_t vectorCatchFlag() const
Definition: faults.hh:254
OperatingMode getToMode() const
Definition: faults.hh:259
void updateControl(DBGBCR val)
Definition: self_debug.hh:141
bool test(ThreadContext *tc, Addr pc, ExceptionLevel el, DBGBCR ctr, bool from_link)
Definition: self_debug.cc:215
bool testLinkedBk(ThreadContext *tc, Addr vaddr, ExceptionLevel el)
Definition: self_debug.cc:208
const DBGBCR getControlReg(ThreadContext *tc)
Definition: self_debug.hh:120
bool isEnabled(ThreadContext *tc, ExceptionLevel el, uint8_t hmc, uint8_t ssc, uint8_t pmc)
Definition: self_debug.cc:466
vmid_t getVMIDfromReg(ThreadContext *tc, bool vs)
Definition: self_debug.cc:521
MiscRegIndex valRegIndex
Definition: self_debug.hh:65
bool testContextMatch(ThreadContext *tc, bool ctx1, bool low_ctx)
Definition: self_debug.cc:423
bool testAddrMissMatch(ThreadContext *tc, Addr pc, uint8_t bas)
Definition: self_debug.cc:397
bool testVMIDMatch(ThreadContext *tc)
Definition: self_debug.cc:447
RegVal getContextfromReg(ThreadContext *tc, bool ctxid1) const
Definition: self_debug.hh:101
bool testAddrMatch(ThreadContext *tc, Addr pc, uint8_t bas)
Definition: self_debug.cc:378
Addr getAddrfromReg(ThreadContext *tc) const
Definition: self_debug.hh:95
Fault triggerException(ThreadContext *tc, Addr vaddr)
Definition: self_debug.cc:110
bool targetAArch32(ThreadContext *tc)
Definition: self_debug.hh:455
void setenableTDETGE(HCR hcr, HDCR mdcr)
Definition: self_debug.hh:396
Fault triggerWatchpointException(ThreadContext *tc, Addr vaddr, bool write, bool cm)
Definition: self_debug.cc:145
static bool securityStateMatch(ThreadContext *tc, uint8_t ssc, bool hmc)
Definition: self_debug.hh:332
void init(ThreadContext *tc)
Definition: self_debug.cc:327
void updateOSLock(RegVal val)
Definition: self_debug.hh:402
BrkPoint * getBrkPoint(uint8_t index)
Definition: self_debug.hh:326
void setMDSCRvals(RegVal val)
Definition: self_debug.hh:382
Fault testBreakPoints(ThreadContext *tc, Addr vaddr)
Definition: self_debug.cc:76
Fault testDebug(ThreadContext *tc, const RequestPtr &req, BaseMMU::Mode mode)
Definition: self_debug.cc:51
void setbSDD(RegVal val)
Definition: self_debug.hh:376
bool isDebugEnabled(ThreadContext *tc)
Definition: self_debug.hh:362
std::vector< BrkPoint > arBrkPoints
Definition: self_debug.hh:280
bool isAArch32() const
Definition: self_debug.hh:426
VectorCatch * vcExcpt
Definition: self_debug.hh:283
SoftwareStep * softStep
Definition: self_debug.hh:282
void setAArch32(ThreadContext *tc)
Definition: self_debug.hh:432
Fault testVectorCatch(ThreadContext *tc, Addr addr, ArmFault *flt)
Definition: self_debug.cc:710
bool isDebugEnabledForEL64(ThreadContext *tc, ExceptionLevel el, bool secure, bool mask)
Definition: self_debug.cc:161
Fault testWatchPoints(ThreadContext *tc, Addr vaddr, bool write, bool atomic, unsigned size, bool cm)
Definition: self_debug.cc:123
bool isDebugEnabledForEL32(ThreadContext *tc, ExceptionLevel el, bool secure, bool mask)
Definition: self_debug.cc:181
std::vector< WatchPoint > arWatchPoints
Definition: self_debug.hh:281
bool advanceSS(ThreadContext *tc)
Definition: self_debug.cc:673
bool debugExceptionReturnSS(ThreadContext *tc, CPSR spsr, ExceptionLevel dest)
Definition: self_debug.cc:641
static const uint8_t ACTIVE_NOT_PENDING_STATE
Definition: self_debug.hh:200
static const uint8_t INACTIVE_STATE
Definition: self_debug.hh:198
static const uint8_t ACTIVE_PENDING_STATE
Definition: self_debug.hh:199
bool exceptionTrapping(ThreadContext *tc, ExceptionLevel el, ArmFault *fault)
Definition: self_debug.cc:799
Addr getVectorBase(ThreadContext *tc, bool monitor)
Definition: self_debug.hh:261
bool addressMatching(ThreadContext *tc, Addr addr, ExceptionLevel el)
Definition: self_debug.cc:741
void updateControl(DBGWCR val)
Definition: self_debug.hh:184
MiscRegIndex ctrlRegIndex
Definition: self_debug.hh:150
bool compareAddress(ThreadContext *tc, Addr in_addr, uint8_t bas, uint8_t mask, unsigned size)
Definition: self_debug.cc:597
bool isEnabled(ThreadContext *tc, ExceptionLevel el, bool hmc, uint8_t ssc, uint8_t pac)
Definition: self_debug.cc:531
Addr getAddrfromReg(ThreadContext *tc)
Definition: self_debug.hh:172
bool isDoubleAligned(Addr addr)
Definition: self_debug.hh:178
bool test(ThreadContext *tc, Addr addr, ExceptionLevel el, bool &wrt, bool atomic, unsigned size)
Definition: self_debug.cc:577
static bool haveEL(ThreadContext *tc, ArmISA::ExceptionLevel el)
Return true if the system implements a specific exception level.
Definition: system.cc:131
@ Execute
Definition: mmu.hh:56
Target & as()
Definition: pcstate.hh:72
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal readMiscReg(RegIndex misc_reg)=0
virtual const PCStateBase & pcState() const =0
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 23, 20 > atomic
Definition: misc_types.hh:100
bool ELIs32(ThreadContext *tc, ExceptionLevel el)
Definition: utility.cc:275
Bitfield< 28 > v
Definition: misc_types.hh:54
Bitfield< 15, 14 > ssc
Definition: misc_types.hh:765
Bitfield< 13 > hmc
Definition: misc_types.hh:766
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:283
Bitfield< 3, 0 > mask
Definition: pcstate.hh:63
ExceptionLevel debugTargetFrom(ThreadContext *tc, bool secure)
Definition: utility.cc:93
Bitfield< 4, 0 > mode
Definition: misc_types.hh:74
ExceptionLevel currEL(const ThreadContext *tc)
Returns the current Exception Level (EL) of the provided ThreadContext.
Definition: utility.cc:124
bool isSecure(ThreadContext *tc)
Definition: utility.cc:74
Bitfield< 7 > i
Definition: misc_types.hh:67
bool ELStateUsingAArch32(ThreadContext *tc, ExceptionLevel el, bool secure)
Definition: utility.cc:367
Bitfield< 36 > thumb
Definition: types.hh:79
bool isSecureBelowEL3(ThreadContext *tc)
Definition: utility.cc:86
Bitfield< 2, 1 > pmc
Definition: misc_types.hh:770
bool EL2Enabled(ThreadContext *tc)
Definition: utility.cc:260
MiscRegIndex
Definition: misc.hh:64
@ MISCREG_SDER
Definition: misc.hh:249
@ MISCREG_DBGDEVID0
Definition: misc.hh:202
@ MISCREG_CONTEXTIDR_EL1
Definition: misc.hh:750
@ MISCREG_ID_AA64DFR0_EL1
Definition: misc.hh:568
@ MISCREG_OSLAR_EL1
Definition: misc.hh:533
@ MISCREG_DBGWVR0_EL1
Definition: misc.hh:495
@ MISCREG_DBGBCR0_EL1
Definition: misc.hh:479
@ MISCREG_ID_AA64MMFR1_EL1
Definition: misc.hh:575
@ MISCREG_DBGBVR0_EL1
Definition: misc.hh:463
@ MISCREG_CPSR
Definition: misc.hh:65
@ MISCREG_CONTEXTIDR
Definition: misc.hh:404
@ MISCREG_CONTEXTIDR_EL2
Definition: misc.hh:822
@ MISCREG_MDSCR_EL1
Definition: misc.hh:460
@ MISCREG_HCR_EL2
Definition: misc.hh:591
@ MISCREG_ID_AA64MMFR2_EL1
Definition: misc.hh:827
@ MISCREG_VTCR_EL2
Definition: misc.hh:611
@ MISCREG_DBGVCR
Definition: misc.hh:106
@ MISCREG_MDCR_EL2
Definition: misc.hh:592
@ MISCREG_DBGWCR0_EL1
Definition: misc.hh:511
@ MISCREG_VTTBR_EL2
Definition: misc.hh:610
@ MISCREG_MDCR_EL3
Definition: misc.hh:601
Bitfield< 12 > md
Definition: misc_types.hh:826
Bitfield< 3, 2 > el
Definition: misc_types.hh:73
uint16_t vmid_t
Definition: types.hh:57
Bitfield< 13 > cm
Definition: misc_types.hh:435
Bitfield< 2, 1 > pac
Definition: misc_types.hh:784
bool HaveExt(ThreadContext *tc, ArmExtension ext)
Returns true if the provided ThreadContext supports the ArmExtension passed as a second argument.
Definition: utility.cc:224
Bitfield< 19 > vs
Definition: misc_types.hh:576
Bitfield< 9 > d
Definition: misc_types.hh:64
Bitfield< 8, 5 > bas
Definition: misc_types.hh:768
Bitfield< 24 > j
Definition: misc_types.hh:57
Bitfield< 4 > pc
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 3 > addr
Definition: types.hh:84
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition: types.hh:248
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint64_t RegVal
Definition: types.hh:173
constexpr decltype(nullptr) NoFault
Definition: types.hh:253

Generated on Wed Dec 21 2022 10:22:27 for gem5 by doxygen 1.9.1