cpu,sim: Get rid of a bunch of conditional compilation for PCEvents.
[gem5.git] / src / cpu / pc_event.cc
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
34 #include <algorithm>
35 #include <string>
36 #include <utility>
37
38 #include "base/debug.hh"
39 #include "base/trace.hh"
40 #include "debug/PCEvent.hh"
41 #include "sim/core.hh"
42 #include "sim/system.hh"
43
44 using namespace std;
45
46 PCEventQueue::PCEventQueue()
47 {}
48
49 PCEventQueue::~PCEventQueue()
50 {}
51
52 bool
53 PCEventQueue::remove(PCEvent *event)
54 {
55 int removed = 0;
56 range_t range = equal_range(event);
57 iterator i = range.first;
58 while (i != range.second && i != pcMap.end()) {
59 if (*i == event) {
60 DPRINTF(PCEvent, "PC based event removed at %#x: %s\n",
61 event->pc(), event->descr());
62 i = pcMap.erase(i);
63 ++removed;
64 } else {
65 i++;
66 }
67 }
68
69 return removed > 0;
70 }
71
72 bool
73 PCEventQueue::schedule(PCEvent *event)
74 {
75 pcMap.push_back(event);
76 sort(pcMap.begin(), pcMap.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
84 bool
85 PCEventQueue::doService(Addr pc, ThreadContext *tc)
86 {
87 // Using the raw PC address will fail to break on Alpha PALcode addresses,
88 // but that is a rare use case.
89 int serviced = 0;
90 range_t range = equal_range(pc);
91 for (iterator i = range.first; i != range.second; ++i) {
92 DPRINTF(PCEvent, "PC based event serviced at %#x: %s\n",
93 (*i)->pc(), (*i)->descr());
94
95 (*i)->process(tc);
96 ++serviced;
97 }
98
99 return serviced > 0;
100 }
101
102 void
103 PCEventQueue::dump() const
104 {
105 const_iterator i = pcMap.begin();
106 const_iterator e = pcMap.end();
107
108 for (; i != e; ++i)
109 cprintf("%d: event at %#x: %s\n", curTick(), (*i)->pc(),
110 (*i)->descr());
111 }
112
113 PCEventQueue::range_t
114 PCEventQueue::equal_range(Addr pc)
115 {
116 return std::equal_range(pcMap.begin(), pcMap.end(), pc, MapCompare());
117 }
118
119 BreakPCEvent::BreakPCEvent(PCEventScope *s, const std::string &desc, Addr addr,
120 bool del)
121 : PCEvent(s, desc, addr), remove(del)
122 {
123 }
124
125 void
126 BreakPCEvent::process(ThreadContext *tc)
127 {
128 StringWrap name("break_event");
129 DPRINTFN("break event %s triggered\n", descr());
130 Debug::breakpoint();
131 if (remove)
132 delete this;
133 }
134
135 PanicPCEvent::PanicPCEvent(PCEventScope *s, const std::string &desc, Addr pc)
136 : PCEvent(s, desc, pc)
137 {
138 }
139
140 void
141 PanicPCEvent::process(ThreadContext *tc)
142 {
143 StringWrap name("panic_event");
144 panic(descr());
145 }