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