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
451798SN/A#ifndef __SIM_SIM_EVENTS_HH__
461798SN/A#define __SIM_SIM_EVENTS_HH__
472SN/A
489983Sstever@gmail.com#include "sim/global_event.hh"
499952Sdam.sunwoo@arm.com#include "sim/serialize.hh"
502SN/A
512SN/A//
522SN/A// Event to terminate simulation at a particular cycle/instruction
532SN/A//
549983Sstever@gmail.comclass GlobalSimLoopExitEvent : public GlobalEvent
552SN/A{
565606Snate@binkert.org  protected:
572SN/A    // string explaining why we're terminating
582SN/A    std::string cause;
592SN/A    int code;
603144Shsul@eecs.umich.edu    Tick repeat;
612SN/A
622SN/A  public:
639983Sstever@gmail.com    GlobalSimLoopExitEvent(Tick when, const std::string &_cause, int c,
6411070Sandreas.sandberg@arm.com                           Tick repeat = 0);
6513694Sgabeblack@google.com    GlobalSimLoopExitEvent(const std::string &_cause, int c, Tick repeat = 0);
662SN/A
679983Sstever@gmail.com    const std::string getCause() const { return cause; }
6811294Sandreas.hansson@arm.com    int getCode() const { return code; }
699983Sstever@gmail.com
709983Sstever@gmail.com    void process();     // process event
719983Sstever@gmail.com
729983Sstever@gmail.com    virtual const char *description() const;
739983Sstever@gmail.com};
749983Sstever@gmail.com
759983Sstever@gmail.comclass LocalSimLoopExitEvent : public Event
769983Sstever@gmail.com{
779983Sstever@gmail.com  protected:
789983Sstever@gmail.com    // string explaining why we're terminating
799983Sstever@gmail.com    std::string cause;
809983Sstever@gmail.com    int code;
819983Sstever@gmail.com    Tick repeat;
829983Sstever@gmail.com
839983Sstever@gmail.com  public:
849983Sstever@gmail.com    LocalSimLoopExitEvent();
8511070Sandreas.sandberg@arm.com    LocalSimLoopExitEvent(const std::string &_cause, int c, Tick repeat = 0);
869983Sstever@gmail.com
879983Sstever@gmail.com    const std::string getCause() const { return cause; }
8811294Sandreas.hansson@arm.com    int getCode() const { return code; }
892SN/A
9011169Sandreas.hansson@arm.com    void process() override;     // process event
912SN/A
9211169Sandreas.hansson@arm.com    const char *description() const override;
939952Sdam.sunwoo@arm.com
9411168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
9511168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
962SN/A};
972SN/A
982SN/A//
992SN/A// Event class to terminate simulation after 'n' related events have
1002SN/A// occurred using a shared counter: used to terminate when *all*
1012SN/A// threads have reached a particular instruction count
1022SN/A//
1032SN/Aclass CountedExitEvent : public Event
1042SN/A{
1052SN/A  private:
1065543Ssaidi@eecs.umich.edu    std::string cause;  // string explaining why we're terminating
1075543Ssaidi@eecs.umich.edu    int &downCounter;   // decrement & terminate if zero
1082SN/A
1092SN/A  public:
1105606Snate@binkert.org    CountedExitEvent(const std::string &_cause, int &_downCounter);
1112SN/A
11211169Sandreas.hansson@arm.com    void process() override;     // process event
1132SN/A
11411169Sandreas.hansson@arm.com    const char *description() const override;
1152SN/A};
1162SN/A
1172SN/A
1181798SN/A#endif  // __SIM_SIM_EVENTS_HH__
119