process.cc revision 11851
12SN/A/*
210298Salexandru.dutu@amd.com * Copyright (c) 2014 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
442SN/A */
452SN/A
4611793Sbrandon.potter@amd.com#include "sim/process.hh"
4711793Sbrandon.potter@amd.com
488229Snate@binkert.org#include <fcntl.h>
492SN/A#include <unistd.h>
506712Snate@binkert.org
5111800Sbrandon.potter@amd.com#include <array>
5210930Sbrandon.potter@amd.com#include <map>
532SN/A#include <string>
5411800Sbrandon.potter@amd.com#include <vector>
552SN/A
5611793Sbrandon.potter@amd.com#include "base/intmath.hh"
5756SN/A#include "base/loader/object_file.hh"
581158SN/A#include "base/loader/symtab.hh"
59146SN/A#include "base/statistics.hh"
606658Snate@binkert.org#include "config/the_isa.hh"
612680Sktlim@umich.edu#include "cpu/thread_context.hh"
622378SN/A#include "mem/page_table.hh"
638706Sandreas.hansson@arm.com#include "mem/se_translating_port_proxy.hh"
645154Sgblack@eecs.umich.edu#include "params/Process.hh"
6511800Sbrandon.potter@amd.com#include "sim/emul_driver.hh"
6611794Sbrandon.potter@amd.com#include "sim/syscall_desc.hh"
672378SN/A#include "sim/system.hh"
682SN/A
692715Sstever@eecs.umich.edu#if THE_ISA == ALPHA_ISA
702715Sstever@eecs.umich.edu#include "arch/alpha/linux/process.hh"
712715Sstever@eecs.umich.edu#elif THE_ISA == SPARC_ISA
722715Sstever@eecs.umich.edu#include "arch/sparc/linux/process.hh"
732715Sstever@eecs.umich.edu#include "arch/sparc/solaris/process.hh"
742715Sstever@eecs.umich.edu#elif THE_ISA == MIPS_ISA
752715Sstever@eecs.umich.edu#include "arch/mips/linux/process.hh"
765335Shines@cs.fsu.edu#elif THE_ISA == ARM_ISA
775335Shines@cs.fsu.edu#include "arch/arm/linux/process.hh"
7810810Sbr@bsdpad.com#include "arch/arm/freebsd/process.hh"
794157Sgblack@eecs.umich.edu#elif THE_ISA == X86_ISA
804166Sgblack@eecs.umich.edu#include "arch/x86/linux/process.hh"
816691Stjones1@inf.ed.ac.uk#elif THE_ISA == POWER_ISA
826691Stjones1@inf.ed.ac.uk#include "arch/power/linux/process.hh"
8311723Sar4jc@virginia.edu#elif THE_ISA == RISCV_ISA
8411723Sar4jc@virginia.edu#include "arch/riscv/linux/process.hh"
852715Sstever@eecs.umich.edu#else
862715Sstever@eecs.umich.edu#error "THE_ISA not set"
872715Sstever@eecs.umich.edu#endif
882715Sstever@eecs.umich.edu
892715Sstever@eecs.umich.edu
902SN/Ausing namespace std;
912107SN/Ausing namespace TheISA;
922SN/A
932SN/A// current number of allocated processes
942SN/Aint num_processes = 0;
952SN/A
965758Shsul@eecs.umich.edutemplate<class IntType>
9710932Sbrandon.potter@amd.com
985771Shsul@eecs.umich.eduAuxVector<IntType>::AuxVector(IntType type, IntType val)
995758Shsul@eecs.umich.edu{
1005758Shsul@eecs.umich.edu    a_type = TheISA::htog(type);
1015758Shsul@eecs.umich.edu    a_val = TheISA::htog(val);
1025758Shsul@eecs.umich.edu}
1035758Shsul@eecs.umich.edu
1048737Skoansin.tan@gmail.comtemplate struct AuxVector<uint32_t>;
1058737Skoansin.tan@gmail.comtemplate struct AuxVector<uint64_t>;
1065758Shsul@eecs.umich.edu
10710930Sbrandon.potter@amd.comstatic int
10810930Sbrandon.potter@amd.comopenFile(const string& filename, int flags, mode_t mode)
10910930Sbrandon.potter@amd.com{
11010930Sbrandon.potter@amd.com    int sim_fd = open(filename.c_str(), flags, mode);
11110930Sbrandon.potter@amd.com    if (sim_fd != -1)
11210930Sbrandon.potter@amd.com        return sim_fd;
11310930Sbrandon.potter@amd.com    fatal("Unable to open %s with mode %O", filename, mode);
11410930Sbrandon.potter@amd.com}
11510930Sbrandon.potter@amd.com
11610930Sbrandon.potter@amd.comstatic int
11710930Sbrandon.potter@amd.comopenInputFile(const string &filename)
11810930Sbrandon.potter@amd.com{
11910930Sbrandon.potter@amd.com    return openFile(filename, O_RDONLY, 0);
12010930Sbrandon.potter@amd.com}
12110930Sbrandon.potter@amd.com
12210930Sbrandon.potter@amd.comstatic int
12310930Sbrandon.potter@amd.comopenOutputFile(const string &filename)
12410930Sbrandon.potter@amd.com{
12510930Sbrandon.potter@amd.com    return openFile(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
12610930Sbrandon.potter@amd.com}
12710930Sbrandon.potter@amd.com
12811851Sbrandon.potter@amd.comProcess::Process(ProcessParams * params, ObjectFile * obj_file)
1297532Ssteve.reinhardt@amd.com    : SimObject(params), system(params->system),
13010559Sandreas.hansson@arm.com      brk_point(0), stack_base(0), stack_size(0), stack_min(0),
1318852Sandreas.hansson@arm.com      max_stack_size(params->max_stack_size),
13210559Sandreas.hansson@arm.com      next_thread_stack_base(0),
13310299Salexandru.dutu@amd.com      useArchPT(params->useArchPT),
13410554Salexandru.dutu@amd.com      kvmInSE(params->kvmInSE),
13510299Salexandru.dutu@amd.com      pTable(useArchPT ?
13611813Sbaz21@cam.ac.uk        static_cast<PageTableBase *>(new ArchPageTable(name(), params->pid,
13711813Sbaz21@cam.ac.uk            system)) :
13811813Sbaz21@cam.ac.uk        static_cast<PageTableBase *>(new FuncPageTable(name(), params->pid))),
1398852Sandreas.hansson@arm.com      initVirtMem(system->getSystemPort(), this,
14010929Sbrandon.potter@amd.com                  SETranslatingPortProxy::Always),
14110930Sbrandon.potter@amd.com      fd_array(make_shared<array<FDEntry, NUM_FDS>>()),
14210930Sbrandon.potter@amd.com      imap {{"",       -1},
14310930Sbrandon.potter@amd.com            {"cin",    STDIN_FILENO},
14410930Sbrandon.potter@amd.com            {"stdin",  STDIN_FILENO}},
14510930Sbrandon.potter@amd.com      oemap{{"",       -1},
14610930Sbrandon.potter@amd.com            {"cout",   STDOUT_FILENO},
14710930Sbrandon.potter@amd.com            {"stdout", STDOUT_FILENO},
14810930Sbrandon.potter@amd.com            {"cerr",   STDERR_FILENO},
14911801Sbrandon.potter@amd.com            {"stderr", STDERR_FILENO}},
15011851Sbrandon.potter@amd.com      objFile(obj_file),
15111851Sbrandon.potter@amd.com      argv(params->cmd), envp(params->env), cwd(params->cwd),
15211851Sbrandon.potter@amd.com      executable(params->executable),
15311801Sbrandon.potter@amd.com      _uid(params->uid), _euid(params->euid),
15411801Sbrandon.potter@amd.com      _gid(params->gid), _egid(params->egid),
15511851Sbrandon.potter@amd.com      _pid(params->pid), _ppid(params->ppid),
15611851Sbrandon.potter@amd.com      drivers(params->drivers)
1572SN/A{
15810930Sbrandon.potter@amd.com    int sim_fd;
15910930Sbrandon.potter@amd.com    std::map<string,int>::iterator it;
1605154Sgblack@eecs.umich.edu
16110930Sbrandon.potter@amd.com    // Search through the input options and set fd if match is found;
16210930Sbrandon.potter@amd.com    // otherwise, open an input file and seek to location.
16310932Sbrandon.potter@amd.com    FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
16410930Sbrandon.potter@amd.com    if ((it = imap.find(params->input)) != imap.end())
16510930Sbrandon.potter@amd.com        sim_fd = it->second;
16610930Sbrandon.potter@amd.com    else
16710930Sbrandon.potter@amd.com        sim_fd = openInputFile(params->input);
16810930Sbrandon.potter@amd.com    fde_stdin->set(sim_fd, params->input, O_RDONLY, -1, false);
1695154Sgblack@eecs.umich.edu
17010930Sbrandon.potter@amd.com    // Search through the output/error options and set fd if match is found;
17110930Sbrandon.potter@amd.com    // otherwise, open an output file and seek to location.
17210932Sbrandon.potter@amd.com    FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO);
17310930Sbrandon.potter@amd.com    if ((it = oemap.find(params->output)) != oemap.end())
17410930Sbrandon.potter@amd.com        sim_fd = it->second;
1755154Sgblack@eecs.umich.edu    else
17610930Sbrandon.potter@amd.com        sim_fd = openOutputFile(params->output);
17710930Sbrandon.potter@amd.com    fde_stdout->set(sim_fd, params->output, O_WRONLY | O_CREAT | O_TRUNC,
17810930Sbrandon.potter@amd.com                    0664, false);
1795154Sgblack@eecs.umich.edu
18010932Sbrandon.potter@amd.com    FDEntry *fde_stderr = getFDEntry(STDERR_FILENO);
18110930Sbrandon.potter@amd.com    if (params->output == params->errout)
18210930Sbrandon.potter@amd.com        // Reuse the same file descriptor if these match.
18310930Sbrandon.potter@amd.com        sim_fd = fde_stdout->fd;
18410930Sbrandon.potter@amd.com    else if ((it = oemap.find(params->errout)) != oemap.end())
18510930Sbrandon.potter@amd.com        sim_fd = it->second;
1865154Sgblack@eecs.umich.edu    else
18710930Sbrandon.potter@amd.com        sim_fd = openOutputFile(params->errout);
18810930Sbrandon.potter@amd.com    fde_stderr->set(sim_fd, params->errout, O_WRONLY | O_CREAT | O_TRUNC,
18910930Sbrandon.potter@amd.com                    0664, false);
1902SN/A
19111386Ssteve.reinhardt@amd.com    mmap_end = 0;
1921514SN/A    nxm_start = nxm_end = 0;
1932SN/A    // other parameters will be initialized when the program is loaded
19411851Sbrandon.potter@amd.com
19511851Sbrandon.potter@amd.com    // load up symbols, if any... these may be used for debugging or
19611851Sbrandon.potter@amd.com    // profiling.
19711851Sbrandon.potter@amd.com    if (!debugSymbolTable) {
19811851Sbrandon.potter@amd.com        debugSymbolTable = new SymbolTable();
19911851Sbrandon.potter@amd.com        if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
20011851Sbrandon.potter@amd.com            !objFile->loadLocalSymbols(debugSymbolTable) ||
20111851Sbrandon.potter@amd.com            !objFile->loadWeakSymbols(debugSymbolTable)) {
20211851Sbrandon.potter@amd.com            // didn't load any symbols
20311851Sbrandon.potter@amd.com            delete debugSymbolTable;
20411851Sbrandon.potter@amd.com            debugSymbolTable = NULL;
20511851Sbrandon.potter@amd.com        }
20611851Sbrandon.potter@amd.com    }
2072SN/A}
2082SN/A
2092378SN/A
2102SN/Avoid
2112SN/AProcess::regStats()
2122SN/A{
21311522Sstephan.diestelhorst@arm.com    SimObject::regStats();
21411522Sstephan.diestelhorst@arm.com
215729SN/A    using namespace Stats;
2162SN/A
2172SN/A    num_syscalls
2188240Snate@binkert.org        .name(name() + ".num_syscalls")
2192SN/A        .desc("Number of system calls")
2202SN/A        ;
2212SN/A}
2222SN/A
22310930Sbrandon.potter@amd.comvoid
22410932Sbrandon.potter@amd.comProcess::inheritFDArray(Process *p)
2252SN/A{
22610930Sbrandon.potter@amd.com    fd_array = p->fd_array;
2272SN/A}
2282SN/A
2295713Shsul@eecs.umich.eduThreadContext *
2305713Shsul@eecs.umich.eduProcess::findFreeContext()
2312SN/A{
23210929Sbrandon.potter@amd.com    for (int id : contextIds) {
23310929Sbrandon.potter@amd.com        ThreadContext *tc = system->getThreadContext(id);
23410929Sbrandon.potter@amd.com        if (tc->status() == ThreadContext::Halted)
2355713Shsul@eecs.umich.edu            return tc;
2365512SMichael.Adler@intel.com    }
2375713Shsul@eecs.umich.edu    return NULL;
2382SN/A}
2392SN/A
2401395SN/Avoid
2417532Ssteve.reinhardt@amd.comProcess::initState()
2421395SN/A{
2435713Shsul@eecs.umich.edu    if (contextIds.empty())
2445713Shsul@eecs.umich.edu        fatal("Process %s is not associated with any HW contexts!\n", name());
2452378SN/A
2462680Sktlim@umich.edu    // first thread context for this process... initialize & enable
2475713Shsul@eecs.umich.edu    ThreadContext *tc = system->getThreadContext(contextIds[0]);
2481395SN/A
2491634SN/A    // mark this context as active so it will start ticking.
25010407Smitch.hayenga@arm.com    tc->activate();
25110298Salexandru.dutu@amd.com
25210298Salexandru.dutu@amd.com    pTable->initState(tc);
2531395SN/A}
2542SN/A
25510913Sandreas.sandberg@arm.comDrainState
25610913Sandreas.sandberg@arm.comProcess::drain()
25710905Sandreas.sandberg@arm.com{
25810932Sbrandon.potter@amd.com    findFileOffsets();
25910913Sandreas.sandberg@arm.com    return DrainState::Drained;
26010905Sandreas.sandberg@arm.com}
26110905Sandreas.sandberg@arm.com
2622SN/Aint
26310932Sbrandon.potter@amd.comProcess::allocFD(int sim_fd, const string& filename, int flags, int mode,
26410932Sbrandon.potter@amd.com                 bool pipe)
2652SN/A{
26610930Sbrandon.potter@amd.com    for (int free_fd = 0; free_fd < fd_array->size(); free_fd++) {
26710932Sbrandon.potter@amd.com        FDEntry *fde = getFDEntry(free_fd);
26810930Sbrandon.potter@amd.com        if (fde->isFree()) {
26910930Sbrandon.potter@amd.com            fde->set(sim_fd, filename, flags, mode, pipe);
2701970SN/A            return free_fd;
2711970SN/A        }
2722SN/A    }
2732SN/A
27410930Sbrandon.potter@amd.com    fatal("Out of target file descriptors");
2751970SN/A}
2762SN/A
2771970SN/Avoid
27810932Sbrandon.potter@amd.comProcess::resetFDEntry(int tgt_fd)
2791970SN/A{
28010932Sbrandon.potter@amd.com    FDEntry *fde = getFDEntry(tgt_fd);
28110930Sbrandon.potter@amd.com    assert(fde->fd > -1);
2821970SN/A
28310930Sbrandon.potter@amd.com    fde->reset();
2842SN/A}
2852SN/A
2862SN/Aint
28710932Sbrandon.potter@amd.comProcess::getSimFD(int tgt_fd)
2882SN/A{
28910932Sbrandon.potter@amd.com    FDEntry *entry = getFDEntry(tgt_fd);
29010930Sbrandon.potter@amd.com    return entry ? entry->fd : -1;
2912SN/A}
2922SN/A
29310930Sbrandon.potter@amd.comFDEntry *
29410932Sbrandon.potter@amd.comProcess::getFDEntry(int tgt_fd)
2955282Srstrong@cs.ucsd.edu{
29610930Sbrandon.potter@amd.com    assert(0 <= tgt_fd && tgt_fd < fd_array->size());
29710930Sbrandon.potter@amd.com    return &(*fd_array)[tgt_fd];
29810929Sbrandon.potter@amd.com}
2995282Srstrong@cs.ucsd.edu
30010929Sbrandon.potter@amd.comint
30110932Sbrandon.potter@amd.comProcess::getTgtFD(int sim_fd)
30210929Sbrandon.potter@amd.com{
30310930Sbrandon.potter@amd.com    for (int index = 0; index < fd_array->size(); index++)
30410930Sbrandon.potter@amd.com        if ((*fd_array)[index].fd == sim_fd)
30510929Sbrandon.potter@amd.com            return index;
30610929Sbrandon.potter@amd.com    return -1;
3075282Srstrong@cs.ucsd.edu}
3087487Ssteve.reinhardt@amd.com
3098601Ssteve.reinhardt@amd.comvoid
3108601Ssteve.reinhardt@amd.comProcess::allocateMem(Addr vaddr, int64_t size, bool clobber)
3118601Ssteve.reinhardt@amd.com{
31210318Sandreas.hansson@arm.com    int npages = divCeil(size, (int64_t)PageBytes);
3138601Ssteve.reinhardt@amd.com    Addr paddr = system->allocPhysPages(npages);
31411294Sandreas.hansson@arm.com    pTable->map(vaddr, paddr, size,
31511294Sandreas.hansson@arm.com                clobber ? PageTableBase::Clobber : PageTableBase::Zero);
3168601Ssteve.reinhardt@amd.com}
3178601Ssteve.reinhardt@amd.com
3184434Ssaidi@eecs.umich.edubool
3198539Sgblack@eecs.umich.eduProcess::fixupStackFault(Addr vaddr)
3204434Ssaidi@eecs.umich.edu{
3218539Sgblack@eecs.umich.edu    // Check if this is already on the stack and there's just no page there
3228539Sgblack@eecs.umich.edu    // yet.
3234434Ssaidi@eecs.umich.edu    if (vaddr >= stack_min && vaddr < stack_base) {
32410318Sandreas.hansson@arm.com        allocateMem(roundDown(vaddr, PageBytes), PageBytes);
3254434Ssaidi@eecs.umich.edu        return true;
3264434Ssaidi@eecs.umich.edu    }
3274434Ssaidi@eecs.umich.edu
3288539Sgblack@eecs.umich.edu    // We've accessed the next page of the stack, so extend it to include
3298539Sgblack@eecs.umich.edu    // this address.
3305154Sgblack@eecs.umich.edu    if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
3315154Sgblack@eecs.umich.edu        while (vaddr < stack_min) {
3325154Sgblack@eecs.umich.edu            stack_min -= TheISA::PageBytes;
3338539Sgblack@eecs.umich.edu            if (stack_base - stack_min > max_stack_size)
3345154Sgblack@eecs.umich.edu                fatal("Maximum stack size exceeded\n");
3358601Ssteve.reinhardt@amd.com            allocateMem(stack_min, TheISA::PageBytes);
3365823Ssaidi@eecs.umich.edu            inform("Increasing stack size by one page.");
3375154Sgblack@eecs.umich.edu        };
3384434Ssaidi@eecs.umich.edu        return true;
3394434Ssaidi@eecs.umich.edu    }
3404434Ssaidi@eecs.umich.edu    return false;
3414434Ssaidi@eecs.umich.edu}
3424434Ssaidi@eecs.umich.edu
3435282Srstrong@cs.ucsd.eduvoid
34410932Sbrandon.potter@amd.comProcess::fixFileOffsets()
3457487Ssteve.reinhardt@amd.com{
34610930Sbrandon.potter@amd.com    auto seek = [] (FDEntry *fde)
34710930Sbrandon.potter@amd.com    {
34810930Sbrandon.potter@amd.com        if (lseek(fde->fd, fde->fileOffset, SEEK_SET) < 0)
34910930Sbrandon.potter@amd.com            fatal("Unable to see to location in %s", fde->filename);
35010930Sbrandon.potter@amd.com    };
3515282Srstrong@cs.ucsd.edu
35210930Sbrandon.potter@amd.com    std::map<string,int>::iterator it;
3535282Srstrong@cs.ucsd.edu
35410930Sbrandon.potter@amd.com    // Search through the input options and set fd if match is found;
35510930Sbrandon.potter@amd.com    // otherwise, open an input file and seek to location.
35610932Sbrandon.potter@amd.com    FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
35711785Sjthestness@gmail.com
35811785Sjthestness@gmail.com    // Check if user has specified a different input file, and if so, use it
35911785Sjthestness@gmail.com    // instead of the file specified in the checkpoint. This also resets the
36011785Sjthestness@gmail.com    // file offset from the checkpointed value
36111785Sjthestness@gmail.com    string new_in = ((ProcessParams*)params())->input;
36211785Sjthestness@gmail.com    if (new_in != fde_stdin->filename) {
36311785Sjthestness@gmail.com        warn("Using new input file (%s) rather than checkpointed (%s)\n",
36411785Sjthestness@gmail.com             new_in, fde_stdin->filename);
36511785Sjthestness@gmail.com        fde_stdin->filename = new_in;
36611785Sjthestness@gmail.com        fde_stdin->fileOffset = 0;
36711785Sjthestness@gmail.com    }
36811785Sjthestness@gmail.com
36910930Sbrandon.potter@amd.com    if ((it = imap.find(fde_stdin->filename)) != imap.end()) {
37010930Sbrandon.potter@amd.com        fde_stdin->fd = it->second;
37110930Sbrandon.potter@amd.com    } else {
37210930Sbrandon.potter@amd.com        fde_stdin->fd = openInputFile(fde_stdin->filename);
37310930Sbrandon.potter@amd.com        seek(fde_stdin);
3745282Srstrong@cs.ucsd.edu    }
3755282Srstrong@cs.ucsd.edu
37610930Sbrandon.potter@amd.com    // Search through the output/error options and set fd if match is found;
37710930Sbrandon.potter@amd.com    // otherwise, open an output file and seek to location.
37810932Sbrandon.potter@amd.com    FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO);
37911785Sjthestness@gmail.com
38011785Sjthestness@gmail.com    // Check if user has specified a different output file, and if so, use it
38111785Sjthestness@gmail.com    // instead of the file specified in the checkpoint. This also resets the
38211785Sjthestness@gmail.com    // file offset from the checkpointed value
38311785Sjthestness@gmail.com    string new_out = ((ProcessParams*)params())->output;
38411785Sjthestness@gmail.com    if (new_out != fde_stdout->filename) {
38511785Sjthestness@gmail.com        warn("Using new output file (%s) rather than checkpointed (%s)\n",
38611785Sjthestness@gmail.com             new_out, fde_stdout->filename);
38711785Sjthestness@gmail.com        fde_stdout->filename = new_out;
38811785Sjthestness@gmail.com        fde_stdout->fileOffset = 0;
38911785Sjthestness@gmail.com    }
39011785Sjthestness@gmail.com
39110930Sbrandon.potter@amd.com    if ((it = oemap.find(fde_stdout->filename)) != oemap.end()) {
39210930Sbrandon.potter@amd.com        fde_stdout->fd = it->second;
39310930Sbrandon.potter@amd.com    } else {
39410930Sbrandon.potter@amd.com        fde_stdout->fd = openOutputFile(fde_stdout->filename);
39510930Sbrandon.potter@amd.com        seek(fde_stdout);
3965282Srstrong@cs.ucsd.edu    }
3975282Srstrong@cs.ucsd.edu
39810932Sbrandon.potter@amd.com    FDEntry *fde_stderr = getFDEntry(STDERR_FILENO);
39911785Sjthestness@gmail.com
40011785Sjthestness@gmail.com    // Check if user has specified a different error file, and if so, use it
40111785Sjthestness@gmail.com    // instead of the file specified in the checkpoint. This also resets the
40211785Sjthestness@gmail.com    // file offset from the checkpointed value
40311785Sjthestness@gmail.com    string new_err = ((ProcessParams*)params())->errout;
40411785Sjthestness@gmail.com    if (new_err != fde_stderr->filename) {
40511785Sjthestness@gmail.com        warn("Using new error file (%s) rather than checkpointed (%s)\n",
40611785Sjthestness@gmail.com             new_err, fde_stderr->filename);
40711785Sjthestness@gmail.com        fde_stderr->filename = new_err;
40811785Sjthestness@gmail.com        fde_stderr->fileOffset = 0;
40911785Sjthestness@gmail.com    }
41011785Sjthestness@gmail.com
41110930Sbrandon.potter@amd.com    if (fde_stdout->filename == fde_stderr->filename) {
41210930Sbrandon.potter@amd.com        // Reuse the same file descriptor if these match.
41310930Sbrandon.potter@amd.com        fde_stderr->fd = fde_stdout->fd;
41410930Sbrandon.potter@amd.com    } else if ((it = oemap.find(fde_stderr->filename)) != oemap.end()) {
41510930Sbrandon.potter@amd.com        fde_stderr->fd = it->second;
41610930Sbrandon.potter@amd.com    } else {
41710930Sbrandon.potter@amd.com        fde_stderr->fd = openOutputFile(fde_stderr->filename);
41810930Sbrandon.potter@amd.com        seek(fde_stderr);
4195514SMichael.Adler@intel.com    }
4205282Srstrong@cs.ucsd.edu
42110930Sbrandon.potter@amd.com    for (int tgt_fd = 3; tgt_fd < fd_array->size(); tgt_fd++) {
42210932Sbrandon.potter@amd.com        FDEntry *fde = getFDEntry(tgt_fd);
42310930Sbrandon.potter@amd.com        if (fde->fd == -1)
42410930Sbrandon.potter@amd.com            continue;
4255282Srstrong@cs.ucsd.edu
42610930Sbrandon.potter@amd.com        if (fde->isPipe) {
42710930Sbrandon.potter@amd.com            if (fde->filename == "PIPE-WRITE")
42810930Sbrandon.potter@amd.com                continue;
42910930Sbrandon.potter@amd.com            assert(fde->filename == "PIPE-READ");
4305282Srstrong@cs.ucsd.edu
43110930Sbrandon.potter@amd.com            int fds[2];
43210930Sbrandon.potter@amd.com            if (pipe(fds) < 0)
43310930Sbrandon.potter@amd.com                fatal("Unable to create new pipe");
4345282Srstrong@cs.ucsd.edu
43510930Sbrandon.potter@amd.com            fde->fd = fds[0];
4365282Srstrong@cs.ucsd.edu
43710932Sbrandon.potter@amd.com            FDEntry *fde_write = getFDEntry(fde->readPipeSource);
43811378Sbrandon.potter@amd.com            assert(fde_write->filename == "PIPE-WRITE");
43910930Sbrandon.potter@amd.com            fde_write->fd = fds[1];
44010930Sbrandon.potter@amd.com        } else {
44110930Sbrandon.potter@amd.com            fde->fd = openFile(fde->filename.c_str(), fde->flags, fde->mode);
44210930Sbrandon.potter@amd.com            seek(fde);
4435282Srstrong@cs.ucsd.edu        }
4445282Srstrong@cs.ucsd.edu    }
4455282Srstrong@cs.ucsd.edu}
4467487Ssteve.reinhardt@amd.com
4475282Srstrong@cs.ucsd.eduvoid
44810932Sbrandon.potter@amd.comProcess::findFileOffsets()
4497487Ssteve.reinhardt@amd.com{
45010930Sbrandon.potter@amd.com    for (auto& fde : *fd_array) {
45110930Sbrandon.potter@amd.com        if (fde.fd != -1)
45210930Sbrandon.potter@amd.com            fde.fileOffset = lseek(fde.fd, 0, SEEK_CUR);
4535282Srstrong@cs.ucsd.edu    }
4545282Srstrong@cs.ucsd.edu}
4555282Srstrong@cs.ucsd.edu
4565282Srstrong@cs.ucsd.eduvoid
4577487Ssteve.reinhardt@amd.comProcess::setReadPipeSource(int read_pipe_fd, int source_fd)
4587487Ssteve.reinhardt@amd.com{
45910932Sbrandon.potter@amd.com    FDEntry *fde = getFDEntry(read_pipe_fd);
46010930Sbrandon.potter@amd.com    assert(source_fd >= -1);
46110930Sbrandon.potter@amd.com    fde->readPipeSource = source_fd;
4625282Srstrong@cs.ucsd.edu}
4635282Srstrong@cs.ucsd.edu
4643311Ssaidi@eecs.umich.eduvoid
46510905Sandreas.sandberg@arm.comProcess::serialize(CheckpointOut &cp) const
4663311Ssaidi@eecs.umich.edu{
4673311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(brk_point);
4683311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(stack_base);
4693311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(stack_size);
4703311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(stack_min);
4713311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(next_thread_stack_base);
4723311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(mmap_end);
4733311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(nxm_start);
4743311Ssaidi@eecs.umich.edu    SERIALIZE_SCALAR(nxm_end);
47510905Sandreas.sandberg@arm.com    pTable->serialize(cp);
47610930Sbrandon.potter@amd.com    for (int x = 0; x < fd_array->size(); x++) {
47710930Sbrandon.potter@amd.com        (*fd_array)[x].serializeSection(cp, csprintf("FDEntry%d", x));
4785282Srstrong@cs.ucsd.edu    }
4793311Ssaidi@eecs.umich.edu
4803311Ssaidi@eecs.umich.edu}
4813311Ssaidi@eecs.umich.edu
4823311Ssaidi@eecs.umich.eduvoid
48310905Sandreas.sandberg@arm.comProcess::unserialize(CheckpointIn &cp)
4843311Ssaidi@eecs.umich.edu{
4853311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(brk_point);
4863311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(stack_base);
4873311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(stack_size);
4883311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(stack_min);
4893311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(next_thread_stack_base);
4903311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(mmap_end);
4913311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(nxm_start);
4923311Ssaidi@eecs.umich.edu    UNSERIALIZE_SCALAR(nxm_end);
49310905Sandreas.sandberg@arm.com    pTable->unserialize(cp);
49410930Sbrandon.potter@amd.com    for (int x = 0; x < fd_array->size(); x++) {
49510932Sbrandon.potter@amd.com        FDEntry *fde = getFDEntry(x);
49610930Sbrandon.potter@amd.com        fde->unserializeSection(cp, csprintf("FDEntry%d", x));
4977487Ssteve.reinhardt@amd.com    }
49810932Sbrandon.potter@amd.com    fixFileOffsets();
4996820SLisa.Hsu@amd.com    // The above returns a bool so that you could do something if you don't
5006820SLisa.Hsu@amd.com    // find the param in the checkpoint if you wanted to, like set a default
50110930Sbrandon.potter@amd.com    // but in this case we'll just stick with the instantiated value if not
50210929Sbrandon.potter@amd.com    // found.
5033311Ssaidi@eecs.umich.edu}
5042SN/A
5052SN/A
5069110Ssteve.reinhardt@amd.combool
50710558Salexandru.dutu@amd.comProcess::map(Addr vaddr, Addr paddr, int size, bool cacheable)
5089110Ssteve.reinhardt@amd.com{
50910558Salexandru.dutu@amd.com    pTable->map(vaddr, paddr, size,
51011294Sandreas.hansson@arm.com                cacheable ? PageTableBase::Zero : PageTableBase::Uncacheable);
5119110Ssteve.reinhardt@amd.com    return true;
5129110Ssteve.reinhardt@amd.com}
5139110Ssteve.reinhardt@amd.com
5149110Ssteve.reinhardt@amd.com
5152378SN/Avoid
51611851Sbrandon.potter@amd.comProcess::syscall(int64_t callnum, ThreadContext *tc)
5172093SN/A{
5182093SN/A    num_syscalls++;
5192093SN/A
5202093SN/A    SyscallDesc *desc = getDesc(callnum);
5212093SN/A    if (desc == NULL)
5222093SN/A        fatal("Syscall %d out of range", callnum);
5232093SN/A
5242680Sktlim@umich.edu    desc->doSyscall(callnum, this, tc);
5252093SN/A}
5262SN/A
5276701Sgblack@eecs.umich.eduIntReg
52811851Sbrandon.potter@amd.comProcess::getSyscallArg(ThreadContext *tc, int &i, int width)
5296701Sgblack@eecs.umich.edu{
5306701Sgblack@eecs.umich.edu    return getSyscallArg(tc, i);
5316701Sgblack@eecs.umich.edu}
5326701Sgblack@eecs.umich.edu
53310496Ssteve.reinhardt@amd.com
53410496Ssteve.reinhardt@amd.comEmulatedDriver *
53511851Sbrandon.potter@amd.comProcess::findDriver(std::string filename)
53610496Ssteve.reinhardt@amd.com{
53710496Ssteve.reinhardt@amd.com    for (EmulatedDriver *d : drivers) {
53810496Ssteve.reinhardt@amd.com        if (d->match(filename))
53910496Ssteve.reinhardt@amd.com            return d;
54010496Ssteve.reinhardt@amd.com    }
54110496Ssteve.reinhardt@amd.com
54210496Ssteve.reinhardt@amd.com    return NULL;
54310496Ssteve.reinhardt@amd.com}
54410496Ssteve.reinhardt@amd.com
54511389Sbrandon.potter@amd.comvoid
54611851Sbrandon.potter@amd.comProcess::updateBias()
54711389Sbrandon.potter@amd.com{
54811389Sbrandon.potter@amd.com    ObjectFile *interp = objFile->getInterpreter();
54911389Sbrandon.potter@amd.com
55011389Sbrandon.potter@amd.com    if (!interp || !interp->relocatable())
55111389Sbrandon.potter@amd.com        return;
55211389Sbrandon.potter@amd.com
55311389Sbrandon.potter@amd.com    // Determine how large the interpreters footprint will be in the process
55411389Sbrandon.potter@amd.com    // address space.
55511389Sbrandon.potter@amd.com    Addr interp_mapsize = roundUp(interp->mapSize(), TheISA::PageBytes);
55611389Sbrandon.potter@amd.com
55711389Sbrandon.potter@amd.com    // We are allocating the memory area; set the bias to the lowest address
55811389Sbrandon.potter@amd.com    // in the allocated memory region.
55911389Sbrandon.potter@amd.com    Addr ld_bias = mmapGrowsDown() ? mmap_end - interp_mapsize : mmap_end;
56011389Sbrandon.potter@amd.com
56111389Sbrandon.potter@amd.com    // Adjust the process mmap area to give the interpreter room; the real
56211389Sbrandon.potter@amd.com    // execve system call would just invoke the kernel's internal mmap
56311389Sbrandon.potter@amd.com    // functions to make these adjustments.
56411389Sbrandon.potter@amd.com    mmap_end = mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
56511389Sbrandon.potter@amd.com
56611389Sbrandon.potter@amd.com    interp->updateBias(ld_bias);
56711389Sbrandon.potter@amd.com}
56811389Sbrandon.potter@amd.com
56911389Sbrandon.potter@amd.com
57011392Sbrandon.potter@amd.comObjectFile *
57111851Sbrandon.potter@amd.comProcess::getInterpreter()
57211392Sbrandon.potter@amd.com{
57311392Sbrandon.potter@amd.com    return objFile->getInterpreter();
57411392Sbrandon.potter@amd.com}
57511392Sbrandon.potter@amd.com
57611392Sbrandon.potter@amd.com
57711389Sbrandon.potter@amd.comAddr
57811851Sbrandon.potter@amd.comProcess::getBias()
57911389Sbrandon.potter@amd.com{
58011392Sbrandon.potter@amd.com    ObjectFile *interp = getInterpreter();
58111389Sbrandon.potter@amd.com
58211389Sbrandon.potter@amd.com    return interp ? interp->bias() : objFile->bias();
58311389Sbrandon.potter@amd.com}
58411389Sbrandon.potter@amd.com
58511389Sbrandon.potter@amd.com
58611389Sbrandon.potter@amd.comAddr
58711851Sbrandon.potter@amd.comProcess::getStartPC()
58811389Sbrandon.potter@amd.com{
58911392Sbrandon.potter@amd.com    ObjectFile *interp = getInterpreter();
59011389Sbrandon.potter@amd.com
59111389Sbrandon.potter@amd.com    return interp ? interp->entryPoint() : objFile->entryPoint();
59211389Sbrandon.potter@amd.com}
59311389Sbrandon.potter@amd.com
59410496Ssteve.reinhardt@amd.com
59511851Sbrandon.potter@amd.comProcess *
59611851Sbrandon.potter@amd.comProcessParams::create()
5972715Sstever@eecs.umich.edu{
59811851Sbrandon.potter@amd.com    Process *process = NULL;
5992715Sstever@eecs.umich.edu
60011140Sjthestness@gmail.com    // If not specified, set the executable parameter equal to the
60111140Sjthestness@gmail.com    // simulated system's zeroth command line parameter
60211851Sbrandon.potter@amd.com    if (executable == "") {
60311851Sbrandon.potter@amd.com        executable = cmd[0];
60411140Sjthestness@gmail.com    }
60511140Sjthestness@gmail.com
60611851Sbrandon.potter@amd.com    ObjectFile *obj_file = createObjectFile(executable);
60711851Sbrandon.potter@amd.com    if (obj_file == NULL) {
60811851Sbrandon.potter@amd.com        fatal("Can't load object file %s", executable);
6092715Sstever@eecs.umich.edu    }
6102715Sstever@eecs.umich.edu
6115089Sgblack@eecs.umich.edu#if THE_ISA == ALPHA_ISA
61211851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Alpha)
6135753Ssteve.reinhardt@amd.com        fatal("Object file architecture does not match compiled ISA (Alpha).");
6145753Ssteve.reinhardt@amd.com
61511851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6165753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
6175753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
6185753Ssteve.reinhardt@amd.com        // fall through
6192715Sstever@eecs.umich.edu      case ObjectFile::Linux:
62011851Sbrandon.potter@amd.com        process = new AlphaLinuxProcess(this, obj_file);
6212715Sstever@eecs.umich.edu        break;
6222715Sstever@eecs.umich.edu
6232715Sstever@eecs.umich.edu      default:
6242715Sstever@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
6252715Sstever@eecs.umich.edu    }
6262715Sstever@eecs.umich.edu#elif THE_ISA == SPARC_ISA
62711851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::SPARC64 &&
62811851Sbrandon.potter@amd.com        obj_file->getArch() != ObjectFile::SPARC32)
6292715Sstever@eecs.umich.edu        fatal("Object file architecture does not match compiled ISA (SPARC).");
63011851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6315753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
6325753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
6335753Ssteve.reinhardt@amd.com        // fall through
6342715Sstever@eecs.umich.edu      case ObjectFile::Linux:
63511851Sbrandon.potter@amd.com        if (obj_file->getArch() == ObjectFile::SPARC64) {
63611851Sbrandon.potter@amd.com            process = new Sparc64LinuxProcess(this, obj_file);
6374111Sgblack@eecs.umich.edu        } else {
63811851Sbrandon.potter@amd.com            process = new Sparc32LinuxProcess(this, obj_file);
6394111Sgblack@eecs.umich.edu        }
6402715Sstever@eecs.umich.edu        break;
6412715Sstever@eecs.umich.edu
6422715Sstever@eecs.umich.edu
6432715Sstever@eecs.umich.edu      case ObjectFile::Solaris:
64411851Sbrandon.potter@amd.com        process = new SparcSolarisProcess(this, obj_file);
6452715Sstever@eecs.umich.edu        break;
6465753Ssteve.reinhardt@amd.com
6472715Sstever@eecs.umich.edu      default:
6482715Sstever@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
6492715Sstever@eecs.umich.edu    }
6504157Sgblack@eecs.umich.edu#elif THE_ISA == X86_ISA
65111851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::X86_64 &&
65211851Sbrandon.potter@amd.com        obj_file->getArch() != ObjectFile::I386)
6534166Sgblack@eecs.umich.edu        fatal("Object file architecture does not match compiled ISA (x86).");
65411851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6555753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
6565753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
6575753Ssteve.reinhardt@amd.com        // fall through
6584166Sgblack@eecs.umich.edu      case ObjectFile::Linux:
65911851Sbrandon.potter@amd.com        if (obj_file->getArch() == ObjectFile::X86_64) {
66011851Sbrandon.potter@amd.com            process = new X86_64LinuxProcess(this, obj_file);
6615874Sgblack@eecs.umich.edu        } else {
66211851Sbrandon.potter@amd.com            process = new I386LinuxProcess(this, obj_file);
6635874Sgblack@eecs.umich.edu        }
6644166Sgblack@eecs.umich.edu        break;
6655753Ssteve.reinhardt@amd.com
6664157Sgblack@eecs.umich.edu      default:
6674157Sgblack@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
6684157Sgblack@eecs.umich.edu    }
6692715Sstever@eecs.umich.edu#elif THE_ISA == MIPS_ISA
67011851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Mips)
6712715Sstever@eecs.umich.edu        fatal("Object file architecture does not match compiled ISA (MIPS).");
67211851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6735753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
6745753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
6755753Ssteve.reinhardt@amd.com        // fall through
6762715Sstever@eecs.umich.edu      case ObjectFile::Linux:
67711851Sbrandon.potter@amd.com        process = new MipsLinuxProcess(this, obj_file);
6782715Sstever@eecs.umich.edu        break;
6792715Sstever@eecs.umich.edu
6802715Sstever@eecs.umich.edu      default:
6812715Sstever@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
6822715Sstever@eecs.umich.edu    }
6835335Shines@cs.fsu.edu#elif THE_ISA == ARM_ISA
68411851Sbrandon.potter@amd.com    ObjectFile::Arch arch = obj_file->getArch();
68510037SARM gem5 Developers    if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
68610037SARM gem5 Developers        arch != ObjectFile::Arm64)
6875335Shines@cs.fsu.edu        fatal("Object file architecture does not match compiled ISA (ARM).");
68811851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6895753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
6905753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
6915753Ssteve.reinhardt@amd.com        // fall through
6925335Shines@cs.fsu.edu      case ObjectFile::Linux:
69310037SARM gem5 Developers        if (arch == ObjectFile::Arm64) {
69411851Sbrandon.potter@amd.com            process = new ArmLinuxProcess64(this, obj_file,
69511851Sbrandon.potter@amd.com                                            obj_file->getArch());
69610037SARM gem5 Developers        } else {
69711851Sbrandon.potter@amd.com            process = new ArmLinuxProcess32(this, obj_file,
69811851Sbrandon.potter@amd.com                                            obj_file->getArch());
69910037SARM gem5 Developers        }
7005335Shines@cs.fsu.edu        break;
70110810Sbr@bsdpad.com      case ObjectFile::FreeBSD:
70210810Sbr@bsdpad.com        if (arch == ObjectFile::Arm64) {
70311851Sbrandon.potter@amd.com            process = new ArmFreebsdProcess64(this, obj_file,
70411851Sbrandon.potter@amd.com                                              obj_file->getArch());
70510810Sbr@bsdpad.com        } else {
70611851Sbrandon.potter@amd.com            process = new ArmFreebsdProcess32(this, obj_file,
70711851Sbrandon.potter@amd.com                                              obj_file->getArch());
70810810Sbr@bsdpad.com        }
70910810Sbr@bsdpad.com        break;
7106392Ssaidi@eecs.umich.edu      case ObjectFile::LinuxArmOABI:
7116392Ssaidi@eecs.umich.edu        fatal("M5 does not support ARM OABI binaries. Please recompile with an"
7126392Ssaidi@eecs.umich.edu              " EABI compiler.");
7135335Shines@cs.fsu.edu      default:
7145335Shines@cs.fsu.edu        fatal("Unknown/unsupported operating system.");
7155335Shines@cs.fsu.edu    }
7166691Stjones1@inf.ed.ac.uk#elif THE_ISA == POWER_ISA
71711851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Power)
7186691Stjones1@inf.ed.ac.uk        fatal("Object file architecture does not match compiled ISA (Power).");
71911851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
7206691Stjones1@inf.ed.ac.uk      case ObjectFile::UnknownOpSys:
7216691Stjones1@inf.ed.ac.uk        warn("Unknown operating system; assuming Linux.");
7226691Stjones1@inf.ed.ac.uk        // fall through
7236691Stjones1@inf.ed.ac.uk      case ObjectFile::Linux:
72411851Sbrandon.potter@amd.com        process = new PowerLinuxProcess(this, obj_file);
7256691Stjones1@inf.ed.ac.uk        break;
7266691Stjones1@inf.ed.ac.uk
7276691Stjones1@inf.ed.ac.uk      default:
7286691Stjones1@inf.ed.ac.uk        fatal("Unknown/unsupported operating system.");
7296691Stjones1@inf.ed.ac.uk    }
73011723Sar4jc@virginia.edu#elif THE_ISA == RISCV_ISA
73111851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Riscv)
73211723Sar4jc@virginia.edu        fatal("Object file architecture does not match compiled ISA (RISCV).");
73311851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
73411723Sar4jc@virginia.edu      case ObjectFile::UnknownOpSys:
73511723Sar4jc@virginia.edu        warn("Unknown operating system; assuming Linux.");
73611723Sar4jc@virginia.edu        // fall through
73711723Sar4jc@virginia.edu      case ObjectFile::Linux:
73811851Sbrandon.potter@amd.com        process = new RiscvLinuxProcess(this, obj_file);
73911723Sar4jc@virginia.edu        break;
74011723Sar4jc@virginia.edu      default:
74111723Sar4jc@virginia.edu        fatal("Unknown/unsupported operating system.");
74211723Sar4jc@virginia.edu    }
7432715Sstever@eecs.umich.edu#else
7442715Sstever@eecs.umich.edu#error "THE_ISA not set"
7452715Sstever@eecs.umich.edu#endif
7462715Sstever@eecs.umich.edu
7472715Sstever@eecs.umich.edu    if (process == NULL)
7482715Sstever@eecs.umich.edu        fatal("Unknown error creating process object.");
7492715Sstever@eecs.umich.edu    return process;
7502715Sstever@eecs.umich.edu}
751