process.hh revision 9552
12SN/A/* 21762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu * Steve Reinhardt 302SN/A */ 312SN/A 32360SN/A#ifndef __PROCESS_HH__ 33360SN/A#define __PROCESS_HH__ 342SN/A 354117Sgblack@eecs.umich.edu#include <string> 36180SN/A#include <vector> 372SN/A 386329Sgblack@eecs.umich.edu#include "arch/registers.hh" 392378SN/A#include "base/statistics.hh" 406214Snate@binkert.org#include "base/types.hh" 416658Snate@binkert.org#include "config/the_isa.hh" 428852Sandreas.hansson@arm.com#include "mem/se_translating_port_proxy.hh" 4356SN/A#include "sim/sim_object.hh" 445958Sgblack@eecs.umich.edu#include "sim/syscallreturn.hh" 452SN/A 465154Sgblack@eecs.umich.educlass PageTable; 478737Skoansin.tan@gmail.comstruct ProcessParams; 488737Skoansin.tan@gmail.comstruct LiveProcessParams; 495154Sgblack@eecs.umich.educlass SyscallDesc; 505154Sgblack@eecs.umich.educlass System; 512680Sktlim@umich.educlass ThreadContext; 522378SN/A 535758Shsul@eecs.umich.edutemplate<class IntType> 545771Shsul@eecs.umich.edustruct AuxVector 555758Shsul@eecs.umich.edu{ 565758Shsul@eecs.umich.edu IntType a_type; 575771Shsul@eecs.umich.edu IntType a_val; 585758Shsul@eecs.umich.edu 595771Shsul@eecs.umich.edu AuxVector() 605758Shsul@eecs.umich.edu {} 615758Shsul@eecs.umich.edu 625771Shsul@eecs.umich.edu AuxVector(IntType type, IntType val); 635758Shsul@eecs.umich.edu}; 645758Shsul@eecs.umich.edu 652SN/Aclass Process : public SimObject 662SN/A{ 672SN/A public: 682SN/A 692378SN/A /// Pointer to object representing the system this process is 702378SN/A /// running on. 712378SN/A System *system; 722378SN/A 732680Sktlim@umich.edu // thread contexts associated with this process 745713Shsul@eecs.umich.edu std::vector<int> contextIds; 75180SN/A 76180SN/A // number of CPUs (esxec contexts, really) assigned to this process. 775713Shsul@eecs.umich.edu unsigned int numCpus() { return contextIds.size(); } 782SN/A 792SN/A // record of blocked context 802SN/A struct WaitRec 812SN/A { 822SN/A Addr waitChan; 832680Sktlim@umich.edu ThreadContext *waitingContext; 842SN/A 852680Sktlim@umich.edu WaitRec(Addr chan, ThreadContext *ctx) 862SN/A : waitChan(chan), waitingContext(ctx) 875543Ssaidi@eecs.umich.edu { } 882SN/A }; 892SN/A 902SN/A // list of all blocked contexts 912SN/A std::list<WaitRec> waitList; 922SN/A 935543Ssaidi@eecs.umich.edu Addr brk_point; // top of the data segment 942SN/A 955543Ssaidi@eecs.umich.edu Addr stack_base; // stack segment base (highest address) 965543Ssaidi@eecs.umich.edu unsigned stack_size; // initial stack size 975543Ssaidi@eecs.umich.edu Addr stack_min; // lowest address accessed on the stack 982SN/A 995154Sgblack@eecs.umich.edu // The maximum size allowed for the stack. 1005154Sgblack@eecs.umich.edu Addr max_stack_size; 1015154Sgblack@eecs.umich.edu 1022SN/A // addr to use for next stack region (for multithreaded apps) 1032SN/A Addr next_thread_stack_base; 1042SN/A 105360SN/A // Base of region for mmaps (when user doesn't specify an address). 1061408SN/A Addr mmap_start; 1071408SN/A Addr mmap_end; 108360SN/A 1091514SN/A // Base of region for nxm data 1101514SN/A Addr nxm_start; 1111514SN/A Addr nxm_end; 1121514SN/A 1135999Snate@binkert.org Stats::Scalar num_syscalls; // number of syscalls executed 1142SN/A 1152SN/A protected: 1162SN/A // constructor 1178325Ssteve.reinhardt@amd.com Process(ProcessParams *params); 1182SN/A 1197532Ssteve.reinhardt@amd.com virtual void initState(); 1202SN/A 1212378SN/A public: 1222SN/A 1234997Sgblack@eecs.umich.edu //This id is assigned by m5 and is used to keep process' tlb entries 1244997Sgblack@eecs.umich.edu //separated. 1254997Sgblack@eecs.umich.edu uint64_t M5_pid; 1264997Sgblack@eecs.umich.edu 1278852Sandreas.hansson@arm.com PageTable* pTable; 1288852Sandreas.hansson@arm.com 1295282Srstrong@cs.ucsd.edu class FdMap 1305282Srstrong@cs.ucsd.edu { 1315282Srstrong@cs.ucsd.edu public: 1328325Ssteve.reinhardt@amd.com int fd; 1338325Ssteve.reinhardt@amd.com std::string filename; 1348325Ssteve.reinhardt@amd.com int mode; 1358325Ssteve.reinhardt@amd.com int flags; 1368325Ssteve.reinhardt@amd.com bool isPipe; 1378325Ssteve.reinhardt@amd.com int readPipeSource; 1388325Ssteve.reinhardt@amd.com uint64_t fileOffset; 1395282Srstrong@cs.ucsd.edu 1408325Ssteve.reinhardt@amd.com FdMap() 1418325Ssteve.reinhardt@amd.com : fd(-1), filename("NULL"), mode(0), flags(0), 1428325Ssteve.reinhardt@amd.com isPipe(false), readPipeSource(0), fileOffset(0) 1438325Ssteve.reinhardt@amd.com { } 1445282Srstrong@cs.ucsd.edu 1455282Srstrong@cs.ucsd.edu void serialize(std::ostream &os); 1465282Srstrong@cs.ucsd.edu void unserialize(Checkpoint *cp, const std::string §ion); 1475282Srstrong@cs.ucsd.edu }; 1485282Srstrong@cs.ucsd.edu 1498852Sandreas.hansson@arm.com protected: 1508852Sandreas.hansson@arm.com /// Memory proxy for initialization (image loading) 1518852Sandreas.hansson@arm.com SETranslatingPortProxy initVirtMem; 1528852Sandreas.hansson@arm.com 1532SN/A private: 1542SN/A // file descriptor remapping support 1555282Srstrong@cs.ucsd.edu static const int MAX_FD = 256; // max legal fd value 1565282Srstrong@cs.ucsd.edu FdMap fd_map[MAX_FD+1]; 1575282Srstrong@cs.ucsd.edu 1582SN/A 1592SN/A public: 1602SN/A // static helper functions to generate file descriptors for constructor 1612SN/A static int openInputFile(const std::string &filename); 1622SN/A static int openOutputFile(const std::string &filename); 1632SN/A 1642SN/A // override of virtual SimObject method: register statistics 1652SN/A virtual void regStats(); 1662SN/A 1675713Shsul@eecs.umich.edu // After getting registered with system object, tell process which 1685713Shsul@eecs.umich.edu // system-wide context id it is assigned. 1695713Shsul@eecs.umich.edu void assignThreadContext(int context_id) 1705713Shsul@eecs.umich.edu { 1715713Shsul@eecs.umich.edu contextIds.push_back(context_id); 1725713Shsul@eecs.umich.edu } 173180SN/A 1745713Shsul@eecs.umich.edu // Find a free context to use 1758325Ssteve.reinhardt@amd.com ThreadContext *findFreeContext(); 1762SN/A 1779144Ssteve.reinhardt@amd.com // provide program name for debug messages 1789144Ssteve.reinhardt@amd.com virtual const char *progName() const { return "<unknown>"; } 1799144Ssteve.reinhardt@amd.com 1802SN/A // map simulator fd sim_fd to target fd tgt_fd 1812SN/A void dup_fd(int sim_fd, int tgt_fd); 1822SN/A 1832SN/A // generate new target fd for sim_fd 1848325Ssteve.reinhardt@amd.com int alloc_fd(int sim_fd, std::string filename, int flags, int mode, 1858325Ssteve.reinhardt@amd.com bool pipe); 1861970SN/A 1871970SN/A // free target fd (e.g., after close) 1881970SN/A void free_fd(int tgt_fd); 1892SN/A 1902SN/A // look up simulator fd for given target fd 1912SN/A int sim_fd(int tgt_fd); 1922SN/A 1935282Srstrong@cs.ucsd.edu // look up simulator fd_map object for a given target fd 1948325Ssteve.reinhardt@amd.com FdMap *sim_fd_obj(int tgt_fd); 1955282Srstrong@cs.ucsd.edu 1965282Srstrong@cs.ucsd.edu // fix all offsets for currently open files and save them 1975282Srstrong@cs.ucsd.edu void fix_file_offsets(); 1985282Srstrong@cs.ucsd.edu 1995282Srstrong@cs.ucsd.edu // find all offsets for currently open files and save them 2005282Srstrong@cs.ucsd.edu void find_file_offsets(); 2015282Srstrong@cs.ucsd.edu 2025282Srstrong@cs.ucsd.edu // set the source of this read pipe for a checkpoint resume 2035282Srstrong@cs.ucsd.edu void setReadPipeSource(int read_pipe_fd, int source_fd); 2045282Srstrong@cs.ucsd.edu 2052680Sktlim@umich.edu virtual void syscall(int64_t callnum, ThreadContext *tc) = 0; 2063311Ssaidi@eecs.umich.edu 2078601Ssteve.reinhardt@amd.com void allocateMem(Addr vaddr, int64_t size, bool clobber = false); 2088601Ssteve.reinhardt@amd.com 2098539Sgblack@eecs.umich.edu /// Attempt to fix up a fault at vaddr by allocating a page on the stack. 2108539Sgblack@eecs.umich.edu /// @return Whether the fault has been fixed. 2118539Sgblack@eecs.umich.edu bool fixupStackFault(Addr vaddr); 2124434Ssaidi@eecs.umich.edu 2139110Ssteve.reinhardt@amd.com /** 2149110Ssteve.reinhardt@amd.com * Map a contiguous range of virtual addresses in this process's 2159110Ssteve.reinhardt@amd.com * address space to a contiguous range of physical addresses. 2169110Ssteve.reinhardt@amd.com * This function exists primarily to enable exposing the map 2179110Ssteve.reinhardt@amd.com * operation to python, so that configuration scripts can set up 2189110Ssteve.reinhardt@amd.com * mappings in SE mode. 2199110Ssteve.reinhardt@amd.com * 2209110Ssteve.reinhardt@amd.com * @param vaddr The starting virtual address of the range. 2219110Ssteve.reinhardt@amd.com * @param paddr The starting physical address of the range. 2229110Ssteve.reinhardt@amd.com * @param size The length of the range in bytes. 2239110Ssteve.reinhardt@amd.com * @return True if the map operation was successful. (At this 2249110Ssteve.reinhardt@amd.com * point in time, the map operation always succeeds.) 2259110Ssteve.reinhardt@amd.com */ 2269110Ssteve.reinhardt@amd.com bool map(Addr vaddr, Addr paddr, int size); 2279110Ssteve.reinhardt@amd.com 2283311Ssaidi@eecs.umich.edu void serialize(std::ostream &os); 2293311Ssaidi@eecs.umich.edu void unserialize(Checkpoint *cp, const std::string §ion); 2302SN/A}; 2312SN/A 2322SN/A// 2332SN/A// "Live" process with system calls redirected to host system 2342SN/A// 235360SN/Aclass ObjectFile; 2362SN/Aclass LiveProcess : public Process 2372SN/A{ 238360SN/A protected: 2392378SN/A ObjectFile *objFile; 2402378SN/A std::vector<std::string> argv; 2412378SN/A std::vector<std::string> envp; 2423669Sbinkertn@umich.edu std::string cwd; 2432378SN/A 2448325Ssteve.reinhardt@amd.com LiveProcess(LiveProcessParams *params, ObjectFile *objFile); 2452SN/A 2463114Sgblack@eecs.umich.edu // Id of the owner of the process 2473114Sgblack@eecs.umich.edu uint64_t __uid; 2483114Sgblack@eecs.umich.edu uint64_t __euid; 2493114Sgblack@eecs.umich.edu uint64_t __gid; 2503114Sgblack@eecs.umich.edu uint64_t __egid; 2513114Sgblack@eecs.umich.edu 2523114Sgblack@eecs.umich.edu // pid of the process and it's parent 2533114Sgblack@eecs.umich.edu uint64_t __pid; 2543114Sgblack@eecs.umich.edu uint64_t __ppid; 2553114Sgblack@eecs.umich.edu 256360SN/A public: 2573114Sgblack@eecs.umich.edu 2584793Sgblack@eecs.umich.edu enum AuxiliaryVectorType { 2594793Sgblack@eecs.umich.edu M5_AT_NULL = 0, 2604793Sgblack@eecs.umich.edu M5_AT_IGNORE = 1, 2614793Sgblack@eecs.umich.edu M5_AT_EXECFD = 2, 2624793Sgblack@eecs.umich.edu M5_AT_PHDR = 3, 2634793Sgblack@eecs.umich.edu M5_AT_PHENT = 4, 2644793Sgblack@eecs.umich.edu M5_AT_PHNUM = 5, 2654793Sgblack@eecs.umich.edu M5_AT_PAGESZ = 6, 2664793Sgblack@eecs.umich.edu M5_AT_BASE = 7, 2674793Sgblack@eecs.umich.edu M5_AT_FLAGS = 8, 2684793Sgblack@eecs.umich.edu M5_AT_ENTRY = 9, 2694793Sgblack@eecs.umich.edu M5_AT_NOTELF = 10, 2704793Sgblack@eecs.umich.edu M5_AT_UID = 11, 2714793Sgblack@eecs.umich.edu M5_AT_EUID = 12, 2724793Sgblack@eecs.umich.edu M5_AT_GID = 13, 2734793Sgblack@eecs.umich.edu M5_AT_EGID = 14, 2744793Sgblack@eecs.umich.edu // The following may be specific to Linux 2754793Sgblack@eecs.umich.edu M5_AT_PLATFORM = 15, 2764793Sgblack@eecs.umich.edu M5_AT_HWCAP = 16, 2774793Sgblack@eecs.umich.edu M5_AT_CLKTCK = 17, 2784793Sgblack@eecs.umich.edu 2794793Sgblack@eecs.umich.edu M5_AT_SECURE = 23, 2806399Sgblack@eecs.umich.edu M5_BASE_PLATFORM = 24, 2816399Sgblack@eecs.umich.edu M5_AT_RANDOM = 25, 2826399Sgblack@eecs.umich.edu 2836399Sgblack@eecs.umich.edu M5_AT_EXECFN = 31, 2844793Sgblack@eecs.umich.edu 2854793Sgblack@eecs.umich.edu M5_AT_VECTOR_SIZE = 44 2864793Sgblack@eecs.umich.edu }; 2874793Sgblack@eecs.umich.edu 2883114Sgblack@eecs.umich.edu inline uint64_t uid() {return __uid;} 2893114Sgblack@eecs.umich.edu inline uint64_t euid() {return __euid;} 2903114Sgblack@eecs.umich.edu inline uint64_t gid() {return __gid;} 2913114Sgblack@eecs.umich.edu inline uint64_t egid() {return __egid;} 2923114Sgblack@eecs.umich.edu inline uint64_t pid() {return __pid;} 2933114Sgblack@eecs.umich.edu inline uint64_t ppid() {return __ppid;} 2943114Sgblack@eecs.umich.edu 2959144Ssteve.reinhardt@amd.com // provide program name for debug messages 2969144Ssteve.reinhardt@amd.com virtual const char *progName() const { return argv[0].c_str(); } 2979144Ssteve.reinhardt@amd.com 2983669Sbinkertn@umich.edu std::string 2993669Sbinkertn@umich.edu fullPath(const std::string &filename) 3003669Sbinkertn@umich.edu { 3013669Sbinkertn@umich.edu if (filename[0] == '/' || cwd.empty()) 3023669Sbinkertn@umich.edu return filename; 3033669Sbinkertn@umich.edu 3043669Sbinkertn@umich.edu std::string full = cwd; 3053669Sbinkertn@umich.edu 3063669Sbinkertn@umich.edu if (cwd[cwd.size() - 1] != '/') 3073669Sbinkertn@umich.edu full += '/'; 3083669Sbinkertn@umich.edu 3093669Sbinkertn@umich.edu return full + filename; 3103669Sbinkertn@umich.edu } 3113669Sbinkertn@umich.edu 3125513SMichael.Adler@intel.com std::string getcwd() const { return cwd; } 3135513SMichael.Adler@intel.com 3142680Sktlim@umich.edu virtual void syscall(int64_t callnum, ThreadContext *tc); 3156701Sgblack@eecs.umich.edu 3166701Sgblack@eecs.umich.edu virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i) = 0; 3176701Sgblack@eecs.umich.edu virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i, int width); 3185958Sgblack@eecs.umich.edu virtual void setSyscallArg(ThreadContext *tc, 3195958Sgblack@eecs.umich.edu int i, TheISA::IntReg val) = 0; 3205958Sgblack@eecs.umich.edu virtual void setSyscallReturn(ThreadContext *tc, 3215958Sgblack@eecs.umich.edu SyscallReturn return_value) = 0; 3222093SN/A 3238325Ssteve.reinhardt@amd.com virtual SyscallDesc *getDesc(int callnum) = 0; 3242715Sstever@eecs.umich.edu 3252715Sstever@eecs.umich.edu // this function is used to create the LiveProcess object, since 3262715Sstever@eecs.umich.edu // we can't tell which subclass of LiveProcess to use until we 3272715Sstever@eecs.umich.edu // open and look at the object file. 3288325Ssteve.reinhardt@amd.com static LiveProcess *create(LiveProcessParams *params); 3292SN/A}; 3302SN/A 331360SN/A 332360SN/A#endif // __PROCESS_HH__ 333