pc_event.hh revision 6214
12SN/A/*
21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
32SN/A * All rights reserved.
42SN/A *
52SN/A * Redistribution and use in source and binary forms, with or without
62SN/A * modification, are permitted provided that the following conditions are
72SN/A * met: redistributions of source code must retain the above copyright
82SN/A * notice, this list of conditions and the following disclaimer;
92SN/A * redistributions in binary form must reproduce the above copyright
102SN/A * notice, this list of conditions and the following disclaimer in the
112SN/A * documentation and/or other materials provided with the distribution;
122SN/A * neither the name of the copyright holders nor the names of its
132SN/A * contributors may be used to endorse or promote products derived from
142SN/A * this software without specific prior written permission.
152SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
292665Ssaidi@eecs.umich.edu *          Steve Reinhardt
302SN/A */
312SN/A
322SN/A#ifndef __PC_EVENT_HH__
332SN/A#define __PC_EVENT_HH__
342SN/A
352SN/A#include <vector>
362SN/A
372439SN/A#include "base/misc.hh"
386214Snate@binkert.org#include "base/types.hh"
392439SN/A
402680Sktlim@umich.educlass ThreadContext;
412SN/Aclass PCEventQueue;
422SN/A
432SN/Aclass PCEvent
442SN/A{
452SN/A  protected:
462SN/A    std::string description;
472SN/A    PCEventQueue *queue;
482SN/A    Addr evpc;
492SN/A
502SN/A  public:
511885SN/A    PCEvent(PCEventQueue *q, const std::string &desc, Addr pc);
522SN/A
532SN/A    virtual ~PCEvent() { if (queue) remove(); }
542SN/A
551885SN/A    // for DPRINTF
561885SN/A    virtual const std::string name() const { return description; }
571885SN/A
582SN/A    std::string descr() const { return description; }
592SN/A    Addr pc() const { return evpc; }
602SN/A
612SN/A    bool remove();
622680Sktlim@umich.edu    virtual void process(ThreadContext *tc) = 0;
632SN/A};
642SN/A
652SN/Aclass PCEventQueue
662SN/A{
672SN/A  protected:
682SN/A    typedef PCEvent * record_t;
692SN/A    class MapCompare {
702SN/A      public:
712SN/A        bool operator()(const record_t &l, const record_t &r) const {
722SN/A            return l->pc() < r->pc();
732SN/A        }
742SN/A        bool operator()(const record_t &l, Addr pc) const {
752SN/A            return l->pc() < pc;
762SN/A        }
772SN/A        bool operator()(Addr pc, const record_t &r) const {
782SN/A            return pc < r->pc();
792SN/A        }
802SN/A    };
812SN/A    typedef std::vector<record_t> map_t;
822SN/A
832SN/A  public:
842SN/A    typedef map_t::iterator iterator;
852SN/A    typedef map_t::const_iterator const_iterator;
862SN/A
872SN/A  protected:
882SN/A    typedef std::pair<iterator, iterator> range_t;
892SN/A    typedef std::pair<const_iterator, const_iterator> const_range_t;
902SN/A
912SN/A  protected:
922SN/A    map_t pc_map;
932SN/A
942680Sktlim@umich.edu    bool doService(ThreadContext *tc);
9576SN/A
962SN/A  public:
972SN/A    PCEventQueue();
982SN/A    ~PCEventQueue();
992SN/A
1002SN/A    bool remove(PCEvent *event);
1012SN/A    bool schedule(PCEvent *event);
1022680Sktlim@umich.edu    bool service(ThreadContext *tc)
10376SN/A    {
10476SN/A        if (pc_map.empty())
10576SN/A            return false;
10676SN/A
1072680Sktlim@umich.edu        return doService(tc);
10876SN/A    }
1092SN/A
1102SN/A    range_t equal_range(Addr pc);
1112SN/A    range_t equal_range(PCEvent *event) { return equal_range(event->pc()); }
1122SN/A
1132SN/A    void dump() const;
1142SN/A};
1152SN/A
1161885SN/A
1171885SN/Ainline
1181885SN/APCEvent::PCEvent(PCEventQueue *q, const std::string &desc, Addr pc)
1191885SN/A    : description(desc), queue(q), evpc(pc)
1201885SN/A{
1211885SN/A    queue->schedule(this);
1221885SN/A}
1231885SN/A
1242SN/Ainline bool
1252SN/APCEvent::remove()
1262SN/A{
1272SN/A    if (!queue)
1282SN/A        panic("cannot remove an uninitialized event;");
1292SN/A
1302SN/A    return queue->remove(this);
1312SN/A}
1322SN/A
1332SN/Aclass BreakPCEvent : public PCEvent
1342SN/A{
1352SN/A  protected:
1362SN/A    bool remove;
1372SN/A
1382SN/A  public:
1391885SN/A    BreakPCEvent(PCEventQueue *q, const std::string &desc, Addr addr,
1401885SN/A                 bool del = false);
1412680Sktlim@umich.edu    virtual void process(ThreadContext *tc);
1422SN/A};
1432SN/A
1442SN/A#endif // __PC_EVENT_HH__
145