gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/regs/misc.hh"
44#include "arch/arm/system.hh"
45#include "arch/arm/types.hh"
46#include "arch/arm/utility.hh"
47#include "arch/generic/tlb.hh"
48#include "cpu/thread_context.hh"
49
50namespace gem5
51{
52
53class ThreadContext;
54
55namespace ArmISA
56{
57
58class SelfDebug;
59
61{
62 private:
69 bool enable;
71 bool onUse;
72
73 public:
74 friend class SelfDebug;
75
76 BrkPoint(MiscRegIndex ctrl_index, MiscRegIndex val_index,
77 SelfDebug* _conf, bool ctx_aw, bool lva,
78 bool vmid16, bool aarch32):
79 ctrlRegIndex(ctrl_index), valRegIndex(val_index),
80 conf(_conf), isCntxtAware(ctx_aw),
81 VMID16enabled(vmid16), activePc(0x0), enable(false)
82 {
83 maxAddrSize = lva ? 52: 48 ;
84 maxAddrSize = aarch32 ? 31 : maxAddrSize;
85 onUse = false;
86 }
87
89 bool test(ThreadContext *tc, Addr pc, ExceptionLevel el, DBGBCR ctr,
90 bool from_link);
91
92 protected:
93 inline Addr
95 {
96 return bits(tc->readMiscReg(valRegIndex), maxAddrSize, 2);
97 }
98
99 inline RegVal
100 getContextfromReg(ThreadContext *tc, bool ctxid1) const
101 {
102 if (ctxid1)
103 return bits(tc->readMiscReg(valRegIndex), 31, 0);
104 else
105 return bits(tc->readMiscReg(valRegIndex), 63, 32);
106 }
107
108
110
111 public:
112 bool testAddrMatch(ThreadContext *tc, Addr pc, uint8_t bas);
113 bool testAddrMissMatch(ThreadContext *tc, Addr pc, uint8_t bas);
114 bool testContextMatch(ThreadContext *tc, bool ctx1, bool low_ctx);
115 bool testContextMatch(ThreadContext *tc, bool ctx1);
117
118 const DBGBCR
120 {
121 return tc->readMiscReg(ctrlRegIndex);
122 }
123
125 uint8_t hmc, uint8_t ssc, uint8_t pmc);
126
127 bool
129 {
130 if (vaddr == activePc) {
131 activePc = 0x0;
132 return false;
133 } else {
134 activePc = vaddr;
135 return true;
136 }
137 }
138
139 inline void
141 {
142 enable = val.e == 0x1;
143 }
144};
145
147{
148 private:
152 bool enable;
154
155 public:
156 friend class SelfDebug;
157
158 WatchPoint(MiscRegIndex ctrl_index, MiscRegIndex val_index,
159 SelfDebug* _conf, bool lva, bool aarch32) :
160 ctrlRegIndex(ctrl_index),
161 valRegIndex(val_index), conf(_conf), enable(false)
162 {
163 maxAddrSize = lva ? 52: 48 ;
164 maxAddrSize = aarch32 ? 31 : maxAddrSize;
165 }
166
167 bool compareAddress(ThreadContext *tc, Addr in_addr,
168 uint8_t bas, uint8_t mask, unsigned size);
169
170 inline Addr
172 {
173 return bits(tc->readMiscReg(valRegIndex), maxAddrSize, 0);
174 }
175
176 inline bool
178 {
179 return addr & 0x4;
180 }
181
182 inline void
184 {
185 enable = val.e == 0x1;
186 }
187
189 uint8_t ssc, uint8_t pac);
190 bool test(ThreadContext *tc, Addr addr, ExceptionLevel el, bool& wrt,
191 bool atomic, unsigned size);
192};
193
195{
196 private:
197 static const uint8_t INACTIVE_STATE = 0;
198 static const uint8_t ACTIVE_PENDING_STATE = 1;
199 static const uint8_t ACTIVE_NOT_PENDING_STATE = 2;
200
201 bool bSS;
206 bool cpsrD;
207
208 public:
209 friend class SelfDebug;
210
212 : bSS(false), stateSS(INACTIVE_STATE),
213 conf(s), steppedLdx(false)
214 {}
215
216 bool debugExceptionReturnSS(ThreadContext *tc, CPSR spsr,
217 ExceptionLevel dest);
218 bool advanceSS(ThreadContext *tc);
219
220 void
222 {
224 steppedLdx = true;
225 }
226
227 void
229 {
231 steppedLdx = false;
232 }
233
234 bool
235 getLdx() const
236 {
237 return prevSteppedLdx;
238 }
239};
240
242{
243 private:
247
248 bool enableTdeTge; // MDCR_EL2.TDE || HCR_EL2.TGE
249
250 bool mde; // MDSCR_EL1.MDE, DBGDSCRext.MDBGen
251 bool sdd; // MDCR_EL3.SDD
252 bool kde; // MDSCR_EL1.KDE
253 bool oslk; // OS lock flag
254
255 bool aarch32; // updates with stage1 aarch64/32
256 bool to32;
257
258 public:
260 : softStep(nullptr), enableTdeTge(false),
261 mde(false), sdd(false), kde(false), oslk(false)
262 {
263 softStep = new SoftwareStep(this);
264 }
265
267 {
268 delete softStep;
269 }
270
271 Fault testDebug(ThreadContext *tc, const RequestPtr &req,
273
274 protected:
277 bool atomic, unsigned size, bool cm);
278
281 bool write, bool cm);
282 public:
283 bool enabled() const { return mde || softStep->bSS; };
284
285 inline BrkPoint*
287 {
288 return &arBrkPoints[index];
289 }
290
291 static inline bool
293 {
294 switch (ssc) {
295 case 0x0: return true;
296 case 0x1: return !isSecure(tc);
297 case 0x2: return isSecure(tc);
298 case 0x3:
299 {
300 bool b = hmc? true: isSecure(tc);
301 return b;
302 }
303 default: panic("Unreachable value");
304 }
305 return false;
306 }
307
309 bool secure, bool mask);
311 bool secure, bool mask);
312
313 void
315 {
316 for (auto &p: arBrkPoints){
317 p.onUse = false;
318 }
319 }
320
321 inline bool
323 {
324 CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
326 if (aarch32) {
327 return isDebugEnabledForEL32(tc, el, isSecure(tc),
328 (bool)cpsr.d == 1);
329 } else {
330 return isDebugEnabledForEL64(tc, el, isSecure(tc),
331 (bool)cpsr.d == 1 );
332 }
333 }
334
335 inline void
337 {
338 sdd = bits(val, 16);
339 }
340
341 inline void
343 {
344 mde = bits(val, 15);
345 kde = bits(val, 13);
346 softStep->bSS = bits(val, 0);
347 }
348
349 inline void
351 {
352 mde = bits(val, 15);
353 }
354
355 inline void
356 setenableTDETGE(HCR hcr, HDCR mdcr)
357 {
358 enableTdeTge = (mdcr.tde == 0x1 || hcr.tge == 0x1);
359 }
360
361 inline void
363 {
364 oslk = bool(bits(val, 0));
365 }
366
367 inline void
368 updateDBGBCR(int index, DBGBCR val)
369 {
370 arBrkPoints[index].updateControl(val);
371 }
372
373 inline void
374 updateDBGWCR(int index, DBGWCR val)
375 {
376 arWatchPoints[index].updateControl(val);
377 }
378
379 inline void
381 {
383 }
384
385 inline bool
386 isAArch32() const
387 {
388 return aarch32;
389 }
390
391 inline void
393 {
394 ExceptionLevel from_el = (ExceptionLevel) currEL(tc);
395 if (from_el == EL0)
396 aarch32 = ELIs32(tc, EL0) && ELIs32(tc, EL1);
397 else
398 aarch32 = ELIs32(tc, from_el);
399 return;
400 }
401
404 {
405 return softStep;
406 }
407
408 bool
410 {
412 return ELIs32(tc, ELd) && aarch32;
413 }
414
415 void init(ThreadContext *tc);
416};
417
418} // namespace ArmISA
419} // namespace gem5
420
421#endif
void updateControl(DBGBCR val)
bool testLinkedBk(ThreadContext *tc, Addr vaddr, ExceptionLevel el)
const DBGBCR getControlReg(ThreadContext *tc)
bool isEnabled(ThreadContext *tc, ExceptionLevel el, uint8_t hmc, uint8_t ssc, uint8_t pmc)
MiscRegIndex ctrlRegIndex
Definition self_debug.hh:63
vmid_t getVMIDfromReg(ThreadContext *tc, bool vs)
MiscRegIndex valRegIndex
Definition self_debug.hh:64
bool isActive(Addr vaddr)
BrkPoint(MiscRegIndex ctrl_index, MiscRegIndex val_index, SelfDebug *_conf, bool ctx_aw, bool lva, bool vmid16, bool aarch32)
Definition self_debug.hh:76
bool testContextMatch(ThreadContext *tc, bool ctx1, bool low_ctx)
bool testAddrMissMatch(ThreadContext *tc, Addr pc, uint8_t bas)
bool testVMIDMatch(ThreadContext *tc)
RegVal getContextfromReg(ThreadContext *tc, bool ctxid1) const
bool testAddrMatch(ThreadContext *tc, Addr pc, uint8_t bas)
Addr getAddrfromReg(ThreadContext *tc) const
Definition self_debug.hh:94
Fault triggerException(ThreadContext *tc, Addr vaddr)
bool targetAArch32(ThreadContext *tc)
void setenableTDETGE(HCR hcr, HDCR mdcr)
Fault triggerWatchpointException(ThreadContext *tc, Addr vaddr, bool write, bool cm)
BrkPoint * getBrkPoint(uint8_t index)
static bool securityStateMatch(ThreadContext *tc, uint8_t ssc, bool hmc)
void updateOSLock(RegVal val)
void setMDSCRvals(RegVal val)
void updateDBGBCR(int index, DBGBCR val)
Fault testBreakPoints(ThreadContext *tc, Addr vaddr)
Definition self_debug.cc:74
Fault testDebug(ThreadContext *tc, const RequestPtr &req, BaseMMU::Mode mode)
Definition self_debug.cc:51
void setbSDD(RegVal val)
bool isDebugEnabled(ThreadContext *tc)
std::vector< BrkPoint > arBrkPoints
void updateDBGWCR(int index, DBGWCR val)
void setMDBGen(RegVal val)
void setDebugMask(bool mask)
SoftwareStep * softStep
SoftwareStep * getSstep()
void setAArch32(ThreadContext *tc)
bool isDebugEnabledForEL64(ThreadContext *tc, ExceptionLevel el, bool secure, bool mask)
Fault testWatchPoints(ThreadContext *tc, Addr vaddr, bool write, bool atomic, unsigned size, bool cm)
bool isDebugEnabledForEL32(ThreadContext *tc, ExceptionLevel el, bool secure, bool mask)
std::vector< WatchPoint > arWatchPoints
bool advanceSS(ThreadContext *tc)
bool debugExceptionReturnSS(ThreadContext *tc, CPSR spsr, ExceptionLevel dest)
static const uint8_t ACTIVE_NOT_PENDING_STATE
static const uint8_t INACTIVE_STATE
static const uint8_t ACTIVE_PENDING_STATE
void updateControl(DBGWCR val)
bool compareAddress(ThreadContext *tc, Addr in_addr, uint8_t bas, uint8_t mask, unsigned size)
bool isEnabled(ThreadContext *tc, ExceptionLevel el, bool hmc, uint8_t ssc, uint8_t pac)
Addr getAddrfromReg(ThreadContext *tc)
bool isDoubleAligned(Addr addr)
WatchPoint(MiscRegIndex ctrl_index, MiscRegIndex val_index, SelfDebug *_conf, bool lva, bool aarch32)
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:79
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 23, 20 > atomic
bool ELIs32(ThreadContext *tc, ExceptionLevel el)
Definition utility.cc:283
Bitfield< 15, 14 > ssc
Bitfield< 13 > hmc
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
ExceptionLevel debugTargetFrom(ThreadContext *tc, bool secure)
Definition utility.cc:103
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:134
bool isSecure(ThreadContext *tc)
Definition utility.cc:74
Bitfield< 4 > s
Bitfield< 7 > b
Bitfield< 2, 1 > pmc
@ MISCREG_CPSR
Definition misc.hh:79
Bitfield< 3, 2 > el
Definition misc_types.hh:73
uint16_t vmid_t
Definition types.hh:57
Bitfield< 13 > cm
Bitfield< 2, 1 > pac
Bitfield< 19 > vs
Bitfield< 8, 5 > bas
Bitfield< 4 > pc
Bitfield< 30, 0 > index
Bitfield< 0 > p
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
const FlagsType init
This Stat is Initialized.
Definition info.hh:55
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
Bitfield< 18 > vmid16
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
Definition test.h:38

Generated on Mon Jan 13 2025 04:28:20 for gem5 by doxygen 1.9.8