process.hh revision 2680
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 352SN/A// 362SN/A// The purpose of this code is to fake the loader & syscall mechanism 372SN/A// when there's no OS: thus there's no reason to use it in FULL_SYSTEM 382SN/A// mode when we do have an OS. 392SN/A// 401858SN/A#include "config/full_system.hh" 411858SN/A 421858SN/A#if !FULL_SYSTEM 432SN/A 44180SN/A#include <vector> 452SN/A 462378SN/A#include "base/statistics.hh" 4756SN/A#include "sim/sim_object.hh" 482SN/A 492190SN/Aclass CPUExecContext; 502680Sktlim@umich.educlass ThreadContext; 512093SN/Aclass SyscallDesc; 522462SN/Aclass PageTable; 532401SN/Aclass TranslatingPort; 542378SN/Aclass System; 552378SN/A 562561SN/Avoid 572561SN/AcopyStringArray(std::vector<std::string> &strings, Addr array_ptr, 582561SN/A Addr data_ptr, TranslatingPort* memPort); 592561SN/A 602SN/Aclass Process : public SimObject 612SN/A{ 622SN/A public: 632SN/A 642378SN/A /// Pointer to object representing the system this process is 652378SN/A /// running on. 662378SN/A System *system; 672378SN/A 682680Sktlim@umich.edu // have we initialized a thread context from this process? If 692SN/A // yes, subsequent contexts are assumed to be for dynamically 702SN/A // created threads and are not initialized. 712SN/A bool initialContextLoaded; 722SN/A 732680Sktlim@umich.edu // thread contexts associated with this process 742680Sktlim@umich.edu std::vector<ThreadContext *> threadContexts; 75180SN/A 76180SN/A // number of CPUs (esxec contexts, really) assigned to this process. 772680Sktlim@umich.edu unsigned int numCpus() { return threadContexts.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) 872378SN/A { } 882SN/A }; 892SN/A 902SN/A // list of all blocked contexts 912SN/A std::list<WaitRec> waitList; 922SN/A 932SN/A Addr brk_point; // top of the data segment 942SN/A 952SN/A Addr stack_base; // stack segment base (highest address) 962SN/A unsigned stack_size; // initial stack size 972SN/A Addr stack_min; // lowest address accessed on the stack 982SN/A 992SN/A // addr to use for next stack region (for multithreaded apps) 1002SN/A Addr next_thread_stack_base; 1012SN/A 102360SN/A // Base of region for mmaps (when user doesn't specify an address). 1031408SN/A Addr mmap_start; 1041408SN/A Addr mmap_end; 105360SN/A 1061514SN/A // Base of region for nxm data 1071514SN/A Addr nxm_start; 1081514SN/A Addr nxm_end; 1091514SN/A 1102SN/A std::string prog_fname; // file name 1112SN/A 112729SN/A Stats::Scalar<> num_syscalls; // number of syscalls executed 1132SN/A 1142SN/A 1152SN/A protected: 1162SN/A // constructor 1171450SN/A Process(const std::string &nm, 1182378SN/A System *_system, 1192SN/A int stdin_fd, // initial I/O descriptors 1202SN/A int stdout_fd, 1212SN/A int stderr_fd); 1222SN/A 1231395SN/A // post initialization startup 1241395SN/A virtual void startup(); 1252SN/A 1262SN/A protected: 1272378SN/A /// Memory object for initialization (image loading) 1282401SN/A TranslatingPort *initVirtMem; 1292378SN/A 1302378SN/A public: 1312378SN/A PageTable *pTable; 1322SN/A 1332SN/A private: 1342SN/A // file descriptor remapping support 1351970SN/A static const int MAX_FD = 256; // max legal fd value 1362SN/A int fd_map[MAX_FD+1]; 1372SN/A 1382SN/A public: 1392SN/A // static helper functions to generate file descriptors for constructor 1402SN/A static int openInputFile(const std::string &filename); 1412SN/A static int openOutputFile(const std::string &filename); 1422SN/A 1432SN/A // override of virtual SimObject method: register statistics 1442SN/A virtual void regStats(); 1452SN/A 1462680Sktlim@umich.edu // register a thread context for this process. 1472680Sktlim@umich.edu // returns tc's cpu number (index into threadContexts[]) 1482680Sktlim@umich.edu int registerThreadContext(ThreadContext *tc); 149180SN/A 150180SN/A 1512680Sktlim@umich.edu void replaceThreadContext(ThreadContext *tc, int tcIndex); 1522SN/A 1532SN/A // map simulator fd sim_fd to target fd tgt_fd 1542SN/A void dup_fd(int sim_fd, int tgt_fd); 1552SN/A 1562SN/A // generate new target fd for sim_fd 1571970SN/A int alloc_fd(int sim_fd); 1581970SN/A 1591970SN/A // free target fd (e.g., after close) 1601970SN/A void free_fd(int tgt_fd); 1612SN/A 1622SN/A // look up simulator fd for given target fd 1632SN/A int sim_fd(int tgt_fd); 1642SN/A 1652680Sktlim@umich.edu virtual void syscall(int64_t callnum, ThreadContext *tc) = 0; 1662SN/A}; 1672SN/A 1682SN/A// 1692SN/A// "Live" process with system calls redirected to host system 1702SN/A// 171360SN/Aclass ObjectFile; 1722SN/Aclass LiveProcess : public Process 1732SN/A{ 174360SN/A protected: 1752378SN/A ObjectFile *objFile; 1762378SN/A std::vector<std::string> argv; 1772378SN/A std::vector<std::string> envp; 1782378SN/A 1791450SN/A LiveProcess(const std::string &nm, ObjectFile *objFile, 1802378SN/A System *_system, int stdin_fd, int stdout_fd, int stderr_fd, 1812SN/A std::vector<std::string> &argv, 1822SN/A std::vector<std::string> &envp); 1832SN/A 1842561SN/A virtual void argsInit(int intSize, int pageSize); 1852378SN/A 186360SN/A public: 1872680Sktlim@umich.edu virtual void syscall(int64_t callnum, ThreadContext *tc); 1882093SN/A 1892462SN/A virtual SyscallDesc* getDesc(int callnum) = 0; 1902SN/A}; 1912SN/A 192360SN/A 1932SN/A#endif // !FULL_SYSTEM 1942SN/A 195360SN/A#endif // __PROCESS_HH__ 196