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