process.cc revision 11378:8457e0a24e5d
12SN/A/*
21762SN/A * Copyright (c) 2014 Advanced Micro Devices, Inc.
32SN/A * Copyright (c) 2012 ARM Limited
42SN/A * All rights reserved
52SN/A *
62SN/A * The license below extends only to copyright in the software and shall
72SN/A * not be construed as granting a license to any other intellectual
82SN/A * property including but not limited to intellectual property relating
92SN/A * to a hardware implementation of the functionality of the software
102SN/A * licensed hereunder.  You may use the software subject to the license
112SN/A * terms below provided that you ensure that this notice is replicated
122SN/A * unmodified and in its entirety in all distributions of the software,
132SN/A * modified or unmodified, in source code or in binary form.
142SN/A *
152SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
162SN/A * All rights reserved.
172SN/A *
182SN/A * Redistribution and use in source and binary forms, with or without
192SN/A * modification, are permitted provided that the following conditions are
202SN/A * met: redistributions of source code must retain the above copyright
212SN/A * notice, this list of conditions and the following disclaimer;
222SN/A * redistributions in binary form must reproduce the above copyright
232SN/A * notice, this list of conditions and the following disclaimer in the
242SN/A * documentation and/or other materials provided with the distribution;
252SN/A * neither the name of the copyright holders nor the names of its
262SN/A * contributors may be used to endorse or promote products derived from
272665Ssaidi@eecs.umich.edu * this software without specific prior written permission.
282760Sbinkertn@umich.edu *
292760Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302665Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34363SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35363SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
361354SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
372SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402SN/A *
412SN/A * Authors: Nathan Binkert
422SN/A *          Steve Reinhardt
43363SN/A *          Ali Saidi
4456SN/A */
451388SN/A
46217SN/A#include <fcntl.h>
47363SN/A#include <unistd.h>
4856SN/A
4956SN/A#include <cstdio>
5056SN/A#include <map>
5156SN/A#include <string>
521638SN/A
5356SN/A#include "base/loader/object_file.hh"
542SN/A#include "base/loader/symtab.hh"
552SN/A#include "base/intmath.hh"
562SN/A#include "base/statistics.hh"
572287SN/A#include "config/the_isa.hh"
582287SN/A#include "cpu/thread_context.hh"
592287SN/A#include "mem/page_table.hh"
601637SN/A#include "mem/multi_level_page_table.hh"
612SN/A#include "mem/se_translating_port_proxy.hh"
62395SN/A#include "params/LiveProcess.hh"
632SN/A#include "params/Process.hh"
64217SN/A#include "sim/debug.hh"
652SN/A#include "sim/process.hh"
662SN/A#include "sim/process_impl.hh"
672SN/A#include "sim/stats.hh"
68395SN/A#include "sim/syscall_emul.hh"
692SN/A#include "sim/system.hh"
70217SN/A
712SN/A#if THE_ISA == ALPHA_ISA
722SN/A#include "arch/alpha/linux/process.hh"
73217SN/A#include "arch/alpha/tru64/process.hh"
742SN/A#elif THE_ISA == SPARC_ISA
75502SN/A#include "arch/sparc/linux/process.hh"
762SN/A#include "arch/sparc/solaris/process.hh"
77217SN/A#elif THE_ISA == MIPS_ISA
78217SN/A#include "arch/mips/linux/process.hh"
79217SN/A#elif THE_ISA == ARM_ISA
802SN/A#include "arch/arm/linux/process.hh"
812SN/A#include "arch/arm/freebsd/process.hh"
82217SN/A#elif THE_ISA == X86_ISA
83217SN/A#include "arch/x86/linux/process.hh"
84217SN/A#elif THE_ISA == POWER_ISA
85237SN/A#include "arch/power/linux/process.hh"
86502SN/A#else
872SN/A#error "THE_ISA not set"
88217SN/A#endif
89237SN/A
90217SN/A
91217SN/Ausing namespace std;
922SN/Ausing namespace TheISA;
932SN/A
94217SN/A// current number of allocated processes
95217SN/Aint num_processes = 0;
96217SN/A
97217SN/Atemplate<class IntType>
98217SN/A
99217SN/AAuxVector<IntType>::AuxVector(IntType type, IntType val)
100217SN/A{
101217SN/A    a_type = TheISA::htog(type);
102217SN/A    a_val = TheISA::htog(val);
103217SN/A}
104217SN/A
105217SN/Atemplate struct AuxVector<uint32_t>;
106217SN/Atemplate struct AuxVector<uint64_t>;
107217SN/A
108217SN/Astatic int
109217SN/AopenFile(const string& filename, int flags, mode_t mode)
110217SN/A{
111217SN/A    int sim_fd = open(filename.c_str(), flags, mode);
112217SN/A    if (sim_fd != -1)
113237SN/A        return sim_fd;
114217SN/A    fatal("Unable to open %s with mode %O", filename, mode);
115217SN/A}
116217SN/A
117237SN/Astatic int
118217SN/AopenInputFile(const string &filename)
119217SN/A{
120217SN/A    return openFile(filename, O_RDONLY, 0);
121217SN/A}
122217SN/A
123217SN/Astatic int
124217SN/AopenOutputFile(const string &filename)
125217SN/A{
126217SN/A    return openFile(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
127217SN/A}
128217SN/A
129217SN/AProcess::Process(ProcessParams * params)
130217SN/A    : SimObject(params), system(params->system),
131217SN/A      brk_point(0), stack_base(0), stack_size(0), stack_min(0),
132217SN/A      max_stack_size(params->max_stack_size),
133217SN/A      next_thread_stack_base(0),
134217SN/A      M5_pid(system->allocatePID()),
135217SN/A      useArchPT(params->useArchPT),
136217SN/A      kvmInSE(params->kvmInSE),
137217SN/A      pTable(useArchPT ?
138217SN/A        static_cast<PageTableBase *>(new ArchPageTable(name(), M5_pid, system)) :
139217SN/A        static_cast<PageTableBase *>(new FuncPageTable(name(), M5_pid)) ),
140217SN/A      initVirtMem(system->getSystemPort(), this,
141217SN/A                  SETranslatingPortProxy::Always),
142217SN/A      fd_array(make_shared<array<FDEntry, NUM_FDS>>()),
143217SN/A      imap {{"",       -1},
144217SN/A            {"cin",    STDIN_FILENO},
145217SN/A            {"stdin",  STDIN_FILENO}},
146217SN/A      oemap{{"",       -1},
147217SN/A            {"cout",   STDOUT_FILENO},
148217SN/A            {"stdout", STDOUT_FILENO},
149217SN/A            {"cerr",   STDERR_FILENO},
150217SN/A            {"stderr", STDERR_FILENO}}
151217SN/A{
152217SN/A    int sim_fd;
153217SN/A    std::map<string,int>::iterator it;
154217SN/A
155217SN/A    // Search through the input options and set fd if match is found;
156237SN/A    // otherwise, open an input file and seek to location.
157237SN/A    FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
158395SN/A    if ((it = imap.find(params->input)) != imap.end())
159237SN/A        sim_fd = it->second;
160237SN/A    else
161237SN/A        sim_fd = openInputFile(params->input);
162237SN/A    fde_stdin->set(sim_fd, params->input, O_RDONLY, -1, false);
163237SN/A
164237SN/A    // Search through the output/error options and set fd if match is found;
165237SN/A    // otherwise, open an output file and seek to location.
166221SN/A    FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO);
167221SN/A    if ((it = oemap.find(params->output)) != oemap.end())
168237SN/A        sim_fd = it->second;
169221SN/A    else
170237SN/A        sim_fd = openOutputFile(params->output);
171221SN/A    fde_stdout->set(sim_fd, params->output, O_WRONLY | O_CREAT | O_TRUNC,
172221SN/A                    0664, false);
173221SN/A
174237SN/A    FDEntry *fde_stderr = getFDEntry(STDERR_FILENO);
175221SN/A    if (params->output == params->errout)
176237SN/A        // Reuse the same file descriptor if these match.
177217SN/A        sim_fd = fde_stdout->fd;
178217SN/A    else if ((it = oemap.find(params->errout)) != oemap.end())
1791642SN/A        sim_fd = it->second;
1801642SN/A    else
1811642SN/A        sim_fd = openOutputFile(params->errout);
1821642SN/A    fde_stderr->set(sim_fd, params->errout, O_WRONLY | O_CREAT | O_TRUNC,
1831642SN/A                    0664, false);
1841642SN/A
1851642SN/A    mmap_start = mmap_end = 0;
1861642SN/A    nxm_start = nxm_end = 0;
1871642SN/A    // other parameters will be initialized when the program is loaded
1881642SN/A}
189219SN/A
190217SN/A
191217SN/Avoid
192217SN/AProcess::regStats()
193395SN/A{
194395SN/A    using namespace Stats;
195395SN/A
196395SN/A    num_syscalls
197395SN/A        .name(name() + ".num_syscalls")
1982SN/A        .desc("Number of system calls")
199395SN/A        ;
200512SN/A}
201510SN/A
202395SN/Avoid
203395SN/AProcess::inheritFDArray(Process *p)
2042SN/A{
205395SN/A    fd_array = p->fd_array;
206395SN/A}
2072SN/A
208512SN/AThreadContext *
209395SN/AProcess::findFreeContext()
2102SN/A{
211395SN/A    for (int id : contextIds) {
2122SN/A        ThreadContext *tc = system->getThreadContext(id);
2132SN/A        if (tc->status() == ThreadContext::Halted)
2142SN/A            return tc;
215510SN/A    }
2162SN/A    return NULL;
217395SN/A}
218395SN/A
219395SN/Avoid
220395SN/AProcess::initState()
221395SN/A{
2222SN/A    if (contextIds.empty())
2232SN/A        fatal("Process %s is not associated with any HW contexts!\n", name());
2242SN/A
225395SN/A    // first thread context for this process... initialize & enable
2262SN/A    ThreadContext *tc = system->getThreadContext(contextIds[0]);
227395SN/A
228395SN/A    // mark this context as active so it will start ticking.
2292SN/A    tc->activate();
230395SN/A
2312SN/A    pTable->initState(tc);
2322SN/A}
2332SN/A
2342868Sktlim@umich.eduDrainState
2352SN/AProcess::drain()
2362868Sktlim@umich.edu{
237449SN/A    findFileOffsets();
238363SN/A    return DrainState::Drained;
239449SN/A}
240363SN/A
241449SN/Aint
242395SN/AProcess::allocFD(int sim_fd, const string& filename, int flags, int mode,
2432SN/A                 bool pipe)
244395SN/A{
2452SN/A    for (int free_fd = 0; free_fd < fd_array->size(); free_fd++) {
246395SN/A        FDEntry *fde = getFDEntry(free_fd);
247395SN/A        if (fde->isFree()) {
248395SN/A            fde->set(sim_fd, filename, flags, mode, pipe);
2492SN/A            return free_fd;
2502797Sktlim@umich.edu        }
2512868Sktlim@umich.edu    }
2522797Sktlim@umich.edu
2532868Sktlim@umich.edu    fatal("Out of target file descriptors");
2542797Sktlim@umich.edu}
2552797Sktlim@umich.edu
2562797Sktlim@umich.eduvoid
2572797Sktlim@umich.eduProcess::resetFDEntry(int tgt_fd)
2582797Sktlim@umich.edu{
2592797Sktlim@umich.edu    FDEntry *fde = getFDEntry(tgt_fd);
2602797Sktlim@umich.edu    assert(fde->fd > -1);
2612797Sktlim@umich.edu
2622797Sktlim@umich.edu    fde->reset();
2632797Sktlim@umich.edu}
2642797Sktlim@umich.edu
2652SN/Aint
266395SN/AProcess::getSimFD(int tgt_fd)
267395SN/A{
268395SN/A    FDEntry *entry = getFDEntry(tgt_fd);
269395SN/A    return entry ? entry->fd : -1;
270395SN/A}
2712SN/A
272449SN/AFDEntry *
273449SN/AProcess::getFDEntry(int tgt_fd)
274449SN/A{
275294SN/A    assert(0 <= tgt_fd && tgt_fd < fd_array->size());
2762797Sktlim@umich.edu    return &(*fd_array)[tgt_fd];
2772797Sktlim@umich.edu}
2782797Sktlim@umich.edu
2792797Sktlim@umich.eduint
2802797Sktlim@umich.eduProcess::getTgtFD(int sim_fd)
2812797Sktlim@umich.edu{
2822797Sktlim@umich.edu    for (int index = 0; index < fd_array->size(); index++)
2832797Sktlim@umich.edu        if ((*fd_array)[index].fd == sim_fd)
284294SN/A            return index;
285449SN/A    return -1;
286294SN/A}
287449SN/A
288449SN/Avoid
289449SN/AProcess::allocateMem(Addr vaddr, int64_t size, bool clobber)
290449SN/A{
2912SN/A    int npages = divCeil(size, (int64_t)PageBytes);
2922SN/A    Addr paddr = system->allocPhysPages(npages);
2932SN/A    pTable->map(vaddr, paddr, size,
2942868Sktlim@umich.edu                clobber ? PageTableBase::Clobber : PageTableBase::Zero);
2952SN/A}
2962868Sktlim@umich.edu
2972SN/Abool
2982SN/AProcess::fixupStackFault(Addr vaddr)
2992SN/A{
3002SN/A    // Check if this is already on the stack and there's just no page there
3012SN/A    // yet.
302395SN/A    if (vaddr >= stack_min && vaddr < stack_base) {
3032SN/A        allocateMem(roundDown(vaddr, PageBytes), PageBytes);
3042SN/A        return true;
3052SN/A    }
306395SN/A
3072SN/A    // We've accessed the next page of the stack, so extend it to include
308395SN/A    // this address.
3092SN/A    if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
310395SN/A        while (vaddr < stack_min) {
3112SN/A            stack_min -= TheISA::PageBytes;
312395SN/A            if (stack_base - stack_min > max_stack_size)
313395SN/A                fatal("Maximum stack size exceeded\n");
3142SN/A            allocateMem(stack_min, TheISA::PageBytes);
3152SN/A            inform("Increasing stack size by one page.");
3162SN/A        };
317395SN/A        return true;
3182SN/A    }
3192SN/A    return false;
3202SN/A}
3212SN/A
3222SN/Avoid
3232SN/AProcess::fixFileOffsets()
3242SN/A{
3252SN/A    auto seek = [] (FDEntry *fde)
3262SN/A    {
3272SN/A        if (lseek(fde->fd, fde->fileOffset, SEEK_SET) < 0)
3282SN/A            fatal("Unable to see to location in %s", fde->filename);
3292SN/A    };
3302SN/A
3312SN/A    std::map<string,int>::iterator it;
3322SN/A
333395SN/A    // Search through the input options and set fd if match is found;
334395SN/A    // otherwise, open an input file and seek to location.
335237SN/A    FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
3362SN/A    if ((it = imap.find(fde_stdin->filename)) != imap.end()) {
337237SN/A        fde_stdin->fd = it->second;
3382SN/A    } else {
339237SN/A        fde_stdin->fd = openInputFile(fde_stdin->filename);
340395SN/A        seek(fde_stdin);
341237SN/A    }
3422SN/A
3432SN/A    // Search through the output/error options and set fd if match is found;
344237SN/A    // otherwise, open an output file and seek to location.
345237SN/A    FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO);
346237SN/A    if ((it = oemap.find(fde_stdout->filename)) != oemap.end()) {
347395SN/A        fde_stdout->fd = it->second;
348237SN/A    } else {
3492SN/A        fde_stdout->fd = openOutputFile(fde_stdout->filename);
3502SN/A        seek(fde_stdout);
351395SN/A    }
3522SN/A
3532SN/A    FDEntry *fde_stderr = getFDEntry(STDERR_FILENO);
3542SN/A    if (fde_stdout->filename == fde_stderr->filename) {
3552SN/A        // Reuse the same file descriptor if these match.
3562SN/A        fde_stderr->fd = fde_stdout->fd;
3572SN/A    } else if ((it = oemap.find(fde_stderr->filename)) != oemap.end()) {
358237SN/A        fde_stderr->fd = it->second;
359395SN/A    } else {
360395SN/A        fde_stderr->fd = openOutputFile(fde_stderr->filename);
361237SN/A        seek(fde_stderr);
362395SN/A    }
363237SN/A
364237SN/A    for (int tgt_fd = 3; tgt_fd < fd_array->size(); tgt_fd++) {
365237SN/A        FDEntry *fde = getFDEntry(tgt_fd);
366237SN/A        if (fde->fd == -1)
367237SN/A            continue;
3682738Sstever@eecs.umich.edu
3692738Sstever@eecs.umich.edu        if (fde->isPipe) {
370237SN/A            if (fde->filename == "PIPE-WRITE")
371449SN/A                continue;
372237SN/A            assert(fde->filename == "PIPE-READ");
373237SN/A
374237SN/A            int fds[2];
375237SN/A            if (pipe(fds) < 0)
376237SN/A                fatal("Unable to create new pipe");
377237SN/A
378237SN/A            fde->fd = fds[0];
379237SN/A
380237SN/A            FDEntry *fde_write = getFDEntry(fde->readPipeSource);
381237SN/A            assert(fde_write->filename == "PIPE-WRITE");
382237SN/A            fde_write->fd = fds[1];
383237SN/A        } else {
384237SN/A            fde->fd = openFile(fde->filename.c_str(), fde->flags, fde->mode);
385237SN/A            seek(fde);
386237SN/A        }
387237SN/A    }
388395SN/A}
389237SN/A
390237SN/Avoid
391237SN/AProcess::findFileOffsets()
392237SN/A{
393237SN/A    for (auto& fde : *fd_array) {
394237SN/A        if (fde.fd != -1)
395237SN/A            fde.fileOffset = lseek(fde.fd, 0, SEEK_CUR);
396237SN/A    }
397237SN/A}
398237SN/A
399237SN/Avoid
400304SN/AProcess::setReadPipeSource(int read_pipe_fd, int source_fd)
401304SN/A{
402304SN/A    FDEntry *fde = getFDEntry(read_pipe_fd);
403304SN/A    assert(source_fd >= -1);
404304SN/A    fde->readPipeSource = source_fd;
405304SN/A}
406304SN/A
407void
408Process::serialize(CheckpointOut &cp) const
409{
410    SERIALIZE_SCALAR(brk_point);
411    SERIALIZE_SCALAR(stack_base);
412    SERIALIZE_SCALAR(stack_size);
413    SERIALIZE_SCALAR(stack_min);
414    SERIALIZE_SCALAR(next_thread_stack_base);
415    SERIALIZE_SCALAR(mmap_start);
416    SERIALIZE_SCALAR(mmap_end);
417    SERIALIZE_SCALAR(nxm_start);
418    SERIALIZE_SCALAR(nxm_end);
419    pTable->serialize(cp);
420    for (int x = 0; x < fd_array->size(); x++) {
421        (*fd_array)[x].serializeSection(cp, csprintf("FDEntry%d", x));
422    }
423    SERIALIZE_SCALAR(M5_pid);
424
425}
426
427void
428Process::unserialize(CheckpointIn &cp)
429{
430    UNSERIALIZE_SCALAR(brk_point);
431    UNSERIALIZE_SCALAR(stack_base);
432    UNSERIALIZE_SCALAR(stack_size);
433    UNSERIALIZE_SCALAR(stack_min);
434    UNSERIALIZE_SCALAR(next_thread_stack_base);
435    UNSERIALIZE_SCALAR(mmap_start);
436    UNSERIALIZE_SCALAR(mmap_end);
437    UNSERIALIZE_SCALAR(nxm_start);
438    UNSERIALIZE_SCALAR(nxm_end);
439    pTable->unserialize(cp);
440    for (int x = 0; x < fd_array->size(); x++) {
441        FDEntry *fde = getFDEntry(x);
442        fde->unserializeSection(cp, csprintf("FDEntry%d", x));
443    }
444    fixFileOffsets();
445    UNSERIALIZE_OPT_SCALAR(M5_pid);
446    // The above returns a bool so that you could do something if you don't
447    // find the param in the checkpoint if you wanted to, like set a default
448    // but in this case we'll just stick with the instantiated value if not
449    // found.
450}
451
452
453bool
454Process::map(Addr vaddr, Addr paddr, int size, bool cacheable)
455{
456    pTable->map(vaddr, paddr, size,
457                cacheable ? PageTableBase::Zero : PageTableBase::Uncacheable);
458    return true;
459}
460
461
462////////////////////////////////////////////////////////////////////////
463//
464// LiveProcess member definitions
465//
466////////////////////////////////////////////////////////////////////////
467
468
469LiveProcess::LiveProcess(LiveProcessParams *params, ObjectFile *_objFile)
470    : Process(params), objFile(_objFile),
471      argv(params->cmd), envp(params->env), cwd(params->cwd),
472      executable(params->executable),
473      __uid(params->uid), __euid(params->euid),
474      __gid(params->gid), __egid(params->egid),
475      __pid(params->pid), __ppid(params->ppid),
476      drivers(params->drivers)
477{
478
479    // load up symbols, if any... these may be used for debugging or
480    // profiling.
481    if (!debugSymbolTable) {
482        debugSymbolTable = new SymbolTable();
483        if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
484            !objFile->loadLocalSymbols(debugSymbolTable) ||
485            !objFile->loadWeakSymbols(debugSymbolTable)) {
486            // didn't load any symbols
487            delete debugSymbolTable;
488            debugSymbolTable = NULL;
489        }
490    }
491}
492
493void
494LiveProcess::syscall(int64_t callnum, ThreadContext *tc)
495{
496    num_syscalls++;
497
498    SyscallDesc *desc = getDesc(callnum);
499    if (desc == NULL)
500        fatal("Syscall %d out of range", callnum);
501
502    desc->doSyscall(callnum, this, tc);
503}
504
505IntReg
506LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width)
507{
508    return getSyscallArg(tc, i);
509}
510
511
512EmulatedDriver *
513LiveProcess::findDriver(std::string filename)
514{
515    for (EmulatedDriver *d : drivers) {
516        if (d->match(filename))
517            return d;
518    }
519
520    return NULL;
521}
522
523
524LiveProcess *
525LiveProcess::create(LiveProcessParams * params)
526{
527    LiveProcess *process = NULL;
528
529    // If not specified, set the executable parameter equal to the
530    // simulated system's zeroth command line parameter
531    if (params->executable == "") {
532        params->executable = params->cmd[0];
533    }
534
535    ObjectFile *objFile = createObjectFile(params->executable);
536    if (objFile == NULL) {
537        fatal("Can't load object file %s", params->executable);
538    }
539
540    if (objFile->isDynamic())
541       fatal("Object file is a dynamic executable however only static "
542             "executables are supported!\n       Please recompile your "
543             "executable as a static binary and try again.\n");
544
545#if THE_ISA == ALPHA_ISA
546    if (objFile->getArch() != ObjectFile::Alpha)
547        fatal("Object file architecture does not match compiled ISA (Alpha).");
548
549    switch (objFile->getOpSys()) {
550      case ObjectFile::Tru64:
551        process = new AlphaTru64Process(params, objFile);
552        break;
553
554      case ObjectFile::UnknownOpSys:
555        warn("Unknown operating system; assuming Linux.");
556        // fall through
557      case ObjectFile::Linux:
558        process = new AlphaLinuxProcess(params, objFile);
559        break;
560
561      default:
562        fatal("Unknown/unsupported operating system.");
563    }
564#elif THE_ISA == SPARC_ISA
565    if (objFile->getArch() != ObjectFile::SPARC64 &&
566        objFile->getArch() != ObjectFile::SPARC32)
567        fatal("Object file architecture does not match compiled ISA (SPARC).");
568    switch (objFile->getOpSys()) {
569      case ObjectFile::UnknownOpSys:
570        warn("Unknown operating system; assuming Linux.");
571        // fall through
572      case ObjectFile::Linux:
573        if (objFile->getArch() == ObjectFile::SPARC64) {
574            process = new Sparc64LinuxProcess(params, objFile);
575        } else {
576            process = new Sparc32LinuxProcess(params, objFile);
577        }
578        break;
579
580
581      case ObjectFile::Solaris:
582        process = new SparcSolarisProcess(params, objFile);
583        break;
584
585      default:
586        fatal("Unknown/unsupported operating system.");
587    }
588#elif THE_ISA == X86_ISA
589    if (objFile->getArch() != ObjectFile::X86_64 &&
590        objFile->getArch() != ObjectFile::I386)
591        fatal("Object file architecture does not match compiled ISA (x86).");
592    switch (objFile->getOpSys()) {
593      case ObjectFile::UnknownOpSys:
594        warn("Unknown operating system; assuming Linux.");
595        // fall through
596      case ObjectFile::Linux:
597        if (objFile->getArch() == ObjectFile::X86_64) {
598            process = new X86_64LinuxProcess(params, objFile);
599        } else {
600            process = new I386LinuxProcess(params, objFile);
601        }
602        break;
603
604      default:
605        fatal("Unknown/unsupported operating system.");
606    }
607#elif THE_ISA == MIPS_ISA
608    if (objFile->getArch() != ObjectFile::Mips)
609        fatal("Object file architecture does not match compiled ISA (MIPS).");
610    switch (objFile->getOpSys()) {
611      case ObjectFile::UnknownOpSys:
612        warn("Unknown operating system; assuming Linux.");
613        // fall through
614      case ObjectFile::Linux:
615        process = new MipsLinuxProcess(params, objFile);
616        break;
617
618      default:
619        fatal("Unknown/unsupported operating system.");
620    }
621#elif THE_ISA == ARM_ISA
622    ObjectFile::Arch arch = objFile->getArch();
623    if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
624        arch != ObjectFile::Arm64)
625        fatal("Object file architecture does not match compiled ISA (ARM).");
626    switch (objFile->getOpSys()) {
627      case ObjectFile::UnknownOpSys:
628        warn("Unknown operating system; assuming Linux.");
629        // fall through
630      case ObjectFile::Linux:
631        if (arch == ObjectFile::Arm64) {
632            process = new ArmLinuxProcess64(params, objFile,
633                                            objFile->getArch());
634        } else {
635            process = new ArmLinuxProcess32(params, objFile,
636                                            objFile->getArch());
637        }
638        break;
639      case ObjectFile::FreeBSD:
640        if (arch == ObjectFile::Arm64) {
641            process = new ArmFreebsdProcess64(params, objFile,
642                                              objFile->getArch());
643        } else {
644            process = new ArmFreebsdProcess32(params, objFile,
645                                              objFile->getArch());
646        }
647        break;
648      case ObjectFile::LinuxArmOABI:
649        fatal("M5 does not support ARM OABI binaries. Please recompile with an"
650              " EABI compiler.");
651      default:
652        fatal("Unknown/unsupported operating system.");
653    }
654#elif THE_ISA == POWER_ISA
655    if (objFile->getArch() != ObjectFile::Power)
656        fatal("Object file architecture does not match compiled ISA (Power).");
657    switch (objFile->getOpSys()) {
658      case ObjectFile::UnknownOpSys:
659        warn("Unknown operating system; assuming Linux.");
660        // fall through
661      case ObjectFile::Linux:
662        process = new PowerLinuxProcess(params, objFile);
663        break;
664
665      default:
666        fatal("Unknown/unsupported operating system.");
667    }
668#else
669#error "THE_ISA not set"
670#endif
671
672    if (process == NULL)
673        fatal("Unknown error creating process object.");
674    return process;
675}
676
677LiveProcess *
678LiveProcessParams::create()
679{
680    return LiveProcess::create(this);
681}
682