process.cc (10913:38dbdeea7f1f) process.cc (10929:b2bbfec74eca)
1/*
2 * Copyright (c) 2014 Advanced Micro Devices, Inc.
3 * Copyright (c) 2012 ARM Limited
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2001-2005 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Nathan Binkert
42 * Steve Reinhardt
43 * Ali Saidi
44 */
45
46#include <fcntl.h>
47#include <unistd.h>
48
49#include <cstdio>
50#include <string>
51
52#include "base/loader/object_file.hh"
53#include "base/loader/symtab.hh"
54#include "base/intmath.hh"
55#include "base/statistics.hh"
56#include "config/the_isa.hh"
57#include "cpu/thread_context.hh"
58#include "mem/page_table.hh"
59#include "mem/multi_level_page_table.hh"
60#include "mem/se_translating_port_proxy.hh"
61#include "params/LiveProcess.hh"
62#include "params/Process.hh"
63#include "sim/debug.hh"
64#include "sim/process.hh"
65#include "sim/process_impl.hh"
66#include "sim/stats.hh"
67#include "sim/syscall_emul.hh"
68#include "sim/system.hh"
69
70#if THE_ISA == ALPHA_ISA
71#include "arch/alpha/linux/process.hh"
72#include "arch/alpha/tru64/process.hh"
73#elif THE_ISA == SPARC_ISA
74#include "arch/sparc/linux/process.hh"
75#include "arch/sparc/solaris/process.hh"
76#elif THE_ISA == MIPS_ISA
77#include "arch/mips/linux/process.hh"
78#elif THE_ISA == ARM_ISA
79#include "arch/arm/linux/process.hh"
80#include "arch/arm/freebsd/process.hh"
81#elif THE_ISA == X86_ISA
82#include "arch/x86/linux/process.hh"
83#elif THE_ISA == POWER_ISA
84#include "arch/power/linux/process.hh"
85#else
86#error "THE_ISA not set"
87#endif
88
89
90using namespace std;
91using namespace TheISA;
92
93// current number of allocated processes
94int num_processes = 0;
95
96template<class IntType>
97AuxVector<IntType>::AuxVector(IntType type, IntType val)
98{
99 a_type = TheISA::htog(type);
100 a_val = TheISA::htog(val);
101}
102
103template struct AuxVector<uint32_t>;
104template struct AuxVector<uint64_t>;
105
106Process::Process(ProcessParams * params)
107 : SimObject(params), system(params->system),
108 brk_point(0), stack_base(0), stack_size(0), stack_min(0),
109 max_stack_size(params->max_stack_size),
110 next_thread_stack_base(0),
111 M5_pid(system->allocatePID()),
112 useArchPT(params->useArchPT),
113 kvmInSE(params->kvmInSE),
114 pTable(useArchPT ?
115 static_cast<PageTableBase *>(new ArchPageTable(name(), M5_pid, system)) :
116 static_cast<PageTableBase *>(new FuncPageTable(name(), M5_pid)) ),
117 initVirtMem(system->getSystemPort(), this,
1/*
2 * Copyright (c) 2014 Advanced Micro Devices, Inc.
3 * Copyright (c) 2012 ARM Limited
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2001-2005 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Authors: Nathan Binkert
42 * Steve Reinhardt
43 * Ali Saidi
44 */
45
46#include <fcntl.h>
47#include <unistd.h>
48
49#include <cstdio>
50#include <string>
51
52#include "base/loader/object_file.hh"
53#include "base/loader/symtab.hh"
54#include "base/intmath.hh"
55#include "base/statistics.hh"
56#include "config/the_isa.hh"
57#include "cpu/thread_context.hh"
58#include "mem/page_table.hh"
59#include "mem/multi_level_page_table.hh"
60#include "mem/se_translating_port_proxy.hh"
61#include "params/LiveProcess.hh"
62#include "params/Process.hh"
63#include "sim/debug.hh"
64#include "sim/process.hh"
65#include "sim/process_impl.hh"
66#include "sim/stats.hh"
67#include "sim/syscall_emul.hh"
68#include "sim/system.hh"
69
70#if THE_ISA == ALPHA_ISA
71#include "arch/alpha/linux/process.hh"
72#include "arch/alpha/tru64/process.hh"
73#elif THE_ISA == SPARC_ISA
74#include "arch/sparc/linux/process.hh"
75#include "arch/sparc/solaris/process.hh"
76#elif THE_ISA == MIPS_ISA
77#include "arch/mips/linux/process.hh"
78#elif THE_ISA == ARM_ISA
79#include "arch/arm/linux/process.hh"
80#include "arch/arm/freebsd/process.hh"
81#elif THE_ISA == X86_ISA
82#include "arch/x86/linux/process.hh"
83#elif THE_ISA == POWER_ISA
84#include "arch/power/linux/process.hh"
85#else
86#error "THE_ISA not set"
87#endif
88
89
90using namespace std;
91using namespace TheISA;
92
93// current number of allocated processes
94int num_processes = 0;
95
96template<class IntType>
97AuxVector<IntType>::AuxVector(IntType type, IntType val)
98{
99 a_type = TheISA::htog(type);
100 a_val = TheISA::htog(val);
101}
102
103template struct AuxVector<uint32_t>;
104template struct AuxVector<uint64_t>;
105
106Process::Process(ProcessParams * params)
107 : SimObject(params), system(params->system),
108 brk_point(0), stack_base(0), stack_size(0), stack_min(0),
109 max_stack_size(params->max_stack_size),
110 next_thread_stack_base(0),
111 M5_pid(system->allocatePID()),
112 useArchPT(params->useArchPT),
113 kvmInSE(params->kvmInSE),
114 pTable(useArchPT ?
115 static_cast<PageTableBase *>(new ArchPageTable(name(), M5_pid, system)) :
116 static_cast<PageTableBase *>(new FuncPageTable(name(), M5_pid)) ),
117 initVirtMem(system->getSystemPort(), this,
118 SETranslatingPortProxy::Always)
118 SETranslatingPortProxy::Always),
119 fd_map(new FdMap[NUM_FDS])
119{
120 string in = params->input;
121 string out = params->output;
122 string err = params->errout;
123
124 // initialize file descriptors to default: same as simulator
125 int stdin_fd, stdout_fd, stderr_fd;
126
127 if (in == "stdin" || in == "cin")
128 stdin_fd = STDIN_FILENO;
129 else if (in == "None")
130 stdin_fd = -1;
131 else
132 stdin_fd = Process::openInputFile(in);
133
134 if (out == "stdout" || out == "cout")
135 stdout_fd = STDOUT_FILENO;
136 else if (out == "stderr" || out == "cerr")
137 stdout_fd = STDERR_FILENO;
138 else if (out == "None")
139 stdout_fd = -1;
140 else
141 stdout_fd = Process::openOutputFile(out);
142
143 if (err == "stdout" || err == "cout")
144 stderr_fd = STDOUT_FILENO;
145 else if (err == "stderr" || err == "cerr")
146 stderr_fd = STDERR_FILENO;
147 else if (err == "None")
148 stderr_fd = -1;
149 else if (err == out)
150 stderr_fd = stdout_fd;
151 else
152 stderr_fd = Process::openOutputFile(err);
153
154 // initialize first 3 fds (stdin, stdout, stderr)
155 Process::FdMap *fdo = &fd_map[STDIN_FILENO];
156 fdo->fd = stdin_fd;
157 fdo->filename = in;
158 fdo->flags = O_RDONLY;
159 fdo->mode = -1;
160 fdo->fileOffset = 0;
161
162 fdo = &fd_map[STDOUT_FILENO];
163 fdo->fd = stdout_fd;
164 fdo->filename = out;
165 fdo->flags = O_WRONLY | O_CREAT | O_TRUNC;
166 fdo->mode = 0774;
167 fdo->fileOffset = 0;
168
169 fdo = &fd_map[STDERR_FILENO];
170 fdo->fd = stderr_fd;
171 fdo->filename = err;
172 fdo->flags = O_WRONLY;
173 fdo->mode = -1;
174 fdo->fileOffset = 0;
175
176
177 // mark remaining fds as free
120{
121 string in = params->input;
122 string out = params->output;
123 string err = params->errout;
124
125 // initialize file descriptors to default: same as simulator
126 int stdin_fd, stdout_fd, stderr_fd;
127
128 if (in == "stdin" || in == "cin")
129 stdin_fd = STDIN_FILENO;
130 else if (in == "None")
131 stdin_fd = -1;
132 else
133 stdin_fd = Process::openInputFile(in);
134
135 if (out == "stdout" || out == "cout")
136 stdout_fd = STDOUT_FILENO;
137 else if (out == "stderr" || out == "cerr")
138 stdout_fd = STDERR_FILENO;
139 else if (out == "None")
140 stdout_fd = -1;
141 else
142 stdout_fd = Process::openOutputFile(out);
143
144 if (err == "stdout" || err == "cout")
145 stderr_fd = STDOUT_FILENO;
146 else if (err == "stderr" || err == "cerr")
147 stderr_fd = STDERR_FILENO;
148 else if (err == "None")
149 stderr_fd = -1;
150 else if (err == out)
151 stderr_fd = stdout_fd;
152 else
153 stderr_fd = Process::openOutputFile(err);
154
155 // initialize first 3 fds (stdin, stdout, stderr)
156 Process::FdMap *fdo = &fd_map[STDIN_FILENO];
157 fdo->fd = stdin_fd;
158 fdo->filename = in;
159 fdo->flags = O_RDONLY;
160 fdo->mode = -1;
161 fdo->fileOffset = 0;
162
163 fdo = &fd_map[STDOUT_FILENO];
164 fdo->fd = stdout_fd;
165 fdo->filename = out;
166 fdo->flags = O_WRONLY | O_CREAT | O_TRUNC;
167 fdo->mode = 0774;
168 fdo->fileOffset = 0;
169
170 fdo = &fd_map[STDERR_FILENO];
171 fdo->fd = stderr_fd;
172 fdo->filename = err;
173 fdo->flags = O_WRONLY;
174 fdo->mode = -1;
175 fdo->fileOffset = 0;
176
177
178 // mark remaining fds as free
178 for (int i = 3; i <= MAX_FD; ++i) {
179 for (int i = 3; i < NUM_FDS; ++i) {
179 fdo = &fd_map[i];
180 fdo->fd = -1;
181 }
182
183 mmap_start = mmap_end = 0;
184 nxm_start = nxm_end = 0;
185 // other parameters will be initialized when the program is loaded
186}
187
188
189void
190Process::regStats()
191{
192 using namespace Stats;
193
194 num_syscalls
195 .name(name() + ".num_syscalls")
196 .desc("Number of system calls")
197 ;
198}
199
200//
201// static helper functions
202//
180 fdo = &fd_map[i];
181 fdo->fd = -1;
182 }
183
184 mmap_start = mmap_end = 0;
185 nxm_start = nxm_end = 0;
186 // other parameters will be initialized when the program is loaded
187}
188
189
190void
191Process::regStats()
192{
193 using namespace Stats;
194
195 num_syscalls
196 .name(name() + ".num_syscalls")
197 .desc("Number of system calls")
198 ;
199}
200
201//
202// static helper functions
203//
204
203int
204Process::openInputFile(const string &filename)
205{
206 int fd = open(filename.c_str(), O_RDONLY);
207
208 if (fd == -1) {
209 perror(NULL);
210 cerr << "unable to open \"" << filename << "\" for reading\n";
211 fatal("can't open input file");
212 }
213
214 return fd;
215}
216
217
218int
219Process::openOutputFile(const string &filename)
220{
221 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0664);
222
223 if (fd == -1) {
224 perror(NULL);
225 cerr << "unable to open \"" << filename << "\" for writing\n";
226 fatal("can't open output file");
227 }
228
229 return fd;
230}
231
232ThreadContext *
233Process::findFreeContext()
234{
205int
206Process::openInputFile(const string &filename)
207{
208 int fd = open(filename.c_str(), O_RDONLY);
209
210 if (fd == -1) {
211 perror(NULL);
212 cerr << "unable to open \"" << filename << "\" for reading\n";
213 fatal("can't open input file");
214 }
215
216 return fd;
217}
218
219
220int
221Process::openOutputFile(const string &filename)
222{
223 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0664);
224
225 if (fd == -1) {
226 perror(NULL);
227 cerr << "unable to open \"" << filename << "\" for writing\n";
228 fatal("can't open output file");
229 }
230
231 return fd;
232}
233
234ThreadContext *
235Process::findFreeContext()
236{
235 int size = contextIds.size();
236 ThreadContext *tc;
237 for (int i = 0; i < size; ++i) {
238 tc = system->getThreadContext(contextIds[i]);
239 if (tc->status() == ThreadContext::Halted) {
240 // inactive context, free to use
237 for (int id : contextIds) {
238 ThreadContext *tc = system->getThreadContext(id);
239 if (tc->status() == ThreadContext::Halted)
241 return tc;
240 return tc;
242 }
243 }
244 return NULL;
245}
246
247void
248Process::initState()
249{
250 if (contextIds.empty())
251 fatal("Process %s is not associated with any HW contexts!\n", name());
252
253 // first thread context for this process... initialize & enable
254 ThreadContext *tc = system->getThreadContext(contextIds[0]);
255
256 // mark this context as active so it will start ticking.
257 tc->activate();
258
259 pTable->initState(tc);
260}
261
262DrainState
263Process::drain()
264{
265 find_file_offsets();
266 return DrainState::Drained;
267}
268
241 }
242 return NULL;
243}
244
245void
246Process::initState()
247{
248 if (contextIds.empty())
249 fatal("Process %s is not associated with any HW contexts!\n", name());
250
251 // first thread context for this process... initialize & enable
252 ThreadContext *tc = system->getThreadContext(contextIds[0]);
253
254 // mark this context as active so it will start ticking.
255 tc->activate();
256
257 pTable->initState(tc);
258}
259
260DrainState
261Process::drain()
262{
263 find_file_offsets();
264 return DrainState::Drained;
265}
266
269// map simulator fd sim_fd to target fd tgt_fd
270void
271Process::dup_fd(int sim_fd, int tgt_fd)
272{
273 if (tgt_fd < 0 || tgt_fd > MAX_FD)
274 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd);
275
276 Process::FdMap *fdo = &fd_map[tgt_fd];
277 fdo->fd = sim_fd;
278}
279
280
281// generate new target fd for sim_fd
282int
283Process::alloc_fd(int sim_fd, const string& filename, int flags, int mode,
284 bool pipe)
285{
286 // in case open() returns an error, don't allocate a new fd
287 if (sim_fd == -1)
288 return -1;
289
290 // find first free target fd
267int
268Process::alloc_fd(int sim_fd, const string& filename, int flags, int mode,
269 bool pipe)
270{
271 // in case open() returns an error, don't allocate a new fd
272 if (sim_fd == -1)
273 return -1;
274
275 // find first free target fd
291 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) {
276 for (int free_fd = 0; free_fd < NUM_FDS; ++free_fd) {
292 Process::FdMap *fdo = &fd_map[free_fd];
293 if (fdo->fd == -1 && fdo->driver == NULL) {
294 fdo->fd = sim_fd;
295 fdo->filename = filename;
296 fdo->mode = mode;
297 fdo->fileOffset = 0;
298 fdo->flags = flags;
299 fdo->isPipe = pipe;
300 fdo->readPipeSource = 0;
301 return free_fd;
302 }
303 }
304
305 panic("Process::alloc_fd: out of file descriptors!");
306}
307
277 Process::FdMap *fdo = &fd_map[free_fd];
278 if (fdo->fd == -1 && fdo->driver == NULL) {
279 fdo->fd = sim_fd;
280 fdo->filename = filename;
281 fdo->mode = mode;
282 fdo->fileOffset = 0;
283 fdo->flags = flags;
284 fdo->isPipe = pipe;
285 fdo->readPipeSource = 0;
286 return free_fd;
287 }
288 }
289
290 panic("Process::alloc_fd: out of file descriptors!");
291}
292
308
309// free target fd (e.g., after close)
310void
293void
311Process::free_fd(int tgt_fd)
294Process::free_fdmap_entry(int tgt_fd)
312{
313 Process::FdMap *fdo = &fd_map[tgt_fd];
295{
296 Process::FdMap *fdo = &fd_map[tgt_fd];
314 if (fdo->fd == -1)
315 warn("Process::free_fd: request to free unused fd %d", tgt_fd);
297 assert(fd_map[tgt_fd].fd > -1);
316
317 fdo->fd = -1;
318 fdo->filename = "NULL";
319 fdo->mode = 0;
320 fdo->fileOffset = 0;
321 fdo->flags = 0;
322 fdo->isPipe = false;
323 fdo->readPipeSource = 0;
324 fdo->driver = NULL;
325}
326
298
299 fdo->fd = -1;
300 fdo->filename = "NULL";
301 fdo->mode = 0;
302 fdo->fileOffset = 0;
303 fdo->flags = 0;
304 fdo->isPipe = false;
305 fdo->readPipeSource = 0;
306 fdo->driver = NULL;
307}
308
327
328// look up simulator fd for given target fd
329int
330Process::sim_fd(int tgt_fd)
331{
309int
310Process::sim_fd(int tgt_fd)
311{
332 if (tgt_fd < 0 || tgt_fd > MAX_FD)
333 return -1;
334
335 return fd_map[tgt_fd].fd;
312 FdMap *obj = sim_fd_obj(tgt_fd);
313 return obj ? obj->fd : -1;
336}
337
338Process::FdMap *
339Process::sim_fd_obj(int tgt_fd)
340{
314}
315
316Process::FdMap *
317Process::sim_fd_obj(int tgt_fd)
318{
341 if (tgt_fd < 0 || tgt_fd > MAX_FD)
319 if (tgt_fd < 0 || tgt_fd >= NUM_FDS)
342 return NULL;
320 return NULL;
343
344 return &fd_map[tgt_fd];
345}
346
321 return &fd_map[tgt_fd];
322}
323
324int
325Process::tgt_fd(int sim_fd)
326{
327 for (int index = 0; index < NUM_FDS; ++index)
328 if (fd_map[index].fd == sim_fd)
329 return index;
330 return -1;
331}
332
347void
348Process::allocateMem(Addr vaddr, int64_t size, bool clobber)
349{
350 int npages = divCeil(size, (int64_t)PageBytes);
351 Addr paddr = system->allocPhysPages(npages);
352 pTable->map(vaddr, paddr, size, clobber ? PageTableBase::Clobber : 0);
353}
354
355bool
356Process::fixupStackFault(Addr vaddr)
357{
358 // Check if this is already on the stack and there's just no page there
359 // yet.
360 if (vaddr >= stack_min && vaddr < stack_base) {
361 allocateMem(roundDown(vaddr, PageBytes), PageBytes);
362 return true;
363 }
364
365 // We've accessed the next page of the stack, so extend it to include
366 // this address.
367 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
368 while (vaddr < stack_min) {
369 stack_min -= TheISA::PageBytes;
370 if (stack_base - stack_min > max_stack_size)
371 fatal("Maximum stack size exceeded\n");
372 allocateMem(stack_min, TheISA::PageBytes);
373 inform("Increasing stack size by one page.");
374 };
375 return true;
376 }
377 return false;
378}
379
380// find all offsets for currently open files and save them
381void
382Process::fix_file_offsets()
383{
384 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO];
385 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO];
386 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO];
387 string in = fdo_stdin->filename;
388 string out = fdo_stdout->filename;
389 string err = fdo_stderr->filename;
390
391 // initialize file descriptors to default: same as simulator
392 int stdin_fd, stdout_fd, stderr_fd;
393
394 if (in == "stdin" || in == "cin")
395 stdin_fd = STDIN_FILENO;
396 else if (in == "NULL")
397 stdin_fd = -1;
398 else {
399 // open standard in and seek to the right location
400 stdin_fd = Process::openInputFile(in);
401 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0)
402 panic("Unable to seek to correct location in file: %s", in);
403 }
404
405 if (out == "stdout" || out == "cout")
406 stdout_fd = STDOUT_FILENO;
407 else if (out == "stderr" || out == "cerr")
408 stdout_fd = STDERR_FILENO;
409 else if (out == "NULL")
410 stdout_fd = -1;
411 else {
412 stdout_fd = Process::openOutputFile(out);
413 if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
414 panic("Unable to seek to correct location in file: %s", out);
415 }
416
417 if (err == "stdout" || err == "cout")
418 stderr_fd = STDOUT_FILENO;
419 else if (err == "stderr" || err == "cerr")
420 stderr_fd = STDERR_FILENO;
421 else if (err == "NULL")
422 stderr_fd = -1;
423 else if (err == out)
424 stderr_fd = stdout_fd;
425 else {
426 stderr_fd = Process::openOutputFile(err);
427 if (lseek(stderr_fd, fdo_stderr->fileOffset, SEEK_SET) < 0)
428 panic("Unable to seek to correct location in file: %s", err);
429 }
430
431 fdo_stdin->fd = stdin_fd;
432 fdo_stdout->fd = stdout_fd;
433 fdo_stderr->fd = stderr_fd;
434
435
333void
334Process::allocateMem(Addr vaddr, int64_t size, bool clobber)
335{
336 int npages = divCeil(size, (int64_t)PageBytes);
337 Addr paddr = system->allocPhysPages(npages);
338 pTable->map(vaddr, paddr, size, clobber ? PageTableBase::Clobber : 0);
339}
340
341bool
342Process::fixupStackFault(Addr vaddr)
343{
344 // Check if this is already on the stack and there's just no page there
345 // yet.
346 if (vaddr >= stack_min && vaddr < stack_base) {
347 allocateMem(roundDown(vaddr, PageBytes), PageBytes);
348 return true;
349 }
350
351 // We've accessed the next page of the stack, so extend it to include
352 // this address.
353 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
354 while (vaddr < stack_min) {
355 stack_min -= TheISA::PageBytes;
356 if (stack_base - stack_min > max_stack_size)
357 fatal("Maximum stack size exceeded\n");
358 allocateMem(stack_min, TheISA::PageBytes);
359 inform("Increasing stack size by one page.");
360 };
361 return true;
362 }
363 return false;
364}
365
366// find all offsets for currently open files and save them
367void
368Process::fix_file_offsets()
369{
370 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO];
371 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO];
372 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO];
373 string in = fdo_stdin->filename;
374 string out = fdo_stdout->filename;
375 string err = fdo_stderr->filename;
376
377 // initialize file descriptors to default: same as simulator
378 int stdin_fd, stdout_fd, stderr_fd;
379
380 if (in == "stdin" || in == "cin")
381 stdin_fd = STDIN_FILENO;
382 else if (in == "NULL")
383 stdin_fd = -1;
384 else {
385 // open standard in and seek to the right location
386 stdin_fd = Process::openInputFile(in);
387 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0)
388 panic("Unable to seek to correct location in file: %s", in);
389 }
390
391 if (out == "stdout" || out == "cout")
392 stdout_fd = STDOUT_FILENO;
393 else if (out == "stderr" || out == "cerr")
394 stdout_fd = STDERR_FILENO;
395 else if (out == "NULL")
396 stdout_fd = -1;
397 else {
398 stdout_fd = Process::openOutputFile(out);
399 if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
400 panic("Unable to seek to correct location in file: %s", out);
401 }
402
403 if (err == "stdout" || err == "cout")
404 stderr_fd = STDOUT_FILENO;
405 else if (err == "stderr" || err == "cerr")
406 stderr_fd = STDERR_FILENO;
407 else if (err == "NULL")
408 stderr_fd = -1;
409 else if (err == out)
410 stderr_fd = stdout_fd;
411 else {
412 stderr_fd = Process::openOutputFile(err);
413 if (lseek(stderr_fd, fdo_stderr->fileOffset, SEEK_SET) < 0)
414 panic("Unable to seek to correct location in file: %s", err);
415 }
416
417 fdo_stdin->fd = stdin_fd;
418 fdo_stdout->fd = stdout_fd;
419 fdo_stderr->fd = stderr_fd;
420
421
436 for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) {
422 for (int free_fd = 3; free_fd < NUM_FDS; ++free_fd) {
437 Process::FdMap *fdo = &fd_map[free_fd];
438 if (fdo->fd != -1) {
439 if (fdo->isPipe){
440 if (fdo->filename == "PIPE-WRITE")
441 continue;
442 else {
443 assert (fdo->filename == "PIPE-READ");
444 //create a new pipe
445 int fds[2];
446 int pipe_retval = pipe(fds);
447
448 if (pipe_retval < 0) {
449 // error
450 panic("Unable to create new pipe.");
451 }
452 fdo->fd = fds[0]; //set read pipe
453 Process::FdMap *fdo_write = &fd_map[fdo->readPipeSource];
454 if (fdo_write->filename != "PIPE-WRITE")
455 panic ("Couldn't find write end of the pipe");
456
457 fdo_write->fd = fds[1];//set write pipe
458 }
459 } else {
460 //Open file
461 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode);
462
463 if (fd == -1)
464 panic("Unable to open file: %s", fdo->filename);
465 fdo->fd = fd;
466
467 //Seek to correct location before checkpoint
468 if (lseek(fd, fdo->fileOffset, SEEK_SET) < 0)
469 panic("Unable to seek to correct location in file: %s",
470 fdo->filename);
471 }
472 }
473 }
474}
475
476void
477Process::find_file_offsets()
478{
423 Process::FdMap *fdo = &fd_map[free_fd];
424 if (fdo->fd != -1) {
425 if (fdo->isPipe){
426 if (fdo->filename == "PIPE-WRITE")
427 continue;
428 else {
429 assert (fdo->filename == "PIPE-READ");
430 //create a new pipe
431 int fds[2];
432 int pipe_retval = pipe(fds);
433
434 if (pipe_retval < 0) {
435 // error
436 panic("Unable to create new pipe.");
437 }
438 fdo->fd = fds[0]; //set read pipe
439 Process::FdMap *fdo_write = &fd_map[fdo->readPipeSource];
440 if (fdo_write->filename != "PIPE-WRITE")
441 panic ("Couldn't find write end of the pipe");
442
443 fdo_write->fd = fds[1];//set write pipe
444 }
445 } else {
446 //Open file
447 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode);
448
449 if (fd == -1)
450 panic("Unable to open file: %s", fdo->filename);
451 fdo->fd = fd;
452
453 //Seek to correct location before checkpoint
454 if (lseek(fd, fdo->fileOffset, SEEK_SET) < 0)
455 panic("Unable to seek to correct location in file: %s",
456 fdo->filename);
457 }
458 }
459 }
460}
461
462void
463Process::find_file_offsets()
464{
479 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) {
465 for (int free_fd = 0; free_fd < NUM_FDS; ++free_fd) {
480 Process::FdMap *fdo = &fd_map[free_fd];
481 if (fdo->fd != -1) {
482 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR);
483 } else {
484 fdo->filename = "NULL";
485 fdo->fileOffset = 0;
486 }
487 }
488}
489
490void
491Process::setReadPipeSource(int read_pipe_fd, int source_fd)
492{
493 Process::FdMap *fdo = &fd_map[read_pipe_fd];
494 fdo->readPipeSource = source_fd;
495}
496
497void
498Process::FdMap::serialize(CheckpointOut &cp) const
499{
500 SERIALIZE_SCALAR(fd);
501 SERIALIZE_SCALAR(isPipe);
502 SERIALIZE_SCALAR(filename);
503 SERIALIZE_SCALAR(flags);
504 SERIALIZE_SCALAR(readPipeSource);
505 SERIALIZE_SCALAR(fileOffset);
506}
507
508void
509Process::FdMap::unserialize(CheckpointIn &cp)
510{
511 UNSERIALIZE_SCALAR(fd);
512 UNSERIALIZE_SCALAR(isPipe);
513 UNSERIALIZE_SCALAR(filename);
514 UNSERIALIZE_SCALAR(flags);
515 UNSERIALIZE_SCALAR(readPipeSource);
516 UNSERIALIZE_SCALAR(fileOffset);
517}
518
519void
520Process::serialize(CheckpointOut &cp) const
521{
522 SERIALIZE_SCALAR(brk_point);
523 SERIALIZE_SCALAR(stack_base);
524 SERIALIZE_SCALAR(stack_size);
525 SERIALIZE_SCALAR(stack_min);
526 SERIALIZE_SCALAR(next_thread_stack_base);
527 SERIALIZE_SCALAR(mmap_start);
528 SERIALIZE_SCALAR(mmap_end);
529 SERIALIZE_SCALAR(nxm_start);
530 SERIALIZE_SCALAR(nxm_end);
531 pTable->serialize(cp);
466 Process::FdMap *fdo = &fd_map[free_fd];
467 if (fdo->fd != -1) {
468 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR);
469 } else {
470 fdo->filename = "NULL";
471 fdo->fileOffset = 0;
472 }
473 }
474}
475
476void
477Process::setReadPipeSource(int read_pipe_fd, int source_fd)
478{
479 Process::FdMap *fdo = &fd_map[read_pipe_fd];
480 fdo->readPipeSource = source_fd;
481}
482
483void
484Process::FdMap::serialize(CheckpointOut &cp) const
485{
486 SERIALIZE_SCALAR(fd);
487 SERIALIZE_SCALAR(isPipe);
488 SERIALIZE_SCALAR(filename);
489 SERIALIZE_SCALAR(flags);
490 SERIALIZE_SCALAR(readPipeSource);
491 SERIALIZE_SCALAR(fileOffset);
492}
493
494void
495Process::FdMap::unserialize(CheckpointIn &cp)
496{
497 UNSERIALIZE_SCALAR(fd);
498 UNSERIALIZE_SCALAR(isPipe);
499 UNSERIALIZE_SCALAR(filename);
500 UNSERIALIZE_SCALAR(flags);
501 UNSERIALIZE_SCALAR(readPipeSource);
502 UNSERIALIZE_SCALAR(fileOffset);
503}
504
505void
506Process::serialize(CheckpointOut &cp) const
507{
508 SERIALIZE_SCALAR(brk_point);
509 SERIALIZE_SCALAR(stack_base);
510 SERIALIZE_SCALAR(stack_size);
511 SERIALIZE_SCALAR(stack_min);
512 SERIALIZE_SCALAR(next_thread_stack_base);
513 SERIALIZE_SCALAR(mmap_start);
514 SERIALIZE_SCALAR(mmap_end);
515 SERIALIZE_SCALAR(nxm_start);
516 SERIALIZE_SCALAR(nxm_end);
517 pTable->serialize(cp);
532 for (int x = 0; x <= MAX_FD; x++) {
518 for (int x = 0; x < NUM_FDS; x++) {
533 fd_map[x].serializeSection(cp, csprintf("FdMap%d", x));
534 }
535 SERIALIZE_SCALAR(M5_pid);
536
537}
538
539void
540Process::unserialize(CheckpointIn &cp)
541{
542 UNSERIALIZE_SCALAR(brk_point);
543 UNSERIALIZE_SCALAR(stack_base);
544 UNSERIALIZE_SCALAR(stack_size);
545 UNSERIALIZE_SCALAR(stack_min);
546 UNSERIALIZE_SCALAR(next_thread_stack_base);
547 UNSERIALIZE_SCALAR(mmap_start);
548 UNSERIALIZE_SCALAR(mmap_end);
549 UNSERIALIZE_SCALAR(nxm_start);
550 UNSERIALIZE_SCALAR(nxm_end);
551 pTable->unserialize(cp);
519 fd_map[x].serializeSection(cp, csprintf("FdMap%d", x));
520 }
521 SERIALIZE_SCALAR(M5_pid);
522
523}
524
525void
526Process::unserialize(CheckpointIn &cp)
527{
528 UNSERIALIZE_SCALAR(brk_point);
529 UNSERIALIZE_SCALAR(stack_base);
530 UNSERIALIZE_SCALAR(stack_size);
531 UNSERIALIZE_SCALAR(stack_min);
532 UNSERIALIZE_SCALAR(next_thread_stack_base);
533 UNSERIALIZE_SCALAR(mmap_start);
534 UNSERIALIZE_SCALAR(mmap_end);
535 UNSERIALIZE_SCALAR(nxm_start);
536 UNSERIALIZE_SCALAR(nxm_end);
537 pTable->unserialize(cp);
552 for (int x = 0; x <= MAX_FD; x++) {
538 for (int x = 0; x < NUM_FDS; x++) {
553 fd_map[x].unserializeSection(cp, csprintf("FdMap%d", x));
554 }
555 fix_file_offsets();
556 UNSERIALIZE_OPT_SCALAR(M5_pid);
557 // The above returns a bool so that you could do something if you don't
558 // find the param in the checkpoint if you wanted to, like set a default
559 // but in this case we'll just stick with the instantianted value if not
539 fd_map[x].unserializeSection(cp, csprintf("FdMap%d", x));
540 }
541 fix_file_offsets();
542 UNSERIALIZE_OPT_SCALAR(M5_pid);
543 // The above returns a bool so that you could do something if you don't
544 // find the param in the checkpoint if you wanted to, like set a default
545 // but in this case we'll just stick with the instantianted value if not
560 // found.
546 // found.
561}
562
563
564bool
565Process::map(Addr vaddr, Addr paddr, int size, bool cacheable)
566{
567 pTable->map(vaddr, paddr, size,
568 cacheable ? 0 : PageTableBase::Uncacheable);
569 return true;
570}
571
572
573////////////////////////////////////////////////////////////////////////
574//
575// LiveProcess member definitions
576//
577////////////////////////////////////////////////////////////////////////
578
579
580LiveProcess::LiveProcess(LiveProcessParams *params, ObjectFile *_objFile)
581 : Process(params), objFile(_objFile),
582 argv(params->cmd), envp(params->env), cwd(params->cwd),
583 __uid(params->uid), __euid(params->euid),
584 __gid(params->gid), __egid(params->egid),
585 __pid(params->pid), __ppid(params->ppid),
586 drivers(params->drivers)
587{
588
589 // load up symbols, if any... these may be used for debugging or
590 // profiling.
591 if (!debugSymbolTable) {
592 debugSymbolTable = new SymbolTable();
593 if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
594 !objFile->loadLocalSymbols(debugSymbolTable) ||
595 !objFile->loadWeakSymbols(debugSymbolTable)) {
596 // didn't load any symbols
597 delete debugSymbolTable;
598 debugSymbolTable = NULL;
599 }
600 }
601}
602
603void
604LiveProcess::syscall(int64_t callnum, ThreadContext *tc)
605{
606 num_syscalls++;
607
608 SyscallDesc *desc = getDesc(callnum);
609 if (desc == NULL)
610 fatal("Syscall %d out of range", callnum);
611
612 desc->doSyscall(callnum, this, tc);
613}
614
615IntReg
616LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width)
617{
618 return getSyscallArg(tc, i);
619}
620
621
622EmulatedDriver *
623LiveProcess::findDriver(std::string filename)
624{
625 for (EmulatedDriver *d : drivers) {
626 if (d->match(filename))
627 return d;
628 }
629
630 return NULL;
631}
632
633
634LiveProcess *
635LiveProcess::create(LiveProcessParams * params)
636{
637 LiveProcess *process = NULL;
638
639 string executable =
640 params->executable == "" ? params->cmd[0] : params->executable;
641 ObjectFile *objFile = createObjectFile(executable);
642 if (objFile == NULL) {
643 fatal("Can't load object file %s", executable);
644 }
645
646 if (objFile->isDynamic())
647 fatal("Object file is a dynamic executable however only static "
648 "executables are supported!\n Please recompile your "
649 "executable as a static binary and try again.\n");
650
651#if THE_ISA == ALPHA_ISA
652 if (objFile->getArch() != ObjectFile::Alpha)
653 fatal("Object file architecture does not match compiled ISA (Alpha).");
654
655 switch (objFile->getOpSys()) {
656 case ObjectFile::Tru64:
657 process = new AlphaTru64Process(params, objFile);
658 break;
659
660 case ObjectFile::UnknownOpSys:
661 warn("Unknown operating system; assuming Linux.");
662 // fall through
663 case ObjectFile::Linux:
664 process = new AlphaLinuxProcess(params, objFile);
665 break;
666
667 default:
668 fatal("Unknown/unsupported operating system.");
669 }
670#elif THE_ISA == SPARC_ISA
671 if (objFile->getArch() != ObjectFile::SPARC64 &&
672 objFile->getArch() != ObjectFile::SPARC32)
673 fatal("Object file architecture does not match compiled ISA (SPARC).");
674 switch (objFile->getOpSys()) {
675 case ObjectFile::UnknownOpSys:
676 warn("Unknown operating system; assuming Linux.");
677 // fall through
678 case ObjectFile::Linux:
679 if (objFile->getArch() == ObjectFile::SPARC64) {
680 process = new Sparc64LinuxProcess(params, objFile);
681 } else {
682 process = new Sparc32LinuxProcess(params, objFile);
683 }
684 break;
685
686
687 case ObjectFile::Solaris:
688 process = new SparcSolarisProcess(params, objFile);
689 break;
690
691 default:
692 fatal("Unknown/unsupported operating system.");
693 }
694#elif THE_ISA == X86_ISA
695 if (objFile->getArch() != ObjectFile::X86_64 &&
696 objFile->getArch() != ObjectFile::I386)
697 fatal("Object file architecture does not match compiled ISA (x86).");
698 switch (objFile->getOpSys()) {
699 case ObjectFile::UnknownOpSys:
700 warn("Unknown operating system; assuming Linux.");
701 // fall through
702 case ObjectFile::Linux:
703 if (objFile->getArch() == ObjectFile::X86_64) {
704 process = new X86_64LinuxProcess(params, objFile);
705 } else {
706 process = new I386LinuxProcess(params, objFile);
707 }
708 break;
709
710 default:
711 fatal("Unknown/unsupported operating system.");
712 }
713#elif THE_ISA == MIPS_ISA
714 if (objFile->getArch() != ObjectFile::Mips)
715 fatal("Object file architecture does not match compiled ISA (MIPS).");
716 switch (objFile->getOpSys()) {
717 case ObjectFile::UnknownOpSys:
718 warn("Unknown operating system; assuming Linux.");
719 // fall through
720 case ObjectFile::Linux:
721 process = new MipsLinuxProcess(params, objFile);
722 break;
723
724 default:
725 fatal("Unknown/unsupported operating system.");
726 }
727#elif THE_ISA == ARM_ISA
728 ObjectFile::Arch arch = objFile->getArch();
729 if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
730 arch != ObjectFile::Arm64)
731 fatal("Object file architecture does not match compiled ISA (ARM).");
732 switch (objFile->getOpSys()) {
733 case ObjectFile::UnknownOpSys:
734 warn("Unknown operating system; assuming Linux.");
735 // fall through
736 case ObjectFile::Linux:
737 if (arch == ObjectFile::Arm64) {
738 process = new ArmLinuxProcess64(params, objFile,
739 objFile->getArch());
740 } else {
741 process = new ArmLinuxProcess32(params, objFile,
742 objFile->getArch());
743 }
744 break;
745 case ObjectFile::FreeBSD:
746 if (arch == ObjectFile::Arm64) {
747 process = new ArmFreebsdProcess64(params, objFile,
748 objFile->getArch());
749 } else {
750 process = new ArmFreebsdProcess32(params, objFile,
751 objFile->getArch());
752 }
753 break;
754 case ObjectFile::LinuxArmOABI:
755 fatal("M5 does not support ARM OABI binaries. Please recompile with an"
756 " EABI compiler.");
757 default:
758 fatal("Unknown/unsupported operating system.");
759 }
760#elif THE_ISA == POWER_ISA
761 if (objFile->getArch() != ObjectFile::Power)
762 fatal("Object file architecture does not match compiled ISA (Power).");
763 switch (objFile->getOpSys()) {
764 case ObjectFile::UnknownOpSys:
765 warn("Unknown operating system; assuming Linux.");
766 // fall through
767 case ObjectFile::Linux:
768 process = new PowerLinuxProcess(params, objFile);
769 break;
770
771 default:
772 fatal("Unknown/unsupported operating system.");
773 }
774#else
775#error "THE_ISA not set"
776#endif
777
778 if (process == NULL)
779 fatal("Unknown error creating process object.");
780 return process;
781}
782
783LiveProcess *
784LiveProcessParams::create()
785{
786 return LiveProcess::create(this);
787}
547}
548
549
550bool
551Process::map(Addr vaddr, Addr paddr, int size, bool cacheable)
552{
553 pTable->map(vaddr, paddr, size,
554 cacheable ? 0 : PageTableBase::Uncacheable);
555 return true;
556}
557
558
559////////////////////////////////////////////////////////////////////////
560//
561// LiveProcess member definitions
562//
563////////////////////////////////////////////////////////////////////////
564
565
566LiveProcess::LiveProcess(LiveProcessParams *params, ObjectFile *_objFile)
567 : Process(params), objFile(_objFile),
568 argv(params->cmd), envp(params->env), cwd(params->cwd),
569 __uid(params->uid), __euid(params->euid),
570 __gid(params->gid), __egid(params->egid),
571 __pid(params->pid), __ppid(params->ppid),
572 drivers(params->drivers)
573{
574
575 // load up symbols, if any... these may be used for debugging or
576 // profiling.
577 if (!debugSymbolTable) {
578 debugSymbolTable = new SymbolTable();
579 if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
580 !objFile->loadLocalSymbols(debugSymbolTable) ||
581 !objFile->loadWeakSymbols(debugSymbolTable)) {
582 // didn't load any symbols
583 delete debugSymbolTable;
584 debugSymbolTable = NULL;
585 }
586 }
587}
588
589void
590LiveProcess::syscall(int64_t callnum, ThreadContext *tc)
591{
592 num_syscalls++;
593
594 SyscallDesc *desc = getDesc(callnum);
595 if (desc == NULL)
596 fatal("Syscall %d out of range", callnum);
597
598 desc->doSyscall(callnum, this, tc);
599}
600
601IntReg
602LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width)
603{
604 return getSyscallArg(tc, i);
605}
606
607
608EmulatedDriver *
609LiveProcess::findDriver(std::string filename)
610{
611 for (EmulatedDriver *d : drivers) {
612 if (d->match(filename))
613 return d;
614 }
615
616 return NULL;
617}
618
619
620LiveProcess *
621LiveProcess::create(LiveProcessParams * params)
622{
623 LiveProcess *process = NULL;
624
625 string executable =
626 params->executable == "" ? params->cmd[0] : params->executable;
627 ObjectFile *objFile = createObjectFile(executable);
628 if (objFile == NULL) {
629 fatal("Can't load object file %s", executable);
630 }
631
632 if (objFile->isDynamic())
633 fatal("Object file is a dynamic executable however only static "
634 "executables are supported!\n Please recompile your "
635 "executable as a static binary and try again.\n");
636
637#if THE_ISA == ALPHA_ISA
638 if (objFile->getArch() != ObjectFile::Alpha)
639 fatal("Object file architecture does not match compiled ISA (Alpha).");
640
641 switch (objFile->getOpSys()) {
642 case ObjectFile::Tru64:
643 process = new AlphaTru64Process(params, objFile);
644 break;
645
646 case ObjectFile::UnknownOpSys:
647 warn("Unknown operating system; assuming Linux.");
648 // fall through
649 case ObjectFile::Linux:
650 process = new AlphaLinuxProcess(params, objFile);
651 break;
652
653 default:
654 fatal("Unknown/unsupported operating system.");
655 }
656#elif THE_ISA == SPARC_ISA
657 if (objFile->getArch() != ObjectFile::SPARC64 &&
658 objFile->getArch() != ObjectFile::SPARC32)
659 fatal("Object file architecture does not match compiled ISA (SPARC).");
660 switch (objFile->getOpSys()) {
661 case ObjectFile::UnknownOpSys:
662 warn("Unknown operating system; assuming Linux.");
663 // fall through
664 case ObjectFile::Linux:
665 if (objFile->getArch() == ObjectFile::SPARC64) {
666 process = new Sparc64LinuxProcess(params, objFile);
667 } else {
668 process = new Sparc32LinuxProcess(params, objFile);
669 }
670 break;
671
672
673 case ObjectFile::Solaris:
674 process = new SparcSolarisProcess(params, objFile);
675 break;
676
677 default:
678 fatal("Unknown/unsupported operating system.");
679 }
680#elif THE_ISA == X86_ISA
681 if (objFile->getArch() != ObjectFile::X86_64 &&
682 objFile->getArch() != ObjectFile::I386)
683 fatal("Object file architecture does not match compiled ISA (x86).");
684 switch (objFile->getOpSys()) {
685 case ObjectFile::UnknownOpSys:
686 warn("Unknown operating system; assuming Linux.");
687 // fall through
688 case ObjectFile::Linux:
689 if (objFile->getArch() == ObjectFile::X86_64) {
690 process = new X86_64LinuxProcess(params, objFile);
691 } else {
692 process = new I386LinuxProcess(params, objFile);
693 }
694 break;
695
696 default:
697 fatal("Unknown/unsupported operating system.");
698 }
699#elif THE_ISA == MIPS_ISA
700 if (objFile->getArch() != ObjectFile::Mips)
701 fatal("Object file architecture does not match compiled ISA (MIPS).");
702 switch (objFile->getOpSys()) {
703 case ObjectFile::UnknownOpSys:
704 warn("Unknown operating system; assuming Linux.");
705 // fall through
706 case ObjectFile::Linux:
707 process = new MipsLinuxProcess(params, objFile);
708 break;
709
710 default:
711 fatal("Unknown/unsupported operating system.");
712 }
713#elif THE_ISA == ARM_ISA
714 ObjectFile::Arch arch = objFile->getArch();
715 if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
716 arch != ObjectFile::Arm64)
717 fatal("Object file architecture does not match compiled ISA (ARM).");
718 switch (objFile->getOpSys()) {
719 case ObjectFile::UnknownOpSys:
720 warn("Unknown operating system; assuming Linux.");
721 // fall through
722 case ObjectFile::Linux:
723 if (arch == ObjectFile::Arm64) {
724 process = new ArmLinuxProcess64(params, objFile,
725 objFile->getArch());
726 } else {
727 process = new ArmLinuxProcess32(params, objFile,
728 objFile->getArch());
729 }
730 break;
731 case ObjectFile::FreeBSD:
732 if (arch == ObjectFile::Arm64) {
733 process = new ArmFreebsdProcess64(params, objFile,
734 objFile->getArch());
735 } else {
736 process = new ArmFreebsdProcess32(params, objFile,
737 objFile->getArch());
738 }
739 break;
740 case ObjectFile::LinuxArmOABI:
741 fatal("M5 does not support ARM OABI binaries. Please recompile with an"
742 " EABI compiler.");
743 default:
744 fatal("Unknown/unsupported operating system.");
745 }
746#elif THE_ISA == POWER_ISA
747 if (objFile->getArch() != ObjectFile::Power)
748 fatal("Object file architecture does not match compiled ISA (Power).");
749 switch (objFile->getOpSys()) {
750 case ObjectFile::UnknownOpSys:
751 warn("Unknown operating system; assuming Linux.");
752 // fall through
753 case ObjectFile::Linux:
754 process = new PowerLinuxProcess(params, objFile);
755 break;
756
757 default:
758 fatal("Unknown/unsupported operating system.");
759 }
760#else
761#error "THE_ISA not set"
762#endif
763
764 if (process == NULL)
765 fatal("Unknown error creating process object.");
766 return process;
767}
768
769LiveProcess *
770LiveProcessParams::create()
771{
772 return LiveProcess::create(this);
773}