pc_event.cc revision 1885
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
292665Ssaidi@eecs.umich.edu#include <algorithm>
302SN/A#include <map>
312SN/A#include <string>
322SN/A#include <utility>
332SN/A
342SN/A#include "base/trace.hh"
352SN/A#include "config/full_system.hh"
362SN/A#include "cpu/base.hh"
375882Snate@binkert.org#include "cpu/exec_context.hh"
381492SN/A#include "cpu/pc_event.hh"
391717SN/A#include "sim/debug.hh"
408229Snate@binkert.org#include "sim/root.hh"
412680Sktlim@umich.edu
428232Snate@binkert.orgusing namespace std;
434167Sbinkertn@umich.edu
442190SN/APCEventQueue::PCEventQueue()
452SN/A{}
462SN/A
472SN/APCEventQueue::~PCEventQueue()
482SN/A{}
492SN/A
502SN/Abool
512SN/APCEventQueue::remove(PCEvent *event)
522SN/A{
532SN/A    int removed = 0;
542SN/A    range_t range = equal_range(event);
552SN/A    for (iterator i = range.first; i != range.second; ++i) {
562SN/A        if (*i == event) {
572SN/A            DPRINTF(PCEvent, "PC based event removed at %#x: %s\n",
582SN/A                    event->pc(), event->descr());
598991SAli.Saidi@ARM.com            pc_map.erase(i);
608991SAli.Saidi@ARM.com            ++removed;
618991SAli.Saidi@ARM.com        }
622SN/A    }
632SN/A
642SN/A    return removed > 0;
658991SAli.Saidi@ARM.com}
662SN/A
678991SAli.Saidi@ARM.combool
688991SAli.Saidi@ARM.comPCEventQueue::schedule(PCEvent *event)
692SN/A{
708991SAli.Saidi@ARM.com    pc_map.push_back(event);
712SN/A    sort(pc_map.begin(), pc_map.end(), MapCompare());
722SN/A
732SN/A    DPRINTF(PCEvent, "PC based event scheduled for %#x: %s\n",
742SN/A            event->pc(), event->descr());
752SN/A
762SN/A    return true;
772SN/A}
782SN/A
792SN/Abool
802SN/APCEventQueue::doService(ExecContext *xc)
812SN/A{
822SN/A    Addr pc = xc->regs.pc & ~0x3;
832SN/A    int serviced = 0;
842SN/A    range_t range = equal_range(pc);
852SN/A    for (iterator i = range.first; i != range.second; ++i) {
862SN/A        // Make sure that the pc wasn't changed as the side effect of
872SN/A        // another event.  This for example, prevents two invocations
882SN/A        // of the SkipFuncEvent.  Maybe we should have separate PC
892680Sktlim@umich.edu        // event queues for each processor?
902SN/A        if (pc != (xc->regs.pc & ~0x3))
918670Ss052838@student.dtu.dk            continue;
928670Ss052838@student.dtu.dk
938670Ss052838@student.dtu.dk        DPRINTF(PCEvent, "PC based event serviced at %#x: %s\n",
942SN/A                (*i)->pc(), (*i)->descr());
952SN/A
962SN/A        (*i)->process(xc);
972SN/A        ++serviced;
982SN/A    }
992SN/A
1002SN/A    return serviced > 0;
1018670Ss052838@student.dtu.dk}
1022SN/A
1032SN/Avoid
1042SN/APCEventQueue::dump() const
1052SN/A{
1062SN/A    const_iterator i = pc_map.begin();
1072680Sktlim@umich.edu    const_iterator e = pc_map.end();
1082SN/A
1092SN/A    for (; i != e; ++i)
1102SN/A        cprintf("%d: event at %#x: %s\n", curTick, (*i)->pc(),
1112SN/A                (*i)->descr());
1122SN/A}
1132SN/A
1142SN/APCEventQueue::range_t
1152SN/APCEventQueue::equal_range(Addr pc)
1162SN/A{
1172SN/A    return std::equal_range(pc_map.begin(), pc_map.end(), pc, MapCompare());
1182SN/A}
1192SN/A
1202SN/ABreakPCEvent::BreakPCEvent(PCEventQueue *q, const std::string &desc, Addr addr,
1217823Ssteve.reinhardt@amd.com                           bool del)
1222SN/A    : PCEvent(q, desc, addr), remove(del)
1232SN/A{
1242SN/A}
1252SN/A
1262SN/Avoid
1272SN/ABreakPCEvent::process(ExecContext *xc)
1282SN/A{
1292SN/A    StringWrap name(xc->cpu->name() + ".break_event");
1302SN/A    DPRINTFN("break event %s triggered\n", descr());
1311885SN/A    debug_break();
1321885SN/A    if (remove)
1331885SN/A        delete this;
1342SN/A}
1352SN/A
1362SN/A#if FULL_SYSTEM
1372SN/Aextern "C"
1382680Sktlim@umich.eduvoid
1392SN/Asched_break_pc_sys(System *sys, Addr addr)
1402680Sktlim@umich.edu{
1411646SN/A    new BreakPCEvent(&sys->pcEventQueue, "debug break", addr, true);
1428231Snate@binkert.org}
1432SN/A
1442SN/Aextern "C"
1452SN/Avoid
1462SN/Asched_break_pc(Addr addr)
1472SN/A{
1482130SN/A     for (vector<System *>::iterator sysi = System::systemList.begin();
1492SN/A          sysi != System::systemList.end(); ++sysi) {
1501885SN/A         sched_break_pc_sys(*sysi, addr);
1512SN/A    }
1522SN/A
1532SN/A}
1542130SN/A#endif
1552SN/A