pc_event.cc revision 9649
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#include <algorithm>
332SN/A#include <string>
342SN/A#include <utility>
352SN/A
365882Snate@binkert.org#include "base/debug.hh"
371492SN/A#include "base/trace.hh"
381717SN/A#include "cpu/base.hh"
398229Snate@binkert.org#include "cpu/pc_event.hh"
402680Sktlim@umich.edu#include "cpu/thread_context.hh"
418232Snate@binkert.org#include "debug/PCEvent.hh"
424167Sbinkertn@umich.edu#include "sim/core.hh"
432190SN/A#include "sim/system.hh"
442SN/A
452SN/Ausing namespace std;
462SN/A
472SN/APCEventQueue::PCEventQueue()
482SN/A{}
492SN/A
502SN/APCEventQueue::~PCEventQueue()
512SN/A{}
522SN/A
532SN/Abool
542SN/APCEventQueue::remove(PCEvent *event)
552SN/A{
562SN/A    int removed = 0;
572SN/A    range_t range = equal_range(event);
588991SAli.Saidi@ARM.com    iterator i = range.first;
598991SAli.Saidi@ARM.com    while (i != range.second &&
608991SAli.Saidi@ARM.com           i != pc_map.end()) {
612SN/A        if (*i == event) {
622SN/A            DPRINTF(PCEvent, "PC based event removed at %#x: %s\n",
632SN/A                    event->pc(), event->descr());
648991SAli.Saidi@ARM.com            i = pc_map.erase(i);
652SN/A            ++removed;
668991SAli.Saidi@ARM.com        } else {
678991SAli.Saidi@ARM.com            i++;
682SN/A        }
698991SAli.Saidi@ARM.com
702SN/A    }
712SN/A
722SN/A    return removed > 0;
732SN/A}
742SN/A
752SN/Abool
762SN/APCEventQueue::schedule(PCEvent *event)
772SN/A{
782SN/A    pc_map.push_back(event);
792SN/A    sort(pc_map.begin(), pc_map.end(), MapCompare());
802SN/A
812SN/A    DPRINTF(PCEvent, "PC based event scheduled for %#x: %s\n",
822SN/A            event->pc(), event->descr());
832SN/A
842SN/A    return true;
852SN/A}
862SN/A
872SN/Abool
882680Sktlim@umich.eduPCEventQueue::doService(ThreadContext *tc)
892SN/A{
908670Ss052838@student.dtu.dk    // This will fail to break on Alpha PALcode addresses, but that is
918670Ss052838@student.dtu.dk    // a rare use case.
928670Ss052838@student.dtu.dk    Addr pc = tc->instAddr();
932SN/A    int serviced = 0;
942SN/A    range_t range = equal_range(pc);
952SN/A    for (iterator i = range.first; i != range.second; ++i) {
962SN/A        // Make sure that the pc wasn't changed as the side effect of
972SN/A        // another event.  This for example, prevents two invocations
982SN/A        // of the SkipFuncEvent.  Maybe we should have separate PC
992SN/A        // event queues for each processor?
1008670Ss052838@student.dtu.dk        if (pc != tc->instAddr())
1012SN/A            continue;
1022SN/A
1032SN/A        DPRINTF(PCEvent, "PC based event serviced at %#x: %s\n",
1042SN/A                (*i)->pc(), (*i)->descr());
1052SN/A
1062680Sktlim@umich.edu        (*i)->process(tc);
1072SN/A        ++serviced;
1082SN/A    }
1092SN/A
1102SN/A    return serviced > 0;
1112SN/A}
1122SN/A
1132SN/Avoid
1142SN/APCEventQueue::dump() const
1152SN/A{
1162SN/A    const_iterator i = pc_map.begin();
1172SN/A    const_iterator e = pc_map.end();
1182SN/A
1192SN/A    for (; i != e; ++i)
1207823Ssteve.reinhardt@amd.com        cprintf("%d: event at %#x: %s\n", curTick(), (*i)->pc(),
1212SN/A                (*i)->descr());
1222SN/A}
1232SN/A
1242SN/APCEventQueue::range_t
1252SN/APCEventQueue::equal_range(Addr pc)
1262SN/A{
1272SN/A    return std::equal_range(pc_map.begin(), pc_map.end(), pc, MapCompare());
1282SN/A}
1292SN/A
1301885SN/ABreakPCEvent::BreakPCEvent(PCEventQueue *q, const std::string &desc, Addr addr,
1311885SN/A                           bool del)
1321885SN/A    : PCEvent(q, desc, addr), remove(del)
1332SN/A{
1342SN/A}
1352SN/A
1362SN/Avoid
1372680Sktlim@umich.eduBreakPCEvent::process(ThreadContext *tc)
1382SN/A{
1392680Sktlim@umich.edu    StringWrap name(tc->getCpuPtr()->name() + ".break_event");
1401646SN/A    DPRINTFN("break event %s triggered\n", descr());
1418231Snate@binkert.org    Debug::breakpoint();
1422SN/A    if (remove)
1432SN/A        delete this;
1442SN/A}
1452SN/A
1462SN/Avoid
1472130SN/Asched_break_pc_sys(System *sys, Addr addr)
1482SN/A{
1491885SN/A    new BreakPCEvent(&sys->pcEventQueue, "debug break", addr, true);
1502SN/A}
1512SN/A
1522SN/Avoid
1532130SN/Asched_break_pc(Addr addr)
1542SN/A{
1552SN/A     for (vector<System *>::iterator sysi = System::systemList.begin();
1562SN/A          sysi != System::systemList.end(); ++sysi) {
1572SN/A         sched_break_pc_sys(*sysi, addr);
1582SN/A    }
1592SN/A
1602SN/A}
1619649SAndreas.Sandberg@ARM.com
1629649SAndreas.Sandberg@ARM.comPanicPCEvent::PanicPCEvent(PCEventQueue *q, const std::string &desc, Addr pc)
1639649SAndreas.Sandberg@ARM.com    : PCEvent(q, desc, pc)
1649649SAndreas.Sandberg@ARM.com{
1659649SAndreas.Sandberg@ARM.com}
1669649SAndreas.Sandberg@ARM.com
1679649SAndreas.Sandberg@ARM.comvoid
1689649SAndreas.Sandberg@ARM.comPanicPCEvent::process(ThreadContext *tc)
1699649SAndreas.Sandberg@ARM.com{
1709649SAndreas.Sandberg@ARM.com    StringWrap name(tc->getCpuPtr()->name() + ".panic_event");
1719649SAndreas.Sandberg@ARM.com    panic(descr());
1729649SAndreas.Sandberg@ARM.com}
173