process.cc (5335:69d45f5f21a2) process.cc (5512:755fcaf7a4cf)
1/*
2 * Copyright (c) 2001-2005 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;
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.
15 *
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.
27 *
28 * Authors: Nathan Binkert
29 * Steve Reinhardt
30 * Ali Saidi
31 */
32
33#include <unistd.h>
34#include <fcntl.h>
35#include <string>
36
37#include "arch/remote_gdb.hh"
38#include "base/intmath.hh"
39#include "base/loader/object_file.hh"
40#include "base/loader/symtab.hh"
41#include "base/statistics.hh"
42#include "config/full_system.hh"
43#include "cpu/thread_context.hh"
44#include "mem/page_table.hh"
45#include "mem/physical.hh"
46#include "mem/translating_port.hh"
47#include "params/Process.hh"
48#include "params/LiveProcess.hh"
1/*
2 * Copyright (c) 2001-2005 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;
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.
15 *
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.
27 *
28 * Authors: Nathan Binkert
29 * Steve Reinhardt
30 * Ali Saidi
31 */
32
33#include <unistd.h>
34#include <fcntl.h>
35#include <string>
36
37#include "arch/remote_gdb.hh"
38#include "base/intmath.hh"
39#include "base/loader/object_file.hh"
40#include "base/loader/symtab.hh"
41#include "base/statistics.hh"
42#include "config/full_system.hh"
43#include "cpu/thread_context.hh"
44#include "mem/page_table.hh"
45#include "mem/physical.hh"
46#include "mem/translating_port.hh"
47#include "params/Process.hh"
48#include "params/LiveProcess.hh"
49#include "sim/debug.hh"
49#include "sim/process.hh"
50#include "sim/process_impl.hh"
51#include "sim/stats.hh"
52#include "sim/syscall_emul.hh"
53#include "sim/system.hh"
54
55#include "arch/isa_specific.hh"
56#if THE_ISA == ALPHA_ISA
57#include "arch/alpha/linux/process.hh"
58#include "arch/alpha/tru64/process.hh"
59#elif THE_ISA == SPARC_ISA
60#include "arch/sparc/linux/process.hh"
61#include "arch/sparc/solaris/process.hh"
62#elif THE_ISA == MIPS_ISA
63#include "arch/mips/linux/process.hh"
64#elif THE_ISA == ARM_ISA
65#include "arch/arm/linux/process.hh"
66#elif THE_ISA == X86_ISA
67#include "arch/x86/linux/process.hh"
68#else
69#error "THE_ISA not set"
70#endif
71
72
73using namespace std;
74using namespace TheISA;
75
76//
77// The purpose of this code is to fake the loader & syscall mechanism
78// when there's no OS: thus there's no resone to use it in FULL_SYSTEM
79// mode when we do have an OS
80//
81#if FULL_SYSTEM
82#error "process.cc not compatible with FULL_SYSTEM"
83#endif
84
85// current number of allocated processes
86int num_processes = 0;
87
88Process::Process(ProcessParams * params)
89 : SimObject(params), system(params->system), checkpointRestored(false),
90 max_stack_size(params->max_stack_size)
91{
92 string in = params->input;
93 string out = params->output;
94
95 // initialize file descriptors to default: same as simulator
96 int stdin_fd, stdout_fd, stderr_fd;
97
98 if (in == "stdin" || in == "cin")
99 stdin_fd = STDIN_FILENO;
100 else if (in == "None")
101 stdin_fd = -1;
102 else
103 stdin_fd = Process::openInputFile(in);
104
105 if (out == "stdout" || out == "cout")
106 stdout_fd = STDOUT_FILENO;
107 else if (out == "stderr" || out == "cerr")
108 stdout_fd = STDERR_FILENO;
109 else if (out == "None")
110 stdout_fd = -1;
111 else
112 stdout_fd = Process::openOutputFile(out);
113
114 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
115
116 M5_pid = system->allocatePID();
117 // initialize first 3 fds (stdin, stdout, stderr)
118 Process::FdMap *fdo = &fd_map[STDIN_FILENO];
119 fdo->fd = stdin_fd;
120 fdo->filename = in;
121 fdo->flags = O_RDONLY;
122 fdo->mode = -1;
123 fdo->fileOffset = 0;
124
125 fdo = &fd_map[STDOUT_FILENO];
126 fdo->fd = stdout_fd;
127 fdo->filename = out;
128 fdo->flags = O_WRONLY | O_CREAT | O_TRUNC;
129 fdo->mode = 0774;
130 fdo->fileOffset = 0;
131
132 fdo = &fd_map[STDERR_FILENO];
133 fdo->fd = stderr_fd;
134 fdo->filename = "STDERR";
135 fdo->flags = O_WRONLY;
136 fdo->mode = -1;
137 fdo->fileOffset = 0;
138
139
140 // mark remaining fds as free
141 for (int i = 3; i <= MAX_FD; ++i) {
142 Process::FdMap *fdo = &fd_map[i];
143 fdo->fd = -1;
144 }
145
146 mmap_start = mmap_end = 0;
147 nxm_start = nxm_end = 0;
148 pTable = new PageTable(this);
149 // other parameters will be initialized when the program is loaded
150}
151
152
153void
154Process::regStats()
155{
156 using namespace Stats;
157
158 num_syscalls
159 .name(name() + ".PROG:num_syscalls")
160 .desc("Number of system calls")
161 ;
162}
163
164//
165// static helper functions
166//
167int
168Process::openInputFile(const string &filename)
169{
170 int fd = open(filename.c_str(), O_RDONLY);
171
172 if (fd == -1) {
173 perror(NULL);
174 cerr << "unable to open \"" << filename << "\" for reading\n";
175 fatal("can't open input file");
176 }
177
178 return fd;
179}
180
181
182int
183Process::openOutputFile(const string &filename)
184{
185 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0774);
186
187 if (fd == -1) {
188 perror(NULL);
189 cerr << "unable to open \"" << filename << "\" for writing\n";
190 fatal("can't open output file");
191 }
192
193 return fd;
194}
195
196
197int
198Process::registerThreadContext(ThreadContext *tc)
199{
200 // add to list
201 int myIndex = threadContexts.size();
202 threadContexts.push_back(tc);
203
50#include "sim/process.hh"
51#include "sim/process_impl.hh"
52#include "sim/stats.hh"
53#include "sim/syscall_emul.hh"
54#include "sim/system.hh"
55
56#include "arch/isa_specific.hh"
57#if THE_ISA == ALPHA_ISA
58#include "arch/alpha/linux/process.hh"
59#include "arch/alpha/tru64/process.hh"
60#elif THE_ISA == SPARC_ISA
61#include "arch/sparc/linux/process.hh"
62#include "arch/sparc/solaris/process.hh"
63#elif THE_ISA == MIPS_ISA
64#include "arch/mips/linux/process.hh"
65#elif THE_ISA == ARM_ISA
66#include "arch/arm/linux/process.hh"
67#elif THE_ISA == X86_ISA
68#include "arch/x86/linux/process.hh"
69#else
70#error "THE_ISA not set"
71#endif
72
73
74using namespace std;
75using namespace TheISA;
76
77//
78// The purpose of this code is to fake the loader & syscall mechanism
79// when there's no OS: thus there's no resone to use it in FULL_SYSTEM
80// mode when we do have an OS
81//
82#if FULL_SYSTEM
83#error "process.cc not compatible with FULL_SYSTEM"
84#endif
85
86// current number of allocated processes
87int num_processes = 0;
88
89Process::Process(ProcessParams * params)
90 : SimObject(params), system(params->system), checkpointRestored(false),
91 max_stack_size(params->max_stack_size)
92{
93 string in = params->input;
94 string out = params->output;
95
96 // initialize file descriptors to default: same as simulator
97 int stdin_fd, stdout_fd, stderr_fd;
98
99 if (in == "stdin" || in == "cin")
100 stdin_fd = STDIN_FILENO;
101 else if (in == "None")
102 stdin_fd = -1;
103 else
104 stdin_fd = Process::openInputFile(in);
105
106 if (out == "stdout" || out == "cout")
107 stdout_fd = STDOUT_FILENO;
108 else if (out == "stderr" || out == "cerr")
109 stdout_fd = STDERR_FILENO;
110 else if (out == "None")
111 stdout_fd = -1;
112 else
113 stdout_fd = Process::openOutputFile(out);
114
115 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
116
117 M5_pid = system->allocatePID();
118 // initialize first 3 fds (stdin, stdout, stderr)
119 Process::FdMap *fdo = &fd_map[STDIN_FILENO];
120 fdo->fd = stdin_fd;
121 fdo->filename = in;
122 fdo->flags = O_RDONLY;
123 fdo->mode = -1;
124 fdo->fileOffset = 0;
125
126 fdo = &fd_map[STDOUT_FILENO];
127 fdo->fd = stdout_fd;
128 fdo->filename = out;
129 fdo->flags = O_WRONLY | O_CREAT | O_TRUNC;
130 fdo->mode = 0774;
131 fdo->fileOffset = 0;
132
133 fdo = &fd_map[STDERR_FILENO];
134 fdo->fd = stderr_fd;
135 fdo->filename = "STDERR";
136 fdo->flags = O_WRONLY;
137 fdo->mode = -1;
138 fdo->fileOffset = 0;
139
140
141 // mark remaining fds as free
142 for (int i = 3; i <= MAX_FD; ++i) {
143 Process::FdMap *fdo = &fd_map[i];
144 fdo->fd = -1;
145 }
146
147 mmap_start = mmap_end = 0;
148 nxm_start = nxm_end = 0;
149 pTable = new PageTable(this);
150 // other parameters will be initialized when the program is loaded
151}
152
153
154void
155Process::regStats()
156{
157 using namespace Stats;
158
159 num_syscalls
160 .name(name() + ".PROG:num_syscalls")
161 .desc("Number of system calls")
162 ;
163}
164
165//
166// static helper functions
167//
168int
169Process::openInputFile(const string &filename)
170{
171 int fd = open(filename.c_str(), O_RDONLY);
172
173 if (fd == -1) {
174 perror(NULL);
175 cerr << "unable to open \"" << filename << "\" for reading\n";
176 fatal("can't open input file");
177 }
178
179 return fd;
180}
181
182
183int
184Process::openOutputFile(const string &filename)
185{
186 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0774);
187
188 if (fd == -1) {
189 perror(NULL);
190 cerr << "unable to open \"" << filename << "\" for writing\n";
191 fatal("can't open output file");
192 }
193
194 return fd;
195}
196
197
198int
199Process::registerThreadContext(ThreadContext *tc)
200{
201 // add to list
202 int myIndex = threadContexts.size();
203 threadContexts.push_back(tc);
204
204 RemoteGDB *rgdb = new RemoteGDB(system, tc);
205 GDBListener *gdbl = new GDBListener(rgdb, 7000 + myIndex);
206 gdbl->listen();
207 //gdbl->accept();
205 int port = getRemoteGDBPort();
206 if (port) {
207 RemoteGDB *rgdb = new RemoteGDB(system, tc);
208 GDBListener *gdbl = new GDBListener(rgdb, port + myIndex);
209 gdbl->listen();
208
210
209 remoteGDB.push_back(rgdb);
211 remoteGDB.push_back(rgdb);
212 }
210
211 // return CPU number to caller
212 return myIndex;
213}
214
215void
216Process::startup()
217{
218 if (threadContexts.empty())
219 fatal("Process %s is not associated with any CPUs!\n", name());
220
221 // first thread context for this process... initialize & enable
222 ThreadContext *tc = threadContexts[0];
223
224 // mark this context as active so it will start ticking.
225 tc->activate(0);
226
227 Port *mem_port;
228 mem_port = system->physmem->getPort("functional");
229 initVirtMem = new TranslatingPort("process init port", this,
230 TranslatingPort::Always);
231 mem_port->setPeer(initVirtMem);
232 initVirtMem->setPeer(mem_port);
233}
234
235void
236Process::replaceThreadContext(ThreadContext *tc, int tcIndex)
237{
238 if (tcIndex >= threadContexts.size()) {
239 panic("replaceThreadContext: bad tcIndex, %d >= %d\n",
240 tcIndex, threadContexts.size());
241 }
242
243 threadContexts[tcIndex] = tc;
244}
245
246// map simulator fd sim_fd to target fd tgt_fd
247void
248Process::dup_fd(int sim_fd, int tgt_fd)
249{
250 if (tgt_fd < 0 || tgt_fd > MAX_FD)
251 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd);
252
253 Process::FdMap *fdo = &fd_map[tgt_fd];
254 fdo->fd = sim_fd;
255}
256
257
258// generate new target fd for sim_fd
259int
260Process::alloc_fd(int sim_fd, string filename, int flags, int mode, bool pipe)
261{
262 // in case open() returns an error, don't allocate a new fd
263 if (sim_fd == -1)
264 return -1;
265
266 // find first free target fd
267 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) {
268 Process::FdMap *fdo = &fd_map[free_fd];
269 if (fdo->fd == -1) {
270 fdo->fd = sim_fd;
271 fdo->filename = filename;
272 fdo->mode = mode;
273 fdo->fileOffset = 0;
274 fdo->flags = flags;
275 fdo->isPipe = pipe;
276 fdo->readPipeSource = 0;
277 return free_fd;
278 }
279 }
280
281 panic("Process::alloc_fd: out of file descriptors!");
282}
283
284
285// free target fd (e.g., after close)
286void
287Process::free_fd(int tgt_fd)
288{
289 Process::FdMap *fdo = &fd_map[tgt_fd];
290 if (fdo->fd == -1)
291 warn("Process::free_fd: request to free unused fd %d", tgt_fd);
292
293 fdo->fd = -1;
294 fdo->filename = "NULL";
295 fdo->mode = 0;
296 fdo->fileOffset = 0;
297 fdo->flags = 0;
298 fdo->isPipe = false;
299 fdo->readPipeSource = 0;
300}
301
302
303// look up simulator fd for given target fd
304int
305Process::sim_fd(int tgt_fd)
306{
307 if (tgt_fd > MAX_FD)
308 return -1;
309
310 return fd_map[tgt_fd].fd;
311}
312
313Process::FdMap *
314Process::sim_fd_obj(int tgt_fd)
315{
316 if (tgt_fd > MAX_FD)
317 panic("sim_fd_obj called in fd out of range.");
318
319 return &fd_map[tgt_fd];
320}
321bool
322Process::checkAndAllocNextPage(Addr vaddr)
323{
324 // if this is an initial write we might not have
325 if (vaddr >= stack_min && vaddr < stack_base) {
326 pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize);
327 return true;
328 }
329
330 // We've accessed the next page of the stack, so extend the stack
331 // to cover it.
332 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
333 while (vaddr < stack_min) {
334 stack_min -= TheISA::PageBytes;
335 if(stack_base - stack_min > max_stack_size)
336 fatal("Maximum stack size exceeded\n");
337 if(stack_base - stack_min > 8*1024*1024)
338 fatal("Over max stack size for one thread\n");
339 pTable->allocate(stack_min, TheISA::PageBytes);
340 warn("Increasing stack size by one page.");
341 };
342 return true;
343 }
344 return false;
345}
346
347 // find all offsets for currently open files and save them
348void
349Process::fix_file_offsets() {
350 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO];
351 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO];
352 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO];
353 string in = fdo_stdin->filename;
354 string out = fdo_stdout->filename;
355
356 // initialize file descriptors to default: same as simulator
357 int stdin_fd, stdout_fd, stderr_fd;
358
359 if (in == "stdin" || in == "cin")
360 stdin_fd = STDIN_FILENO;
361 else if (in == "None")
362 stdin_fd = -1;
363 else{
364 //OPEN standard in and seek to the right location
365 stdin_fd = Process::openInputFile(in);
366 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0)
367 panic("Unable to seek to correct location in file: %s", in);
368 }
369
370 if (out == "stdout" || out == "cout")
371 stdout_fd = STDOUT_FILENO;
372 else if (out == "stderr" || out == "cerr")
373 stdout_fd = STDERR_FILENO;
374 else if (out == "None")
375 stdout_fd = -1;
376 else{
377 stdout_fd = Process::openOutputFile(out);
378 if (lseek(stdin_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
379 panic("Unable to seek to correct in file: %s", out);
380 }
381
382 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
383
384 fdo_stdin->fd = stdin_fd;
385 fdo_stdout->fd = stdout_fd;
386 fdo_stderr->fd = stderr_fd;
387
388
389 for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) {
390 Process::FdMap *fdo = &fd_map[free_fd];
391 if (fdo->fd != -1) {
392 if (fdo->isPipe){
393 if (fdo->filename == "PIPE-WRITE")
394 continue;
395 else {
396 assert (fdo->filename == "PIPE-READ");
397 //create a new pipe
398 int fds[2];
399 int pipe_retval = pipe(fds);
400
401 if (pipe_retval < 0) {
402 // error
403 panic("Unable to create new pipe.");
404 }
405 fdo->fd = fds[0]; //set read pipe
406 Process::FdMap *fdo_write = &fd_map[fdo->readPipeSource];
407 if (fdo_write->filename != "PIPE-WRITE")
408 panic ("Couldn't find write end of the pipe");
409
410 fdo_write->fd = fds[1];//set write pipe
411 }
412 } else {
413 //Open file
414 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode);
415
416 if (fd == -1)
417 panic("Unable to open file: %s", fdo->filename);
418 fdo->fd = fd;
419
420 //Seek to correct location before checkpoint
421 if (lseek(fd,fdo->fileOffset, SEEK_SET) < 0)
422 panic("Unable to seek to correct location in file: %s", fdo->filename);
423 }
424 }
425 }
426}
427void
428Process::find_file_offsets(){
429 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) {
430 Process::FdMap *fdo = &fd_map[free_fd];
431 if (fdo->fd != -1) {
432 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR);
433 } else {
434 fdo->filename = "NULL";
435 fdo->fileOffset = 0;
436 }
437 }
438}
439
440void
441Process::setReadPipeSource(int read_pipe_fd, int source_fd){
442 Process::FdMap *fdo = &fd_map[read_pipe_fd];
443 fdo->readPipeSource = source_fd;
444}
445
446void
447Process::FdMap::serialize(std::ostream &os)
448{
449 SERIALIZE_SCALAR(fd);
450 SERIALIZE_SCALAR(isPipe);
451 SERIALIZE_SCALAR(filename);
452 SERIALIZE_SCALAR(flags);
453 SERIALIZE_SCALAR(readPipeSource);
454 SERIALIZE_SCALAR(fileOffset);
455}
456
457void
458Process::FdMap::unserialize(Checkpoint *cp, const std::string &section)
459{
460 UNSERIALIZE_SCALAR(fd);
461 UNSERIALIZE_SCALAR(isPipe);
462 UNSERIALIZE_SCALAR(filename);
463 UNSERIALIZE_SCALAR(flags);
464 UNSERIALIZE_SCALAR(readPipeSource);
465 UNSERIALIZE_SCALAR(fileOffset);
466}
467
468void
469Process::serialize(std::ostream &os)
470{
471 SERIALIZE_SCALAR(initialContextLoaded);
472 SERIALIZE_SCALAR(brk_point);
473 SERIALIZE_SCALAR(stack_base);
474 SERIALIZE_SCALAR(stack_size);
475 SERIALIZE_SCALAR(stack_min);
476 SERIALIZE_SCALAR(next_thread_stack_base);
477 SERIALIZE_SCALAR(mmap_start);
478 SERIALIZE_SCALAR(mmap_end);
479 SERIALIZE_SCALAR(nxm_start);
480 SERIALIZE_SCALAR(nxm_end);
481 find_file_offsets();
482 pTable->serialize(os);
483 for (int x = 0; x <= MAX_FD; x++) {
484 nameOut(os, csprintf("%s.FdMap%d", name(), x));
485 fd_map[x].serialize(os);
486 }
487
488}
489
490void
491Process::unserialize(Checkpoint *cp, const std::string &section)
492{
493 UNSERIALIZE_SCALAR(initialContextLoaded);
494 UNSERIALIZE_SCALAR(brk_point);
495 UNSERIALIZE_SCALAR(stack_base);
496 UNSERIALIZE_SCALAR(stack_size);
497 UNSERIALIZE_SCALAR(stack_min);
498 UNSERIALIZE_SCALAR(next_thread_stack_base);
499 UNSERIALIZE_SCALAR(mmap_start);
500 UNSERIALIZE_SCALAR(mmap_end);
501 UNSERIALIZE_SCALAR(nxm_start);
502 UNSERIALIZE_SCALAR(nxm_end);
503 pTable->unserialize(cp, section);
504 for (int x = 0; x <= MAX_FD; x++) {
505 fd_map[x].unserialize(cp, csprintf("%s.FdMap%d", section, x));
506 }
507 fix_file_offsets();
508
509 checkpointRestored = true;
510
511}
512
513
514////////////////////////////////////////////////////////////////////////
515//
516// LiveProcess member definitions
517//
518////////////////////////////////////////////////////////////////////////
519
520
521LiveProcess::LiveProcess(LiveProcessParams * params, ObjectFile *_objFile)
522 : Process(params), objFile(_objFile),
523 argv(params->cmd), envp(params->env), cwd(params->cwd)
524{
525 __uid = params->uid;
526 __euid = params->euid;
527 __gid = params->gid;
528 __egid = params->egid;
529 __pid = params->pid;
530 __ppid = params->ppid;
531
532 prog_fname = params->cmd[0];
533
534 // load up symbols, if any... these may be used for debugging or
535 // profiling.
536 if (!debugSymbolTable) {
537 debugSymbolTable = new SymbolTable();
538 if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
539 !objFile->loadLocalSymbols(debugSymbolTable)) {
540 // didn't load any symbols
541 delete debugSymbolTable;
542 debugSymbolTable = NULL;
543 }
544 }
545}
546
547void
548LiveProcess::argsInit(int intSize, int pageSize)
549{
550 Process::startup();
551
552 // load object file into target memory
553 objFile->loadSections(initVirtMem);
554
555 // Calculate how much space we need for arg & env arrays.
556 int argv_array_size = intSize * (argv.size() + 1);
557 int envp_array_size = intSize * (envp.size() + 1);
558 int arg_data_size = 0;
559 for (int i = 0; i < argv.size(); ++i) {
560 arg_data_size += argv[i].size() + 1;
561 }
562 int env_data_size = 0;
563 for (int i = 0; i < envp.size(); ++i) {
564 env_data_size += envp[i].size() + 1;
565 }
566
567 int space_needed =
568 argv_array_size + envp_array_size + arg_data_size + env_data_size;
569 if (space_needed < 32*1024)
570 space_needed = 32*1024;
571
572 // set bottom of stack
573 stack_min = stack_base - space_needed;
574 // align it
575 stack_min = roundDown(stack_min, pageSize);
576 stack_size = stack_base - stack_min;
577 // map memory
578 pTable->allocate(stack_min, roundUp(stack_size, pageSize));
579
580 // map out initial stack contents
581 Addr argv_array_base = stack_min + intSize; // room for argc
582 Addr envp_array_base = argv_array_base + argv_array_size;
583 Addr arg_data_base = envp_array_base + envp_array_size;
584 Addr env_data_base = arg_data_base + arg_data_size;
585
586 // write contents to stack
587 uint64_t argc = argv.size();
588 if (intSize == 8)
589 argc = htog((uint64_t)argc);
590 else if (intSize == 4)
591 argc = htog((uint32_t)argc);
592 else
593 panic("Unknown int size");
594
595 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize);
596
597 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
598 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
599
600 assert(NumArgumentRegs >= 2);
601 threadContexts[0]->setIntReg(ArgumentReg[0], argc);
602 threadContexts[0]->setIntReg(ArgumentReg[1], argv_array_base);
603 threadContexts[0]->setIntReg(StackPointerReg, stack_min);
604
605 Addr prog_entry = objFile->entryPoint();
606 threadContexts[0]->setPC(prog_entry);
607 threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
608
609#if THE_ISA != ALPHA_ISA //e.g. MIPS or Sparc
610 threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
611#endif
612
613 num_processes++;
614}
615
616void
617LiveProcess::syscall(int64_t callnum, ThreadContext *tc)
618{
619 num_syscalls++;
620
621 SyscallDesc *desc = getDesc(callnum);
622 if (desc == NULL)
623 fatal("Syscall %d out of range", callnum);
624
625 desc->doSyscall(callnum, this, tc);
626}
627
628LiveProcess *
629LiveProcess::create(LiveProcessParams * params)
630{
631 LiveProcess *process = NULL;
632
633 string executable =
634 params->executable == "" ? params->cmd[0] : params->executable;
635 ObjectFile *objFile = createObjectFile(executable);
636 if (objFile == NULL) {
637 fatal("Can't load object file %s", executable);
638 }
639
640 if (objFile->isDynamic())
641 fatal("Object file is a dynamic executable however only static "
642 "executables are supported!\n Please recompile your "
643 "executable as a static binary and try again.\n");
644
645#if THE_ISA == ALPHA_ISA
646 if (objFile->hasTLS())
647 fatal("Object file has a TLS section and single threaded TLS is not\n"
648 " currently supported for Alpha! Please recompile your "
649 "executable with \n a non-TLS toolchain.\n");
650
651 if (objFile->getArch() != ObjectFile::Alpha)
652 fatal("Object file architecture does not match compiled ISA (Alpha).");
653 switch (objFile->getOpSys()) {
654 case ObjectFile::Tru64:
655 process = new AlphaTru64Process(params, objFile);
656 break;
657
658 case ObjectFile::Linux:
659 process = new AlphaLinuxProcess(params, objFile);
660 break;
661
662 default:
663 fatal("Unknown/unsupported operating system.");
664 }
665#elif THE_ISA == SPARC_ISA
666 if (objFile->getArch() != ObjectFile::SPARC64 && objFile->getArch() != ObjectFile::SPARC32)
667 fatal("Object file architecture does not match compiled ISA (SPARC).");
668 switch (objFile->getOpSys()) {
669 case ObjectFile::Linux:
670 if (objFile->getArch() == ObjectFile::SPARC64) {
671 process = new Sparc64LinuxProcess(params, objFile);
672 } else {
673 process = new Sparc32LinuxProcess(params, objFile);
674 }
675 break;
676
677
678 case ObjectFile::Solaris:
679 process = new SparcSolarisProcess(params, objFile);
680 break;
681 default:
682 fatal("Unknown/unsupported operating system.");
683 }
684#elif THE_ISA == X86_ISA
685 if (objFile->getArch() != ObjectFile::X86)
686 fatal("Object file architecture does not match compiled ISA (x86).");
687 switch (objFile->getOpSys()) {
688 case ObjectFile::Linux:
689 process = new X86LinuxProcess(params, objFile);
690 break;
691 default:
692 fatal("Unknown/unsupported operating system.");
693 }
694#elif THE_ISA == MIPS_ISA
695 if (objFile->getArch() != ObjectFile::Mips)
696 fatal("Object file architecture does not match compiled ISA (MIPS).");
697 switch (objFile->getOpSys()) {
698 case ObjectFile::Linux:
699 process = new MipsLinuxProcess(params, objFile);
700 break;
701
702 default:
703 fatal("Unknown/unsupported operating system.");
704 }
705#elif THE_ISA == ARM_ISA
706 if (objFile->getArch() != ObjectFile::Arm)
707 fatal("Object file architecture does not match compiled ISA (ARM).");
708 switch (objFile->getOpSys()) {
709 case ObjectFile::Linux:
710 process = new ArmLinuxProcess(params, objFile);
711 break;
712
713 default:
714 fatal("Unknown/unsupported operating system.");
715 }
716#else
717#error "THE_ISA not set"
718#endif
719
720
721 if (process == NULL)
722 fatal("Unknown error creating process object.");
723 return process;
724}
725
726LiveProcess *
727LiveProcessParams::create()
728{
729 return LiveProcess::create(this);
730}
213
214 // return CPU number to caller
215 return myIndex;
216}
217
218void
219Process::startup()
220{
221 if (threadContexts.empty())
222 fatal("Process %s is not associated with any CPUs!\n", name());
223
224 // first thread context for this process... initialize & enable
225 ThreadContext *tc = threadContexts[0];
226
227 // mark this context as active so it will start ticking.
228 tc->activate(0);
229
230 Port *mem_port;
231 mem_port = system->physmem->getPort("functional");
232 initVirtMem = new TranslatingPort("process init port", this,
233 TranslatingPort::Always);
234 mem_port->setPeer(initVirtMem);
235 initVirtMem->setPeer(mem_port);
236}
237
238void
239Process::replaceThreadContext(ThreadContext *tc, int tcIndex)
240{
241 if (tcIndex >= threadContexts.size()) {
242 panic("replaceThreadContext: bad tcIndex, %d >= %d\n",
243 tcIndex, threadContexts.size());
244 }
245
246 threadContexts[tcIndex] = tc;
247}
248
249// map simulator fd sim_fd to target fd tgt_fd
250void
251Process::dup_fd(int sim_fd, int tgt_fd)
252{
253 if (tgt_fd < 0 || tgt_fd > MAX_FD)
254 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd);
255
256 Process::FdMap *fdo = &fd_map[tgt_fd];
257 fdo->fd = sim_fd;
258}
259
260
261// generate new target fd for sim_fd
262int
263Process::alloc_fd(int sim_fd, string filename, int flags, int mode, bool pipe)
264{
265 // in case open() returns an error, don't allocate a new fd
266 if (sim_fd == -1)
267 return -1;
268
269 // find first free target fd
270 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) {
271 Process::FdMap *fdo = &fd_map[free_fd];
272 if (fdo->fd == -1) {
273 fdo->fd = sim_fd;
274 fdo->filename = filename;
275 fdo->mode = mode;
276 fdo->fileOffset = 0;
277 fdo->flags = flags;
278 fdo->isPipe = pipe;
279 fdo->readPipeSource = 0;
280 return free_fd;
281 }
282 }
283
284 panic("Process::alloc_fd: out of file descriptors!");
285}
286
287
288// free target fd (e.g., after close)
289void
290Process::free_fd(int tgt_fd)
291{
292 Process::FdMap *fdo = &fd_map[tgt_fd];
293 if (fdo->fd == -1)
294 warn("Process::free_fd: request to free unused fd %d", tgt_fd);
295
296 fdo->fd = -1;
297 fdo->filename = "NULL";
298 fdo->mode = 0;
299 fdo->fileOffset = 0;
300 fdo->flags = 0;
301 fdo->isPipe = false;
302 fdo->readPipeSource = 0;
303}
304
305
306// look up simulator fd for given target fd
307int
308Process::sim_fd(int tgt_fd)
309{
310 if (tgt_fd > MAX_FD)
311 return -1;
312
313 return fd_map[tgt_fd].fd;
314}
315
316Process::FdMap *
317Process::sim_fd_obj(int tgt_fd)
318{
319 if (tgt_fd > MAX_FD)
320 panic("sim_fd_obj called in fd out of range.");
321
322 return &fd_map[tgt_fd];
323}
324bool
325Process::checkAndAllocNextPage(Addr vaddr)
326{
327 // if this is an initial write we might not have
328 if (vaddr >= stack_min && vaddr < stack_base) {
329 pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize);
330 return true;
331 }
332
333 // We've accessed the next page of the stack, so extend the stack
334 // to cover it.
335 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
336 while (vaddr < stack_min) {
337 stack_min -= TheISA::PageBytes;
338 if(stack_base - stack_min > max_stack_size)
339 fatal("Maximum stack size exceeded\n");
340 if(stack_base - stack_min > 8*1024*1024)
341 fatal("Over max stack size for one thread\n");
342 pTable->allocate(stack_min, TheISA::PageBytes);
343 warn("Increasing stack size by one page.");
344 };
345 return true;
346 }
347 return false;
348}
349
350 // find all offsets for currently open files and save them
351void
352Process::fix_file_offsets() {
353 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO];
354 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO];
355 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO];
356 string in = fdo_stdin->filename;
357 string out = fdo_stdout->filename;
358
359 // initialize file descriptors to default: same as simulator
360 int stdin_fd, stdout_fd, stderr_fd;
361
362 if (in == "stdin" || in == "cin")
363 stdin_fd = STDIN_FILENO;
364 else if (in == "None")
365 stdin_fd = -1;
366 else{
367 //OPEN standard in and seek to the right location
368 stdin_fd = Process::openInputFile(in);
369 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0)
370 panic("Unable to seek to correct location in file: %s", in);
371 }
372
373 if (out == "stdout" || out == "cout")
374 stdout_fd = STDOUT_FILENO;
375 else if (out == "stderr" || out == "cerr")
376 stdout_fd = STDERR_FILENO;
377 else if (out == "None")
378 stdout_fd = -1;
379 else{
380 stdout_fd = Process::openOutputFile(out);
381 if (lseek(stdin_fd, fdo_stdout->fileOffset, SEEK_SET) < 0)
382 panic("Unable to seek to correct in file: %s", out);
383 }
384
385 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
386
387 fdo_stdin->fd = stdin_fd;
388 fdo_stdout->fd = stdout_fd;
389 fdo_stderr->fd = stderr_fd;
390
391
392 for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) {
393 Process::FdMap *fdo = &fd_map[free_fd];
394 if (fdo->fd != -1) {
395 if (fdo->isPipe){
396 if (fdo->filename == "PIPE-WRITE")
397 continue;
398 else {
399 assert (fdo->filename == "PIPE-READ");
400 //create a new pipe
401 int fds[2];
402 int pipe_retval = pipe(fds);
403
404 if (pipe_retval < 0) {
405 // error
406 panic("Unable to create new pipe.");
407 }
408 fdo->fd = fds[0]; //set read pipe
409 Process::FdMap *fdo_write = &fd_map[fdo->readPipeSource];
410 if (fdo_write->filename != "PIPE-WRITE")
411 panic ("Couldn't find write end of the pipe");
412
413 fdo_write->fd = fds[1];//set write pipe
414 }
415 } else {
416 //Open file
417 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode);
418
419 if (fd == -1)
420 panic("Unable to open file: %s", fdo->filename);
421 fdo->fd = fd;
422
423 //Seek to correct location before checkpoint
424 if (lseek(fd,fdo->fileOffset, SEEK_SET) < 0)
425 panic("Unable to seek to correct location in file: %s", fdo->filename);
426 }
427 }
428 }
429}
430void
431Process::find_file_offsets(){
432 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) {
433 Process::FdMap *fdo = &fd_map[free_fd];
434 if (fdo->fd != -1) {
435 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR);
436 } else {
437 fdo->filename = "NULL";
438 fdo->fileOffset = 0;
439 }
440 }
441}
442
443void
444Process::setReadPipeSource(int read_pipe_fd, int source_fd){
445 Process::FdMap *fdo = &fd_map[read_pipe_fd];
446 fdo->readPipeSource = source_fd;
447}
448
449void
450Process::FdMap::serialize(std::ostream &os)
451{
452 SERIALIZE_SCALAR(fd);
453 SERIALIZE_SCALAR(isPipe);
454 SERIALIZE_SCALAR(filename);
455 SERIALIZE_SCALAR(flags);
456 SERIALIZE_SCALAR(readPipeSource);
457 SERIALIZE_SCALAR(fileOffset);
458}
459
460void
461Process::FdMap::unserialize(Checkpoint *cp, const std::string &section)
462{
463 UNSERIALIZE_SCALAR(fd);
464 UNSERIALIZE_SCALAR(isPipe);
465 UNSERIALIZE_SCALAR(filename);
466 UNSERIALIZE_SCALAR(flags);
467 UNSERIALIZE_SCALAR(readPipeSource);
468 UNSERIALIZE_SCALAR(fileOffset);
469}
470
471void
472Process::serialize(std::ostream &os)
473{
474 SERIALIZE_SCALAR(initialContextLoaded);
475 SERIALIZE_SCALAR(brk_point);
476 SERIALIZE_SCALAR(stack_base);
477 SERIALIZE_SCALAR(stack_size);
478 SERIALIZE_SCALAR(stack_min);
479 SERIALIZE_SCALAR(next_thread_stack_base);
480 SERIALIZE_SCALAR(mmap_start);
481 SERIALIZE_SCALAR(mmap_end);
482 SERIALIZE_SCALAR(nxm_start);
483 SERIALIZE_SCALAR(nxm_end);
484 find_file_offsets();
485 pTable->serialize(os);
486 for (int x = 0; x <= MAX_FD; x++) {
487 nameOut(os, csprintf("%s.FdMap%d", name(), x));
488 fd_map[x].serialize(os);
489 }
490
491}
492
493void
494Process::unserialize(Checkpoint *cp, const std::string &section)
495{
496 UNSERIALIZE_SCALAR(initialContextLoaded);
497 UNSERIALIZE_SCALAR(brk_point);
498 UNSERIALIZE_SCALAR(stack_base);
499 UNSERIALIZE_SCALAR(stack_size);
500 UNSERIALIZE_SCALAR(stack_min);
501 UNSERIALIZE_SCALAR(next_thread_stack_base);
502 UNSERIALIZE_SCALAR(mmap_start);
503 UNSERIALIZE_SCALAR(mmap_end);
504 UNSERIALIZE_SCALAR(nxm_start);
505 UNSERIALIZE_SCALAR(nxm_end);
506 pTable->unserialize(cp, section);
507 for (int x = 0; x <= MAX_FD; x++) {
508 fd_map[x].unserialize(cp, csprintf("%s.FdMap%d", section, x));
509 }
510 fix_file_offsets();
511
512 checkpointRestored = true;
513
514}
515
516
517////////////////////////////////////////////////////////////////////////
518//
519// LiveProcess member definitions
520//
521////////////////////////////////////////////////////////////////////////
522
523
524LiveProcess::LiveProcess(LiveProcessParams * params, ObjectFile *_objFile)
525 : Process(params), objFile(_objFile),
526 argv(params->cmd), envp(params->env), cwd(params->cwd)
527{
528 __uid = params->uid;
529 __euid = params->euid;
530 __gid = params->gid;
531 __egid = params->egid;
532 __pid = params->pid;
533 __ppid = params->ppid;
534
535 prog_fname = params->cmd[0];
536
537 // load up symbols, if any... these may be used for debugging or
538 // profiling.
539 if (!debugSymbolTable) {
540 debugSymbolTable = new SymbolTable();
541 if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
542 !objFile->loadLocalSymbols(debugSymbolTable)) {
543 // didn't load any symbols
544 delete debugSymbolTable;
545 debugSymbolTable = NULL;
546 }
547 }
548}
549
550void
551LiveProcess::argsInit(int intSize, int pageSize)
552{
553 Process::startup();
554
555 // load object file into target memory
556 objFile->loadSections(initVirtMem);
557
558 // Calculate how much space we need for arg & env arrays.
559 int argv_array_size = intSize * (argv.size() + 1);
560 int envp_array_size = intSize * (envp.size() + 1);
561 int arg_data_size = 0;
562 for (int i = 0; i < argv.size(); ++i) {
563 arg_data_size += argv[i].size() + 1;
564 }
565 int env_data_size = 0;
566 for (int i = 0; i < envp.size(); ++i) {
567 env_data_size += envp[i].size() + 1;
568 }
569
570 int space_needed =
571 argv_array_size + envp_array_size + arg_data_size + env_data_size;
572 if (space_needed < 32*1024)
573 space_needed = 32*1024;
574
575 // set bottom of stack
576 stack_min = stack_base - space_needed;
577 // align it
578 stack_min = roundDown(stack_min, pageSize);
579 stack_size = stack_base - stack_min;
580 // map memory
581 pTable->allocate(stack_min, roundUp(stack_size, pageSize));
582
583 // map out initial stack contents
584 Addr argv_array_base = stack_min + intSize; // room for argc
585 Addr envp_array_base = argv_array_base + argv_array_size;
586 Addr arg_data_base = envp_array_base + envp_array_size;
587 Addr env_data_base = arg_data_base + arg_data_size;
588
589 // write contents to stack
590 uint64_t argc = argv.size();
591 if (intSize == 8)
592 argc = htog((uint64_t)argc);
593 else if (intSize == 4)
594 argc = htog((uint32_t)argc);
595 else
596 panic("Unknown int size");
597
598 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize);
599
600 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
601 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
602
603 assert(NumArgumentRegs >= 2);
604 threadContexts[0]->setIntReg(ArgumentReg[0], argc);
605 threadContexts[0]->setIntReg(ArgumentReg[1], argv_array_base);
606 threadContexts[0]->setIntReg(StackPointerReg, stack_min);
607
608 Addr prog_entry = objFile->entryPoint();
609 threadContexts[0]->setPC(prog_entry);
610 threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
611
612#if THE_ISA != ALPHA_ISA //e.g. MIPS or Sparc
613 threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
614#endif
615
616 num_processes++;
617}
618
619void
620LiveProcess::syscall(int64_t callnum, ThreadContext *tc)
621{
622 num_syscalls++;
623
624 SyscallDesc *desc = getDesc(callnum);
625 if (desc == NULL)
626 fatal("Syscall %d out of range", callnum);
627
628 desc->doSyscall(callnum, this, tc);
629}
630
631LiveProcess *
632LiveProcess::create(LiveProcessParams * params)
633{
634 LiveProcess *process = NULL;
635
636 string executable =
637 params->executable == "" ? params->cmd[0] : params->executable;
638 ObjectFile *objFile = createObjectFile(executable);
639 if (objFile == NULL) {
640 fatal("Can't load object file %s", executable);
641 }
642
643 if (objFile->isDynamic())
644 fatal("Object file is a dynamic executable however only static "
645 "executables are supported!\n Please recompile your "
646 "executable as a static binary and try again.\n");
647
648#if THE_ISA == ALPHA_ISA
649 if (objFile->hasTLS())
650 fatal("Object file has a TLS section and single threaded TLS is not\n"
651 " currently supported for Alpha! Please recompile your "
652 "executable with \n a non-TLS toolchain.\n");
653
654 if (objFile->getArch() != ObjectFile::Alpha)
655 fatal("Object file architecture does not match compiled ISA (Alpha).");
656 switch (objFile->getOpSys()) {
657 case ObjectFile::Tru64:
658 process = new AlphaTru64Process(params, objFile);
659 break;
660
661 case ObjectFile::Linux:
662 process = new AlphaLinuxProcess(params, objFile);
663 break;
664
665 default:
666 fatal("Unknown/unsupported operating system.");
667 }
668#elif THE_ISA == SPARC_ISA
669 if (objFile->getArch() != ObjectFile::SPARC64 && objFile->getArch() != ObjectFile::SPARC32)
670 fatal("Object file architecture does not match compiled ISA (SPARC).");
671 switch (objFile->getOpSys()) {
672 case ObjectFile::Linux:
673 if (objFile->getArch() == ObjectFile::SPARC64) {
674 process = new Sparc64LinuxProcess(params, objFile);
675 } else {
676 process = new Sparc32LinuxProcess(params, objFile);
677 }
678 break;
679
680
681 case ObjectFile::Solaris:
682 process = new SparcSolarisProcess(params, objFile);
683 break;
684 default:
685 fatal("Unknown/unsupported operating system.");
686 }
687#elif THE_ISA == X86_ISA
688 if (objFile->getArch() != ObjectFile::X86)
689 fatal("Object file architecture does not match compiled ISA (x86).");
690 switch (objFile->getOpSys()) {
691 case ObjectFile::Linux:
692 process = new X86LinuxProcess(params, objFile);
693 break;
694 default:
695 fatal("Unknown/unsupported operating system.");
696 }
697#elif THE_ISA == MIPS_ISA
698 if (objFile->getArch() != ObjectFile::Mips)
699 fatal("Object file architecture does not match compiled ISA (MIPS).");
700 switch (objFile->getOpSys()) {
701 case ObjectFile::Linux:
702 process = new MipsLinuxProcess(params, objFile);
703 break;
704
705 default:
706 fatal("Unknown/unsupported operating system.");
707 }
708#elif THE_ISA == ARM_ISA
709 if (objFile->getArch() != ObjectFile::Arm)
710 fatal("Object file architecture does not match compiled ISA (ARM).");
711 switch (objFile->getOpSys()) {
712 case ObjectFile::Linux:
713 process = new ArmLinuxProcess(params, objFile);
714 break;
715
716 default:
717 fatal("Unknown/unsupported operating system.");
718 }
719#else
720#error "THE_ISA not set"
721#endif
722
723
724 if (process == NULL)
725 fatal("Unknown error creating process object.");
726 return process;
727}
728
729LiveProcess *
730LiveProcessParams::create()
731{
732 return LiveProcess::create(this);
733}