process.cc revision 11877
12SN/A/*
211856Sbrandon.potter@amd.com * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
38852Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited
48852Sandreas.hansson@arm.com * All rights reserved
58852Sandreas.hansson@arm.com *
68852Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
78852Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
88852Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
98852Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
108852Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
118852Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
128852Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
138852Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
148852Sandreas.hansson@arm.com *
151762SN/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
272SN/A * this software without specific prior written permission.
282SN/A *
292SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302SN/A * "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,
342SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
362SN/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.
402665Ssaidi@eecs.umich.edu *
412665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
422665Ssaidi@eecs.umich.edu *          Steve Reinhardt
432665Ssaidi@eecs.umich.edu *          Ali Saidi
4411856Sbrandon.potter@amd.com *          Brandon Potter
452SN/A */
462SN/A
4711793Sbrandon.potter@amd.com#include "sim/process.hh"
4811793Sbrandon.potter@amd.com
498229Snate@binkert.org#include <fcntl.h>
502SN/A#include <unistd.h>
516712Snate@binkert.org
5211800Sbrandon.potter@amd.com#include <array>
5310930Sbrandon.potter@amd.com#include <map>
542SN/A#include <string>
5511800Sbrandon.potter@amd.com#include <vector>
562SN/A
5711793Sbrandon.potter@amd.com#include "base/intmath.hh"
5856SN/A#include "base/loader/object_file.hh"
591158SN/A#include "base/loader/symtab.hh"
60146SN/A#include "base/statistics.hh"
616658Snate@binkert.org#include "config/the_isa.hh"
622680Sktlim@umich.edu#include "cpu/thread_context.hh"
632378SN/A#include "mem/page_table.hh"
648706Sandreas.hansson@arm.com#include "mem/se_translating_port_proxy.hh"
655154Sgblack@eecs.umich.edu#include "params/Process.hh"
6611800Sbrandon.potter@amd.com#include "sim/emul_driver.hh"
6711856Sbrandon.potter@amd.com#include "sim/fd_array.hh"
6811856Sbrandon.potter@amd.com#include "sim/fd_entry.hh"
6911794Sbrandon.potter@amd.com#include "sim/syscall_desc.hh"
702378SN/A#include "sim/system.hh"
712SN/A
722715Sstever@eecs.umich.edu#if THE_ISA == ALPHA_ISA
732715Sstever@eecs.umich.edu#include "arch/alpha/linux/process.hh"
742715Sstever@eecs.umich.edu#elif THE_ISA == SPARC_ISA
752715Sstever@eecs.umich.edu#include "arch/sparc/linux/process.hh"
762715Sstever@eecs.umich.edu#include "arch/sparc/solaris/process.hh"
772715Sstever@eecs.umich.edu#elif THE_ISA == MIPS_ISA
782715Sstever@eecs.umich.edu#include "arch/mips/linux/process.hh"
795335Shines@cs.fsu.edu#elif THE_ISA == ARM_ISA
805335Shines@cs.fsu.edu#include "arch/arm/linux/process.hh"
8110810Sbr@bsdpad.com#include "arch/arm/freebsd/process.hh"
824157Sgblack@eecs.umich.edu#elif THE_ISA == X86_ISA
834166Sgblack@eecs.umich.edu#include "arch/x86/linux/process.hh"
846691Stjones1@inf.ed.ac.uk#elif THE_ISA == POWER_ISA
856691Stjones1@inf.ed.ac.uk#include "arch/power/linux/process.hh"
8611723Sar4jc@virginia.edu#elif THE_ISA == RISCV_ISA
8711723Sar4jc@virginia.edu#include "arch/riscv/linux/process.hh"
882715Sstever@eecs.umich.edu#else
892715Sstever@eecs.umich.edu#error "THE_ISA not set"
902715Sstever@eecs.umich.edu#endif
912715Sstever@eecs.umich.edu
922715Sstever@eecs.umich.edu
932SN/Ausing namespace std;
942107SN/Ausing namespace TheISA;
952SN/A
9611851Sbrandon.potter@amd.comProcess::Process(ProcessParams * params, ObjectFile * obj_file)
977532Ssteve.reinhardt@amd.com    : SimObject(params), system(params->system),
9810559Sandreas.hansson@arm.com      brk_point(0), stack_base(0), stack_size(0), stack_min(0),
998852Sandreas.hansson@arm.com      max_stack_size(params->max_stack_size),
10010559Sandreas.hansson@arm.com      next_thread_stack_base(0),
10110299Salexandru.dutu@amd.com      useArchPT(params->useArchPT),
10210554Salexandru.dutu@amd.com      kvmInSE(params->kvmInSE),
10310299Salexandru.dutu@amd.com      pTable(useArchPT ?
10411813Sbaz21@cam.ac.uk        static_cast<PageTableBase *>(new ArchPageTable(name(), params->pid,
10511813Sbaz21@cam.ac.uk            system)) :
10611813Sbaz21@cam.ac.uk        static_cast<PageTableBase *>(new FuncPageTable(name(), params->pid))),
1078852Sandreas.hansson@arm.com      initVirtMem(system->getSystemPort(), this,
10810929Sbrandon.potter@amd.com                  SETranslatingPortProxy::Always),
10911851Sbrandon.potter@amd.com      objFile(obj_file),
11011851Sbrandon.potter@amd.com      argv(params->cmd), envp(params->env), cwd(params->cwd),
11111851Sbrandon.potter@amd.com      executable(params->executable),
11211801Sbrandon.potter@amd.com      _uid(params->uid), _euid(params->euid),
11311801Sbrandon.potter@amd.com      _gid(params->gid), _egid(params->egid),
11411851Sbrandon.potter@amd.com      _pid(params->pid), _ppid(params->ppid),
11511856Sbrandon.potter@amd.com      drivers(params->drivers),
11611856Sbrandon.potter@amd.com      fds(make_shared<FDArray>(params->input, params->output, params->errout))
1172SN/A{
11811386Ssteve.reinhardt@amd.com    mmap_end = 0;
11911851Sbrandon.potter@amd.com
12011851Sbrandon.potter@amd.com    // load up symbols, if any... these may be used for debugging or
12111851Sbrandon.potter@amd.com    // profiling.
12211851Sbrandon.potter@amd.com    if (!debugSymbolTable) {
12311851Sbrandon.potter@amd.com        debugSymbolTable = new SymbolTable();
12411851Sbrandon.potter@amd.com        if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
12511851Sbrandon.potter@amd.com            !objFile->loadLocalSymbols(debugSymbolTable) ||
12611851Sbrandon.potter@amd.com            !objFile->loadWeakSymbols(debugSymbolTable)) {
12711851Sbrandon.potter@amd.com            // didn't load any symbols
12811851Sbrandon.potter@amd.com            delete debugSymbolTable;
12911851Sbrandon.potter@amd.com            debugSymbolTable = NULL;
13011851Sbrandon.potter@amd.com        }
13111851Sbrandon.potter@amd.com    }
1322SN/A}
1332SN/A
1342SN/Avoid
1352SN/AProcess::regStats()
1362SN/A{
13711522Sstephan.diestelhorst@arm.com    SimObject::regStats();
13811522Sstephan.diestelhorst@arm.com
139729SN/A    using namespace Stats;
1402SN/A
1412SN/A    num_syscalls
1428240Snate@binkert.org        .name(name() + ".num_syscalls")
1432SN/A        .desc("Number of system calls")
1442SN/A        ;
1452SN/A}
1462SN/A
1475713Shsul@eecs.umich.eduThreadContext *
1485713Shsul@eecs.umich.eduProcess::findFreeContext()
1492SN/A{
15010929Sbrandon.potter@amd.com    for (int id : contextIds) {
15110929Sbrandon.potter@amd.com        ThreadContext *tc = system->getThreadContext(id);
15210929Sbrandon.potter@amd.com        if (tc->status() == ThreadContext::Halted)
1535713Shsul@eecs.umich.edu            return tc;
1545512SMichael.Adler@intel.com    }
1555713Shsul@eecs.umich.edu    return NULL;
1562SN/A}
1572SN/A
1581395SN/Avoid
1597532Ssteve.reinhardt@amd.comProcess::initState()
1601395SN/A{
1615713Shsul@eecs.umich.edu    if (contextIds.empty())
1625713Shsul@eecs.umich.edu        fatal("Process %s is not associated with any HW contexts!\n", name());
1632378SN/A
1642680Sktlim@umich.edu    // first thread context for this process... initialize & enable
1655713Shsul@eecs.umich.edu    ThreadContext *tc = system->getThreadContext(contextIds[0]);
1661395SN/A
1671634SN/A    // mark this context as active so it will start ticking.
16810407Smitch.hayenga@arm.com    tc->activate();
16910298Salexandru.dutu@amd.com
17010298Salexandru.dutu@amd.com    pTable->initState(tc);
1711395SN/A}
1722SN/A
17310913Sandreas.sandberg@arm.comDrainState
17410913Sandreas.sandberg@arm.comProcess::drain()
17510905Sandreas.sandberg@arm.com{
17611856Sbrandon.potter@amd.com    fds->updateFileOffsets();
17710913Sandreas.sandberg@arm.com    return DrainState::Drained;
17810905Sandreas.sandberg@arm.com}
17910905Sandreas.sandberg@arm.com
1808601Ssteve.reinhardt@amd.comvoid
1818601Ssteve.reinhardt@amd.comProcess::allocateMem(Addr vaddr, int64_t size, bool clobber)
1828601Ssteve.reinhardt@amd.com{
18310318Sandreas.hansson@arm.com    int npages = divCeil(size, (int64_t)PageBytes);
1848601Ssteve.reinhardt@amd.com    Addr paddr = system->allocPhysPages(npages);
18511294Sandreas.hansson@arm.com    pTable->map(vaddr, paddr, size,
18611294Sandreas.hansson@arm.com                clobber ? PageTableBase::Clobber : PageTableBase::Zero);
1878601Ssteve.reinhardt@amd.com}
1888601Ssteve.reinhardt@amd.com
1894434Ssaidi@eecs.umich.edubool
1908539Sgblack@eecs.umich.eduProcess::fixupStackFault(Addr vaddr)
1914434Ssaidi@eecs.umich.edu{
1928539Sgblack@eecs.umich.edu    // Check if this is already on the stack and there's just no page there
1938539Sgblack@eecs.umich.edu    // yet.
1944434Ssaidi@eecs.umich.edu    if (vaddr >= stack_min && vaddr < stack_base) {
19510318Sandreas.hansson@arm.com        allocateMem(roundDown(vaddr, PageBytes), PageBytes);
1964434Ssaidi@eecs.umich.edu        return true;
1974434Ssaidi@eecs.umich.edu    }
1984434Ssaidi@eecs.umich.edu
1998539Sgblack@eecs.umich.edu    // We've accessed the next page of the stack, so extend it to include
2008539Sgblack@eecs.umich.edu    // this address.
2015154Sgblack@eecs.umich.edu    if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
2025154Sgblack@eecs.umich.edu        while (vaddr < stack_min) {
2035154Sgblack@eecs.umich.edu            stack_min -= TheISA::PageBytes;
2048539Sgblack@eecs.umich.edu            if (stack_base - stack_min > max_stack_size)
2055154Sgblack@eecs.umich.edu                fatal("Maximum stack size exceeded\n");
2068601Ssteve.reinhardt@amd.com            allocateMem(stack_min, TheISA::PageBytes);
2075823Ssaidi@eecs.umich.edu            inform("Increasing stack size by one page.");
2085154Sgblack@eecs.umich.edu        };
2094434Ssaidi@eecs.umich.edu        return true;
2104434Ssaidi@eecs.umich.edu    }
2114434Ssaidi@eecs.umich.edu    return false;
2124434Ssaidi@eecs.umich.edu}
2134434Ssaidi@eecs.umich.edu
2145282Srstrong@cs.ucsd.eduvoid
21510905Sandreas.sandberg@arm.comProcess::serialize(CheckpointOut &cp) const
2163311Ssaidi@eecs.umich.edu{
2173311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(brk_point);
2183311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(stack_base);
2193311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(stack_size);
2203311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(stack_min);
2213311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(next_thread_stack_base);
2223311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(mmap_end);
22310905Sandreas.sandberg@arm.com    pTable->serialize(cp);
22411856Sbrandon.potter@amd.com    /**
22511856Sbrandon.potter@amd.com     * Checkpoints for file descriptors currently do not work. Need to
22611856Sbrandon.potter@amd.com     * come back and fix them at a later date.
22711856Sbrandon.potter@amd.com     */
22811856Sbrandon.potter@amd.com
22911856Sbrandon.potter@amd.com    warn("Checkpoints for file descriptors currently do not work.");
23011856Sbrandon.potter@amd.com#if 0
23111856Sbrandon.potter@amd.com    for (int x = 0; x < fds->getSize(); x++)
23211856Sbrandon.potter@amd.com        (*fds)[x].serializeSection(cp, csprintf("FDEntry%d", x));
23311856Sbrandon.potter@amd.com#endif
2343311Ssaidi@eecs.umich.edu
2353311Ssaidi@eecs.umich.edu}
2363311Ssaidi@eecs.umich.edu
2373311Ssaidi@eecs.umich.eduvoid
23810905Sandreas.sandberg@arm.comProcess::unserialize(CheckpointIn &cp)
2393311Ssaidi@eecs.umich.edu{
2403311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(brk_point);
2413311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(stack_base);
2423311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(stack_size);
2433311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(stack_min);
2443311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(next_thread_stack_base);
2453311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(mmap_end);
24610905Sandreas.sandberg@arm.com    pTable->unserialize(cp);
24711856Sbrandon.potter@amd.com    /**
24811856Sbrandon.potter@amd.com     * Checkpoints for file descriptors currently do not work. Need to
24911856Sbrandon.potter@amd.com     * come back and fix them at a later date.
25011856Sbrandon.potter@amd.com     */
25111856Sbrandon.potter@amd.com    warn("Checkpoints for file descriptors currently do not work.");
25211856Sbrandon.potter@amd.com#if 0
25311856Sbrandon.potter@amd.com    for (int x = 0; x < fds->getSize(); x++)
25411856Sbrandon.potter@amd.com        (*fds)[x]->unserializeSection(cp, csprintf("FDEntry%d", x));
25511856Sbrandon.potter@amd.com    fds->restoreFileOffsets();
25611856Sbrandon.potter@amd.com#endif
2576820SLisa.Hsu@amd.com    // The above returns a bool so that you could do something if you don't
2586820SLisa.Hsu@amd.com    // find the param in the checkpoint if you wanted to, like set a default
25910930Sbrandon.potter@amd.com    // but in this case we'll just stick with the instantiated value if not
26010929Sbrandon.potter@amd.com    // found.
2613311Ssaidi@eecs.umich.edu}
2622SN/A
2639110Ssteve.reinhardt@amd.combool
26410558Salexandru.dutu@amd.comProcess::map(Addr vaddr, Addr paddr, int size, bool cacheable)
2659110Ssteve.reinhardt@amd.com{
26610558Salexandru.dutu@amd.com    pTable->map(vaddr, paddr, size,
26711294Sandreas.hansson@arm.com                cacheable ? PageTableBase::Zero : PageTableBase::Uncacheable);
2689110Ssteve.reinhardt@amd.com    return true;
2699110Ssteve.reinhardt@amd.com}
2709110Ssteve.reinhardt@amd.com
2712378SN/Avoid
27211877Sbrandon.potter@amd.comProcess::syscall(int64_t callnum, ThreadContext *tc, Fault *fault)
2732093SN/A{
2742093SN/A    num_syscalls++;
2752093SN/A
2762093SN/A    SyscallDesc *desc = getDesc(callnum);
2772093SN/A    if (desc == NULL)
2782093SN/A        fatal("Syscall %d out of range", callnum);
2792093SN/A
28011877Sbrandon.potter@amd.com    desc->doSyscall(callnum, this, tc, fault);
2812093SN/A}
2822SN/A
2836701Sgblack@eecs.umich.eduIntReg
28411851Sbrandon.potter@amd.comProcess::getSyscallArg(ThreadContext *tc, int &i, int width)
2856701Sgblack@eecs.umich.edu{
2866701Sgblack@eecs.umich.edu    return getSyscallArg(tc, i);
2876701Sgblack@eecs.umich.edu}
2886701Sgblack@eecs.umich.edu
28910496Ssteve.reinhardt@amd.comEmulatedDriver *
29011851Sbrandon.potter@amd.comProcess::findDriver(std::string filename)
29110496Ssteve.reinhardt@amd.com{
29210496Ssteve.reinhardt@amd.com    for (EmulatedDriver *d : drivers) {
29310496Ssteve.reinhardt@amd.com        if (d->match(filename))
29410496Ssteve.reinhardt@amd.com            return d;
29510496Ssteve.reinhardt@amd.com    }
29610496Ssteve.reinhardt@amd.com
29710496Ssteve.reinhardt@amd.com    return NULL;
29810496Ssteve.reinhardt@amd.com}
29910496Ssteve.reinhardt@amd.com
30011389Sbrandon.potter@amd.comvoid
30111851Sbrandon.potter@amd.comProcess::updateBias()
30211389Sbrandon.potter@amd.com{
30311389Sbrandon.potter@amd.com    ObjectFile *interp = objFile->getInterpreter();
30411389Sbrandon.potter@amd.com
30511389Sbrandon.potter@amd.com    if (!interp || !interp->relocatable())
30611389Sbrandon.potter@amd.com        return;
30711389Sbrandon.potter@amd.com
30811389Sbrandon.potter@amd.com    // Determine how large the interpreters footprint will be in the process
30911389Sbrandon.potter@amd.com    // address space.
31011389Sbrandon.potter@amd.com    Addr interp_mapsize = roundUp(interp->mapSize(), TheISA::PageBytes);
31111389Sbrandon.potter@amd.com
31211389Sbrandon.potter@amd.com    // We are allocating the memory area; set the bias to the lowest address
31311389Sbrandon.potter@amd.com    // in the allocated memory region.
31411389Sbrandon.potter@amd.com    Addr ld_bias = mmapGrowsDown() ? mmap_end - interp_mapsize : mmap_end;
31511389Sbrandon.potter@amd.com
31611389Sbrandon.potter@amd.com    // Adjust the process mmap area to give the interpreter room; the real
31711389Sbrandon.potter@amd.com    // execve system call would just invoke the kernel's internal mmap
31811389Sbrandon.potter@amd.com    // functions to make these adjustments.
31911389Sbrandon.potter@amd.com    mmap_end = mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
32011389Sbrandon.potter@amd.com
32111389Sbrandon.potter@amd.com    interp->updateBias(ld_bias);
32211389Sbrandon.potter@amd.com}
32311389Sbrandon.potter@amd.com
32411392Sbrandon.potter@amd.comObjectFile *
32511851Sbrandon.potter@amd.comProcess::getInterpreter()
32611392Sbrandon.potter@amd.com{
32711392Sbrandon.potter@amd.com    return objFile->getInterpreter();
32811392Sbrandon.potter@amd.com}
32911392Sbrandon.potter@amd.com
33011389Sbrandon.potter@amd.comAddr
33111851Sbrandon.potter@amd.comProcess::getBias()
33211389Sbrandon.potter@amd.com{
33311392Sbrandon.potter@amd.com    ObjectFile *interp = getInterpreter();
33411389Sbrandon.potter@amd.com
33511389Sbrandon.potter@amd.com    return interp ? interp->bias() : objFile->bias();
33611389Sbrandon.potter@amd.com}
33711389Sbrandon.potter@amd.com
33811389Sbrandon.potter@amd.comAddr
33911851Sbrandon.potter@amd.comProcess::getStartPC()
34011389Sbrandon.potter@amd.com{
34111392Sbrandon.potter@amd.com    ObjectFile *interp = getInterpreter();
34211389Sbrandon.potter@amd.com
34311389Sbrandon.potter@amd.com    return interp ? interp->entryPoint() : objFile->entryPoint();
34411389Sbrandon.potter@amd.com}
34511389Sbrandon.potter@amd.com
34611851Sbrandon.potter@amd.comProcess *
34711851Sbrandon.potter@amd.comProcessParams::create()
3482715Sstever@eecs.umich.edu{
34911851Sbrandon.potter@amd.com    Process *process = NULL;
3502715Sstever@eecs.umich.edu
35111140Sjthestness@gmail.com    // If not specified, set the executable parameter equal to the
35211140Sjthestness@gmail.com    // simulated system's zeroth command line parameter
35311851Sbrandon.potter@amd.com    if (executable == "") {
35411851Sbrandon.potter@amd.com        executable = cmd[0];
35511140Sjthestness@gmail.com    }
35611140Sjthestness@gmail.com
35711851Sbrandon.potter@amd.com    ObjectFile *obj_file = createObjectFile(executable);
35811851Sbrandon.potter@amd.com    if (obj_file == NULL) {
35911851Sbrandon.potter@amd.com        fatal("Can't load object file %s", executable);
3602715Sstever@eecs.umich.edu    }
3612715Sstever@eecs.umich.edu
3625089Sgblack@eecs.umich.edu#if THE_ISA == ALPHA_ISA
36311851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Alpha)
3645753Ssteve.reinhardt@amd.com        fatal("Object file architecture does not match compiled ISA (Alpha).");
3655753Ssteve.reinhardt@amd.com
36611851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
3675753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
3685753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
3695753Ssteve.reinhardt@amd.com        // fall through
3702715Sstever@eecs.umich.edu      case ObjectFile::Linux:
37111851Sbrandon.potter@amd.com        process = new AlphaLinuxProcess(this, obj_file);
3722715Sstever@eecs.umich.edu        break;
3732715Sstever@eecs.umich.edu
3742715Sstever@eecs.umich.edu      default:
3752715Sstever@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
3762715Sstever@eecs.umich.edu    }
3772715Sstever@eecs.umich.edu#elif THE_ISA == SPARC_ISA
37811851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::SPARC64 &&
37911851Sbrandon.potter@amd.com        obj_file->getArch() != ObjectFile::SPARC32)
3802715Sstever@eecs.umich.edu        fatal("Object file architecture does not match compiled ISA (SPARC).");
38111851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
3825753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
3835753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
3845753Ssteve.reinhardt@amd.com        // fall through
3852715Sstever@eecs.umich.edu      case ObjectFile::Linux:
38611851Sbrandon.potter@amd.com        if (obj_file->getArch() == ObjectFile::SPARC64) {
38711851Sbrandon.potter@amd.com            process = new Sparc64LinuxProcess(this, obj_file);
3884111Sgblack@eecs.umich.edu        } else {
38911851Sbrandon.potter@amd.com            process = new Sparc32LinuxProcess(this, obj_file);
3904111Sgblack@eecs.umich.edu        }
3912715Sstever@eecs.umich.edu        break;
3922715Sstever@eecs.umich.edu
3932715Sstever@eecs.umich.edu      case ObjectFile::Solaris:
39411851Sbrandon.potter@amd.com        process = new SparcSolarisProcess(this, obj_file);
3952715Sstever@eecs.umich.edu        break;
3965753Ssteve.reinhardt@amd.com
3972715Sstever@eecs.umich.edu      default:
3982715Sstever@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
3992715Sstever@eecs.umich.edu    }
4004157Sgblack@eecs.umich.edu#elif THE_ISA == X86_ISA
40111851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::X86_64 &&
40211851Sbrandon.potter@amd.com        obj_file->getArch() != ObjectFile::I386)
4034166Sgblack@eecs.umich.edu        fatal("Object file architecture does not match compiled ISA (x86).");
40411851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
4055753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
4065753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
4075753Ssteve.reinhardt@amd.com        // fall through
4084166Sgblack@eecs.umich.edu      case ObjectFile::Linux:
40911851Sbrandon.potter@amd.com        if (obj_file->getArch() == ObjectFile::X86_64) {
41011851Sbrandon.potter@amd.com            process = new X86_64LinuxProcess(this, obj_file);
4115874Sgblack@eecs.umich.edu        } else {
41211851Sbrandon.potter@amd.com            process = new I386LinuxProcess(this, obj_file);
4135874Sgblack@eecs.umich.edu        }
4144166Sgblack@eecs.umich.edu        break;
4155753Ssteve.reinhardt@amd.com
4164157Sgblack@eecs.umich.edu      default:
4174157Sgblack@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
4184157Sgblack@eecs.umich.edu    }
4192715Sstever@eecs.umich.edu#elif THE_ISA == MIPS_ISA
42011851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Mips)
4212715Sstever@eecs.umich.edu        fatal("Object file architecture does not match compiled ISA (MIPS).");
42211851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
4235753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
4245753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
4255753Ssteve.reinhardt@amd.com        // fall through
4262715Sstever@eecs.umich.edu      case ObjectFile::Linux:
42711851Sbrandon.potter@amd.com        process = new MipsLinuxProcess(this, obj_file);
4282715Sstever@eecs.umich.edu        break;
4292715Sstever@eecs.umich.edu
4302715Sstever@eecs.umich.edu      default:
4312715Sstever@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
4322715Sstever@eecs.umich.edu    }
4335335Shines@cs.fsu.edu#elif THE_ISA == ARM_ISA
43411851Sbrandon.potter@amd.com    ObjectFile::Arch arch = obj_file->getArch();
43510037SARM gem5 Developers    if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
43610037SARM gem5 Developers        arch != ObjectFile::Arm64)
4375335Shines@cs.fsu.edu        fatal("Object file architecture does not match compiled ISA (ARM).");
43811851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
4395753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
4405753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
4415753Ssteve.reinhardt@amd.com        // fall through
4425335Shines@cs.fsu.edu      case ObjectFile::Linux:
44310037SARM gem5 Developers        if (arch == ObjectFile::Arm64) {
44411851Sbrandon.potter@amd.com            process = new ArmLinuxProcess64(this, obj_file,
44511851Sbrandon.potter@amd.com                                            obj_file->getArch());
44610037SARM gem5 Developers        } else {
44711851Sbrandon.potter@amd.com            process = new ArmLinuxProcess32(this, obj_file,
44811851Sbrandon.potter@amd.com                                            obj_file->getArch());
44910037SARM gem5 Developers        }
4505335Shines@cs.fsu.edu        break;
45110810Sbr@bsdpad.com      case ObjectFile::FreeBSD:
45210810Sbr@bsdpad.com        if (arch == ObjectFile::Arm64) {
45311851Sbrandon.potter@amd.com            process = new ArmFreebsdProcess64(this, obj_file,
45411851Sbrandon.potter@amd.com                                              obj_file->getArch());
45510810Sbr@bsdpad.com        } else {
45611851Sbrandon.potter@amd.com            process = new ArmFreebsdProcess32(this, obj_file,
45711851Sbrandon.potter@amd.com                                              obj_file->getArch());
45810810Sbr@bsdpad.com        }
45910810Sbr@bsdpad.com        break;
4606392Ssaidi@eecs.umich.edu      case ObjectFile::LinuxArmOABI:
4616392Ssaidi@eecs.umich.edu        fatal("M5 does not support ARM OABI binaries. Please recompile with an"
4626392Ssaidi@eecs.umich.edu              " EABI compiler.");
4635335Shines@cs.fsu.edu      default:
4645335Shines@cs.fsu.edu        fatal("Unknown/unsupported operating system.");
4655335Shines@cs.fsu.edu    }
4666691Stjones1@inf.ed.ac.uk#elif THE_ISA == POWER_ISA
46711851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Power)
4686691Stjones1@inf.ed.ac.uk        fatal("Object file architecture does not match compiled ISA (Power).");
46911851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
4706691Stjones1@inf.ed.ac.uk      case ObjectFile::UnknownOpSys:
4716691Stjones1@inf.ed.ac.uk        warn("Unknown operating system; assuming Linux.");
4726691Stjones1@inf.ed.ac.uk        // fall through
4736691Stjones1@inf.ed.ac.uk      case ObjectFile::Linux:
47411851Sbrandon.potter@amd.com        process = new PowerLinuxProcess(this, obj_file);
4756691Stjones1@inf.ed.ac.uk        break;
4766691Stjones1@inf.ed.ac.uk
4776691Stjones1@inf.ed.ac.uk      default:
4786691Stjones1@inf.ed.ac.uk        fatal("Unknown/unsupported operating system.");
4796691Stjones1@inf.ed.ac.uk    }
48011723Sar4jc@virginia.edu#elif THE_ISA == RISCV_ISA
48111851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Riscv)
48211723Sar4jc@virginia.edu        fatal("Object file architecture does not match compiled ISA (RISCV).");
48311851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
48411723Sar4jc@virginia.edu      case ObjectFile::UnknownOpSys:
48511723Sar4jc@virginia.edu        warn("Unknown operating system; assuming Linux.");
48611723Sar4jc@virginia.edu        // fall through
48711723Sar4jc@virginia.edu      case ObjectFile::Linux:
48811851Sbrandon.potter@amd.com        process = new RiscvLinuxProcess(this, obj_file);
48911723Sar4jc@virginia.edu        break;
49011723Sar4jc@virginia.edu      default:
49111723Sar4jc@virginia.edu        fatal("Unknown/unsupported operating system.");
49211723Sar4jc@virginia.edu    }
4932715Sstever@eecs.umich.edu#else
4942715Sstever@eecs.umich.edu#error "THE_ISA not set"
4952715Sstever@eecs.umich.edu#endif
4962715Sstever@eecs.umich.edu
4972715Sstever@eecs.umich.edu    if (process == NULL)
4982715Sstever@eecs.umich.edu        fatal("Unknown error creating process object.");
4992715Sstever@eecs.umich.edu    return process;
5002715Sstever@eecs.umich.edu}
50111854Sbrandon.potter@amd.com
50211854Sbrandon.potter@amd.comstd::string
50311854Sbrandon.potter@amd.comProcess::fullPath(const std::string &file_name)
50411854Sbrandon.potter@amd.com{
50511854Sbrandon.potter@amd.com    if (file_name[0] == '/' || cwd.empty())
50611854Sbrandon.potter@amd.com        return file_name;
50711854Sbrandon.potter@amd.com
50811854Sbrandon.potter@amd.com    std::string full = cwd;
50911854Sbrandon.potter@amd.com
51011854Sbrandon.potter@amd.com    if (cwd[cwd.size() - 1] != '/')
51111854Sbrandon.potter@amd.com        full += '/';
51211854Sbrandon.potter@amd.com
51311854Sbrandon.potter@amd.com    return full + file_name;
51411854Sbrandon.potter@amd.com}
515