pc_event.cc revision 1717
12292SN/A/* 210333Smitch.hayenga@arm.com * Copyright (c) 2002-2003 The Regents of The University of Michigan 310239Sbinhpham@cs.rutgers.edu * All rights reserved. 48707Sandreas.hansson@arm.com * 58707Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68707Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78707Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98707Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118707Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128707Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 138707Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 148707Sandreas.hansson@arm.com * this software without specific prior written permission. 152727Sktlim@umich.edu * 162292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182292SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212292SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222292SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232292SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242292SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272292SN/A */ 282292SN/A 292292SN/A#include <algorithm> 302292SN/A#include <map> 312292SN/A#include <string> 322292SN/A#include <utility> 332292SN/A 342292SN/A#include "base/trace.hh" 352292SN/A#include "cpu/base.hh" 362292SN/A#include "cpu/exec_context.hh" 372292SN/A#include "cpu/pc_event.hh" 382292SN/A#include "sim/debug.hh" 392292SN/A#include "sim/root.hh" 402689Sktlim@umich.edu 412689Sktlim@umich.eduusing namespace std; 422292SN/A 432292SN/APCEventQueue::PCEventQueue() 449944Smatt.horsnell@ARM.com{} 459944Smatt.horsnell@ARM.com 469944Smatt.horsnell@ARM.comPCEventQueue::~PCEventQueue() 472329SN/A{} 482980Sgblack@eecs.umich.edu 492329SN/Abool 502329SN/APCEventQueue::remove(PCEvent *event) 512292SN/A{ 529444SAndreas.Sandberg@ARM.com int removed = 0; 538232Snate@binkert.org range_t range = equal_range(event); 548232Snate@binkert.org for (iterator i = range.first; i != range.second; ++i) { 558232Snate@binkert.org if (*i == event) { 566221Snate@binkert.org DPRINTF(PCEvent, "PC based event removed at %#x: %s\n", 572292SN/A event->pc(), event->descr()); 586221Snate@binkert.org pc_map.erase(i); 595529Snate@binkert.org ++removed; 602292SN/A } 615529Snate@binkert.org } 628707Sandreas.hansson@arm.com 634329Sktlim@umich.edu return removed > 0; 644329Sktlim@umich.edu} 6510333Smitch.hayenga@arm.com 662292SN/Abool 679868Sjthestness@gmail.comPCEventQueue::schedule(PCEvent *event) 689868Sjthestness@gmail.com{ 692292SN/A pc_map.push_back(event); 702292SN/A sort(pc_map.begin(), pc_map.end(), MapCompare()); 712292SN/A 722980Sgblack@eecs.umich.edu DPRINTF(PCEvent, "PC based event scheduled for %#x: %s\n", 732292SN/A event->pc(), event->descr()); 742292SN/A 752292SN/A return true; 762292SN/A} 772292SN/A 782292SN/Abool 792292SN/APCEventQueue::doService(ExecContext *xc) 802292SN/A{ 812292SN/A Addr pc = xc->regs.pc & ~0x3; 822292SN/A int serviced = 0; 832292SN/A range_t range = equal_range(pc); 844329Sktlim@umich.edu for (iterator i = range.first; i != range.second; ++i) { 852292SN/A // Make sure that the pc wasn't changed as the side effect of 862292SN/A // another event. This for example, prevents two invocations 872292SN/A // of the SkipFuncEvent. Maybe we should have separate PC 882292SN/A // event queues for each processor? 892292SN/A if (pc != (xc->regs.pc & ~0x3)) 902292SN/A continue; 912292SN/A 924329Sktlim@umich.edu DPRINTF(PCEvent, "PC based event serviced at %#x: %s\n", 932292SN/A (*i)->pc(), (*i)->descr()); 948346Sksewell@umich.edu 952292SN/A (*i)->process(xc); 962292SN/A ++serviced; 972292SN/A } 982292SN/A 992292SN/A return serviced > 0; 1002292SN/A} 1012292SN/A 1022292SN/Avoid 1032292SN/APCEventQueue::dump() const 1042292SN/A{ 1052292SN/A const_iterator i = pc_map.begin(); 1062292SN/A const_iterator e = pc_map.end(); 1074329Sktlim@umich.edu 1082292SN/A for (; i != e; ++i) 1098346Sksewell@umich.edu cprintf("%d: event at %#x: %s\n", curTick, (*i)->pc(), 1102292SN/A (*i)->descr()); 1112292SN/A} 1122292SN/A 1132292SN/APCEventQueue::range_t 1142292SN/APCEventQueue::equal_range(Addr pc) 1152292SN/A{ 1162292SN/A return std::equal_range(pc_map.begin(), pc_map.end(), pc, MapCompare()); 1179868Sjthestness@gmail.com} 1186221Snate@binkert.org 1194329Sktlim@umich.eduBreakPCEvent::BreakPCEvent(PCEventQueue *q, const std::string &desc, bool del) 1204329Sktlim@umich.edu : PCEvent(q, desc), remove(del) 1218850Sandreas.hansson@arm.com{ 1222292SN/A} 1232292SN/A 1242292SN/Avoid 1252292SN/ABreakPCEvent::process(ExecContext *xc) 1262292SN/A{ 1272292SN/A StringWrap name(xc->cpu->name() + ".break_event"); 1282292SN/A DPRINTFN("break event %s triggered\n", descr()); 1292292SN/A debug_break(); 1302292SN/A if (remove) 1312292SN/A delete this; 1322292SN/A} 1332292SN/A 1342292SN/A#ifdef FULL_SYSTEM 1352727Sktlim@umich.eduextern "C" 1362727Sktlim@umich.eduvoid 1372727Sktlim@umich.edusched_break_pc_sys(System *sys, Addr addr) 1386221Snate@binkert.org{ 1392727Sktlim@umich.edu PCEvent *event = new BreakPCEvent(&sys->pcEventQueue, "debug break", true); 1402727Sktlim@umich.edu event->schedule(addr); 1412727Sktlim@umich.edu} 1422727Sktlim@umich.edu 1432727Sktlim@umich.eduextern "C" 1442727Sktlim@umich.eduvoid 1456221Snate@binkert.orgsched_break_pc(Addr addr) 1462292SN/A{ 1472292SN/A for (vector<System *>::iterator sysi = System::systemList.begin(); 1482292SN/A sysi != System::systemList.end(); ++sysi) { 1492292SN/A sched_break_pc_sys(*sysi, addr); 1502292SN/A } 1512292SN/A 1522307SN/A} 1539444SAndreas.Sandberg@ARM.com#endif 1542307SN/A