2 * Copyright (c) 2003-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.
35 #include "sim/pseudo_inst.hh"
36 #include "arch/vtophys.hh"
37 #include "cpu/base.hh"
38 #include "cpu/sampler/sampler.hh"
39 #include "cpu/exec_context.hh"
40 #include "kern/kernel_stats.hh"
41 #include "sim/param.hh"
42 #include "sim/serialize.hh"
43 #include "sim/sim_exit.hh"
44 #include "sim/stat_control.hh"
45 #include "sim/stats.hh"
46 #include "sim/system.hh"
47 #include "sim/debug.hh"
48 #include "sim/vptr.hh"
52 extern Sampler
*SampCPU
;
54 using namespace Stats
;
55 using namespace TheISA
;
59 bool doStatisticsInsts
;
60 bool doCheckpointInsts
;
66 xc
->getCpuPtr()->kernelStats
->arm();
70 quiesce(ExecContext
*xc
)
76 xc
->getCpuPtr()->kernelStats
->quiesce();
80 quiesceNs(ExecContext
*xc
, uint64_t ns
)
82 if (!doQuiesce
|| ns
== 0)
85 Event
*quiesceEvent
= xc
->getQuiesceEvent();
87 if (quiesceEvent
->scheduled())
88 quiesceEvent
->reschedule(curTick
+ Clock::Int::ns
* ns
);
90 quiesceEvent
->schedule(curTick
+ Clock::Int::ns
* ns
);
93 xc
->getCpuPtr()->kernelStats
->quiesce();
97 quiesceCycles(ExecContext
*xc
, uint64_t cycles
)
99 if (!doQuiesce
|| cycles
== 0)
102 Event
*quiesceEvent
= xc
->getQuiesceEvent();
104 if (quiesceEvent
->scheduled())
105 quiesceEvent
->reschedule(curTick
+
106 xc
->getCpuPtr()->cycles(cycles
));
108 quiesceEvent
->schedule(curTick
+
109 xc
->getCpuPtr()->cycles(cycles
));
112 xc
->getCpuPtr()->kernelStats
->quiesce();
116 quiesceTime(ExecContext
*xc
)
118 return (xc
->readLastActivate() - xc
->readLastSuspend()) / Clock::Int::ns
;
122 ivlb(ExecContext
*xc
)
124 xc
->getCpuPtr()->kernelStats
->ivlb();
128 ivle(ExecContext
*xc
)
133 m5exit_old(ExecContext
*xc
)
135 SimExit(curTick
, "m5_exit_old instruction encountered");
139 m5exit(ExecContext
*xc
, Tick delay
)
141 Tick when
= curTick
+ delay
* Clock::Int::ns
;
142 SimExit(when
, "m5_exit instruction encountered");
146 resetstats(ExecContext
*xc
, Tick delay
, Tick period
)
148 if (!doStatisticsInsts
)
152 Tick when
= curTick
+ delay
* Clock::Int::ns
;
153 Tick repeat
= period
* Clock::Int::ns
;
155 using namespace Stats
;
156 SetupEvent(Reset
, when
, repeat
);
160 dumpstats(ExecContext
*xc
, Tick delay
, Tick period
)
162 if (!doStatisticsInsts
)
166 Tick when
= curTick
+ delay
* Clock::Int::ns
;
167 Tick repeat
= period
* Clock::Int::ns
;
169 using namespace Stats
;
170 SetupEvent(Dump
, when
, repeat
);
174 addsymbol(ExecContext
*xc
, Addr addr
, Addr symbolAddr
)
177 CopyStringOut(xc
, symb
, symbolAddr
, 100);
178 std::string
symbol(symb
);
180 DPRINTF(Loader
, "Loaded symbol: %s @ %#llx\n", symbol
, addr
);
182 xc
->getSystemPtr()->kernelSymtab
->insert(addr
,symbol
);
186 dumpresetstats(ExecContext
*xc
, Tick delay
, Tick period
)
188 if (!doStatisticsInsts
)
192 Tick when
= curTick
+ delay
* Clock::Int::ns
;
193 Tick repeat
= period
* Clock::Int::ns
;
195 using namespace Stats
;
196 SetupEvent(Dump
|Reset
, when
, repeat
);
200 m5checkpoint(ExecContext
*xc
, Tick delay
, Tick period
)
202 if (!doCheckpointInsts
)
206 Tick when
= curTick
+ delay
* Clock::Int::ns
;
207 Tick repeat
= period
* Clock::Int::ns
;
209 Checkpoint::setup(when
, repeat
);
213 readfile(ExecContext
*xc
, Addr vaddr
, uint64_t len
, uint64_t offset
)
215 const string
&file
= xc
->getCpuPtr()->system
->params()->readfile
;
222 int fd
= ::open(file
.c_str(), O_RDONLY
, 0);
224 panic("could not open file %s\n", file
);
226 if (::lseek(fd
, offset
, SEEK_SET
) < 0)
227 panic("could not seek: %s", strerror(errno
));
229 char *buf
= new char[len
];
232 int bytes
= ::read(fd
, p
, len
);
242 CopyIn(xc
, vaddr
, buf
, result
);
247 class Context
: public ParamContext
250 Context(const string
§ion
) : ParamContext(section
) {}
254 Context
context("pseudo_inst");
256 Param
<bool> __quiesce(&context
, "quiesce",
257 "enable quiesce instructions",
259 Param
<bool> __statistics(&context
, "statistics",
260 "enable statistics pseudo instructions",
262 Param
<bool> __checkpoint(&context
, "checkpoint",
263 "enable checkpoint pseudo instructions",
267 Context::checkParams()
269 doQuiesce
= __quiesce
;
270 doStatisticsInsts
= __statistics
;
271 doCheckpointInsts
= __checkpoint
;
274 void debugbreak(ExecContext
*xc
)
279 void switchcpu(ExecContext
*xc
)
282 SampCPU
->switchCPUs();