process.hh revision 11856
12SN/A/*
211856Sbrandon.potter@amd.com * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
31762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
42SN/A * All rights reserved.
52SN/A *
62SN/A * Redistribution and use in source and binary forms, with or without
72SN/A * modification, are permitted provided that the following conditions are
82SN/A * met: redistributions of source code must retain the above copyright
92SN/A * notice, this list of conditions and the following disclaimer;
102SN/A * redistributions in binary form must reproduce the above copyright
112SN/A * notice, this list of conditions and the following disclaimer in the
122SN/A * documentation and/or other materials provided with the distribution;
132SN/A * neither the name of the copyright holders nor the names of its
142SN/A * contributors may be used to endorse or promote products derived from
152SN/A * this software without specific prior written permission.
162SN/A *
172SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu *
292665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
302665Ssaidi@eecs.umich.edu *          Steve Reinhardt
3111856Sbrandon.potter@amd.com *          Brandon Potter
322SN/A */
332SN/A
34360SN/A#ifndef __PROCESS_HH__
35360SN/A#define __PROCESS_HH__
362SN/A
3711854Sbrandon.potter@amd.com#include <inttypes.h>
3811854Sbrandon.potter@amd.com
3911800Sbrandon.potter@amd.com#include <map>
404117Sgblack@eecs.umich.edu#include <string>
41180SN/A#include <vector>
422SN/A
436329Sgblack@eecs.umich.edu#include "arch/registers.hh"
442378SN/A#include "base/statistics.hh"
456214Snate@binkert.org#include "base/types.hh"
466658Snate@binkert.org#include "config/the_isa.hh"
478852Sandreas.hansson@arm.com#include "mem/se_translating_port_proxy.hh"
4811856Sbrandon.potter@amd.com#include "sim/fd_array.hh"
4910930Sbrandon.potter@amd.com#include "sim/fd_entry.hh"
5056SN/A#include "sim/sim_object.hh"
512SN/A
528737Skoansin.tan@gmail.comstruct ProcessParams;
5311800Sbrandon.potter@amd.com
5411800Sbrandon.potter@amd.comclass EmulatedDriver;
5511851Sbrandon.potter@amd.comclass ObjectFile;
5611800Sbrandon.potter@amd.comclass PageTableBase;
575154Sgblack@eecs.umich.educlass SyscallDesc;
5811800Sbrandon.potter@amd.comclass SyscallReturn;
595154Sgblack@eecs.umich.educlass System;
602680Sktlim@umich.educlass ThreadContext;
612378SN/A
622SN/Aclass Process : public SimObject
632SN/A{
642SN/A  public:
652SN/A    struct WaitRec
662SN/A    {
672SN/A        Addr waitChan;
682680Sktlim@umich.edu        ThreadContext *waitingContext;
692SN/A
702680Sktlim@umich.edu        WaitRec(Addr chan, ThreadContext *ctx)
712SN/A            : waitChan(chan), waitingContext(ctx)
7211854Sbrandon.potter@amd.com        { }
732SN/A    };
742SN/A
7511854Sbrandon.potter@amd.com    Process(ProcessParams *params, ObjectFile *obj_file);
762SN/A
7711854Sbrandon.potter@amd.com    void serialize(CheckpointOut &cp) const override;
7811854Sbrandon.potter@amd.com    void unserialize(CheckpointIn &cp) override;
792SN/A
8011169Sandreas.hansson@arm.com    void initState() override;
8111168Sandreas.hansson@arm.com    DrainState drain() override;
8210905Sandreas.sandberg@arm.com
8311854Sbrandon.potter@amd.com    void syscall(int64_t callnum, ThreadContext *tc);
8411854Sbrandon.potter@amd.com    virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0;
8511854Sbrandon.potter@amd.com    virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width);
8611854Sbrandon.potter@amd.com    virtual void setSyscallArg(ThreadContext *tc, int i,
8711854Sbrandon.potter@amd.com                               TheISA::IntReg val) = 0;
8811854Sbrandon.potter@amd.com    virtual void setSyscallReturn(ThreadContext *tc,
8911854Sbrandon.potter@amd.com                                  SyscallReturn return_value) = 0;
9011854Sbrandon.potter@amd.com    virtual SyscallDesc *getDesc(int callnum) = 0;
912SN/A
9211854Sbrandon.potter@amd.com    inline uint64_t uid() { return _uid; }
9311854Sbrandon.potter@amd.com    inline uint64_t euid() { return _euid; }
9411854Sbrandon.potter@amd.com    inline uint64_t gid() { return _gid; }
9511854Sbrandon.potter@amd.com    inline uint64_t egid() { return _egid; }
9611854Sbrandon.potter@amd.com    inline uint64_t pid() { return _pid; }
9711854Sbrandon.potter@amd.com    inline uint64_t ppid() { return _ppid; }
9810554Salexandru.dutu@amd.com
9911854Sbrandon.potter@amd.com    const char *progName() const { return executable.c_str(); }
10011854Sbrandon.potter@amd.com    std::string fullPath(const std::string &filename);
10111854Sbrandon.potter@amd.com    std::string getcwd() const { return cwd; }
1028852Sandreas.hansson@arm.com
10311854Sbrandon.potter@amd.com    /**
10411854Sbrandon.potter@amd.com     * Find an emulated device driver.
10511854Sbrandon.potter@amd.com     *
10611854Sbrandon.potter@amd.com     * @param filename Name of the device (under /dev)
10711854Sbrandon.potter@amd.com     * @return Pointer to driver object if found, else NULL
10811854Sbrandon.potter@amd.com     */
10911854Sbrandon.potter@amd.com    EmulatedDriver *findDriver(std::string filename);
1108852Sandreas.hansson@arm.com
11111854Sbrandon.potter@amd.com    // This function acts as a callback to update the bias value in
11211854Sbrandon.potter@amd.com    // the object file because the parameters needed to calculate the
11311854Sbrandon.potter@amd.com    // bias are not available when the object file is created.
11411854Sbrandon.potter@amd.com    void updateBias();
11511854Sbrandon.potter@amd.com    Addr getBias();
11611854Sbrandon.potter@amd.com    Addr getStartPC();
11711854Sbrandon.potter@amd.com    ObjectFile *getInterpreter();
1185282Srstrong@cs.ucsd.edu
1192SN/A    // override of virtual SimObject method: register statistics
12011169Sandreas.hansson@arm.com    void regStats() override;
1212SN/A
1228601Ssteve.reinhardt@amd.com    void allocateMem(Addr vaddr, int64_t size, bool clobber = false);
1238601Ssteve.reinhardt@amd.com
1248539Sgblack@eecs.umich.edu    /// Attempt to fix up a fault at vaddr by allocating a page on the stack.
1258539Sgblack@eecs.umich.edu    /// @return Whether the fault has been fixed.
1268539Sgblack@eecs.umich.edu    bool fixupStackFault(Addr vaddr);
1274434Ssaidi@eecs.umich.edu
12811854Sbrandon.potter@amd.com    // After getting registered with system object, tell process which
12911854Sbrandon.potter@amd.com    // system-wide context id it is assigned.
13011854Sbrandon.potter@amd.com    void
13111854Sbrandon.potter@amd.com    assignThreadContext(ContextID context_id)
13211854Sbrandon.potter@amd.com    {
13311854Sbrandon.potter@amd.com        contextIds.push_back(context_id);
13411854Sbrandon.potter@amd.com    }
13511854Sbrandon.potter@amd.com
13611854Sbrandon.potter@amd.com    // Find a free context to use
13711854Sbrandon.potter@amd.com    ThreadContext *findFreeContext();
13811854Sbrandon.potter@amd.com
13911854Sbrandon.potter@amd.com    /**
14011854Sbrandon.potter@amd.com     * Does mmap region grow upward or downward from mmap_end?  Most
14111854Sbrandon.potter@amd.com     * platforms grow downward, but a few (such as Alpha) grow upward
14211854Sbrandon.potter@amd.com     * instead, so they can override this method to return false.
14311854Sbrandon.potter@amd.com     */
14411854Sbrandon.potter@amd.com    virtual bool mmapGrowsDown() const { return true; }
14511854Sbrandon.potter@amd.com
1469110Ssteve.reinhardt@amd.com    /**
14710558Salexandru.dutu@amd.com     * Maps a contiguous range of virtual addresses in this process's
1489110Ssteve.reinhardt@amd.com     * address space to a contiguous range of physical addresses.
14910558Salexandru.dutu@amd.com     * This function exists primarily to expose the map operation to
15010558Salexandru.dutu@amd.com     * python, so that configuration scripts can set up mappings in SE mode.
1519110Ssteve.reinhardt@amd.com     *
1529110Ssteve.reinhardt@amd.com     * @param vaddr The starting virtual address of the range.
1539110Ssteve.reinhardt@amd.com     * @param paddr The starting physical address of the range.
1549110Ssteve.reinhardt@amd.com     * @param size The length of the range in bytes.
15510558Salexandru.dutu@amd.com     * @param cacheable Specifies whether accesses are cacheable.
1569110Ssteve.reinhardt@amd.com     * @return True if the map operation was successful.  (At this
1579110Ssteve.reinhardt@amd.com     *           point in time, the map operation always succeeds.)
1589110Ssteve.reinhardt@amd.com     */
15910558Salexandru.dutu@amd.com    bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true);
1609110Ssteve.reinhardt@amd.com
16111854Sbrandon.potter@amd.com    // list of all blocked contexts
16211854Sbrandon.potter@amd.com    std::list<WaitRec> waitList;
16311801Sbrandon.potter@amd.com
16411854Sbrandon.potter@amd.com    // thread contexts associated with this process
16511854Sbrandon.potter@amd.com    std::vector<ContextID> contextIds;
16611854Sbrandon.potter@amd.com
16711854Sbrandon.potter@amd.com    // system object which owns this process
16811854Sbrandon.potter@amd.com    System *system;
16911854Sbrandon.potter@amd.com
17011854Sbrandon.potter@amd.com    Addr brk_point;              // top of the data segment
17111854Sbrandon.potter@amd.com    Addr stack_base;             // stack segment base
17211854Sbrandon.potter@amd.com    unsigned stack_size;         // initial stack size
17311854Sbrandon.potter@amd.com    Addr stack_min;              // furthest address accessed from stack base
17411854Sbrandon.potter@amd.com    Addr max_stack_size;         // the maximum size allowed for the stack
17511854Sbrandon.potter@amd.com    Addr next_thread_stack_base; // addr for next region w/ multithreaded apps
17611854Sbrandon.potter@amd.com    Addr mmap_end;               // base of automatic mmap region allocs
17711854Sbrandon.potter@amd.com
17811854Sbrandon.potter@amd.com    Stats::Scalar num_syscalls;  // track how many system calls are executed
17911854Sbrandon.potter@amd.com
18011854Sbrandon.potter@amd.com    bool useArchPT; // flag for using architecture specific page table
18111854Sbrandon.potter@amd.com    bool kvmInSE;   // running KVM requires special initialization
18211854Sbrandon.potter@amd.com
18311854Sbrandon.potter@amd.com    PageTableBase* pTable;
18411854Sbrandon.potter@amd.com
18511854Sbrandon.potter@amd.com    SETranslatingPortProxy initVirtMem; // memory proxy for initial image load
18611854Sbrandon.potter@amd.com
18711851Sbrandon.potter@amd.com    ObjectFile *objFile;
18811851Sbrandon.potter@amd.com    std::vector<std::string> argv;
18911851Sbrandon.potter@amd.com    std::vector<std::string> envp;
19011851Sbrandon.potter@amd.com    std::string cwd;
19111851Sbrandon.potter@amd.com    std::string executable;
19211851Sbrandon.potter@amd.com
19311801Sbrandon.potter@amd.com    // Id of the owner of the process
19411801Sbrandon.potter@amd.com    uint64_t _uid;
19511801Sbrandon.potter@amd.com    uint64_t _euid;
19611801Sbrandon.potter@amd.com    uint64_t _gid;
19711801Sbrandon.potter@amd.com    uint64_t _egid;
19811801Sbrandon.potter@amd.com
19911801Sbrandon.potter@amd.com    // pid of the process and it's parent
20011801Sbrandon.potter@amd.com    uint64_t _pid;
20111801Sbrandon.potter@amd.com    uint64_t _ppid;
20211801Sbrandon.potter@amd.com
20310496Ssteve.reinhardt@amd.com    // Emulated drivers available to this process
20410496Ssteve.reinhardt@amd.com    std::vector<EmulatedDriver *> drivers;
20511856Sbrandon.potter@amd.com
20611856Sbrandon.potter@amd.com    std::shared_ptr<FDArray> fds;
2072SN/A};
2082SN/A
209360SN/A#endif // __PROCESS_HH__
210