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