pc_event.hh revision 3555:5390475618b1
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#include "sim/host.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__ 145