pc_event.cc revision 2680
15795Ssaidi@eecs.umich.edu/* 25795Ssaidi@eecs.umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 35795Ssaidi@eecs.umich.edu * All rights reserved. 45795Ssaidi@eecs.umich.edu * 55795Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 65795Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are 75795Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright 85795Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 95795Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 105795Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 115795Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution; 125795Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its 135795Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 145795Ssaidi@eecs.umich.edu * this software without specific prior written permission. 155795Ssaidi@eecs.umich.edu * 165795Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175795Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185795Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195795Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205795Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215795Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225795Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235795Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245795Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255795Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265795Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275795Ssaidi@eecs.umich.edu * 285795Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 295795Ssaidi@eecs.umich.edu * Steve Reinhardt 305795Ssaidi@eecs.umich.edu */ 315795Ssaidi@eecs.umich.edu 325795Ssaidi@eecs.umich.edu#include <algorithm> 335795Ssaidi@eecs.umich.edu#include <map> 345795Ssaidi@eecs.umich.edu#include <string> 355795Ssaidi@eecs.umich.edu#include <utility> 365795Ssaidi@eecs.umich.edu 375795Ssaidi@eecs.umich.edu#include "base/trace.hh" 385795Ssaidi@eecs.umich.edu#include "config/full_system.hh" 395795Ssaidi@eecs.umich.edu#include "cpu/base.hh" 405795Ssaidi@eecs.umich.edu#include "cpu/thread_context.hh" 415795Ssaidi@eecs.umich.edu#include "cpu/pc_event.hh" 425795Ssaidi@eecs.umich.edu#include "sim/debug.hh" 435795Ssaidi@eecs.umich.edu#include "sim/root.hh" 445795Ssaidi@eecs.umich.edu#include "sim/system.hh" 455795Ssaidi@eecs.umich.edu 466227Snate@binkert.orgusing namespace std; 475795Ssaidi@eecs.umich.edu 485795Ssaidi@eecs.umich.eduPCEventQueue::PCEventQueue() 495795Ssaidi@eecs.umich.edu{} 505795Ssaidi@eecs.umich.edu 515795Ssaidi@eecs.umich.eduPCEventQueue::~PCEventQueue() 525795Ssaidi@eecs.umich.edu{} 535795Ssaidi@eecs.umich.edu 545795Ssaidi@eecs.umich.edubool 555795Ssaidi@eecs.umich.eduPCEventQueue::remove(PCEvent *event) 565795Ssaidi@eecs.umich.edu{ 575795Ssaidi@eecs.umich.edu int removed = 0; 585795Ssaidi@eecs.umich.edu range_t range = equal_range(event); 595795Ssaidi@eecs.umich.edu for (iterator i = range.first; i != range.second; ++i) { 605795Ssaidi@eecs.umich.edu if (*i == event) { 615795Ssaidi@eecs.umich.edu DPRINTF(PCEvent, "PC based event removed at %#x: %s\n", 625795Ssaidi@eecs.umich.edu event->pc(), event->descr()); 635795Ssaidi@eecs.umich.edu pc_map.erase(i); 645795Ssaidi@eecs.umich.edu ++removed; 655795Ssaidi@eecs.umich.edu } 66 } 67 68 return removed > 0; 69} 70 71bool 72PCEventQueue::schedule(PCEvent *event) 73{ 74 pc_map.push_back(event); 75 sort(pc_map.begin(), pc_map.end(), MapCompare()); 76 77 DPRINTF(PCEvent, "PC based event scheduled for %#x: %s\n", 78 event->pc(), event->descr()); 79 80 return true; 81} 82 83bool 84PCEventQueue::doService(ThreadContext *tc) 85{ 86 Addr pc = tc->readPC() & ~0x3; 87 int serviced = 0; 88 range_t range = equal_range(pc); 89 for (iterator i = range.first; i != range.second; ++i) { 90 // Make sure that the pc wasn't changed as the side effect of 91 // another event. This for example, prevents two invocations 92 // of the SkipFuncEvent. Maybe we should have separate PC 93 // event queues for each processor? 94 if (pc != (tc->readPC() & ~0x3)) 95 continue; 96 97 DPRINTF(PCEvent, "PC based event serviced at %#x: %s\n", 98 (*i)->pc(), (*i)->descr()); 99 100 (*i)->process(tc); 101 ++serviced; 102 } 103 104 return serviced > 0; 105} 106 107void 108PCEventQueue::dump() const 109{ 110 const_iterator i = pc_map.begin(); 111 const_iterator e = pc_map.end(); 112 113 for (; i != e; ++i) 114 cprintf("%d: event at %#x: %s\n", curTick, (*i)->pc(), 115 (*i)->descr()); 116} 117 118PCEventQueue::range_t 119PCEventQueue::equal_range(Addr pc) 120{ 121 return std::equal_range(pc_map.begin(), pc_map.end(), pc, MapCompare()); 122} 123 124BreakPCEvent::BreakPCEvent(PCEventQueue *q, const std::string &desc, Addr addr, 125 bool del) 126 : PCEvent(q, desc, addr), remove(del) 127{ 128} 129 130void 131BreakPCEvent::process(ThreadContext *tc) 132{ 133 StringWrap name(tc->getCpuPtr()->name() + ".break_event"); 134 DPRINTFN("break event %s triggered\n", descr()); 135 debug_break(); 136 if (remove) 137 delete this; 138} 139 140#if FULL_SYSTEM 141extern "C" 142void 143sched_break_pc_sys(System *sys, Addr addr) 144{ 145 new BreakPCEvent(&sys->pcEventQueue, "debug break", addr, true); 146} 147 148extern "C" 149void 150sched_break_pc(Addr addr) 151{ 152 for (vector<System *>::iterator sysi = System::systemList.begin(); 153 sysi != System::systemList.end(); ++sysi) { 154 sched_break_pc_sys(*sysi, addr); 155 } 156 157} 158#endif 159