process.hh revision 10929
12SN/A/* 210298Salexandru.dutu@amd.com * Copyright (c) 2014 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 312SN/A */ 322SN/A 33360SN/A#ifndef __PROCESS_HH__ 34360SN/A#define __PROCESS_HH__ 352SN/A 364117Sgblack@eecs.umich.edu#include <string> 37180SN/A#include <vector> 382SN/A 396329Sgblack@eecs.umich.edu#include "arch/registers.hh" 402378SN/A#include "base/statistics.hh" 416214Snate@binkert.org#include "base/types.hh" 426658Snate@binkert.org#include "config/the_isa.hh" 438852Sandreas.hansson@arm.com#include "mem/se_translating_port_proxy.hh" 4456SN/A#include "sim/sim_object.hh" 455958Sgblack@eecs.umich.edu#include "sim/syscallreturn.hh" 462SN/A 475154Sgblack@eecs.umich.educlass PageTable; 488737Skoansin.tan@gmail.comstruct ProcessParams; 498737Skoansin.tan@gmail.comstruct LiveProcessParams; 505154Sgblack@eecs.umich.educlass SyscallDesc; 515154Sgblack@eecs.umich.educlass System; 522680Sktlim@umich.educlass ThreadContext; 5310496Ssteve.reinhardt@amd.comclass EmulatedDriver; 542378SN/A 555758Shsul@eecs.umich.edutemplate<class IntType> 565771Shsul@eecs.umich.edustruct AuxVector 575758Shsul@eecs.umich.edu{ 585758Shsul@eecs.umich.edu IntType a_type; 595771Shsul@eecs.umich.edu IntType a_val; 605758Shsul@eecs.umich.edu 615771Shsul@eecs.umich.edu AuxVector() 625758Shsul@eecs.umich.edu {} 635758Shsul@eecs.umich.edu 645771Shsul@eecs.umich.edu AuxVector(IntType type, IntType val); 655758Shsul@eecs.umich.edu}; 665758Shsul@eecs.umich.edu 672SN/Aclass Process : public SimObject 682SN/A{ 692SN/A public: 702SN/A 712378SN/A /// Pointer to object representing the system this process is 722378SN/A /// running on. 732378SN/A System *system; 742378SN/A 752680Sktlim@umich.edu // thread contexts associated with this process 765713Shsul@eecs.umich.edu std::vector<int> contextIds; 77180SN/A 78180SN/A // number of CPUs (esxec contexts, really) assigned to this process. 795713Shsul@eecs.umich.edu unsigned int numCpus() { return contextIds.size(); } 802SN/A 812SN/A // record of blocked context 822SN/A struct WaitRec 832SN/A { 842SN/A Addr waitChan; 852680Sktlim@umich.edu ThreadContext *waitingContext; 862SN/A 872680Sktlim@umich.edu WaitRec(Addr chan, ThreadContext *ctx) 882SN/A : waitChan(chan), waitingContext(ctx) 895543Ssaidi@eecs.umich.edu { } 902SN/A }; 912SN/A 922SN/A // list of all blocked contexts 932SN/A std::list<WaitRec> waitList; 942SN/A 955543Ssaidi@eecs.umich.edu Addr brk_point; // top of the data segment 962SN/A 975543Ssaidi@eecs.umich.edu Addr stack_base; // stack segment base (highest address) 985543Ssaidi@eecs.umich.edu unsigned stack_size; // initial stack size 995543Ssaidi@eecs.umich.edu Addr stack_min; // lowest address accessed on the stack 1002SN/A 1015154Sgblack@eecs.umich.edu // The maximum size allowed for the stack. 1025154Sgblack@eecs.umich.edu Addr max_stack_size; 1035154Sgblack@eecs.umich.edu 1042SN/A // addr to use for next stack region (for multithreaded apps) 1052SN/A Addr next_thread_stack_base; 1062SN/A 107360SN/A // Base of region for mmaps (when user doesn't specify an address). 1081408SN/A Addr mmap_start; 1091408SN/A Addr mmap_end; 110360SN/A 1111514SN/A // Base of region for nxm data 1121514SN/A Addr nxm_start; 1131514SN/A Addr nxm_end; 1141514SN/A 1155999Snate@binkert.org Stats::Scalar num_syscalls; // number of syscalls executed 1162SN/A 1172SN/A protected: 1182SN/A // constructor 1198325Ssteve.reinhardt@amd.com Process(ProcessParams *params); 1202SN/A 1217532Ssteve.reinhardt@amd.com virtual void initState(); 1222SN/A 12310913Sandreas.sandberg@arm.com DrainState drain() M5_ATTR_OVERRIDE; 12410905Sandreas.sandberg@arm.com 1252378SN/A public: 1262SN/A 1274997Sgblack@eecs.umich.edu //This id is assigned by m5 and is used to keep process' tlb entries 1284997Sgblack@eecs.umich.edu //separated. 1294997Sgblack@eecs.umich.edu uint64_t M5_pid; 1304997Sgblack@eecs.umich.edu 13110299Salexandru.dutu@amd.com // flag for using architecture specific page table 13210299Salexandru.dutu@amd.com bool useArchPT; 13310554Salexandru.dutu@amd.com // running KvmCPU in SE mode requires special initialization 13410554Salexandru.dutu@amd.com bool kvmInSE; 13510554Salexandru.dutu@amd.com 13610298Salexandru.dutu@amd.com PageTableBase* pTable; 1378852Sandreas.hansson@arm.com 13810905Sandreas.sandberg@arm.com class FdMap : public Serializable 1395282Srstrong@cs.ucsd.edu { 1405282Srstrong@cs.ucsd.edu public: 1418325Ssteve.reinhardt@amd.com int fd; 1428325Ssteve.reinhardt@amd.com std::string filename; 1438325Ssteve.reinhardt@amd.com int mode; 1448325Ssteve.reinhardt@amd.com int flags; 1458325Ssteve.reinhardt@amd.com bool isPipe; 1468325Ssteve.reinhardt@amd.com int readPipeSource; 1478325Ssteve.reinhardt@amd.com uint64_t fileOffset; 14810496Ssteve.reinhardt@amd.com EmulatedDriver *driver; 1495282Srstrong@cs.ucsd.edu 1508325Ssteve.reinhardt@amd.com FdMap() 1518325Ssteve.reinhardt@amd.com : fd(-1), filename("NULL"), mode(0), flags(0), 15210496Ssteve.reinhardt@amd.com isPipe(false), readPipeSource(0), fileOffset(0), driver(NULL) 1538325Ssteve.reinhardt@amd.com { } 1545282Srstrong@cs.ucsd.edu 15510905Sandreas.sandberg@arm.com void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; 15610905Sandreas.sandberg@arm.com void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; 1575282Srstrong@cs.ucsd.edu }; 1585282Srstrong@cs.ucsd.edu 1598852Sandreas.hansson@arm.com protected: 1608852Sandreas.hansson@arm.com /// Memory proxy for initialization (image loading) 1618852Sandreas.hansson@arm.com SETranslatingPortProxy initVirtMem; 1628852Sandreas.hansson@arm.com 1632SN/A private: 16410929Sbrandon.potter@amd.com static const int NUM_FDS = 1024; 1655282Srstrong@cs.ucsd.edu 16610929Sbrandon.potter@amd.com // File descriptor remapping support. 16710929Sbrandon.potter@amd.com FdMap *fd_map; 1682SN/A 1692SN/A public: 1702SN/A // static helper functions to generate file descriptors for constructor 1712SN/A static int openInputFile(const std::string &filename); 1722SN/A static int openOutputFile(const std::string &filename); 1732SN/A 1742SN/A // override of virtual SimObject method: register statistics 1752SN/A virtual void regStats(); 1762SN/A 1775713Shsul@eecs.umich.edu // After getting registered with system object, tell process which 1785713Shsul@eecs.umich.edu // system-wide context id it is assigned. 1795713Shsul@eecs.umich.edu void assignThreadContext(int context_id) 1805713Shsul@eecs.umich.edu { 1815713Shsul@eecs.umich.edu contextIds.push_back(context_id); 1825713Shsul@eecs.umich.edu } 183180SN/A 1845713Shsul@eecs.umich.edu // Find a free context to use 1858325Ssteve.reinhardt@amd.com ThreadContext *findFreeContext(); 1862SN/A 1879144Ssteve.reinhardt@amd.com // provide program name for debug messages 1889144Ssteve.reinhardt@amd.com virtual const char *progName() const { return "<unknown>"; } 1899144Ssteve.reinhardt@amd.com 1902SN/A // generate new target fd for sim_fd 19110782Snilay@cs.wisc.edu int alloc_fd(int sim_fd, const std::string& filename, int flags, int mode, 1928325Ssteve.reinhardt@amd.com bool pipe); 1931970SN/A 19410929Sbrandon.potter@amd.com // disassociate target fd with simulator fd and cleanup subsidiary fields 19510929Sbrandon.potter@amd.com void free_fdmap_entry(int tgt_fd); 1962SN/A 1972SN/A // look up simulator fd for given target fd 1982SN/A int sim_fd(int tgt_fd); 1992SN/A 2005282Srstrong@cs.ucsd.edu // look up simulator fd_map object for a given target fd 2018325Ssteve.reinhardt@amd.com FdMap *sim_fd_obj(int tgt_fd); 2025282Srstrong@cs.ucsd.edu 20310929Sbrandon.potter@amd.com // look up target fd for given host fd 20410929Sbrandon.potter@amd.com // Assumes a 1:1 mapping between target file descriptor and host file 20510929Sbrandon.potter@amd.com // descriptor. Given the current API, this must be true given that it's 20610929Sbrandon.potter@amd.com // not possible to map multiple target file descriptors to the same host 20710929Sbrandon.potter@amd.com // file descriptor 20810929Sbrandon.potter@amd.com int tgt_fd(int sim_fd); 20910929Sbrandon.potter@amd.com 2105282Srstrong@cs.ucsd.edu // fix all offsets for currently open files and save them 2115282Srstrong@cs.ucsd.edu void fix_file_offsets(); 2125282Srstrong@cs.ucsd.edu 2135282Srstrong@cs.ucsd.edu // find all offsets for currently open files and save them 2145282Srstrong@cs.ucsd.edu void find_file_offsets(); 2155282Srstrong@cs.ucsd.edu 2165282Srstrong@cs.ucsd.edu // set the source of this read pipe for a checkpoint resume 2175282Srstrong@cs.ucsd.edu void setReadPipeSource(int read_pipe_fd, int source_fd); 2185282Srstrong@cs.ucsd.edu 2192680Sktlim@umich.edu virtual void syscall(int64_t callnum, ThreadContext *tc) = 0; 2203311Ssaidi@eecs.umich.edu 2218601Ssteve.reinhardt@amd.com void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 2228601Ssteve.reinhardt@amd.com 2238539Sgblack@eecs.umich.edu /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 2248539Sgblack@eecs.umich.edu /// @return Whether the fault has been fixed. 2258539Sgblack@eecs.umich.edu bool fixupStackFault(Addr vaddr); 2264434Ssaidi@eecs.umich.edu 2279110Ssteve.reinhardt@amd.com /** 22810558Salexandru.dutu@amd.com * Maps a contiguous range of virtual addresses in this process's 2299110Ssteve.reinhardt@amd.com * address space to a contiguous range of physical addresses. 23010558Salexandru.dutu@amd.com * This function exists primarily to expose the map operation to 23110558Salexandru.dutu@amd.com * python, so that configuration scripts can set up mappings in SE mode. 2329110Ssteve.reinhardt@amd.com * 2339110Ssteve.reinhardt@amd.com * @param vaddr The starting virtual address of the range. 2349110Ssteve.reinhardt@amd.com * @param paddr The starting physical address of the range. 2359110Ssteve.reinhardt@amd.com * @param size The length of the range in bytes. 23610558Salexandru.dutu@amd.com * @param cacheable Specifies whether accesses are cacheable. 2379110Ssteve.reinhardt@amd.com * @return True if the map operation was successful. (At this 2389110Ssteve.reinhardt@amd.com * point in time, the map operation always succeeds.) 2399110Ssteve.reinhardt@amd.com */ 24010558Salexandru.dutu@amd.com bool map(Addr vaddr, Addr paddr, int size, bool cacheable = true); 2419110Ssteve.reinhardt@amd.com 24210905Sandreas.sandberg@arm.com void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE; 24310905Sandreas.sandberg@arm.com void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE; 2442SN/A}; 2452SN/A 2462SN/A// 2472SN/A// "Live" process with system calls redirected to host system 2482SN/A// 249360SN/Aclass ObjectFile; 2502SN/Aclass LiveProcess : public Process 2512SN/A{ 252360SN/A protected: 2532378SN/A ObjectFile *objFile; 2542378SN/A std::vector<std::string> argv; 2552378SN/A std::vector<std::string> envp; 2563669Sbinkertn@umich.edu std::string cwd; 2572378SN/A 2588325Ssteve.reinhardt@amd.com LiveProcess(LiveProcessParams *params, ObjectFile *objFile); 2592SN/A 2603114Sgblack@eecs.umich.edu // Id of the owner of the process 2613114Sgblack@eecs.umich.edu uint64_t __uid; 2623114Sgblack@eecs.umich.edu uint64_t __euid; 2633114Sgblack@eecs.umich.edu uint64_t __gid; 2643114Sgblack@eecs.umich.edu uint64_t __egid; 2653114Sgblack@eecs.umich.edu 2663114Sgblack@eecs.umich.edu // pid of the process and it's parent 2673114Sgblack@eecs.umich.edu uint64_t __pid; 2683114Sgblack@eecs.umich.edu uint64_t __ppid; 2693114Sgblack@eecs.umich.edu 27010496Ssteve.reinhardt@amd.com // Emulated drivers available to this process 27110496Ssteve.reinhardt@amd.com std::vector<EmulatedDriver *> drivers; 27210496Ssteve.reinhardt@amd.com 273360SN/A public: 2743114Sgblack@eecs.umich.edu 2754793Sgblack@eecs.umich.edu enum AuxiliaryVectorType { 2764793Sgblack@eecs.umich.edu M5_AT_NULL = 0, 2774793Sgblack@eecs.umich.edu M5_AT_IGNORE = 1, 2784793Sgblack@eecs.umich.edu M5_AT_EXECFD = 2, 2794793Sgblack@eecs.umich.edu M5_AT_PHDR = 3, 2804793Sgblack@eecs.umich.edu M5_AT_PHENT = 4, 2814793Sgblack@eecs.umich.edu M5_AT_PHNUM = 5, 2824793Sgblack@eecs.umich.edu M5_AT_PAGESZ = 6, 2834793Sgblack@eecs.umich.edu M5_AT_BASE = 7, 2844793Sgblack@eecs.umich.edu M5_AT_FLAGS = 8, 2854793Sgblack@eecs.umich.edu M5_AT_ENTRY = 9, 2864793Sgblack@eecs.umich.edu M5_AT_NOTELF = 10, 2874793Sgblack@eecs.umich.edu M5_AT_UID = 11, 2884793Sgblack@eecs.umich.edu M5_AT_EUID = 12, 2894793Sgblack@eecs.umich.edu M5_AT_GID = 13, 2904793Sgblack@eecs.umich.edu M5_AT_EGID = 14, 2914793Sgblack@eecs.umich.edu // The following may be specific to Linux 2924793Sgblack@eecs.umich.edu M5_AT_PLATFORM = 15, 2934793Sgblack@eecs.umich.edu M5_AT_HWCAP = 16, 2944793Sgblack@eecs.umich.edu M5_AT_CLKTCK = 17, 2954793Sgblack@eecs.umich.edu 2964793Sgblack@eecs.umich.edu M5_AT_SECURE = 23, 2976399Sgblack@eecs.umich.edu M5_BASE_PLATFORM = 24, 2986399Sgblack@eecs.umich.edu M5_AT_RANDOM = 25, 2996399Sgblack@eecs.umich.edu 3006399Sgblack@eecs.umich.edu M5_AT_EXECFN = 31, 3014793Sgblack@eecs.umich.edu 3024793Sgblack@eecs.umich.edu M5_AT_VECTOR_SIZE = 44 3034793Sgblack@eecs.umich.edu }; 3044793Sgblack@eecs.umich.edu 3053114Sgblack@eecs.umich.edu inline uint64_t uid() {return __uid;} 3063114Sgblack@eecs.umich.edu inline uint64_t euid() {return __euid;} 3073114Sgblack@eecs.umich.edu inline uint64_t gid() {return __gid;} 3083114Sgblack@eecs.umich.edu inline uint64_t egid() {return __egid;} 3093114Sgblack@eecs.umich.edu inline uint64_t pid() {return __pid;} 3103114Sgblack@eecs.umich.edu inline uint64_t ppid() {return __ppid;} 3113114Sgblack@eecs.umich.edu 3129144Ssteve.reinhardt@amd.com // provide program name for debug messages 3139144Ssteve.reinhardt@amd.com virtual const char *progName() const { return argv[0].c_str(); } 3149144Ssteve.reinhardt@amd.com 3153669Sbinkertn@umich.edu std::string 3163669Sbinkertn@umich.edu fullPath(const std::string &filename) 3173669Sbinkertn@umich.edu { 3183669Sbinkertn@umich.edu if (filename[0] == '/' || cwd.empty()) 3193669Sbinkertn@umich.edu return filename; 3203669Sbinkertn@umich.edu 3213669Sbinkertn@umich.edu std::string full = cwd; 3223669Sbinkertn@umich.edu 3233669Sbinkertn@umich.edu if (cwd[cwd.size() - 1] != '/') 3243669Sbinkertn@umich.edu full += '/'; 3253669Sbinkertn@umich.edu 3263669Sbinkertn@umich.edu return full + filename; 3273669Sbinkertn@umich.edu } 3283669Sbinkertn@umich.edu 3295513SMichael.Adler@intel.com std::string getcwd() const { return cwd; } 3305513SMichael.Adler@intel.com 3312680Sktlim@umich.edu virtual void syscall(int64_t callnum, ThreadContext *tc); 3326701Sgblack@eecs.umich.edu 3336701Sgblack@eecs.umich.edu virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0; 3346701Sgblack@eecs.umich.edu virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width); 3355958Sgblack@eecs.umich.edu virtual void setSyscallArg(ThreadContext *tc, 3365958Sgblack@eecs.umich.edu int i, TheISA::IntReg val) = 0; 3375958Sgblack@eecs.umich.edu virtual void setSyscallReturn(ThreadContext *tc, 3385958Sgblack@eecs.umich.edu SyscallReturn return_value) = 0; 3392093SN/A 3408325Ssteve.reinhardt@amd.com virtual SyscallDesc *getDesc(int callnum) = 0; 3412715Sstever@eecs.umich.edu 34210496Ssteve.reinhardt@amd.com /** 34310496Ssteve.reinhardt@amd.com * Find an emulated device driver. 34410496Ssteve.reinhardt@amd.com * 34510496Ssteve.reinhardt@amd.com * @param filename Name of the device (under /dev) 34610496Ssteve.reinhardt@amd.com * @return Pointer to driver object if found, else NULL 34710496Ssteve.reinhardt@amd.com */ 34810496Ssteve.reinhardt@amd.com EmulatedDriver *findDriver(std::string filename); 34910496Ssteve.reinhardt@amd.com 3502715Sstever@eecs.umich.edu // this function is used to create the LiveProcess object, since 3512715Sstever@eecs.umich.edu // we can't tell which subclass of LiveProcess to use until we 3522715Sstever@eecs.umich.edu // open and look at the object file. 3538325Ssteve.reinhardt@amd.com static LiveProcess *create(LiveProcessParams *params); 3542SN/A}; 3552SN/A 356360SN/A 357360SN/A#endif // __PROCESS_HH__ 358