process.hh revision 11885
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 8311877Sbrandon.potter@amd.com void syscall(int64_t callnum, ThreadContext *tc, Fault *fault); 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; } 9811885Sbrandon.potter@amd.com inline uint64_t pgid() { return _pgid; } 9911885Sbrandon.potter@amd.com inline uint64_t tgid() { return _tgid; } 10011885Sbrandon.potter@amd.com inline void setpgid(uint64_t pgid) { _pgid = pgid; } 10110554Salexandru.dutu@amd.com 10211854Sbrandon.potter@amd.com const char *progName() const { return executable.c_str(); } 10311854Sbrandon.potter@amd.com std::string fullPath(const std::string &filename); 10411854Sbrandon.potter@amd.com std::string getcwd() const { return cwd; } 1058852Sandreas.hansson@arm.com 10611854Sbrandon.potter@amd.com /** 10711854Sbrandon.potter@amd.com * Find an emulated device driver. 10811854Sbrandon.potter@amd.com * 10911854Sbrandon.potter@amd.com * @param filename Name of the device (under /dev) 11011854Sbrandon.potter@amd.com * @return Pointer to driver object if found, else NULL 11111854Sbrandon.potter@amd.com */ 11211854Sbrandon.potter@amd.com EmulatedDriver *findDriver(std::string filename); 1138852Sandreas.hansson@arm.com 11411854Sbrandon.potter@amd.com // This function acts as a callback to update the bias value in 11511854Sbrandon.potter@amd.com // the object file because the parameters needed to calculate the 11611854Sbrandon.potter@amd.com // bias are not available when the object file is created. 11711854Sbrandon.potter@amd.com void updateBias(); 11811854Sbrandon.potter@amd.com Addr getBias(); 11911854Sbrandon.potter@amd.com Addr getStartPC(); 12011854Sbrandon.potter@amd.com ObjectFile *getInterpreter(); 1215282Srstrong@cs.ucsd.edu 1222SN/A // override of virtual SimObject method: register statistics 12311169Sandreas.hansson@arm.com void regStats() override; 1242SN/A 1258601Ssteve.reinhardt@amd.com void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 1268601Ssteve.reinhardt@amd.com 1278539Sgblack@eecs.umich.edu /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 1288539Sgblack@eecs.umich.edu /// @return Whether the fault has been fixed. 1298539Sgblack@eecs.umich.edu bool fixupStackFault(Addr vaddr); 1304434Ssaidi@eecs.umich.edu 13111854Sbrandon.potter@amd.com // After getting registered with system object, tell process which 13211854Sbrandon.potter@amd.com // system-wide context id it is assigned. 13311854Sbrandon.potter@amd.com void 13411854Sbrandon.potter@amd.com assignThreadContext(ContextID context_id) 13511854Sbrandon.potter@amd.com { 13611854Sbrandon.potter@amd.com contextIds.push_back(context_id); 13711854Sbrandon.potter@amd.com } 13811854Sbrandon.potter@amd.com 13911854Sbrandon.potter@amd.com // Find a free context to use 14011854Sbrandon.potter@amd.com ThreadContext *findFreeContext(); 14111854Sbrandon.potter@amd.com 14211854Sbrandon.potter@amd.com /** 14311854Sbrandon.potter@amd.com * Does mmap region grow upward or downward from mmap_end? Most 14411854Sbrandon.potter@amd.com * platforms grow downward, but a few (such as Alpha) grow upward 14511854Sbrandon.potter@amd.com * instead, so they can override this method to return false. 14611854Sbrandon.potter@amd.com */ 14711854Sbrandon.potter@amd.com virtual bool mmapGrowsDown() const { return true; } 14811854Sbrandon.potter@amd.com 1499110Ssteve.reinhardt@amd.com /** 15010558Salexandru.dutu@amd.com * Maps a contiguous range of virtual addresses in this process's 1519110Ssteve.reinhardt@amd.com * address space to a contiguous range of physical addresses. 15210558Salexandru.dutu@amd.com * This function exists primarily to expose the map operation to 15310558Salexandru.dutu@amd.com * python, so that configuration scripts can set up mappings in SE mode. 1549110Ssteve.reinhardt@amd.com * 1559110Ssteve.reinhardt@amd.com * @param vaddr The starting virtual address of the range. 1569110Ssteve.reinhardt@amd.com * @param paddr The starting physical address of the range. 1579110Ssteve.reinhardt@amd.com * @param size The length of the range in bytes. 15810558Salexandru.dutu@amd.com * @param cacheable Specifies whether accesses are cacheable. 1599110Ssteve.reinhardt@amd.com * @return True if the map operation was successful. (At this 1609110Ssteve.reinhardt@amd.com * point in time, the map operation always succeeds.) 1619110Ssteve.reinhardt@amd.com */ 16210558Salexandru.dutu@amd.com bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 1639110Ssteve.reinhardt@amd.com 16411854Sbrandon.potter@amd.com // list of all blocked contexts 16511854Sbrandon.potter@amd.com std::list<WaitRec> waitList; 16611801Sbrandon.potter@amd.com 16711854Sbrandon.potter@amd.com // thread contexts associated with this process 16811854Sbrandon.potter@amd.com std::vector<ContextID> contextIds; 16911854Sbrandon.potter@amd.com 17011854Sbrandon.potter@amd.com // system object which owns this process 17111854Sbrandon.potter@amd.com System *system; 17211854Sbrandon.potter@amd.com 17311854Sbrandon.potter@amd.com Addr brk_point; // top of the data segment 17411854Sbrandon.potter@amd.com Addr stack_base; // stack segment base 17511854Sbrandon.potter@amd.com unsigned stack_size; // initial stack size 17611854Sbrandon.potter@amd.com Addr stack_min; // furthest address accessed from stack base 17711854Sbrandon.potter@amd.com Addr max_stack_size; // the maximum size allowed for the stack 17811854Sbrandon.potter@amd.com Addr next_thread_stack_base; // addr for next region w/ multithreaded apps 17911854Sbrandon.potter@amd.com Addr mmap_end; // base of automatic mmap region allocs 18011854Sbrandon.potter@amd.com 18111854Sbrandon.potter@amd.com Stats::Scalar num_syscalls; // track how many system calls are executed 18211854Sbrandon.potter@amd.com 18311854Sbrandon.potter@amd.com bool useArchPT; // flag for using architecture specific page table 18411854Sbrandon.potter@amd.com bool kvmInSE; // running KVM requires special initialization 18511854Sbrandon.potter@amd.com 18611854Sbrandon.potter@amd.com PageTableBase* pTable; 18711854Sbrandon.potter@amd.com 18811854Sbrandon.potter@amd.com SETranslatingPortProxy initVirtMem; // memory proxy for initial image load 18911854Sbrandon.potter@amd.com 19011851Sbrandon.potter@amd.com ObjectFile *objFile; 19111851Sbrandon.potter@amd.com std::vector<std::string> argv; 19211851Sbrandon.potter@amd.com std::vector<std::string> envp; 19311851Sbrandon.potter@amd.com std::string cwd; 19411851Sbrandon.potter@amd.com std::string executable; 19511851Sbrandon.potter@amd.com 19611801Sbrandon.potter@amd.com // Id of the owner of the process 19711801Sbrandon.potter@amd.com uint64_t _uid; 19811801Sbrandon.potter@amd.com uint64_t _euid; 19911801Sbrandon.potter@amd.com uint64_t _gid; 20011801Sbrandon.potter@amd.com uint64_t _egid; 20111801Sbrandon.potter@amd.com 20211801Sbrandon.potter@amd.com // pid of the process and it's parent 20311801Sbrandon.potter@amd.com uint64_t _pid; 20411801Sbrandon.potter@amd.com uint64_t _ppid; 20511885Sbrandon.potter@amd.com uint64_t _pgid; 20611885Sbrandon.potter@amd.com uint64_t _tgid; 20711801Sbrandon.potter@amd.com 20810496Ssteve.reinhardt@amd.com // Emulated drivers available to this process 20910496Ssteve.reinhardt@amd.com std::vector<EmulatedDriver *> drivers; 21011856Sbrandon.potter@amd.com 21111856Sbrandon.potter@amd.com std::shared_ptr<FDArray> fds; 2122SN/A}; 2132SN/A 214360SN/A#endif // __PROCESS_HH__ 215