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 3712334Sgabeblack@google.com#include "base/logging.hh" 386214Snate@binkert.org#include "base/types.hh" 392439SN/A 402680Sktlim@umich.educlass ThreadContext; 412SN/Aclass PCEventQueue; 429554Sandreas.hansson@arm.comclass System; 432SN/A 442SN/Aclass PCEvent 452SN/A{ 462SN/A protected: 472SN/A std::string description; 482SN/A PCEventQueue *queue; 492SN/A Addr evpc; 502SN/A 512SN/A public: 521885SN/A PCEvent(PCEventQueue *q, const std::string &desc, Addr pc); 532SN/A 542SN/A virtual ~PCEvent() { if (queue) remove(); } 552SN/A 561885SN/A // for DPRINTF 571885SN/A virtual const std::string name() const { return description; } 581885SN/A 592SN/A std::string descr() const { return description; } 602SN/A Addr pc() const { return evpc; } 612SN/A 622SN/A bool remove(); 632680Sktlim@umich.edu virtual void process(ThreadContext *tc) = 0; 642SN/A}; 652SN/A 662SN/Aclass PCEventQueue 672SN/A{ 682SN/A protected: 692SN/A typedef PCEvent * record_t; 702SN/A class MapCompare { 712SN/A public: 722SN/A bool operator()(const record_t &l, const record_t &r) const { 732SN/A return l->pc() < r->pc(); 742SN/A } 752SN/A bool operator()(const record_t &l, Addr pc) const { 762SN/A return l->pc() < pc; 772SN/A } 782SN/A bool operator()(Addr pc, const record_t &r) const { 792SN/A return pc < r->pc(); 802SN/A } 812SN/A }; 822SN/A typedef std::vector<record_t> map_t; 832SN/A 842SN/A public: 852SN/A typedef map_t::iterator iterator; 862SN/A typedef map_t::const_iterator const_iterator; 872SN/A 882SN/A protected: 892SN/A typedef std::pair<iterator, iterator> range_t; 902SN/A typedef std::pair<const_iterator, const_iterator> const_range_t; 912SN/A 922SN/A protected: 932SN/A map_t pc_map; 942SN/A 952680Sktlim@umich.edu bool doService(ThreadContext *tc); 9676SN/A 972SN/A public: 982SN/A PCEventQueue(); 992SN/A ~PCEventQueue(); 1002SN/A 1012SN/A bool remove(PCEvent *event); 1022SN/A bool schedule(PCEvent *event); 1032680Sktlim@umich.edu bool service(ThreadContext *tc) 10476SN/A { 10576SN/A if (pc_map.empty()) 10676SN/A return false; 10776SN/A 1082680Sktlim@umich.edu return doService(tc); 10976SN/A } 1102SN/A 1112SN/A range_t equal_range(Addr pc); 1122SN/A range_t equal_range(PCEvent *event) { return equal_range(event->pc()); } 1132SN/A 1142SN/A void dump() const; 1152SN/A}; 1162SN/A 1171885SN/A 1181885SN/Ainline 1191885SN/APCEvent::PCEvent(PCEventQueue *q, const std::string &desc, Addr pc) 1201885SN/A : description(desc), queue(q), evpc(pc) 1211885SN/A{ 1221885SN/A queue->schedule(this); 1231885SN/A} 1241885SN/A 1252SN/Ainline bool 1262SN/APCEvent::remove() 1272SN/A{ 1282SN/A if (!queue) 1292SN/A panic("cannot remove an uninitialized event;"); 1302SN/A 1312SN/A return queue->remove(this); 1322SN/A} 1332SN/A 1342SN/Aclass BreakPCEvent : public PCEvent 1352SN/A{ 1362SN/A protected: 1372SN/A bool remove; 1382SN/A 1392SN/A public: 1401885SN/A BreakPCEvent(PCEventQueue *q, const std::string &desc, Addr addr, 1411885SN/A bool del = false); 1422680Sktlim@umich.edu virtual void process(ThreadContext *tc); 1432SN/A}; 1442SN/A 1459554Sandreas.hansson@arm.comvoid sched_break_pc_sys(System *sys, Addr addr); 1469554Sandreas.hansson@arm.com 1479554Sandreas.hansson@arm.comvoid sched_break_pc(Addr addr); 1489554Sandreas.hansson@arm.com 1499649SAndreas.Sandberg@ARM.comclass PanicPCEvent : public PCEvent 1509649SAndreas.Sandberg@ARM.com{ 1519649SAndreas.Sandberg@ARM.com public: 1529649SAndreas.Sandberg@ARM.com PanicPCEvent(PCEventQueue *q, const std::string &desc, Addr pc); 1539649SAndreas.Sandberg@ARM.com virtual void process(ThreadContext *tc); 1549649SAndreas.Sandberg@ARM.com}; 1559649SAndreas.Sandberg@ARM.com 1562SN/A#endif // __PC_EVENT_HH__ 157