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 "arch/vtophys.hh"
38 #include "base/annotate.hh"
39 #include "cpu/base.hh"
40 #include "cpu/thread_context.hh"
41 #include "cpu/quiesce_event.hh"
42 #include "arch/kernel_stats.hh"
43 #include "sim/pseudo_inst.hh"
44 #include "sim/serialize.hh"
45 #include "sim/sim_exit.hh"
46 #include "sim/stat_control.hh"
47 #include "sim/stats.hh"
48 #include "sim/system.hh"
49 #include "sim/debug.hh"
50 #include "sim/vptr.hh"
54 using namespace Stats
;
55 using namespace TheISA
;
60 arm(ThreadContext
*tc
)
62 if (tc
->getKernelStats())
63 tc
->getKernelStats()->arm();
67 quiesce(ThreadContext
*tc
)
69 if (!tc
->getCpuPtr()->params
->do_quiesce
)
72 DPRINTF(Quiesce
, "%s: quiesce()\n", tc
->getCpuPtr()->name());
75 if (tc
->getKernelStats())
76 tc
->getKernelStats()->quiesce();
80 quiesceNs(ThreadContext
*tc
, uint64_t ns
)
82 if (!tc
->getCpuPtr()->params
->do_quiesce
|| ns
== 0)
85 EndQuiesceEvent
*quiesceEvent
= tc
->getQuiesceEvent();
87 Tick resume
= curTick
+ Clock::Int::ns
* ns
;
89 if (quiesceEvent
->scheduled())
90 quiesceEvent
->reschedule(resume
);
92 quiesceEvent
->schedule(resume
);
94 DPRINTF(Quiesce
, "%s: quiesceNs(%d) until %d\n",
95 tc
->getCpuPtr()->name(), ns
, resume
);
98 if (tc
->getKernelStats())
99 tc
->getKernelStats()->quiesce();
103 quiesceCycles(ThreadContext
*tc
, uint64_t cycles
)
105 if (!tc
->getCpuPtr()->params
->do_quiesce
|| cycles
== 0)
108 EndQuiesceEvent
*quiesceEvent
= tc
->getQuiesceEvent();
110 Tick resume
= curTick
+ tc
->getCpuPtr()->cycles(cycles
);
112 if (quiesceEvent
->scheduled())
113 quiesceEvent
->reschedule(resume
);
115 quiesceEvent
->schedule(resume
);
117 DPRINTF(Quiesce
, "%s: quiesceCycles(%d) until %d\n",
118 tc
->getCpuPtr()->name(), cycles
, resume
);
121 if (tc
->getKernelStats())
122 tc
->getKernelStats()->quiesce();
126 quiesceTime(ThreadContext
*tc
)
128 return (tc
->readLastActivate() - tc
->readLastSuspend()) / Clock::Int::ns
;
132 m5exit_old(ThreadContext
*tc
)
134 exitSimLoop("m5_exit_old instruction encountered");
138 m5exit(ThreadContext
*tc
, Tick delay
)
140 Tick when
= curTick
+ delay
* Clock::Int::ns
;
141 schedExitSimLoop("m5_exit instruction encountered", when
);
145 loadsymbol(ThreadContext
*tc
)
147 const string
&filename
= tc
->getCpuPtr()->system
->params()->symbolfile
;
148 if (filename
.empty()) {
153 ifstream
file(filename
.c_str());
156 fatal("file error: Can't open symbol table file %s\n", filename
);
158 while (!file
.eof()) {
159 getline(file
, buffer
);
164 int idx
= buffer
.find(' ');
165 if (idx
== string::npos
)
168 string address
= "0x" + buffer
.substr(0, idx
);
173 // Skip over letter and space
174 string symbol
= buffer
.substr(idx
+ 3);
180 if (!to_number(address
, addr
))
183 if (!tc
->getSystemPtr()->kernelSymtab
->insert(addr
, symbol
))
187 DPRINTF(Loader
, "Loaded symbol: %s @ %#llx\n", symbol
, addr
);
193 resetstats(ThreadContext
*tc
, Tick delay
, Tick period
)
195 if (!tc
->getCpuPtr()->params
->do_statistics_insts
)
199 Tick when
= curTick
+ delay
* Clock::Int::ns
;
200 Tick repeat
= period
* Clock::Int::ns
;
202 using namespace Stats
;
203 SetupEvent(Reset
, when
, repeat
);
207 dumpstats(ThreadContext
*tc
, Tick delay
, Tick period
)
209 if (!tc
->getCpuPtr()->params
->do_statistics_insts
)
213 Tick when
= curTick
+ delay
* Clock::Int::ns
;
214 Tick repeat
= period
* Clock::Int::ns
;
216 using namespace Stats
;
217 SetupEvent(Dump
, when
, repeat
);
221 addsymbol(ThreadContext
*tc
, Addr addr
, Addr symbolAddr
)
224 CopyStringOut(tc
, symb
, symbolAddr
, 100);
225 std::string
symbol(symb
);
227 DPRINTF(Loader
, "Loaded symbol: %s @ %#llx\n", symbol
, addr
);
229 tc
->getSystemPtr()->kernelSymtab
->insert(addr
,symbol
);
233 anBegin(ThreadContext
*tc
, uint64_t cur
)
235 Annotate::annotations
.add(tc
->getSystemPtr(), 0, cur
>> 32, cur
&
240 anWait(ThreadContext
*tc
, uint64_t cur
, uint64_t wait
)
242 Annotate::annotations
.add(tc
->getSystemPtr(), 0, cur
>> 32, cur
&
243 0xFFFFFFFF, wait
>> 32, wait
& 0xFFFFFFFF);
248 dumpresetstats(ThreadContext
*tc
, Tick delay
, Tick period
)
250 if (!tc
->getCpuPtr()->params
->do_statistics_insts
)
254 Tick when
= curTick
+ delay
* Clock::Int::ns
;
255 Tick repeat
= period
* Clock::Int::ns
;
257 using namespace Stats
;
258 SetupEvent(Dump
|Reset
, when
, repeat
);
262 m5checkpoint(ThreadContext
*tc
, Tick delay
, Tick period
)
264 if (!tc
->getCpuPtr()->params
->do_checkpoint_insts
)
267 Tick when
= curTick
+ delay
* Clock::Int::ns
;
268 Tick repeat
= period
* Clock::Int::ns
;
270 schedExitSimLoop("checkpoint", when
, repeat
);
274 readfile(ThreadContext
*tc
, Addr vaddr
, uint64_t len
, uint64_t offset
)
276 const string
&file
= tc
->getSystemPtr()->params()->readfile
;
283 int fd
= ::open(file
.c_str(), O_RDONLY
, 0);
285 panic("could not open file %s\n", file
);
287 if (::lseek(fd
, offset
, SEEK_SET
) < 0)
288 panic("could not seek: %s", strerror(errno
));
290 char *buf
= new char[len
];
293 int bytes
= ::read(fd
, p
, len
);
303 CopyIn(tc
, vaddr
, buf
, result
);
308 void debugbreak(ThreadContext
*tc
)
313 void switchcpu(ThreadContext
*tc
)
315 exitSimLoop("switchcpu");