pc_event.cc (9649:c717bd5e0a1d) pc_event.cc (11793:ef606668d247)
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 * Authors: Nathan Binkert
29 * Steve Reinhardt
30 */
31
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 * Authors: Nathan Binkert
29 * Steve Reinhardt
30 */
31
32#include "cpu/pc_event.hh"
33
32#include <algorithm>
33#include <string>
34#include <utility>
35
36#include "base/debug.hh"
37#include "base/trace.hh"
38#include "cpu/base.hh"
34#include <algorithm>
35#include <string>
36#include <utility>
37
38#include "base/debug.hh"
39#include "base/trace.hh"
40#include "cpu/base.hh"
39#include "cpu/pc_event.hh"
40#include "cpu/thread_context.hh"
41#include "debug/PCEvent.hh"
42#include "sim/core.hh"
43#include "sim/system.hh"
44
45using namespace std;
46
47PCEventQueue::PCEventQueue()
48{}
49
50PCEventQueue::~PCEventQueue()
51{}
52
53bool
54PCEventQueue::remove(PCEvent *event)
55{
56 int removed = 0;
57 range_t range = equal_range(event);
58 iterator i = range.first;
59 while (i != range.second &&
60 i != pc_map.end()) {
61 if (*i == event) {
62 DPRINTF(PCEvent, "PC based event removed at %#x: %s\n",
63 event->pc(), event->descr());
64 i = pc_map.erase(i);
65 ++removed;
66 } else {
67 i++;
68 }
69
70 }
71
72 return removed > 0;
73}
74
75bool
76PCEventQueue::schedule(PCEvent *event)
77{
78 pc_map.push_back(event);
79 sort(pc_map.begin(), pc_map.end(), MapCompare());
80
81 DPRINTF(PCEvent, "PC based event scheduled for %#x: %s\n",
82 event->pc(), event->descr());
83
84 return true;
85}
86
87bool
88PCEventQueue::doService(ThreadContext *tc)
89{
90 // This will fail to break on Alpha PALcode addresses, but that is
91 // a rare use case.
92 Addr pc = tc->instAddr();
93 int serviced = 0;
94 range_t range = equal_range(pc);
95 for (iterator i = range.first; i != range.second; ++i) {
96 // Make sure that the pc wasn't changed as the side effect of
97 // another event. This for example, prevents two invocations
98 // of the SkipFuncEvent. Maybe we should have separate PC
99 // event queues for each processor?
100 if (pc != tc->instAddr())
101 continue;
102
103 DPRINTF(PCEvent, "PC based event serviced at %#x: %s\n",
104 (*i)->pc(), (*i)->descr());
105
106 (*i)->process(tc);
107 ++serviced;
108 }
109
110 return serviced > 0;
111}
112
113void
114PCEventQueue::dump() const
115{
116 const_iterator i = pc_map.begin();
117 const_iterator e = pc_map.end();
118
119 for (; i != e; ++i)
120 cprintf("%d: event at %#x: %s\n", curTick(), (*i)->pc(),
121 (*i)->descr());
122}
123
124PCEventQueue::range_t
125PCEventQueue::equal_range(Addr pc)
126{
127 return std::equal_range(pc_map.begin(), pc_map.end(), pc, MapCompare());
128}
129
130BreakPCEvent::BreakPCEvent(PCEventQueue *q, const std::string &desc, Addr addr,
131 bool del)
132 : PCEvent(q, desc, addr), remove(del)
133{
134}
135
136void
137BreakPCEvent::process(ThreadContext *tc)
138{
139 StringWrap name(tc->getCpuPtr()->name() + ".break_event");
140 DPRINTFN("break event %s triggered\n", descr());
141 Debug::breakpoint();
142 if (remove)
143 delete this;
144}
145
146void
147sched_break_pc_sys(System *sys, Addr addr)
148{
149 new BreakPCEvent(&sys->pcEventQueue, "debug break", addr, true);
150}
151
152void
153sched_break_pc(Addr addr)
154{
155 for (vector<System *>::iterator sysi = System::systemList.begin();
156 sysi != System::systemList.end(); ++sysi) {
157 sched_break_pc_sys(*sysi, addr);
158 }
159
160}
161
162PanicPCEvent::PanicPCEvent(PCEventQueue *q, const std::string &desc, Addr pc)
163 : PCEvent(q, desc, pc)
164{
165}
166
167void
168PanicPCEvent::process(ThreadContext *tc)
169{
170 StringWrap name(tc->getCpuPtr()->name() + ".panic_event");
171 panic(descr());
172}
41#include "cpu/thread_context.hh"
42#include "debug/PCEvent.hh"
43#include "sim/core.hh"
44#include "sim/system.hh"
45
46using namespace std;
47
48PCEventQueue::PCEventQueue()
49{}
50
51PCEventQueue::~PCEventQueue()
52{}
53
54bool
55PCEventQueue::remove(PCEvent *event)
56{
57 int removed = 0;
58 range_t range = equal_range(event);
59 iterator i = range.first;
60 while (i != range.second &&
61 i != pc_map.end()) {
62 if (*i == event) {
63 DPRINTF(PCEvent, "PC based event removed at %#x: %s\n",
64 event->pc(), event->descr());
65 i = pc_map.erase(i);
66 ++removed;
67 } else {
68 i++;
69 }
70
71 }
72
73 return removed > 0;
74}
75
76bool
77PCEventQueue::schedule(PCEvent *event)
78{
79 pc_map.push_back(event);
80 sort(pc_map.begin(), pc_map.end(), MapCompare());
81
82 DPRINTF(PCEvent, "PC based event scheduled for %#x: %s\n",
83 event->pc(), event->descr());
84
85 return true;
86}
87
88bool
89PCEventQueue::doService(ThreadContext *tc)
90{
91 // This will fail to break on Alpha PALcode addresses, but that is
92 // a rare use case.
93 Addr pc = tc->instAddr();
94 int serviced = 0;
95 range_t range = equal_range(pc);
96 for (iterator i = range.first; i != range.second; ++i) {
97 // Make sure that the pc wasn't changed as the side effect of
98 // another event. This for example, prevents two invocations
99 // of the SkipFuncEvent. Maybe we should have separate PC
100 // event queues for each processor?
101 if (pc != tc->instAddr())
102 continue;
103
104 DPRINTF(PCEvent, "PC based event serviced at %#x: %s\n",
105 (*i)->pc(), (*i)->descr());
106
107 (*i)->process(tc);
108 ++serviced;
109 }
110
111 return serviced > 0;
112}
113
114void
115PCEventQueue::dump() const
116{
117 const_iterator i = pc_map.begin();
118 const_iterator e = pc_map.end();
119
120 for (; i != e; ++i)
121 cprintf("%d: event at %#x: %s\n", curTick(), (*i)->pc(),
122 (*i)->descr());
123}
124
125PCEventQueue::range_t
126PCEventQueue::equal_range(Addr pc)
127{
128 return std::equal_range(pc_map.begin(), pc_map.end(), pc, MapCompare());
129}
130
131BreakPCEvent::BreakPCEvent(PCEventQueue *q, const std::string &desc, Addr addr,
132 bool del)
133 : PCEvent(q, desc, addr), remove(del)
134{
135}
136
137void
138BreakPCEvent::process(ThreadContext *tc)
139{
140 StringWrap name(tc->getCpuPtr()->name() + ".break_event");
141 DPRINTFN("break event %s triggered\n", descr());
142 Debug::breakpoint();
143 if (remove)
144 delete this;
145}
146
147void
148sched_break_pc_sys(System *sys, Addr addr)
149{
150 new BreakPCEvent(&sys->pcEventQueue, "debug break", addr, true);
151}
152
153void
154sched_break_pc(Addr addr)
155{
156 for (vector<System *>::iterator sysi = System::systemList.begin();
157 sysi != System::systemList.end(); ++sysi) {
158 sched_break_pc_sys(*sysi, addr);
159 }
160
161}
162
163PanicPCEvent::PanicPCEvent(PCEventQueue *q, const std::string &desc, Addr pc)
164 : PCEvent(q, desc, pc)
165{
166}
167
168void
169PanicPCEvent::process(ThreadContext *tc)
170{
171 StringWrap name(tc->getCpuPtr()->name() + ".panic_event");
172 panic(descr());
173}