gem5  v22.1.0.0
self_debug.hh
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 #ifndef __ARCH_ARM_SELF_DEBUG_HH__
40 #define __ARCH_ARM_SELF_DEBUG_HH__
41 
42 
43 #include "arch/arm/faults.hh"
44 #include "arch/arm/regs/misc.hh"
45 #include "arch/arm/system.hh"
46 #include "arch/arm/types.hh"
47 #include "arch/arm/utility.hh"
48 #include "arch/generic/tlb.hh"
49 #include "cpu/thread_context.hh"
50 
51 namespace gem5
52 {
53 
54 class ThreadContext;
55 
56 namespace ArmISA
57 {
58 
59 class SelfDebug;
60 
61 class BrkPoint
62 {
63  private:
70  bool enable;
72  bool onUse;
73 
74  public:
75  friend class SelfDebug;
76 
77  BrkPoint(MiscRegIndex ctrl_index, MiscRegIndex val_index,
78  SelfDebug* _conf, bool ctx_aw, bool lva,
79  bool vmid16, bool aarch32):
80  ctrlRegIndex(ctrl_index), valRegIndex(val_index),
81  conf(_conf), isCntxtAware(ctx_aw),
82  VMID16enabled(vmid16), activePc(0x0), enable(false)
83  {
84  maxAddrSize = lva ? 52: 48 ;
85  maxAddrSize = aarch32 ? 31 : maxAddrSize;
86  onUse = false;
87  }
88 
90  bool test(ThreadContext *tc, Addr pc, ExceptionLevel el, DBGBCR ctr,
91  bool from_link);
92 
93  protected:
94  inline Addr
96  {
97  return bits(tc->readMiscReg(valRegIndex), maxAddrSize, 2);
98  }
99 
100  inline RegVal
101  getContextfromReg(ThreadContext *tc, bool ctxid1) const
102  {
103  if (ctxid1)
104  return bits(tc->readMiscReg(valRegIndex), 31, 0);
105  else
106  return bits(tc->readMiscReg(valRegIndex), 63, 32);
107  }
108 
109 
111 
112  public:
113  bool testAddrMatch(ThreadContext *tc, Addr pc, uint8_t bas);
114  bool testAddrMissMatch(ThreadContext *tc, Addr pc, uint8_t bas);
115  bool testContextMatch(ThreadContext *tc, bool ctx1, bool low_ctx);
116  bool testContextMatch(ThreadContext *tc, bool ctx1);
117  bool testVMIDMatch(ThreadContext *tc);
118 
119  const DBGBCR
121  {
122  return tc->readMiscReg(ctrlRegIndex);
123  }
124 
126  uint8_t hmc, uint8_t ssc, uint8_t pmc);
127 
128  bool
130  {
131  if (vaddr == activePc) {
132  activePc = 0x0;
133  return false;
134  } else {
135  activePc = vaddr;
136  return true;
137  }
138  }
139 
140  inline void
142  {
143  enable = val.e == 0x1;
144  }
145 };
146 
148 {
149  private:
153  bool enable;
155 
156  public:
157  friend class SelfDebug;
158 
159  WatchPoint(MiscRegIndex ctrl_index, MiscRegIndex val_index,
160  SelfDebug* _conf, bool lva, bool aarch32) :
161  ctrlRegIndex(ctrl_index),
162  valRegIndex(val_index), conf(_conf), enable(false)
163  {
164  maxAddrSize = lva ? 52: 48 ;
165  maxAddrSize = aarch32 ? 31 : maxAddrSize;
166  }
167 
168  bool compareAddress(ThreadContext *tc, Addr in_addr,
169  uint8_t bas, uint8_t mask, unsigned size);
170 
171  inline Addr
173  {
174  return bits(tc->readMiscReg(valRegIndex), maxAddrSize, 0);
175  }
176 
177  inline bool
179  {
180  return addr & 0x4;
181  }
182 
183  inline void
185  {
186  enable = val.e == 0x1;
187  }
188 
189  bool isEnabled(ThreadContext* tc, ExceptionLevel el, bool hmc,
190  uint8_t ssc, uint8_t pac);
191  bool test(ThreadContext *tc, Addr addr, ExceptionLevel el, bool& wrt,
192  bool atomic, unsigned size);
193 };
194 
196 {
197  private:
198  static const uint8_t INACTIVE_STATE = 0;
199  static const uint8_t ACTIVE_PENDING_STATE = 1;
200  static const uint8_t ACTIVE_NOT_PENDING_STATE = 2;
201 
202  bool bSS;
203  int stateSS;
207  bool cpsrD;
208 
209  public:
210  friend class SelfDebug;
211 
213  : bSS(false), stateSS(INACTIVE_STATE),
214  conf(s), steppedLdx(false)
215  {}
216 
217  bool debugExceptionReturnSS(ThreadContext *tc, CPSR spsr,
218  ExceptionLevel dest);
219  bool advanceSS(ThreadContext *tc);
220 
221  void
223  {
225  steppedLdx = true;
226  }
227 
228  void
230  {
232  steppedLdx = false;
233  }
234 
235  bool
236  getLdx() const
237  {
238  return prevSteppedLdx;
239  }
240 };
241 
243 {
244  private:
245  bool vcmatch;
248 
249  public:
250  VectorCatch(bool _vcmatch, SelfDebug* s) : vcmatch(_vcmatch), conf(s)
251  {}
252 
255  ArmFault* fault);
256 
257  bool isVCMatch() const { return vcmatch; }
258 
259  private:
260  Addr
261  getVectorBase(ThreadContext *tc, bool monitor)
262  {
263  if (monitor) {
264  return tc->readMiscReg(MISCREG_MVBAR) & ~0x1F;
265  }
266  SCTLR sctlr = tc->readMiscReg(MISCREG_SCTLR_EL1);
267  if (sctlr.v) {
268  return (Addr) 0xFFFF0000;
269  } else {
270  Addr vbar = tc->readMiscReg(MISCREG_VBAR) & ~0x1F;
271  return vbar;
272  }
273  }
274 
275 };
276 
278 {
279  private:
284 
285  bool enableTdeTge; // MDCR_EL2.TDE || HCR_EL2.TGE
286 
287  bool mde; // MDSCR_EL1.MDE, DBGDSCRext.MDBGen
288  bool sdd; // MDCR_EL3.SDD
289  bool kde; // MDSCR_EL1.KDE
290  bool oslk; // OS lock flag
291 
292  bool aarch32; // updates with stage1 aarch64/32
293  bool to32;
294 
295  public:
297  : softStep(nullptr), vcExcpt(nullptr), enableTdeTge(false),
298  mde(false), sdd(false), kde(false), oslk(false)
299  {
300  softStep = new SoftwareStep(this);
301  }
302 
304  {
305  delete softStep;
306  delete vcExcpt;
307  }
308 
309  Fault testDebug(ThreadContext *tc, const RequestPtr &req,
311 
312  protected:
314  Fault testWatchPoints(ThreadContext *tc, Addr vaddr, bool write,
315  bool atomic, unsigned size, bool cm);
316 
319  bool write, bool cm);
320  public:
322 
323  bool enabled() const { return mde || softStep->bSS; };
324 
325  inline BrkPoint*
327  {
328  return &arBrkPoints[index];
329  }
330 
331  static inline bool
333  {
334  switch (ssc) {
335  case 0x0: return true;
336  case 0x1: return !isSecure(tc);
337  case 0x2: return isSecure(tc);
338  case 0x3:
339  {
340  bool b = hmc? true: isSecure(tc);
341  return b;
342  }
343  default: panic("Unreachable value");
344  }
345  return false;
346  }
347 
349  bool secure, bool mask);
351  bool secure, bool mask);
352 
353  void
355  {
356  for (auto &p: arBrkPoints){
357  p.onUse = false;
358  }
359  }
360 
361  inline bool
363  {
364  CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
366  if (aarch32) {
367  return isDebugEnabledForEL32(tc, el, isSecure(tc),
368  (bool)cpsr.d == 1);
369  } else {
370  return isDebugEnabledForEL64(tc, el, isSecure(tc),
371  (bool)cpsr.d == 1 );
372  }
373  }
374 
375  inline void
377  {
378  sdd = bits(val, 16);
379  }
380 
381  inline void
383  {
384  mde = bits(val, 15);
385  kde = bits(val, 13);
386  softStep->bSS = bits(val, 0);
387  }
388 
389  inline void
391  {
392  mde = bits(val, 15);
393  }
394 
395  inline void
396  setenableTDETGE(HCR hcr, HDCR mdcr)
397  {
398  enableTdeTge = (mdcr.tde == 0x1 || hcr.tge == 0x1);
399  }
400 
401  inline void
403  {
404  oslk = bool(bits(val, 0));
405  }
406 
407  inline void
408  updateDBGBCR(int index, DBGBCR val)
409  {
410  arBrkPoints[index].updateControl(val);
411  }
412 
413  inline void
414  updateDBGWCR(int index, DBGWCR val)
415  {
416  arWatchPoints[index].updateControl(val);
417  }
418 
419  inline void
421  {
422  softStep->cpsrD = mask;
423  }
424 
425  inline bool
426  isAArch32() const
427  {
428  return aarch32;
429  }
430 
431  inline void
433  {
434  ExceptionLevel from_el = (ExceptionLevel) currEL(tc);
435  if (from_el == EL0)
436  aarch32 = ELIs32(tc, EL0) && ELIs32(tc, EL1);
437  else
438  aarch32 = ELIs32(tc, from_el);
439  return;
440  }
441 
442  SoftwareStep *
444  {
445  return softStep;
446  }
447 
448  VectorCatch*
450  {
451  return vcExcpt;
452  }
453 
454  bool
456  {
457  ExceptionLevel ELd = debugTargetFrom(tc, isSecure(tc));
458  return ELIs32(tc, ELd) && aarch32;
459  }
460 
461  void init(ThreadContext *tc);
462 };
463 
464 } // namespace ArmISA
465 } // namespace gem5
466 
467 #endif
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
MiscRegIndex ctrlRegIndex
Definition: self_debug.hh:64
vmid_t getVMIDfromReg(ThreadContext *tc, bool vs)
Definition: self_debug.cc:521
MiscRegIndex valRegIndex
Definition: self_debug.hh:65
bool isActive(Addr vaddr)
Definition: self_debug.hh:129
BrkPoint(MiscRegIndex ctrl_index, MiscRegIndex val_index, SelfDebug *_conf, bool ctx_aw, bool lva, bool vmid16, bool aarch32)
Definition: self_debug.hh:77
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
void updateDBGBCR(int index, DBGBCR val)
Definition: self_debug.hh:408
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
VectorCatch * getVectorCatch(ThreadContext *tc)
Definition: self_debug.hh:449
void updateDBGWCR(int index, DBGWCR val)
Definition: self_debug.hh:414
bool isAArch32() const
Definition: self_debug.hh:426
void setMDBGen(RegVal val)
Definition: self_debug.hh:390
void setDebugMask(bool mask)
Definition: self_debug.hh:420
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
SoftwareStep * getSstep()
Definition: self_debug.hh:443
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
SoftwareStep(SelfDebug *s)
Definition: self_debug.hh:212
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
VectorCatch(bool _vcmatch, SelfDebug *s)
Definition: self_debug.hh:250
Addr getVectorBase(ThreadContext *tc, bool monitor)
Definition: self_debug.hh:261
bool addressMatching(ThreadContext *tc, Addr addr, ExceptionLevel el)
Definition: self_debug.cc:741
std::vector< Fault * > vectorTypes()
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
WatchPoint(MiscRegIndex ctrl_index, MiscRegIndex val_index, SelfDebug *_conf, bool lva, bool aarch32)
Definition: self_debug.hh:159
bool test(ThreadContext *tc, Addr addr, ExceptionLevel el, bool &wrt, bool atomic, unsigned size)
Definition: self_debug.cc:577
MiscRegIndex valRegIndex
Definition: self_debug.hh:151
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal readMiscReg(RegIndex misc_reg)=0
STL vector class.
Definition: stl.hh:37
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< 15, 14 > ssc
Definition: misc_types.hh:765
Bitfield< 13 > hmc
Definition: misc_types.hh:766
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< 4 > s
Definition: misc_types.hh:568
Bitfield< 7 > b
Definition: misc_types.hh:388
Bitfield< 2, 1 > pmc
Definition: misc_types.hh:770
MiscRegIndex
Definition: misc.hh:64
@ MISCREG_SCTLR_EL1
Definition: misc.hh:584
@ MISCREG_CPSR
Definition: misc.hh:65
@ MISCREG_VBAR
Definition: misc.hh:396
@ MISCREG_MVBAR
Definition: misc.hh:399
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
Bitfield< 19 > vs
Definition: misc_types.hh:576
Bitfield< 8, 5 > bas
Definition: misc_types.hh:768
Bitfield< 4 > pc
Bitfield< 30, 0 > index
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 63 > val
Definition: misc.hh:776
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

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