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
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 "arch/kernel_stats.hh"
44 #include "sim/pseudo_inst.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
;
61 arm(ThreadContext
*tc
)
63 if (tc
->getKernelStats())
64 tc
->getKernelStats()->arm();
68 quiesce(ThreadContext
*tc
)
70 if (!tc
->getCpuPtr()->params
->do_quiesce
)
73 DPRINTF(Quiesce
, "%s: quiesce()\n", tc
->getCpuPtr()->name());
76 if (tc
->getKernelStats())
77 tc
->getKernelStats()->quiesce();
81 quiesceNs(ThreadContext
*tc
, uint64_t ns
)
83 if (!tc
->getCpuPtr()->params
->do_quiesce
|| ns
== 0)
86 EndQuiesceEvent
*quiesceEvent
= tc
->getQuiesceEvent();
88 Tick resume
= curTick
+ Clock::Int::ns
* ns
;
90 if (quiesceEvent
->scheduled())
91 quiesceEvent
->reschedule(resume
);
93 quiesceEvent
->schedule(resume
);
95 DPRINTF(Quiesce
, "%s: quiesceNs(%d) until %d\n",
96 tc
->getCpuPtr()->name(), ns
, resume
);
99 if (tc
->getKernelStats())
100 tc
->getKernelStats()->quiesce();
104 quiesceCycles(ThreadContext
*tc
, uint64_t cycles
)
106 if (!tc
->getCpuPtr()->params
->do_quiesce
|| cycles
== 0)
109 EndQuiesceEvent
*quiesceEvent
= tc
->getQuiesceEvent();
111 Tick resume
= curTick
+ tc
->getCpuPtr()->cycles(cycles
);
113 if (quiesceEvent
->scheduled())
114 quiesceEvent
->reschedule(resume
);
116 quiesceEvent
->schedule(resume
);
118 DPRINTF(Quiesce
, "%s: quiesceCycles(%d) until %d\n",
119 tc
->getCpuPtr()->name(), cycles
, resume
);
122 if (tc
->getKernelStats())
123 tc
->getKernelStats()->quiesce();
127 quiesceTime(ThreadContext
*tc
)
129 return (tc
->readLastActivate() - tc
->readLastSuspend()) / Clock::Int::ns
;
133 m5exit_old(ThreadContext
*tc
)
135 exitSimLoop("m5_exit_old instruction encountered");
139 m5exit(ThreadContext
*tc
, Tick delay
)
141 Tick when
= curTick
+ delay
* Clock::Int::ns
;
142 schedExitSimLoop("m5_exit instruction encountered", when
);
146 loadsymbol(ThreadContext
*tc
)
148 const string
&filename
= tc
->getCpuPtr()->system
->params()->symbolfile
;
149 if (filename
.empty()) {
154 ifstream
file(filename
.c_str());
157 fatal("file error: Can't open symbol table file %s\n", filename
);
159 while (!file
.eof()) {
160 getline(file
, buffer
);
165 int idx
= buffer
.find(' ');
166 if (idx
== string::npos
)
169 string address
= "0x" + buffer
.substr(0, idx
);
174 // Skip over letter and space
175 string symbol
= buffer
.substr(idx
+ 3);
181 if (!to_number(address
, addr
))
184 if (!tc
->getSystemPtr()->kernelSymtab
->insert(addr
, symbol
))
188 DPRINTF(Loader
, "Loaded symbol: %s @ %#llx\n", symbol
, addr
);
194 resetstats(ThreadContext
*tc
, Tick delay
, Tick period
)
196 if (!tc
->getCpuPtr()->params
->do_statistics_insts
)
200 Tick when
= curTick
+ delay
* Clock::Int::ns
;
201 Tick repeat
= period
* Clock::Int::ns
;
203 Stats::StatEvent(false, true, 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 Stats::StatEvent(true, false, when
, repeat
);
220 addsymbol(ThreadContext
*tc
, Addr addr
, Addr symbolAddr
)
223 CopyStringOut(tc
, symb
, symbolAddr
, 100);
224 std::string
symbol(symb
);
226 DPRINTF(Loader
, "Loaded symbol: %s @ %#llx\n", symbol
, addr
);
228 tc
->getSystemPtr()->kernelSymtab
->insert(addr
,symbol
);
232 anBegin(ThreadContext
*tc
, uint64_t cur
)
234 Annotate::annotations
.add(tc
->getSystemPtr(), 0, cur
>> 32, cur
&
239 anWait(ThreadContext
*tc
, uint64_t cur
, uint64_t wait
)
241 Annotate::annotations
.add(tc
->getSystemPtr(), 0, cur
>> 32, cur
&
242 0xFFFFFFFF, wait
>> 32, wait
& 0xFFFFFFFF);
247 dumpresetstats(ThreadContext
*tc
, Tick delay
, Tick period
)
249 if (!tc
->getCpuPtr()->params
->do_statistics_insts
)
253 Tick when
= curTick
+ delay
* Clock::Int::ns
;
254 Tick repeat
= period
* Clock::Int::ns
;
256 Stats::StatEvent(true, true, when
, repeat
);
260 m5checkpoint(ThreadContext
*tc
, Tick delay
, Tick period
)
262 if (!tc
->getCpuPtr()->params
->do_checkpoint_insts
)
265 Tick when
= curTick
+ delay
* Clock::Int::ns
;
266 Tick repeat
= period
* Clock::Int::ns
;
268 schedExitSimLoop("checkpoint", when
, repeat
);
272 readfile(ThreadContext
*tc
, Addr vaddr
, uint64_t len
, uint64_t offset
)
274 const string
&file
= tc
->getSystemPtr()->params()->readfile
;
281 int fd
= ::open(file
.c_str(), O_RDONLY
, 0);
283 panic("could not open file %s\n", file
);
285 if (::lseek(fd
, offset
, SEEK_SET
) < 0)
286 panic("could not seek: %s", strerror(errno
));
288 char *buf
= new char[len
];
291 int bytes
= ::read(fd
, p
, len
);
301 CopyIn(tc
, vaddr
, buf
, result
);
306 void debugbreak(ThreadContext
*tc
)
311 void switchcpu(ThreadContext
*tc
)
313 exitSimLoop("switchcpu");