12SN/A/*
29952Sdam.sunwoo@arm.com * Copyright (c) 2013 ARM Limited
39952Sdam.sunwoo@arm.com * All rights reserved
49952Sdam.sunwoo@arm.com *
59952Sdam.sunwoo@arm.com * The license below extends only to copyright in the software and shall
69952Sdam.sunwoo@arm.com * not be construed as granting a license to any other intellectual
79952Sdam.sunwoo@arm.com * property including but not limited to intellectual property relating
89952Sdam.sunwoo@arm.com * to a hardware implementation of the functionality of the software
99952Sdam.sunwoo@arm.com * licensed hereunder.  You may use the software subject to the license
109952Sdam.sunwoo@arm.com * terms below provided that you ensure that this notice is replicated
119952Sdam.sunwoo@arm.com * unmodified and in its entirety in all distributions of the software,
129952Sdam.sunwoo@arm.com * modified or unmodified, in source code or in binary form.
139952Sdam.sunwoo@arm.com *
141762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan
159983Sstever@gmail.com * Copyright (c) 2013 Advanced Micro Devices, Inc.
169983Sstever@gmail.com * Copyright (c) 2013 Mark D. Hill and David A. Wood
172SN/A * All rights reserved.
182SN/A *
192SN/A * Redistribution and use in source and binary forms, with or without
202SN/A * modification, are permitted provided that the following conditions are
212SN/A * met: redistributions of source code must retain the above copyright
222SN/A * notice, this list of conditions and the following disclaimer;
232SN/A * redistributions in binary form must reproduce the above copyright
242SN/A * notice, this list of conditions and the following disclaimer in the
252SN/A * documentation and/or other materials provided with the distribution;
262SN/A * neither the name of the copyright holders nor the names of its
272SN/A * contributors may be used to endorse or promote products derived from
282SN/A * this software without specific prior written permission.
292SN/A *
302SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
312SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
322SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
332SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
342SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
352SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
362SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
372SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
382SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
392SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
402SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
412665Ssaidi@eecs.umich.edu *
422665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
432SN/A */
442SN/A
4511793Sbrandon.potter@amd.com#include "sim/sim_events.hh"
4611793Sbrandon.potter@amd.com
472SN/A#include <string>
482SN/A
49601SN/A#include "base/callback.hh"
50601SN/A#include "base/hostinfo.hh"
519356Snilay@cs.wisc.edu#include "sim/eventq_impl.hh"
5256SN/A#include "sim/sim_exit.hh"
53695SN/A#include "sim/stats.hh"
542SN/A
552SN/Ausing namespace std;
562SN/A
579983Sstever@gmail.comGlobalSimLoopExitEvent::GlobalSimLoopExitEvent(Tick when,
589983Sstever@gmail.com                                               const std::string &_cause,
5911070Sandreas.sandberg@arm.com                                               int c, Tick r)
6011070Sandreas.sandberg@arm.com    : GlobalEvent(when, Sim_Exit_Pri, IsExitEvent),
619983Sstever@gmail.com      cause(_cause), code(c), repeat(r)
629983Sstever@gmail.com{
639983Sstever@gmail.com}
649983Sstever@gmail.com
6513694Sgabeblack@google.comGlobalSimLoopExitEvent::GlobalSimLoopExitEvent(const std::string &_cause,
6613694Sgabeblack@google.com                                               int c, Tick r)
6713694Sgabeblack@google.com    : GlobalEvent(curTick(), Minimum_Pri, IsExitEvent),
6813694Sgabeblack@google.com      cause(_cause), code(c), repeat(r)
6913694Sgabeblack@google.com{
7013694Sgabeblack@google.com}
7113694Sgabeblack@google.com
729983Sstever@gmail.comconst char *
739983Sstever@gmail.comGlobalSimLoopExitEvent::description() const
749983Sstever@gmail.com{
759983Sstever@gmail.com    return "global simulation loop exit";
769983Sstever@gmail.com}
779983Sstever@gmail.com
789983Sstever@gmail.com//
799983Sstever@gmail.com// handle termination event
809983Sstever@gmail.com//
819983Sstever@gmail.comvoid
829983Sstever@gmail.comGlobalSimLoopExitEvent::process()
839983Sstever@gmail.com{
849983Sstever@gmail.com    if (repeat) {
859983Sstever@gmail.com        schedule(curTick() + repeat);
869983Sstever@gmail.com    }
879983Sstever@gmail.com}
889983Sstever@gmail.com
899983Sstever@gmail.comvoid
909983Sstever@gmail.comexitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
919983Sstever@gmail.com            bool serialize)
929983Sstever@gmail.com{
9311070Sandreas.sandberg@arm.com    warn_if(serialize && (when != curTick() || repeat),
9411070Sandreas.sandberg@arm.com            "exitSimLoop called with a delay and auto serialization. This is "
9511070Sandreas.sandberg@arm.com            "currently unsupported.");
969983Sstever@gmail.com
9711070Sandreas.sandberg@arm.com    new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat);
989952Sdam.sunwoo@arm.com}
999952Sdam.sunwoo@arm.com
10013694Sgabeblack@google.comvoid
10113694Sgabeblack@google.comexitSimLoopNow(const std::string &message, int exit_code, Tick repeat,
10213694Sgabeblack@google.com               bool serialize)
10313694Sgabeblack@google.com{
10413694Sgabeblack@google.com    new GlobalSimLoopExitEvent(message, exit_code, repeat);
10513694Sgabeblack@google.com}
10613694Sgabeblack@google.com
1079983Sstever@gmail.comLocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
10811070Sandreas.sandberg@arm.com                                   Tick r)
10911070Sandreas.sandberg@arm.com    : Event(Sim_Exit_Pri, IsExitEvent),
1109952Sdam.sunwoo@arm.com      cause(_cause), code(c), repeat(r)
1115606Snate@binkert.org{
1125606Snate@binkert.org}
1135606Snate@binkert.org
1142SN/A//
1152SN/A// handle termination event
1162SN/A//
1172SN/Avoid
1189983Sstever@gmail.comLocalSimLoopExitEvent::process()
1192SN/A{
1209983Sstever@gmail.com    exitSimLoop(cause, 0);
1212SN/A}
1222SN/A
1232SN/A
1242SN/Aconst char *
1259983Sstever@gmail.comLocalSimLoopExitEvent::description() const
1262SN/A{
1272667Sstever@eecs.umich.edu    return "simulation loop exit";
1282667Sstever@eecs.umich.edu}
1292667Sstever@eecs.umich.edu
1302667Sstever@eecs.umich.eduvoid
13110905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::serialize(CheckpointOut &cp) const
1322667Sstever@eecs.umich.edu{
13310905Sandreas.sandberg@arm.com    Event::serialize(cp);
1349952Sdam.sunwoo@arm.com
1359952Sdam.sunwoo@arm.com    SERIALIZE_SCALAR(cause);
1369952Sdam.sunwoo@arm.com    SERIALIZE_SCALAR(code);
1379952Sdam.sunwoo@arm.com    SERIALIZE_SCALAR(repeat);
1389952Sdam.sunwoo@arm.com}
1399952Sdam.sunwoo@arm.com
1409952Sdam.sunwoo@arm.comvoid
14110905Sandreas.sandberg@arm.comLocalSimLoopExitEvent::unserialize(CheckpointIn &cp)
1429952Sdam.sunwoo@arm.com{
14310905Sandreas.sandberg@arm.com    Event::unserialize(cp);
1449952Sdam.sunwoo@arm.com
1459952Sdam.sunwoo@arm.com    UNSERIALIZE_SCALAR(cause);
1469952Sdam.sunwoo@arm.com    UNSERIALIZE_SCALAR(code);
1479952Sdam.sunwoo@arm.com    UNSERIALIZE_SCALAR(repeat);
1489952Sdam.sunwoo@arm.com}
1499952Sdam.sunwoo@arm.com
1502SN/A//
1512SN/A// constructor: automatically schedules at specified time
1522SN/A//
1535606Snate@binkert.orgCountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
1545606Snate@binkert.org    : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
1552SN/A{
1562SN/A    // catch stupid mistakes
1572SN/A    assert(downCounter > 0);
1582SN/A}
1592SN/A
1602SN/A
1612SN/A//
1622SN/A// handle termination event
1632SN/A//
1642SN/Avoid
1652SN/ACountedExitEvent::process()
1662SN/A{
1672SN/A    if (--downCounter == 0) {
1682667Sstever@eecs.umich.edu        exitSimLoop(cause, 0);
1692SN/A    }
1702SN/A}
1712SN/A
1722SN/A
1732SN/Aconst char *
1745336Shines@cs.fsu.eduCountedExitEvent::description() const
1752SN/A{
1762SN/A    return "counted exit";
1772SN/A}
178