pseudo_inst.cc (5100:7a0180040755) pseudo_inst.cc (5504:288b54c2fd8d)
1/*
2 * Copyright (c) 2003-2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 41 unchanged lines hidden (view full) ---

50#include "sim/debug.hh"
51#include "sim/vptr.hh"
52
53using namespace std;
54
55using namespace Stats;
56using namespace TheISA;
57
1/*
2 * Copyright (c) 2003-2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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;

--- 41 unchanged lines hidden (view full) ---

50#include "sim/debug.hh"
51#include "sim/vptr.hh"
52
53using namespace std;
54
55using namespace Stats;
56using namespace TheISA;
57
58namespace PseudoInst
58namespace PseudoInst {
59
60void
61arm(ThreadContext *tc)
59{
62{
60 void
61 arm(ThreadContext *tc)
62 {
63 if (tc->getKernelStats())
64 tc->getKernelStats()->arm();
65 }
63 if (tc->getKernelStats())
64 tc->getKernelStats()->arm();
65}
66
66
67 void
68 quiesce(ThreadContext *tc)
69 {
70 if (!tc->getCpuPtr()->params->do_quiesce)
71 return;
67void
68quiesce(ThreadContext *tc)
69{
70 if (!tc->getCpuPtr()->params->do_quiesce)
71 return;
72
72
73 DPRINTF(Quiesce, "%s: quiesce()\n", tc->getCpuPtr()->name());
73 DPRINTF(Quiesce, "%s: quiesce()\n", tc->getCpuPtr()->name());
74
74
75 tc->suspend();
76 if (tc->getKernelStats())
77 tc->getKernelStats()->quiesce();
78 }
75 tc->suspend();
76 if (tc->getKernelStats())
77 tc->getKernelStats()->quiesce();
78}
79
79
80 void
81 quiesceNs(ThreadContext *tc, uint64_t ns)
82 {
83 if (!tc->getCpuPtr()->params->do_quiesce || ns == 0)
84 return;
80void
81quiesceNs(ThreadContext *tc, uint64_t ns)
82{
83 if (!tc->getCpuPtr()->params->do_quiesce || ns == 0)
84 return;
85
85
86 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent();
86 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent();
87
87
88 Tick resume = curTick + Clock::Int::ns * ns;
88 Tick resume = curTick + Clock::Int::ns * ns;
89
89
90 quiesceEvent->reschedule(resume, true);
90 quiesceEvent->reschedule(resume, true);
91
91
92 DPRINTF(Quiesce, "%s: quiesceNs(%d) until %d\n",
93 tc->getCpuPtr()->name(), ns, resume);
92 DPRINTF(Quiesce, "%s: quiesceNs(%d) until %d\n",
93 tc->getCpuPtr()->name(), ns, resume);
94
94
95 tc->suspend();
96 if (tc->getKernelStats())
97 tc->getKernelStats()->quiesce();
98 }
95 tc->suspend();
96 if (tc->getKernelStats())
97 tc->getKernelStats()->quiesce();
98}
99
99
100 void
101 quiesceCycles(ThreadContext *tc, uint64_t cycles)
102 {
103 if (!tc->getCpuPtr()->params->do_quiesce || cycles == 0)
104 return;
100void
101quiesceCycles(ThreadContext *tc, uint64_t cycles)
102{
103 if (!tc->getCpuPtr()->params->do_quiesce || cycles == 0)
104 return;
105
105
106 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent();
106 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent();
107
107
108 Tick resume = curTick + tc->getCpuPtr()->ticks(cycles);
108 Tick resume = curTick + tc->getCpuPtr()->ticks(cycles);
109
109
110 quiesceEvent->reschedule(resume, true);
110 quiesceEvent->reschedule(resume, true);
111
111
112 DPRINTF(Quiesce, "%s: quiesceCycles(%d) until %d\n",
113 tc->getCpuPtr()->name(), cycles, resume);
112 DPRINTF(Quiesce, "%s: quiesceCycles(%d) until %d\n",
113 tc->getCpuPtr()->name(), cycles, resume);
114
114
115 tc->suspend();
116 if (tc->getKernelStats())
117 tc->getKernelStats()->quiesce();
118 }
115 tc->suspend();
116 if (tc->getKernelStats())
117 tc->getKernelStats()->quiesce();
118}
119
119
120 uint64_t
121 quiesceTime(ThreadContext *tc)
122 {
123 return (tc->readLastActivate() - tc->readLastSuspend()) / Clock::Int::ns;
124 }
120uint64_t
121quiesceTime(ThreadContext *tc)
122{
123 return (tc->readLastActivate() - tc->readLastSuspend()) / Clock::Int::ns;
124}
125
125
126 void
127 m5exit_old(ThreadContext *tc)
128 {
129 exitSimLoop("m5_exit_old instruction encountered");
130 }
126void
127m5exit_old(ThreadContext *tc)
128{
129 exitSimLoop("m5_exit_old instruction encountered");
130}
131
131
132 void
133 m5exit(ThreadContext *tc, Tick delay)
134 {
135 Tick when = curTick + delay * Clock::Int::ns;
136 schedExitSimLoop("m5_exit instruction encountered", when);
132void
133m5exit(ThreadContext *tc, Tick delay)
134{
135 Tick when = curTick + delay * Clock::Int::ns;
136 schedExitSimLoop("m5_exit instruction encountered", when);
137}
138
139void
140loadsymbol(ThreadContext *tc)
141{
142 const string &filename = tc->getCpuPtr()->system->params()->symbolfile;
143 if (filename.empty()) {
144 return;
137 }
138
145 }
146
139 void
140 loadsymbol(ThreadContext *tc)
141 {
142 const string &filename = tc->getCpuPtr()->system->params()->symbolfile;
143 if (filename.empty()) {
144 return;
145 }
147 std::string buffer;
148 ifstream file(filename.c_str());
146
149
147 std::string buffer;
148 ifstream file(filename.c_str());
150 if (!file)
151 fatal("file error: Can't open symbol table file %s\n", filename);
149
152
150 if (!file)
151 fatal("file error: Can't open symbol table file %s\n", filename);
153 while (!file.eof()) {
154 getline(file, buffer);
152
155
153 while (!file.eof()) {
154 getline(file, buffer);
156 if (buffer.empty())
157 continue;
155
158
156 if (buffer.empty())
157 continue;
159 int idx = buffer.find(' ');
160 if (idx == string::npos)
161 continue;
158
162
159 int idx = buffer.find(' ');
160 if (idx == string::npos)
161 continue;
163 string address = "0x" + buffer.substr(0, idx);
164 eat_white(address);
165 if (address.empty())
166 continue;
162
167
163 string address = "0x" + buffer.substr(0, idx);
164 eat_white(address);
165 if (address.empty())
166 continue;
168 // Skip over letter and space
169 string symbol = buffer.substr(idx + 3);
170 eat_white(symbol);
171 if (symbol.empty())
172 continue;
167
173
168 // Skip over letter and space
169 string symbol = buffer.substr(idx + 3);
170 eat_white(symbol);
171 if (symbol.empty())
172 continue;
174 Addr addr;
175 if (!to_number(address, addr))
176 continue;
173
177
174 Addr addr;
175 if (!to_number(address, addr))
176 continue;
178 if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol))
179 continue;
177
180
178 if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol))
179 continue;
180
181
181
182 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
183 }
184 file.close();
182 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
185 }
183 }
184 file.close();
185}
186
186
187 void
188 resetstats(ThreadContext *tc, Tick delay, Tick period)
189 {
190 if (!tc->getCpuPtr()->params->do_statistics_insts)
191 return;
187void
188resetstats(ThreadContext *tc, Tick delay, Tick period)
189{
190 if (!tc->getCpuPtr()->params->do_statistics_insts)
191 return;
192
193
192
193
194 Tick when = curTick + delay * Clock::Int::ns;
195 Tick repeat = period * Clock::Int::ns;
194 Tick when = curTick + delay * Clock::Int::ns;
195 Tick repeat = period * Clock::Int::ns;
196
196
197 Stats::StatEvent(false, true, when, repeat);
198 }
197 Stats::StatEvent(false, true, when, repeat);
198}
199
199
200 void
201 dumpstats(ThreadContext *tc, Tick delay, Tick period)
202 {
203 if (!tc->getCpuPtr()->params->do_statistics_insts)
204 return;
200void
201dumpstats(ThreadContext *tc, Tick delay, Tick period)
202{
203 if (!tc->getCpuPtr()->params->do_statistics_insts)
204 return;
205
206
205
206
207 Tick when = curTick + delay * Clock::Int::ns;
208 Tick repeat = period * Clock::Int::ns;
207 Tick when = curTick + delay * Clock::Int::ns;
208 Tick repeat = period * Clock::Int::ns;
209
209
210 Stats::StatEvent(true, false, when, repeat);
211 }
210 Stats::StatEvent(true, false, when, repeat);
211}
212
212
213 void
214 addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr)
215 {
216 char symb[100];
217 CopyStringOut(tc, symb, symbolAddr, 100);
218 std::string symbol(symb);
213void
214addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr)
215{
216 char symb[100];
217 CopyStringOut(tc, symb, symbolAddr, 100);
218 std::string symbol(symb);
219
219
220 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
220 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
221
221
222 tc->getSystemPtr()->kernelSymtab->insert(addr,symbol);
223 }
222 tc->getSystemPtr()->kernelSymtab->insert(addr,symbol);
223}
224
224
225 void
226 anBegin(ThreadContext *tc, uint64_t cur)
227 {
228 Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur &
229 0xFFFFFFFF, 0,0);
230 }
225void
226anBegin(ThreadContext *tc, uint64_t cur)
227{
228 Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur &
229 0xFFFFFFFF, 0,0);
230}
231
231
232 void
233 anWait(ThreadContext *tc, uint64_t cur, uint64_t wait)
234 {
235 Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur &
236 0xFFFFFFFF, wait >> 32, wait & 0xFFFFFFFF);
237 }
232void
233anWait(ThreadContext *tc, uint64_t cur, uint64_t wait)
234{
235 Annotate::annotations.add(tc->getSystemPtr(), 0, cur >> 32, cur &
236 0xFFFFFFFF, wait >> 32, wait & 0xFFFFFFFF);
237}
238
239
238
239
240 void
241 dumpresetstats(ThreadContext *tc, Tick delay, Tick period)
242 {
243 if (!tc->getCpuPtr()->params->do_statistics_insts)
244 return;
240void
241dumpresetstats(ThreadContext *tc, Tick delay, Tick period)
242{
243 if (!tc->getCpuPtr()->params->do_statistics_insts)
244 return;
245
246
245
246
247 Tick when = curTick + delay * Clock::Int::ns;
248 Tick repeat = period * Clock::Int::ns;
247 Tick when = curTick + delay * Clock::Int::ns;
248 Tick repeat = period * Clock::Int::ns;
249
249
250 Stats::StatEvent(true, true, when, repeat);
251 }
250 Stats::StatEvent(true, true, when, repeat);
251}
252
252
253 void
254 m5checkpoint(ThreadContext *tc, Tick delay, Tick period)
255 {
256 if (!tc->getCpuPtr()->params->do_checkpoint_insts)
257 return;
253void
254m5checkpoint(ThreadContext *tc, Tick delay, Tick period)
255{
256 if (!tc->getCpuPtr()->params->do_checkpoint_insts)
257 return;
258
258
259 Tick when = curTick + delay * Clock::Int::ns;
260 Tick repeat = period * Clock::Int::ns;
259 Tick when = curTick + delay * Clock::Int::ns;
260 Tick repeat = period * Clock::Int::ns;
261
261
262 schedExitSimLoop("checkpoint", when, repeat);
262 schedExitSimLoop("checkpoint", when, repeat);
263}
264
265uint64_t
266readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset)
267{
268 const string &file = tc->getSystemPtr()->params()->readfile;
269 if (file.empty()) {
270 return ULL(0);
263 }
264
271 }
272
265 uint64_t
266 readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset)
267 {
268 const string &file = tc->getSystemPtr()->params()->readfile;
269 if (file.empty()) {
270 return ULL(0);
271 }
273 uint64_t result = 0;
272
274
273 uint64_t result = 0;
275 int fd = ::open(file.c_str(), O_RDONLY, 0);
276 if (fd < 0)
277 panic("could not open file %s\n", file);
274
278
275 int fd = ::open(file.c_str(), O_RDONLY, 0);
276 if (fd < 0)
277 panic("could not open file %s\n", file);
279 if (::lseek(fd, offset, SEEK_SET) < 0)
280 panic("could not seek: %s", strerror(errno));
278
281
279 if (::lseek(fd, offset, SEEK_SET) < 0)
280 panic("could not seek: %s", strerror(errno));
282 char *buf = new char[len];
283 char *p = buf;
284 while (len > 0) {
285 int bytes = ::read(fd, p, len);
286 if (bytes <= 0)
287 break;
281
288
282 char *buf = new char[len];
283 char *p = buf;
284 while (len > 0) {
285 int bytes = ::read(fd, p, len);
286 if (bytes <= 0)
287 break;
288
289 p += bytes;
290 result += bytes;
291 len -= bytes;
292 }
293
294 close(fd);
295 CopyIn(tc, vaddr, buf, result);
296 delete [] buf;
297 return result;
289 p += bytes;
290 result += bytes;
291 len -= bytes;
298 }
299
292 }
293
300 void debugbreak(ThreadContext *tc)
301 {
302 debug_break();
303 }
294 close(fd);
295 CopyIn(tc, vaddr, buf, result);
296 delete [] buf;
297 return result;
298}
304
299
305 void switchcpu(ThreadContext *tc)
306 {
307 exitSimLoop("switchcpu");
308 }
300void
301debugbreak(ThreadContext *tc)
302{
303 debug_break();
309}
304}
305
306void
307switchcpu(ThreadContext *tc)
308{
309 exitSimLoop("switchcpu");
310}
311
312/* namespace PseudoInst */ }