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.
28 * Authors: Nathan Binkert
37 #include "sim/pseudo_inst.hh"
38 #include "arch/vtophys.hh"
39 #include "base/annotate.hh"
40 #include "cpu/base.hh"
41 #include "cpu/thread_context.hh"
42 #include "cpu/quiesce_event.hh"
43 #include "kern/kernel_stats.hh"
44 #include "sim/param.hh"
45 #include "sim/serialize.hh"
46 #include "sim/sim_exit.hh"
47 #include "sim/stat_control.hh"
48 #include "sim/stats.hh"
49 #include "sim/system.hh"
50 #include "sim/debug.hh"
51 #include "sim/vptr.hh"
55 using namespace Stats
;
56 using namespace TheISA
;
60 bool doStatisticsInsts
;
61 bool doCheckpointInsts
;
65 arm(ThreadContext
*tc
)
67 if (tc
->getKernelStats())
68 tc
->getKernelStats()->arm();
72 quiesce(ThreadContext
*tc
)
78 if (tc
->getKernelStats())
79 tc
->getKernelStats()->quiesce();
83 quiesceNs(ThreadContext
*tc
, uint64_t ns
)
85 if (!doQuiesce
|| ns
== 0)
88 EndQuiesceEvent
*quiesceEvent
= tc
->getQuiesceEvent();
90 if (quiesceEvent
->scheduled())
91 quiesceEvent
->reschedule(curTick
+ Clock::Int::ns
* ns
);
93 quiesceEvent
->schedule(curTick
+ Clock::Int::ns
* ns
);
96 if (tc
->getKernelStats())
97 tc
->getKernelStats()->quiesce();
101 quiesceCycles(ThreadContext
*tc
, uint64_t cycles
)
103 if (!doQuiesce
|| cycles
== 0)
106 EndQuiesceEvent
*quiesceEvent
= tc
->getQuiesceEvent();
108 if (quiesceEvent
->scheduled())
109 quiesceEvent
->reschedule(curTick
+
110 tc
->getCpuPtr()->cycles(cycles
));
112 quiesceEvent
->schedule(curTick
+
113 tc
->getCpuPtr()->cycles(cycles
));
116 if (tc
->getKernelStats())
117 tc
->getKernelStats()->quiesce();
121 quiesceTime(ThreadContext
*tc
)
123 return (tc
->readLastActivate() - tc
->readLastSuspend()) / Clock::Int::ns
;
127 ivlb(ThreadContext
*tc
)
129 if (tc
->getKernelStats())
130 tc
->getKernelStats()->ivlb();
134 ivle(ThreadContext
*tc
)
139 m5exit_old(ThreadContext
*tc
)
141 exitSimLoop("m5_exit_old instruction encountered");
145 m5exit(ThreadContext
*tc
, Tick delay
)
147 Tick when
= curTick
+ delay
* Clock::Int::ns
;
148 schedExitSimLoop("m5_exit instruction encountered", when
);
152 loadsymbol(ThreadContext
*tc
)
154 const string
&filename
= tc
->getCpuPtr()->system
->params()->symbolfile
;
155 if (filename
.empty()) {
160 ifstream
file(filename
.c_str());
163 fatal("file error: Can't open symbol table file %s\n", filename
);
165 while (!file
.eof()) {
166 getline(file
, buffer
);
171 int idx
= buffer
.find(' ');
172 if (idx
== string::npos
)
175 string address
= "0x" + buffer
.substr(0, idx
);
180 // Skip over letter and space
181 string symbol
= buffer
.substr(idx
+ 3);
187 if (!to_number(address
, addr
))
190 if (!tc
->getSystemPtr()->kernelSymtab
->insert(addr
, symbol
))
194 DPRINTF(Loader
, "Loaded symbol: %s @ %#llx\n", symbol
, addr
);
200 resetstats(ThreadContext
*tc
, Tick delay
, Tick period
)
202 if (!doStatisticsInsts
)
206 Tick when
= curTick
+ delay
* Clock::Int::ns
;
207 Tick repeat
= period
* Clock::Int::ns
;
209 using namespace Stats
;
210 SetupEvent(Reset
, when
, repeat
);
214 dumpstats(ThreadContext
*tc
, Tick delay
, Tick period
)
216 if (!doStatisticsInsts
)
220 Tick when
= curTick
+ delay
* Clock::Int::ns
;
221 Tick repeat
= period
* Clock::Int::ns
;
223 using namespace Stats
;
224 SetupEvent(Dump
, when
, repeat
);
228 addsymbol(ThreadContext
*tc
, Addr addr
, Addr symbolAddr
)
231 CopyStringOut(tc
, symb
, symbolAddr
, 100);
232 std::string
symbol(symb
);
234 DPRINTF(Loader
, "Loaded symbol: %s @ %#llx\n", symbol
, addr
);
236 tc
->getSystemPtr()->kernelSymtab
->insert(addr
,symbol
);
240 anBegin(ThreadContext
*tc
, uint64_t cur
)
242 Annotate::annotations
.add(tc
->getSystemPtr(), 0, cur
>> 32, cur
&
247 anWait(ThreadContext
*tc
, uint64_t cur
, uint64_t wait
)
249 Annotate::annotations
.add(tc
->getSystemPtr(), 0, cur
>> 32, cur
&
250 0xFFFFFFFF, wait
>> 32, wait
& 0xFFFFFFFF);
255 dumpresetstats(ThreadContext
*tc
, Tick delay
, Tick period
)
257 if (!doStatisticsInsts
)
261 Tick when
= curTick
+ delay
* Clock::Int::ns
;
262 Tick repeat
= period
* Clock::Int::ns
;
264 using namespace Stats
;
265 SetupEvent(Dump
|Reset
, when
, repeat
);
269 m5checkpoint(ThreadContext
*tc
, Tick delay
, Tick period
)
271 if (!doCheckpointInsts
)
274 Tick when
= curTick
+ delay
* Clock::Int::ns
;
275 Tick repeat
= period
* Clock::Int::ns
;
277 schedExitSimLoop("checkpoint", when
, repeat
);
281 readfile(ThreadContext
*tc
, Addr vaddr
, uint64_t len
, uint64_t offset
)
283 const string
&file
= tc
->getCpuPtr()->system
->params()->readfile
;
290 int fd
= ::open(file
.c_str(), O_RDONLY
, 0);
292 panic("could not open file %s\n", file
);
294 if (::lseek(fd
, offset
, SEEK_SET
) < 0)
295 panic("could not seek: %s", strerror(errno
));
297 char *buf
= new char[len
];
300 int bytes
= ::read(fd
, p
, len
);
310 CopyIn(tc
, vaddr
, buf
, result
);
315 class Context
: public ParamContext
318 Context(const string
§ion
) : ParamContext(section
) {}
322 Context
context("pseudo_inst");
324 Param
<bool> __quiesce(&context
, "quiesce",
325 "enable quiesce instructions",
327 Param
<bool> __statistics(&context
, "statistics",
328 "enable statistics pseudo instructions",
330 Param
<bool> __checkpoint(&context
, "checkpoint",
331 "enable checkpoint pseudo instructions",
335 Context::checkParams()
337 doQuiesce
= __quiesce
;
338 doStatisticsInsts
= __statistics
;
339 doCheckpointInsts
= __checkpoint
;
342 void debugbreak(ThreadContext
*tc
)
347 void switchcpu(ThreadContext
*tc
)
349 exitSimLoop("switchcpu");