process.cc revision 13883
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>
5313883Sdavid.hashe@amd.com#include <climits>
5411911SBrandon.Potter@amd.com#include <csignal>
5510930Sbrandon.potter@amd.com#include <map>
562SN/A#include <string>
5711800Sbrandon.potter@amd.com#include <vector>
582SN/A
5911793Sbrandon.potter@amd.com#include "base/intmath.hh"
6056SN/A#include "base/loader/object_file.hh"
611158SN/A#include "base/loader/symtab.hh"
62146SN/A#include "base/statistics.hh"
636658Snate@binkert.org#include "config/the_isa.hh"
642680Sktlim@umich.edu#include "cpu/thread_context.hh"
652378SN/A#include "mem/page_table.hh"
668706Sandreas.hansson@arm.com#include "mem/se_translating_port_proxy.hh"
675154Sgblack@eecs.umich.edu#include "params/Process.hh"
6811800Sbrandon.potter@amd.com#include "sim/emul_driver.hh"
6911856Sbrandon.potter@amd.com#include "sim/fd_array.hh"
7011856Sbrandon.potter@amd.com#include "sim/fd_entry.hh"
7113883Sdavid.hashe@amd.com#include "sim/redirect_path.hh"
7211794Sbrandon.potter@amd.com#include "sim/syscall_desc.hh"
732378SN/A#include "sim/system.hh"
742SN/A
752715Sstever@eecs.umich.edu#if THE_ISA == ALPHA_ISA
762715Sstever@eecs.umich.edu#include "arch/alpha/linux/process.hh"
7711911SBrandon.Potter@amd.com
782715Sstever@eecs.umich.edu#elif THE_ISA == SPARC_ISA
792715Sstever@eecs.umich.edu#include "arch/sparc/linux/process.hh"
802715Sstever@eecs.umich.edu#include "arch/sparc/solaris/process.hh"
8111911SBrandon.Potter@amd.com
822715Sstever@eecs.umich.edu#elif THE_ISA == MIPS_ISA
832715Sstever@eecs.umich.edu#include "arch/mips/linux/process.hh"
8411911SBrandon.Potter@amd.com
855335Shines@cs.fsu.edu#elif THE_ISA == ARM_ISA
8611911SBrandon.Potter@amd.com#include "arch/arm/freebsd/process.hh"
875335Shines@cs.fsu.edu#include "arch/arm/linux/process.hh"
8811911SBrandon.Potter@amd.com
894157Sgblack@eecs.umich.edu#elif THE_ISA == X86_ISA
904166Sgblack@eecs.umich.edu#include "arch/x86/linux/process.hh"
9111911SBrandon.Potter@amd.com
926691Stjones1@inf.ed.ac.uk#elif THE_ISA == POWER_ISA
936691Stjones1@inf.ed.ac.uk#include "arch/power/linux/process.hh"
9411911SBrandon.Potter@amd.com
9511723Sar4jc@virginia.edu#elif THE_ISA == RISCV_ISA
9611723Sar4jc@virginia.edu#include "arch/riscv/linux/process.hh"
9711911SBrandon.Potter@amd.com
982715Sstever@eecs.umich.edu#else
992715Sstever@eecs.umich.edu#error "THE_ISA not set"
1002715Sstever@eecs.umich.edu#endif
1012715Sstever@eecs.umich.edu
1022715Sstever@eecs.umich.edu
1032SN/Ausing namespace std;
1042107SN/Ausing namespace TheISA;
1052SN/A
10613883Sdavid.hashe@amd.comstatic std::string
10713883Sdavid.hashe@amd.comnormalize(std::string& directory)
10813883Sdavid.hashe@amd.com{
10913883Sdavid.hashe@amd.com    if (directory.back() != '/')
11013883Sdavid.hashe@amd.com        directory += '/';
11113883Sdavid.hashe@amd.com    return directory;
11213883Sdavid.hashe@amd.com}
11313883Sdavid.hashe@amd.com
11412448Sgabeblack@google.comProcess::Process(ProcessParams *params, EmulationPageTable *pTable,
11512431Sgabeblack@google.com                 ObjectFile *obj_file)
1167532Ssteve.reinhardt@amd.com    : SimObject(params), system(params->system),
11710299Salexandru.dutu@amd.com      useArchPT(params->useArchPT),
11810554Salexandru.dutu@amd.com      kvmInSE(params->kvmInSE),
11913867Salexandru.dutu@amd.com      useForClone(false),
12012431Sgabeblack@google.com      pTable(pTable),
1218852Sandreas.hansson@arm.com      initVirtMem(system->getSystemPort(), this,
12210929Sbrandon.potter@amd.com                  SETranslatingPortProxy::Always),
12311851Sbrandon.potter@amd.com      objFile(obj_file),
12413883Sdavid.hashe@amd.com      argv(params->cmd), envp(params->env),
12511851Sbrandon.potter@amd.com      executable(params->executable),
12613883Sdavid.hashe@amd.com      tgtCwd(normalize(params->cwd)),
12713883Sdavid.hashe@amd.com      hostCwd(checkPathRedirect(tgtCwd)),
12811801Sbrandon.potter@amd.com      _uid(params->uid), _euid(params->euid),
12911801Sbrandon.potter@amd.com      _gid(params->gid), _egid(params->egid),
13011851Sbrandon.potter@amd.com      _pid(params->pid), _ppid(params->ppid),
13111885Sbrandon.potter@amd.com      _pgid(params->pgid), drivers(params->drivers),
13211886Sbrandon.potter@amd.com      fds(make_shared<FDArray>(params->input, params->output, params->errout)),
13311886Sbrandon.potter@amd.com      childClearTID(0)
1342SN/A{
13511885Sbrandon.potter@amd.com    if (_pid >= System::maxPID)
13611885Sbrandon.potter@amd.com        fatal("_pid is too large: %d", _pid);
13711885Sbrandon.potter@amd.com
13811885Sbrandon.potter@amd.com    auto ret_pair = system->PIDs.emplace(_pid);
13911885Sbrandon.potter@amd.com    if (!ret_pair.second)
14011885Sbrandon.potter@amd.com        fatal("_pid %d is already used", _pid);
14111885Sbrandon.potter@amd.com
14211886Sbrandon.potter@amd.com    /**
14311886Sbrandon.potter@amd.com     * Linux bundles together processes into this concept called a thread
14411886Sbrandon.potter@amd.com     * group. The thread group is responsible for recording which processes
14511886Sbrandon.potter@amd.com     * behave as threads within a process context. The thread group leader
14611886Sbrandon.potter@amd.com     * is the process who's tgid is equal to its pid. Other processes which
14711886Sbrandon.potter@amd.com     * belong to the thread group, but do not lead the thread group, are
14811886Sbrandon.potter@amd.com     * treated as child threads. These threads are created by the clone system
14911886Sbrandon.potter@amd.com     * call with options specified to create threads (differing from the
15011886Sbrandon.potter@amd.com     * options used to implement a fork). By default, set up the tgid/pid
15111886Sbrandon.potter@amd.com     * with a new, equivalent value. If CLONE_THREAD is specified, patch
15211886Sbrandon.potter@amd.com     * the tgid value with the old process' value.
15311886Sbrandon.potter@amd.com     */
15411886Sbrandon.potter@amd.com    _tgid = params->pid;
15511886Sbrandon.potter@amd.com
15611886Sbrandon.potter@amd.com    exitGroup = new bool();
15711886Sbrandon.potter@amd.com    sigchld = new bool();
15811886Sbrandon.potter@amd.com
15911851Sbrandon.potter@amd.com    if (!debugSymbolTable) {
16011851Sbrandon.potter@amd.com        debugSymbolTable = new SymbolTable();
16111851Sbrandon.potter@amd.com        if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
16211851Sbrandon.potter@amd.com            !objFile->loadLocalSymbols(debugSymbolTable) ||
16311851Sbrandon.potter@amd.com            !objFile->loadWeakSymbols(debugSymbolTable)) {
16411851Sbrandon.potter@amd.com            delete debugSymbolTable;
16511919SBrandon.Potter@amd.com            debugSymbolTable = nullptr;
16611851Sbrandon.potter@amd.com        }
16711851Sbrandon.potter@amd.com    }
1682SN/A}
1692SN/A
1702SN/Avoid
17111886Sbrandon.potter@amd.comProcess::clone(ThreadContext *otc, ThreadContext *ntc,
17213557Sgabeblack@google.com               Process *np, RegVal flags)
17311886Sbrandon.potter@amd.com{
17411920SBrandon.Potter@amd.com#ifndef CLONE_VM
17511920SBrandon.Potter@amd.com#define CLONE_VM 0
17611920SBrandon.Potter@amd.com#endif
17711920SBrandon.Potter@amd.com#ifndef CLONE_FILES
17811920SBrandon.Potter@amd.com#define CLONE_FILES 0
17911920SBrandon.Potter@amd.com#endif
18011920SBrandon.Potter@amd.com#ifndef CLONE_THREAD
18111920SBrandon.Potter@amd.com#define CLONE_THREAD 0
18211920SBrandon.Potter@amd.com#endif
18311886Sbrandon.potter@amd.com    if (CLONE_VM & flags) {
18411886Sbrandon.potter@amd.com        /**
18511886Sbrandon.potter@amd.com         * Share the process memory address space between the new process
18611886Sbrandon.potter@amd.com         * and the old process. Changes in one will be visible in the other
18711886Sbrandon.potter@amd.com         * due to the pointer use.
18811886Sbrandon.potter@amd.com         */
18911886Sbrandon.potter@amd.com        delete np->pTable;
19011886Sbrandon.potter@amd.com        np->pTable = pTable;
19111886Sbrandon.potter@amd.com        ntc->getMemProxy().setPageTable(np->pTable);
19211886Sbrandon.potter@amd.com
19311886Sbrandon.potter@amd.com        np->memState = memState;
19411886Sbrandon.potter@amd.com    } else {
19511886Sbrandon.potter@amd.com        /**
19611886Sbrandon.potter@amd.com         * Duplicate the process memory address space. The state needs to be
19711886Sbrandon.potter@amd.com         * copied over (rather than using pointers to share everything).
19811886Sbrandon.potter@amd.com         */
19911886Sbrandon.potter@amd.com        typedef std::vector<pair<Addr,Addr>> MapVec;
20011886Sbrandon.potter@amd.com        MapVec mappings;
20111886Sbrandon.potter@amd.com        pTable->getMappings(&mappings);
20211886Sbrandon.potter@amd.com
20311886Sbrandon.potter@amd.com        for (auto map : mappings) {
20411886Sbrandon.potter@amd.com            Addr paddr, vaddr = map.first;
20511886Sbrandon.potter@amd.com            bool alloc_page = !(np->pTable->translate(vaddr, paddr));
20611886Sbrandon.potter@amd.com            np->replicatePage(vaddr, paddr, otc, ntc, alloc_page);
20711886Sbrandon.potter@amd.com        }
20811886Sbrandon.potter@amd.com
20911886Sbrandon.potter@amd.com        *np->memState = *memState;
21011886Sbrandon.potter@amd.com    }
21111886Sbrandon.potter@amd.com
21211886Sbrandon.potter@amd.com    if (CLONE_FILES & flags) {
21311886Sbrandon.potter@amd.com        /**
21411886Sbrandon.potter@amd.com         * The parent and child file descriptors are shared because the
21511886Sbrandon.potter@amd.com         * two FDArray pointers are pointing to the same FDArray. Opening
21611886Sbrandon.potter@amd.com         * and closing file descriptors will be visible to both processes.
21711886Sbrandon.potter@amd.com         */
21811886Sbrandon.potter@amd.com        np->fds = fds;
21911886Sbrandon.potter@amd.com    } else {
22011886Sbrandon.potter@amd.com        /**
22111886Sbrandon.potter@amd.com         * Copy the file descriptors from the old process into the new
22211886Sbrandon.potter@amd.com         * child process. The file descriptors entry can be opened and
22311886Sbrandon.potter@amd.com         * closed independently of the other process being considered. The
22411886Sbrandon.potter@amd.com         * host file descriptors are also dup'd so that the flags for the
22511886Sbrandon.potter@amd.com         * host file descriptor is independent of the other process.
22611886Sbrandon.potter@amd.com         */
22711886Sbrandon.potter@amd.com        for (int tgt_fd = 0; tgt_fd < fds->getSize(); tgt_fd++) {
22811886Sbrandon.potter@amd.com            std::shared_ptr<FDArray> nfds = np->fds;
22911886Sbrandon.potter@amd.com            std::shared_ptr<FDEntry> this_fde = (*fds)[tgt_fd];
23011886Sbrandon.potter@amd.com            if (!this_fde) {
23111886Sbrandon.potter@amd.com                nfds->setFDEntry(tgt_fd, nullptr);
23211886Sbrandon.potter@amd.com                continue;
23311886Sbrandon.potter@amd.com            }
23411886Sbrandon.potter@amd.com            nfds->setFDEntry(tgt_fd, this_fde->clone());
23511886Sbrandon.potter@amd.com
23611886Sbrandon.potter@amd.com            auto this_hbfd = std::dynamic_pointer_cast<HBFDEntry>(this_fde);
23711886Sbrandon.potter@amd.com            if (!this_hbfd)
23811886Sbrandon.potter@amd.com                continue;
23911886Sbrandon.potter@amd.com
24011886Sbrandon.potter@amd.com            int this_sim_fd = this_hbfd->getSimFD();
24111886Sbrandon.potter@amd.com            if (this_sim_fd <= 2)
24211886Sbrandon.potter@amd.com                continue;
24311886Sbrandon.potter@amd.com
24411886Sbrandon.potter@amd.com            int np_sim_fd = dup(this_sim_fd);
24511886Sbrandon.potter@amd.com            assert(np_sim_fd != -1);
24611886Sbrandon.potter@amd.com
24711886Sbrandon.potter@amd.com            auto nhbfd = std::dynamic_pointer_cast<HBFDEntry>((*nfds)[tgt_fd]);
24811886Sbrandon.potter@amd.com            nhbfd->setSimFD(np_sim_fd);
24911886Sbrandon.potter@amd.com        }
25011886Sbrandon.potter@amd.com    }
25111886Sbrandon.potter@amd.com
25211886Sbrandon.potter@amd.com    if (CLONE_THREAD & flags) {
25311886Sbrandon.potter@amd.com        np->_tgid = _tgid;
25411886Sbrandon.potter@amd.com        delete np->exitGroup;
25511886Sbrandon.potter@amd.com        np->exitGroup = exitGroup;
25611886Sbrandon.potter@amd.com    }
25711886Sbrandon.potter@amd.com
25811886Sbrandon.potter@amd.com    np->argv.insert(np->argv.end(), argv.begin(), argv.end());
25911886Sbrandon.potter@amd.com    np->envp.insert(np->envp.end(), envp.begin(), envp.end());
26011886Sbrandon.potter@amd.com}
26111886Sbrandon.potter@amd.com
26211886Sbrandon.potter@amd.comvoid
2632SN/AProcess::regStats()
2642SN/A{
26511522Sstephan.diestelhorst@arm.com    SimObject::regStats();
26611522Sstephan.diestelhorst@arm.com
267729SN/A    using namespace Stats;
2682SN/A
26911886Sbrandon.potter@amd.com    numSyscalls
27011886Sbrandon.potter@amd.com        .name(name() + ".numSyscalls")
2712SN/A        .desc("Number of system calls")
2722SN/A        ;
2732SN/A}
2742SN/A
2755713Shsul@eecs.umich.eduThreadContext *
2765713Shsul@eecs.umich.eduProcess::findFreeContext()
2772SN/A{
27811886Sbrandon.potter@amd.com    for (auto &it : system->threadContexts) {
27911886Sbrandon.potter@amd.com        if (ThreadContext::Halted == it->status())
28011886Sbrandon.potter@amd.com            return it;
2815512SMichael.Adler@intel.com    }
28211919SBrandon.Potter@amd.com    return nullptr;
2832SN/A}
2842SN/A
2851395SN/Avoid
28611886Sbrandon.potter@amd.comProcess::revokeThreadContext(int context_id)
28711886Sbrandon.potter@amd.com{
28811886Sbrandon.potter@amd.com    std::vector<ContextID>::iterator it;
28911886Sbrandon.potter@amd.com    for (it = contextIds.begin(); it != contextIds.end(); it++) {
29011886Sbrandon.potter@amd.com        if (*it == context_id) {
29111886Sbrandon.potter@amd.com            contextIds.erase(it);
29211886Sbrandon.potter@amd.com            return;
29311886Sbrandon.potter@amd.com        }
29411886Sbrandon.potter@amd.com    }
29511886Sbrandon.potter@amd.com    warn("Unable to find thread context to revoke");
29611886Sbrandon.potter@amd.com}
29711886Sbrandon.potter@amd.com
29811886Sbrandon.potter@amd.comvoid
2997532Ssteve.reinhardt@amd.comProcess::initState()
3001395SN/A{
3015713Shsul@eecs.umich.edu    if (contextIds.empty())
3025713Shsul@eecs.umich.edu        fatal("Process %s is not associated with any HW contexts!\n", name());
3032378SN/A
3042680Sktlim@umich.edu    // first thread context for this process... initialize & enable
3055713Shsul@eecs.umich.edu    ThreadContext *tc = system->getThreadContext(contextIds[0]);
3061395SN/A
3071634SN/A    // mark this context as active so it will start ticking.
30810407Smitch.hayenga@arm.com    tc->activate();
30910298Salexandru.dutu@amd.com
31010298Salexandru.dutu@amd.com    pTable->initState(tc);
3111395SN/A}
3122SN/A
31310913Sandreas.sandberg@arm.comDrainState
31410913Sandreas.sandberg@arm.comProcess::drain()
31510905Sandreas.sandberg@arm.com{
31611856Sbrandon.potter@amd.com    fds->updateFileOffsets();
31710913Sandreas.sandberg@arm.com    return DrainState::Drained;
31810905Sandreas.sandberg@arm.com}
31910905Sandreas.sandberg@arm.com
3208601Ssteve.reinhardt@amd.comvoid
3218601Ssteve.reinhardt@amd.comProcess::allocateMem(Addr vaddr, int64_t size, bool clobber)
3228601Ssteve.reinhardt@amd.com{
32310318Sandreas.hansson@arm.com    int npages = divCeil(size, (int64_t)PageBytes);
3248601Ssteve.reinhardt@amd.com    Addr paddr = system->allocPhysPages(npages);
32511294Sandreas.hansson@arm.com    pTable->map(vaddr, paddr, size,
32612448Sgabeblack@google.com                clobber ? EmulationPageTable::Clobber :
32712460Sgabeblack@google.com                          EmulationPageTable::MappingFlags(0));
3288601Ssteve.reinhardt@amd.com}
3298601Ssteve.reinhardt@amd.com
33011886Sbrandon.potter@amd.comvoid
33111886Sbrandon.potter@amd.comProcess::replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc,
33211886Sbrandon.potter@amd.com                       ThreadContext *new_tc, bool allocate_page)
33311886Sbrandon.potter@amd.com{
33411886Sbrandon.potter@amd.com    if (allocate_page)
33511886Sbrandon.potter@amd.com        new_paddr = system->allocPhysPages(1);
33611886Sbrandon.potter@amd.com
33711886Sbrandon.potter@amd.com    // Read from old physical page.
33811886Sbrandon.potter@amd.com    uint8_t *buf_p = new uint8_t[PageBytes];
33911886Sbrandon.potter@amd.com    old_tc->getMemProxy().readBlob(vaddr, buf_p, PageBytes);
34011886Sbrandon.potter@amd.com
34111886Sbrandon.potter@amd.com    // Create new mapping in process address space by clobbering existing
34211886Sbrandon.potter@amd.com    // mapping (if any existed) and then write to the new physical page.
34311886Sbrandon.potter@amd.com    bool clobber = true;
34411886Sbrandon.potter@amd.com    pTable->map(vaddr, new_paddr, PageBytes, clobber);
34511886Sbrandon.potter@amd.com    new_tc->getMemProxy().writeBlob(vaddr, buf_p, PageBytes);
34611886Sbrandon.potter@amd.com    delete[] buf_p;
34711886Sbrandon.potter@amd.com}
34811886Sbrandon.potter@amd.com
3494434Ssaidi@eecs.umich.edubool
3508539Sgblack@eecs.umich.eduProcess::fixupStackFault(Addr vaddr)
3514434Ssaidi@eecs.umich.edu{
35211905SBrandon.Potter@amd.com    Addr stack_min = memState->getStackMin();
35311905SBrandon.Potter@amd.com    Addr stack_base = memState->getStackBase();
35411905SBrandon.Potter@amd.com    Addr max_stack_size = memState->getMaxStackSize();
35511905SBrandon.Potter@amd.com
3568539Sgblack@eecs.umich.edu    // Check if this is already on the stack and there's just no page there
3578539Sgblack@eecs.umich.edu    // yet.
35811905SBrandon.Potter@amd.com    if (vaddr >= stack_min && vaddr < stack_base) {
35910318Sandreas.hansson@arm.com        allocateMem(roundDown(vaddr, PageBytes), PageBytes);
3604434Ssaidi@eecs.umich.edu        return true;
3614434Ssaidi@eecs.umich.edu    }
3624434Ssaidi@eecs.umich.edu
3638539Sgblack@eecs.umich.edu    // We've accessed the next page of the stack, so extend it to include
3648539Sgblack@eecs.umich.edu    // this address.
36511905SBrandon.Potter@amd.com    if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
36611905SBrandon.Potter@amd.com        while (vaddr < stack_min) {
36711905SBrandon.Potter@amd.com            stack_min -= TheISA::PageBytes;
36811905SBrandon.Potter@amd.com            if (stack_base - stack_min > max_stack_size)
3695154Sgblack@eecs.umich.edu                fatal("Maximum stack size exceeded\n");
37011905SBrandon.Potter@amd.com            allocateMem(stack_min, TheISA::PageBytes);
3715823Ssaidi@eecs.umich.edu            inform("Increasing stack size by one page.");
37211906SBrandon.Potter@amd.com        }
37311905SBrandon.Potter@amd.com        memState->setStackMin(stack_min);
3744434Ssaidi@eecs.umich.edu        return true;
3754434Ssaidi@eecs.umich.edu    }
3764434Ssaidi@eecs.umich.edu    return false;
3774434Ssaidi@eecs.umich.edu}
3784434Ssaidi@eecs.umich.edu
3795282Srstrong@cs.ucsd.eduvoid
38010905Sandreas.sandberg@arm.comProcess::serialize(CheckpointOut &cp) const
3813311Ssaidi@eecs.umich.edu{
38212283Saustinharris@utexas.edu    memState->serialize(cp);
38310905Sandreas.sandberg@arm.com    pTable->serialize(cp);
38411856Sbrandon.potter@amd.com    /**
38511856Sbrandon.potter@amd.com     * Checkpoints for file descriptors currently do not work. Need to
38611856Sbrandon.potter@amd.com     * come back and fix them at a later date.
38711856Sbrandon.potter@amd.com     */
38811856Sbrandon.potter@amd.com
38911856Sbrandon.potter@amd.com    warn("Checkpoints for file descriptors currently do not work.");
39011856Sbrandon.potter@amd.com#if 0
39111856Sbrandon.potter@amd.com    for (int x = 0; x < fds->getSize(); x++)
39211856Sbrandon.potter@amd.com        (*fds)[x].serializeSection(cp, csprintf("FDEntry%d", x));
39311856Sbrandon.potter@amd.com#endif
3943311Ssaidi@eecs.umich.edu
3953311Ssaidi@eecs.umich.edu}
3963311Ssaidi@eecs.umich.edu
3973311Ssaidi@eecs.umich.eduvoid
39810905Sandreas.sandberg@arm.comProcess::unserialize(CheckpointIn &cp)
3993311Ssaidi@eecs.umich.edu{
40012283Saustinharris@utexas.edu    memState->unserialize(cp);
40110905Sandreas.sandberg@arm.com    pTable->unserialize(cp);
40211856Sbrandon.potter@amd.com    /**
40311856Sbrandon.potter@amd.com     * Checkpoints for file descriptors currently do not work. Need to
40411856Sbrandon.potter@amd.com     * come back and fix them at a later date.
40511856Sbrandon.potter@amd.com     */
40611856Sbrandon.potter@amd.com    warn("Checkpoints for file descriptors currently do not work.");
40711856Sbrandon.potter@amd.com#if 0
40811856Sbrandon.potter@amd.com    for (int x = 0; x < fds->getSize(); x++)
40911856Sbrandon.potter@amd.com        (*fds)[x]->unserializeSection(cp, csprintf("FDEntry%d", x));
41011856Sbrandon.potter@amd.com    fds->restoreFileOffsets();
41111856Sbrandon.potter@amd.com#endif
4126820SLisa.Hsu@amd.com    // The above returns a bool so that you could do something if you don't
4136820SLisa.Hsu@amd.com    // find the param in the checkpoint if you wanted to, like set a default
41410930Sbrandon.potter@amd.com    // but in this case we'll just stick with the instantiated value if not
41510929Sbrandon.potter@amd.com    // found.
4163311Ssaidi@eecs.umich.edu}
4172SN/A
4189110Ssteve.reinhardt@amd.combool
41910558Salexandru.dutu@amd.comProcess::map(Addr vaddr, Addr paddr, int size, bool cacheable)
4209110Ssteve.reinhardt@amd.com{
42110558Salexandru.dutu@amd.com    pTable->map(vaddr, paddr, size,
42212460Sgabeblack@google.com                cacheable ? EmulationPageTable::MappingFlags(0) :
42312448Sgabeblack@google.com                            EmulationPageTable::Uncacheable);
4249110Ssteve.reinhardt@amd.com    return true;
4259110Ssteve.reinhardt@amd.com}
4269110Ssteve.reinhardt@amd.com
4272378SN/Avoid
42811877Sbrandon.potter@amd.comProcess::syscall(int64_t callnum, ThreadContext *tc, Fault *fault)
4292093SN/A{
43011886Sbrandon.potter@amd.com    numSyscalls++;
4312093SN/A
4322093SN/A    SyscallDesc *desc = getDesc(callnum);
43311919SBrandon.Potter@amd.com    if (desc == nullptr)
4342093SN/A        fatal("Syscall %d out of range", callnum);
4352093SN/A
43611877Sbrandon.potter@amd.com    desc->doSyscall(callnum, this, tc, fault);
4372093SN/A}
4382SN/A
43913557Sgabeblack@google.comRegVal
44011851Sbrandon.potter@amd.comProcess::getSyscallArg(ThreadContext *tc, int &i, int width)
4416701Sgblack@eecs.umich.edu{
4426701Sgblack@eecs.umich.edu    return getSyscallArg(tc, i);
4436701Sgblack@eecs.umich.edu}
4446701Sgblack@eecs.umich.edu
44510496Ssteve.reinhardt@amd.comEmulatedDriver *
44611851Sbrandon.potter@amd.comProcess::findDriver(std::string filename)
44710496Ssteve.reinhardt@amd.com{
44810496Ssteve.reinhardt@amd.com    for (EmulatedDriver *d : drivers) {
44910496Ssteve.reinhardt@amd.com        if (d->match(filename))
45010496Ssteve.reinhardt@amd.com            return d;
45110496Ssteve.reinhardt@amd.com    }
45210496Ssteve.reinhardt@amd.com
45311919SBrandon.Potter@amd.com    return nullptr;
45410496Ssteve.reinhardt@amd.com}
45510496Ssteve.reinhardt@amd.com
45613883Sdavid.hashe@amd.comstd::string
45713883Sdavid.hashe@amd.comProcess::checkPathRedirect(const std::string &filename)
45813883Sdavid.hashe@amd.com{
45913883Sdavid.hashe@amd.com    // If the input parameter contains a relative path, convert it. Note,
46013883Sdavid.hashe@amd.com    // the return value for this method should always return an absolute
46113883Sdavid.hashe@amd.com    // path on the host filesystem. The return value will be used to
46213883Sdavid.hashe@amd.com    // open and manipulate the path specified by the input parameter. Since
46313883Sdavid.hashe@amd.com    // all filesystem handling in syscall mode is passed through to the host,
46413883Sdavid.hashe@amd.com    // we deal only with host paths.
46513883Sdavid.hashe@amd.com    auto host_fs_abs_path = absolutePath(filename, true);
46613883Sdavid.hashe@amd.com
46713883Sdavid.hashe@amd.com    for (auto path : system->redirectPaths) {
46813883Sdavid.hashe@amd.com        // Search through the redirect paths to see if a starting substring of
46913883Sdavid.hashe@amd.com        // our path falls into any buckets which need to redirected.
47013883Sdavid.hashe@amd.com        if (startswith(host_fs_abs_path, path->appPath())) {
47113883Sdavid.hashe@amd.com            std::string tail = host_fs_abs_path.substr(path->appPath().size());
47213883Sdavid.hashe@amd.com
47313883Sdavid.hashe@amd.com            // If this path needs to be redirected, search through a list
47413883Sdavid.hashe@amd.com            // of targets to see if we can match a valid file (or directory).
47513883Sdavid.hashe@amd.com            for (auto host_path : path->hostPaths()) {
47613883Sdavid.hashe@amd.com                if (access((host_path + tail).c_str(), R_OK) == 0) {
47713883Sdavid.hashe@amd.com                    // Return the valid match.
47813883Sdavid.hashe@amd.com                    return host_path + tail;
47913883Sdavid.hashe@amd.com                }
48013883Sdavid.hashe@amd.com            }
48113883Sdavid.hashe@amd.com            // The path needs to be redirected, but the file or directory
48213883Sdavid.hashe@amd.com            // does not exist on the host filesystem. Return the first
48313883Sdavid.hashe@amd.com            // host path as a default.
48413883Sdavid.hashe@amd.com            return path->hostPaths()[0] + tail;
48513883Sdavid.hashe@amd.com        }
48613883Sdavid.hashe@amd.com    }
48713883Sdavid.hashe@amd.com
48813883Sdavid.hashe@amd.com    // The path does not need to be redirected.
48913883Sdavid.hashe@amd.com    return host_fs_abs_path;
49013883Sdavid.hashe@amd.com}
49113883Sdavid.hashe@amd.com
49211389Sbrandon.potter@amd.comvoid
49311851Sbrandon.potter@amd.comProcess::updateBias()
49411389Sbrandon.potter@amd.com{
49511389Sbrandon.potter@amd.com    ObjectFile *interp = objFile->getInterpreter();
49611389Sbrandon.potter@amd.com
49711389Sbrandon.potter@amd.com    if (!interp || !interp->relocatable())
49811389Sbrandon.potter@amd.com        return;
49911389Sbrandon.potter@amd.com
50011389Sbrandon.potter@amd.com    // Determine how large the interpreters footprint will be in the process
50111389Sbrandon.potter@amd.com    // address space.
50211389Sbrandon.potter@amd.com    Addr interp_mapsize = roundUp(interp->mapSize(), TheISA::PageBytes);
50311389Sbrandon.potter@amd.com
50411389Sbrandon.potter@amd.com    // We are allocating the memory area; set the bias to the lowest address
50511389Sbrandon.potter@amd.com    // in the allocated memory region.
50611905SBrandon.Potter@amd.com    Addr mmap_end = memState->getMmapEnd();
50711905SBrandon.Potter@amd.com    Addr ld_bias = mmapGrowsDown() ? mmap_end - interp_mapsize : mmap_end;
50811389Sbrandon.potter@amd.com
50911389Sbrandon.potter@amd.com    // Adjust the process mmap area to give the interpreter room; the real
51011389Sbrandon.potter@amd.com    // execve system call would just invoke the kernel's internal mmap
51111389Sbrandon.potter@amd.com    // functions to make these adjustments.
51211905SBrandon.Potter@amd.com    mmap_end = mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
51311905SBrandon.Potter@amd.com    memState->setMmapEnd(mmap_end);
51411389Sbrandon.potter@amd.com
51511389Sbrandon.potter@amd.com    interp->updateBias(ld_bias);
51611389Sbrandon.potter@amd.com}
51711389Sbrandon.potter@amd.com
51811392Sbrandon.potter@amd.comObjectFile *
51911851Sbrandon.potter@amd.comProcess::getInterpreter()
52011392Sbrandon.potter@amd.com{
52111392Sbrandon.potter@amd.com    return objFile->getInterpreter();
52211392Sbrandon.potter@amd.com}
52311392Sbrandon.potter@amd.com
52411389Sbrandon.potter@amd.comAddr
52511851Sbrandon.potter@amd.comProcess::getBias()
52611389Sbrandon.potter@amd.com{
52711392Sbrandon.potter@amd.com    ObjectFile *interp = getInterpreter();
52811389Sbrandon.potter@amd.com
52911389Sbrandon.potter@amd.com    return interp ? interp->bias() : objFile->bias();
53011389Sbrandon.potter@amd.com}
53111389Sbrandon.potter@amd.com
53211389Sbrandon.potter@amd.comAddr
53311851Sbrandon.potter@amd.comProcess::getStartPC()
53411389Sbrandon.potter@amd.com{
53511392Sbrandon.potter@amd.com    ObjectFile *interp = getInterpreter();
53611389Sbrandon.potter@amd.com
53711389Sbrandon.potter@amd.com    return interp ? interp->entryPoint() : objFile->entryPoint();
53811389Sbrandon.potter@amd.com}
53911389Sbrandon.potter@amd.com
54013883Sdavid.hashe@amd.comstd::string
54113883Sdavid.hashe@amd.comProcess::absolutePath(const std::string &filename, bool host_filesystem)
54213883Sdavid.hashe@amd.com{
54313883Sdavid.hashe@amd.com    if (filename.empty() || startswith(filename, "/"))
54413883Sdavid.hashe@amd.com        return filename;
54513883Sdavid.hashe@amd.com
54613883Sdavid.hashe@amd.com    // Verify that the current working directories are initialized properly.
54713883Sdavid.hashe@amd.com    // These members should be set initially via params from 'Process.py',
54813883Sdavid.hashe@amd.com    // although they may change over time depending on what the application
54913883Sdavid.hashe@amd.com    // does during simulation.
55013883Sdavid.hashe@amd.com    assert(!tgtCwd.empty());
55113883Sdavid.hashe@amd.com    assert(!hostCwd.empty());
55213883Sdavid.hashe@amd.com
55313883Sdavid.hashe@amd.com    // Construct the absolute path given the current working directory for
55413883Sdavid.hashe@amd.com    // either the host filesystem or target filesystem. The distinction only
55513883Sdavid.hashe@amd.com    // matters if filesystem redirection is utilized in the simulation.
55613883Sdavid.hashe@amd.com    auto path_base = host_filesystem ? hostCwd : tgtCwd;
55713883Sdavid.hashe@amd.com
55813883Sdavid.hashe@amd.com    // Add a trailing '/' if the current working directory did not have one.
55913883Sdavid.hashe@amd.com    normalize(path_base);
56013883Sdavid.hashe@amd.com
56113883Sdavid.hashe@amd.com    // Append the filename onto the current working path.
56213883Sdavid.hashe@amd.com    auto absolute_path = path_base + filename;
56313883Sdavid.hashe@amd.com
56413883Sdavid.hashe@amd.com    return absolute_path;
56513883Sdavid.hashe@amd.com}
56613883Sdavid.hashe@amd.com
56711851Sbrandon.potter@amd.comProcess *
56811851Sbrandon.potter@amd.comProcessParams::create()
5692715Sstever@eecs.umich.edu{
57011919SBrandon.Potter@amd.com    Process *process = nullptr;
5712715Sstever@eecs.umich.edu
57211140Sjthestness@gmail.com    // If not specified, set the executable parameter equal to the
57311140Sjthestness@gmail.com    // simulated system's zeroth command line parameter
57411851Sbrandon.potter@amd.com    if (executable == "") {
57511851Sbrandon.potter@amd.com        executable = cmd[0];
57611140Sjthestness@gmail.com    }
57711140Sjthestness@gmail.com
57811851Sbrandon.potter@amd.com    ObjectFile *obj_file = createObjectFile(executable);
57911919SBrandon.Potter@amd.com    if (obj_file == nullptr) {
58011851Sbrandon.potter@amd.com        fatal("Can't load object file %s", executable);
5812715Sstever@eecs.umich.edu    }
5822715Sstever@eecs.umich.edu
5835089Sgblack@eecs.umich.edu#if THE_ISA == ALPHA_ISA
58411851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Alpha)
5855753Ssteve.reinhardt@amd.com        fatal("Object file architecture does not match compiled ISA (Alpha).");
5865753Ssteve.reinhardt@amd.com
58711851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
5885753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
5895753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
5905753Ssteve.reinhardt@amd.com        // fall through
5912715Sstever@eecs.umich.edu      case ObjectFile::Linux:
59211851Sbrandon.potter@amd.com        process = new AlphaLinuxProcess(this, obj_file);
5932715Sstever@eecs.umich.edu        break;
5942715Sstever@eecs.umich.edu
5952715Sstever@eecs.umich.edu      default:
5962715Sstever@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
5972715Sstever@eecs.umich.edu    }
5982715Sstever@eecs.umich.edu#elif THE_ISA == SPARC_ISA
59911851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::SPARC64 &&
60011851Sbrandon.potter@amd.com        obj_file->getArch() != ObjectFile::SPARC32)
6012715Sstever@eecs.umich.edu        fatal("Object file architecture does not match compiled ISA (SPARC).");
60211851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6035753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
6045753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
6055753Ssteve.reinhardt@amd.com        // fall through
6062715Sstever@eecs.umich.edu      case ObjectFile::Linux:
60711851Sbrandon.potter@amd.com        if (obj_file->getArch() == ObjectFile::SPARC64) {
60811851Sbrandon.potter@amd.com            process = new Sparc64LinuxProcess(this, obj_file);
6094111Sgblack@eecs.umich.edu        } else {
61011851Sbrandon.potter@amd.com            process = new Sparc32LinuxProcess(this, obj_file);
6114111Sgblack@eecs.umich.edu        }
6122715Sstever@eecs.umich.edu        break;
6132715Sstever@eecs.umich.edu
6142715Sstever@eecs.umich.edu      case ObjectFile::Solaris:
61511851Sbrandon.potter@amd.com        process = new SparcSolarisProcess(this, obj_file);
6162715Sstever@eecs.umich.edu        break;
6175753Ssteve.reinhardt@amd.com
6182715Sstever@eecs.umich.edu      default:
6192715Sstever@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
6202715Sstever@eecs.umich.edu    }
6214157Sgblack@eecs.umich.edu#elif THE_ISA == X86_ISA
62211851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::X86_64 &&
62311851Sbrandon.potter@amd.com        obj_file->getArch() != ObjectFile::I386)
6244166Sgblack@eecs.umich.edu        fatal("Object file architecture does not match compiled ISA (x86).");
62511851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6265753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
6275753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
6285753Ssteve.reinhardt@amd.com        // fall through
6294166Sgblack@eecs.umich.edu      case ObjectFile::Linux:
63011851Sbrandon.potter@amd.com        if (obj_file->getArch() == ObjectFile::X86_64) {
63111851Sbrandon.potter@amd.com            process = new X86_64LinuxProcess(this, obj_file);
6325874Sgblack@eecs.umich.edu        } else {
63311851Sbrandon.potter@amd.com            process = new I386LinuxProcess(this, obj_file);
6345874Sgblack@eecs.umich.edu        }
6354166Sgblack@eecs.umich.edu        break;
6365753Ssteve.reinhardt@amd.com
6374157Sgblack@eecs.umich.edu      default:
6384157Sgblack@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
6394157Sgblack@eecs.umich.edu    }
6402715Sstever@eecs.umich.edu#elif THE_ISA == MIPS_ISA
64111851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Mips)
6422715Sstever@eecs.umich.edu        fatal("Object file architecture does not match compiled ISA (MIPS).");
64311851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6445753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
6455753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
6465753Ssteve.reinhardt@amd.com        // fall through
6472715Sstever@eecs.umich.edu      case ObjectFile::Linux:
64811851Sbrandon.potter@amd.com        process = new MipsLinuxProcess(this, obj_file);
6492715Sstever@eecs.umich.edu        break;
6502715Sstever@eecs.umich.edu
6512715Sstever@eecs.umich.edu      default:
6522715Sstever@eecs.umich.edu        fatal("Unknown/unsupported operating system.");
6532715Sstever@eecs.umich.edu    }
6545335Shines@cs.fsu.edu#elif THE_ISA == ARM_ISA
65511851Sbrandon.potter@amd.com    ObjectFile::Arch arch = obj_file->getArch();
65610037SARM gem5 Developers    if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
65710037SARM gem5 Developers        arch != ObjectFile::Arm64)
6585335Shines@cs.fsu.edu        fatal("Object file architecture does not match compiled ISA (ARM).");
65911851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6605753Ssteve.reinhardt@amd.com      case ObjectFile::UnknownOpSys:
6615753Ssteve.reinhardt@amd.com        warn("Unknown operating system; assuming Linux.");
6625753Ssteve.reinhardt@amd.com        // fall through
6635335Shines@cs.fsu.edu      case ObjectFile::Linux:
66410037SARM gem5 Developers        if (arch == ObjectFile::Arm64) {
66511851Sbrandon.potter@amd.com            process = new ArmLinuxProcess64(this, obj_file,
66611851Sbrandon.potter@amd.com                                            obj_file->getArch());
66710037SARM gem5 Developers        } else {
66811851Sbrandon.potter@amd.com            process = new ArmLinuxProcess32(this, obj_file,
66911851Sbrandon.potter@amd.com                                            obj_file->getArch());
67010037SARM gem5 Developers        }
6715335Shines@cs.fsu.edu        break;
67210810Sbr@bsdpad.com      case ObjectFile::FreeBSD:
67310810Sbr@bsdpad.com        if (arch == ObjectFile::Arm64) {
67411851Sbrandon.potter@amd.com            process = new ArmFreebsdProcess64(this, obj_file,
67511851Sbrandon.potter@amd.com                                              obj_file->getArch());
67610810Sbr@bsdpad.com        } else {
67711851Sbrandon.potter@amd.com            process = new ArmFreebsdProcess32(this, obj_file,
67811851Sbrandon.potter@amd.com                                              obj_file->getArch());
67910810Sbr@bsdpad.com        }
68010810Sbr@bsdpad.com        break;
6816392Ssaidi@eecs.umich.edu      case ObjectFile::LinuxArmOABI:
6826392Ssaidi@eecs.umich.edu        fatal("M5 does not support ARM OABI binaries. Please recompile with an"
6836392Ssaidi@eecs.umich.edu              " EABI compiler.");
6845335Shines@cs.fsu.edu      default:
6855335Shines@cs.fsu.edu        fatal("Unknown/unsupported operating system.");
6865335Shines@cs.fsu.edu    }
6876691Stjones1@inf.ed.ac.uk#elif THE_ISA == POWER_ISA
68811851Sbrandon.potter@amd.com    if (obj_file->getArch() != ObjectFile::Power)
6896691Stjones1@inf.ed.ac.uk        fatal("Object file architecture does not match compiled ISA (Power).");
69011851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
6916691Stjones1@inf.ed.ac.uk      case ObjectFile::UnknownOpSys:
6926691Stjones1@inf.ed.ac.uk        warn("Unknown operating system; assuming Linux.");
6936691Stjones1@inf.ed.ac.uk        // fall through
6946691Stjones1@inf.ed.ac.uk      case ObjectFile::Linux:
69511851Sbrandon.potter@amd.com        process = new PowerLinuxProcess(this, obj_file);
6966691Stjones1@inf.ed.ac.uk        break;
6976691Stjones1@inf.ed.ac.uk
6986691Stjones1@inf.ed.ac.uk      default:
6996691Stjones1@inf.ed.ac.uk        fatal("Unknown/unsupported operating system.");
7006691Stjones1@inf.ed.ac.uk    }
70111723Sar4jc@virginia.edu#elif THE_ISA == RISCV_ISA
70213634Saustinharris@utexas.edu    ObjectFile::Arch arch = obj_file->getArch();
70313634Saustinharris@utexas.edu    if (arch != ObjectFile::Riscv64 && arch != ObjectFile::Riscv32)
70411723Sar4jc@virginia.edu        fatal("Object file architecture does not match compiled ISA (RISCV).");
70511851Sbrandon.potter@amd.com    switch (obj_file->getOpSys()) {
70611723Sar4jc@virginia.edu      case ObjectFile::UnknownOpSys:
70711723Sar4jc@virginia.edu        warn("Unknown operating system; assuming Linux.");
70811723Sar4jc@virginia.edu        // fall through
70911723Sar4jc@virginia.edu      case ObjectFile::Linux:
71013634Saustinharris@utexas.edu        if (arch == ObjectFile::Riscv64) {
71113634Saustinharris@utexas.edu            process = new RiscvLinuxProcess64(this, obj_file);
71213634Saustinharris@utexas.edu        } else {
71313634Saustinharris@utexas.edu            process = new RiscvLinuxProcess32(this, obj_file);
71413634Saustinharris@utexas.edu        }
71511723Sar4jc@virginia.edu        break;
71611723Sar4jc@virginia.edu      default:
71711723Sar4jc@virginia.edu        fatal("Unknown/unsupported operating system.");
71811723Sar4jc@virginia.edu    }
7192715Sstever@eecs.umich.edu#else
7202715Sstever@eecs.umich.edu#error "THE_ISA not set"
7212715Sstever@eecs.umich.edu#endif
7222715Sstever@eecs.umich.edu
72311919SBrandon.Potter@amd.com    if (process == nullptr)
7242715Sstever@eecs.umich.edu        fatal("Unknown error creating process object.");
7252715Sstever@eecs.umich.edu    return process;
7262715Sstever@eecs.umich.edu}
727