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