gem5 v24.0.0.0
Loading...
Searching...
No Matches
pc_event.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include "cpu/pc_event.hh"
30
31#include <algorithm>
32#include <string>
33#include <utility>
34
35#include "base/debug.hh"
36#include "base/trace.hh"
37#include "debug/PCEvent.hh"
38#include "sim/cur_tick.hh"
39#include "sim/system.hh"
40
41namespace gem5
42{
43
46
49
50bool
52{
53 int removed = 0;
54 range_t range = equal_range(event);
55 iterator i = range.first;
56 while (i != range.second && i != pcMap.end()) {
57 if (*i == event) {
58 DPRINTF(PCEvent, "PC based event removed at %#x: %s\n",
59 event->pc(), event->descr());
60 i = pcMap.erase(i);
61 ++removed;
62 } else {
63 i++;
64 }
65 }
66
67 return removed > 0;
68}
69
70bool
72{
73 pcMap.push_back(event);
74 std::sort(pcMap.begin(), pcMap.end(), MapCompare());
75
76 DPRINTF(PCEvent, "PC based event scheduled for %#x: %s\n",
77 event->pc(), event->descr());
78
79 return true;
80}
81
82bool
84{
85 // Using the raw PC address will fail to break on Alpha PALcode addresses,
86 // but that is a rare use case.
87 int serviced = 0;
88 range_t range = equal_range(pc);
89 for (iterator i = range.first; i != range.second; ++i) {
90 DPRINTF(PCEvent, "PC based event serviced at %#x: %s\n",
91 (*i)->pc(), (*i)->descr());
92
93 (*i)->process(tc);
94 ++serviced;
95 }
96
97 return serviced > 0;
98}
99
100void
102{
103 const_iterator i = pcMap.begin();
104 const_iterator e = pcMap.end();
105
106 for (; i != e; ++i)
107 cprintf("%d: event at %#x: %s\n", curTick(), (*i)->pc(),
108 (*i)->descr());
109}
110
113{
114 return std::equal_range(pcMap.begin(), pcMap.end(), pc, MapCompare());
115}
116
118 bool del)
119 : PCEvent(s, desc, addr), remove(del)
120{
121}
122
123void
125{
126 StringWrap name("break_event");
127 DPRINTFN("break event %s triggered\n", descr());
129 if (remove)
130 delete this;
131}
132
134 : PCEvent(s, desc, pc)
135{
136}
137
138void
140{
141 StringWrap name("panic_event");
142 panic(descr());
143}
144
145} // namespace gem5
#define DPRINTFN(...)
Definition trace.hh:238
#define DPRINTF(x,...)
Definition trace.hh:210
BreakPCEvent(PCEventScope *s, const std::string &desc, Addr addr, bool del=false)
Definition pc_event.cc:117
virtual void process(ThreadContext *tc)
Definition pc_event.cc:124
range_t equal_range(Addr pc)
Definition pc_event.cc:112
Map::iterator iterator
Definition pc_event.hh:99
Map::const_iterator const_iterator
Definition pc_event.hh:100
bool remove(PCEvent *event) override
Definition pc_event.cc:51
void dump() const
Definition pc_event.cc:101
bool doService(Addr pc, ThreadContext *tc)
Definition pc_event.cc:83
bool schedule(PCEvent *event) override
Definition pc_event.cc:71
virtual const std::string name() const
Definition pc_event.hh:58
Addr pc() const
Definition pc_event.hh:61
std::string descr() const
Definition pc_event.hh:60
PanicPCEvent(PCEventScope *s, const std::string &desc, Addr pc)
Definition pc_event.cc:133
virtual void process(ThreadContext *tc)
Definition pc_event.cc:139
ThreadContext is the external interface to all thread state for anything outside of the CPU.
STL pair class.
Definition stl.hh:58
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 4 > s
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 9 > e
Definition misc_types.hh:65
Bitfield< 4 > pc
Bitfield< 10, 5 > event
Bitfield< 3 > addr
Definition types.hh:84
void breakpoint()
Definition debug.cc:64
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
void cprintf(const char *format, const Args &...args)
Definition cprintf.hh:155
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
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:24:02 for gem5 by doxygen 1.11.0