gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
51namespace gem5
52{
53
54class ThreadContext;
55
56namespace ArmISA
57{
58
59class SelfDebug;
60
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);
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
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;
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:
248
249 bool enableTdeTge; // MDCR_EL2.TDE || HCR_EL2.TGE
250
251 bool mde; // MDSCR_EL1.MDE, DBGDSCRext.MDBGen
252 bool sdd; // MDCR_EL3.SDD
253 bool kde; // MDSCR_EL1.KDE
254 bool oslk; // OS lock flag
255
256 bool aarch32; // updates with stage1 aarch64/32
257 bool to32;
258
259 public:
261 : softStep(nullptr), enableTdeTge(false),
262 mde(false), sdd(false), kde(false), oslk(false)
263 {
264 softStep = new SoftwareStep(this);
265 }
266
268 {
269 delete softStep;
270 }
271
272 Fault testDebug(ThreadContext *tc, const RequestPtr &req,
274
275 protected:
278 bool atomic, unsigned size, bool cm);
279
282 bool write, bool cm);
283 public:
284 bool enabled() const { return mde || softStep->bSS; };
285
286 inline BrkPoint*
288 {
289 return &arBrkPoints[index];
290 }
291
292 static inline bool
294 {
295 switch (ssc) {
296 case 0x0: return true;
297 case 0x1: return !isSecure(tc);
298 case 0x2: return isSecure(tc);
299 case 0x3:
300 {
301 bool b = hmc? true: isSecure(tc);
302 return b;
303 }
304 default: panic("Unreachable value");
305 }
306 return false;
307 }
308
310 bool secure, bool mask);
312 bool secure, bool mask);
313
314 void
316 {
317 for (auto &p: arBrkPoints){
318 p.onUse = false;
319 }
320 }
321
322 inline bool
324 {
325 CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
327 if (aarch32) {
328 return isDebugEnabledForEL32(tc, el, isSecure(tc),
329 (bool)cpsr.d == 1);
330 } else {
331 return isDebugEnabledForEL64(tc, el, isSecure(tc),
332 (bool)cpsr.d == 1 );
333 }
334 }
335
336 inline void
338 {
339 sdd = bits(val, 16);
340 }
341
342 inline void
344 {
345 mde = bits(val, 15);
346 kde = bits(val, 13);
347 softStep->bSS = bits(val, 0);
348 }
349
350 inline void
352 {
353 mde = bits(val, 15);
354 }
355
356 inline void
357 setenableTDETGE(HCR hcr, HDCR mdcr)
358 {
359 enableTdeTge = (mdcr.tde == 0x1 || hcr.tge == 0x1);
360 }
361
362 inline void
364 {
365 oslk = bool(bits(val, 0));
366 }
367
368 inline void
369 updateDBGBCR(int index, DBGBCR val)
370 {
371 arBrkPoints[index].updateControl(val);
372 }
373
374 inline void
375 updateDBGWCR(int index, DBGWCR val)
376 {
377 arWatchPoints[index].updateControl(val);
378 }
379
380 inline void
382 {
384 }
385
386 inline bool
387 isAArch32() const
388 {
389 return aarch32;
390 }
391
392 inline void
394 {
395 ExceptionLevel from_el = (ExceptionLevel) currEL(tc);
396 if (from_el == EL0)
397 aarch32 = ELIs32(tc, EL0) && ELIs32(tc, EL1);
398 else
399 aarch32 = ELIs32(tc, from_el);
400 return;
401 }
402
405 {
406 return softStep;
407 }
408
409 bool
411 {
413 return ELIs32(tc, ELd) && aarch32;
414 }
415
416 void init(ThreadContext *tc);
417};
418
419} // namespace ArmISA
420} // namespace gem5
421
422#endif
void updateControl(DBGBCR val)
bool test(ThreadContext *tc, Addr pc, ExceptionLevel el, DBGBCR ctr, bool from_link)
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:64
vmid_t getVMIDfromReg(ThreadContext *tc, bool vs)
MiscRegIndex valRegIndex
Definition self_debug.hh:65
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:77
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:95
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)
bool test(ThreadContext *tc, Addr addr, ExceptionLevel el, bool &wrt, bool atomic, unsigned size)
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:282
Bitfield< 15, 14 > ssc
Bitfield< 13 > hmc
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
ExceptionLevel debugTargetFrom(ThreadContext *tc, bool secure)
Definition utility.cc:102
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:133
bool isSecure(ThreadContext *tc)
Definition utility.cc:74
Bitfield< 4 > s
Bitfield< 7 > b
Bitfield< 2, 1 > pmc
@ MISCREG_CPSR
Definition misc.hh:67
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 - Pranith Kumar Copyright (c) 2020 Inria 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 RegVal
Definition types.hh:173
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0