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