2 * Copyright (c) 2006 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
32 #include "base/misc.hh"
33 #include "base/pollevent.hh"
34 #include "sim/stat_control.hh"
35 #include "sim/async.hh"
36 #include "sim/eventq.hh"
37 #include "sim/host.hh"
38 #include "sim/sim_events.hh"
39 #include "sim/sim_exit.hh"
40 #include "sim/simulate.hh"
42 /** Simulate for num_cycles additional cycles. If num_cycles is -1
43 * (the default), do not limit simulation; some other event must
44 * terminate the loop. Exported to Python via SWIG.
45 * @return The SimLoopExitEvent that caused the loop to exit.
48 simulate(Tick num_cycles
)
50 warn("Entering event queue @ %d. Starting simulation...\n", curTick
);
53 fatal("simulate: num_cycles must be >= 0 (was %d)\n", num_cycles
);
54 else if (curTick
+ num_cycles
< 0) //Overflow
57 num_cycles
= curTick
+ num_cycles
;
60 limit_event
= schedExitSimLoop("simulate() limit reached", num_cycles
);
63 // there should always be at least one event (the SimLoopExitEvent
64 // we just scheduled) in the queue
65 assert(!mainEventQueue
.empty());
66 assert(curTick
<= mainEventQueue
.nextTick() &&
67 "event scheduled in the past");
69 // forward current cycle to the time of the first event on the
71 curTick
= mainEventQueue
.nextTick();
72 Event
*exit_event
= mainEventQueue
.serviceOne();
73 if (exit_event
!= NULL
) {
74 // hit some kind of exit event; return to Python
75 // event must be subclass of SimLoopExitEvent...
76 SimLoopExitEvent
*se_event
;
77 se_event
= dynamic_cast<SimLoopExitEvent
*>(exit_event
);
80 panic("Bogus exit event class!");
82 // if we didn't hit limit_event, delete it
83 if (se_event
!= limit_event
) {
84 assert(limit_event
->scheduled());
85 limit_event
->deschedule();
94 if (async_statdump
|| async_statreset
) {
95 async_statdump
= false;
96 async_statreset
= false;
98 Stats::StatEvent(async_statdump
, async_statreset
);
103 exitSimLoop("user interrupt received");
106 if (async_io
|| async_alarm
) {
112 if (async_exception
) {
113 async_exception
= false;
119 // not reached... only exit is return on SimLoopExitEvent