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