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#ifndef __PC_EVENT_HH__ 33#define __PC_EVENT_HH__ 34 35#include <vector> 36 37#include "base/misc.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#ifndef __PC_EVENT_HH__ 33#define __PC_EVENT_HH__ 34 35#include <vector> 36 37#include "base/misc.hh"
|
38 39class ThreadContext; 40class PCEventQueue; 41 42class PCEvent 43{ 44 protected: 45 std::string description; 46 PCEventQueue *queue; 47 Addr evpc; 48 49 public: 50 PCEvent(PCEventQueue *q, const std::string &desc, Addr pc); 51 52 virtual ~PCEvent() { if (queue) remove(); } 53 54 // for DPRINTF 55 virtual const std::string name() const { return description; } 56 57 std::string descr() const { return description; } 58 Addr pc() const { return evpc; } 59 60 bool remove(); 61 virtual void process(ThreadContext *tc) = 0; 62}; 63 64class PCEventQueue 65{ 66 protected: 67 typedef PCEvent * record_t; 68 class MapCompare { 69 public: 70 bool operator()(const record_t &l, const record_t &r) const { 71 return l->pc() < r->pc(); 72 } 73 bool operator()(const record_t &l, Addr pc) const { 74 return l->pc() < pc; 75 } 76 bool operator()(Addr pc, const record_t &r) const { 77 return pc < r->pc(); 78 } 79 }; 80 typedef std::vector<record_t> map_t; 81 82 public: 83 typedef map_t::iterator iterator; 84 typedef map_t::const_iterator const_iterator; 85 86 protected: 87 typedef std::pair<iterator, iterator> range_t; 88 typedef std::pair<const_iterator, const_iterator> const_range_t; 89 90 protected: 91 map_t pc_map; 92 93 bool doService(ThreadContext *tc); 94 95 public: 96 PCEventQueue(); 97 ~PCEventQueue(); 98 99 bool remove(PCEvent *event); 100 bool schedule(PCEvent *event); 101 bool service(ThreadContext *tc) 102 { 103 if (pc_map.empty()) 104 return false; 105 106 return doService(tc); 107 } 108 109 range_t equal_range(Addr pc); 110 range_t equal_range(PCEvent *event) { return equal_range(event->pc()); } 111 112 void dump() const; 113}; 114 115 116inline 117PCEvent::PCEvent(PCEventQueue *q, const std::string &desc, Addr pc) 118 : description(desc), queue(q), evpc(pc) 119{ 120 queue->schedule(this); 121} 122 123inline bool 124PCEvent::remove() 125{ 126 if (!queue) 127 panic("cannot remove an uninitialized event;"); 128 129 return queue->remove(this); 130} 131 132class BreakPCEvent : public PCEvent 133{ 134 protected: 135 bool remove; 136 137 public: 138 BreakPCEvent(PCEventQueue *q, const std::string &desc, Addr addr, 139 bool del = false); 140 virtual void process(ThreadContext *tc); 141}; 142 143#endif // __PC_EVENT_HH__
| 39 40class ThreadContext; 41class PCEventQueue; 42 43class PCEvent 44{ 45 protected: 46 std::string description; 47 PCEventQueue *queue; 48 Addr evpc; 49 50 public: 51 PCEvent(PCEventQueue *q, const std::string &desc, Addr pc); 52 53 virtual ~PCEvent() { if (queue) remove(); } 54 55 // for DPRINTF 56 virtual const std::string name() const { return description; } 57 58 std::string descr() const { return description; } 59 Addr pc() const { return evpc; } 60 61 bool remove(); 62 virtual void process(ThreadContext *tc) = 0; 63}; 64 65class PCEventQueue 66{ 67 protected: 68 typedef PCEvent * record_t; 69 class MapCompare { 70 public: 71 bool operator()(const record_t &l, const record_t &r) const { 72 return l->pc() < r->pc(); 73 } 74 bool operator()(const record_t &l, Addr pc) const { 75 return l->pc() < pc; 76 } 77 bool operator()(Addr pc, const record_t &r) const { 78 return pc < r->pc(); 79 } 80 }; 81 typedef std::vector<record_t> map_t; 82 83 public: 84 typedef map_t::iterator iterator; 85 typedef map_t::const_iterator const_iterator; 86 87 protected: 88 typedef std::pair<iterator, iterator> range_t; 89 typedef std::pair<const_iterator, const_iterator> const_range_t; 90 91 protected: 92 map_t pc_map; 93 94 bool doService(ThreadContext *tc); 95 96 public: 97 PCEventQueue(); 98 ~PCEventQueue(); 99 100 bool remove(PCEvent *event); 101 bool schedule(PCEvent *event); 102 bool service(ThreadContext *tc) 103 { 104 if (pc_map.empty()) 105 return false; 106 107 return doService(tc); 108 } 109 110 range_t equal_range(Addr pc); 111 range_t equal_range(PCEvent *event) { return equal_range(event->pc()); } 112 113 void dump() const; 114}; 115 116 117inline 118PCEvent::PCEvent(PCEventQueue *q, const std::string &desc, Addr pc) 119 : description(desc), queue(q), evpc(pc) 120{ 121 queue->schedule(this); 122} 123 124inline bool 125PCEvent::remove() 126{ 127 if (!queue) 128 panic("cannot remove an uninitialized event;"); 129 130 return queue->remove(this); 131} 132 133class BreakPCEvent : public PCEvent 134{ 135 protected: 136 bool remove; 137 138 public: 139 BreakPCEvent(PCEventQueue *q, const std::string &desc, Addr addr, 140 bool del = false); 141 virtual void process(ThreadContext *tc); 142}; 143 144#endif // __PC_EVENT_HH__
|