process.hh revision 2474
12817Sksewell@umich.edu/*
22817Sksewell@umich.edu * Copyright (c) 2001-2005 The Regents of The University of Michigan
32817Sksewell@umich.edu * All rights reserved.
42817Sksewell@umich.edu *
52817Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
62817Sksewell@umich.edu * modification, are permitted provided that the following conditions are
72817Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
82817Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
92817Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
102817Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
112817Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
122817Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
132817Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
142817Sksewell@umich.edu * this software without specific prior written permission.
152817Sksewell@umich.edu *
162817Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172817Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182817Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192817Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202817Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212817Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222817Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232817Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242817Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252817Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262817Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272817Sksewell@umich.edu */
282817Sksewell@umich.edu
292817Sksewell@umich.edu#ifndef __PROCESS_HH__
302817Sksewell@umich.edu#define __PROCESS_HH__
312817Sksewell@umich.edu
323776Sgblack@eecs.umich.edu//
332817Sksewell@umich.edu// The purpose of this code is to fake the loader & syscall mechanism
342834Sksewell@umich.edu// when there's no OS: thus there's no reason to use it in FULL_SYSTEM
352817Sksewell@umich.edu// mode when we do have an OS.
362817Sksewell@umich.edu//
372817Sksewell@umich.edu#include "config/full_system.hh"
382817Sksewell@umich.edu
392817Sksewell@umich.edu#if !FULL_SYSTEM
402817Sksewell@umich.edu
412817Sksewell@umich.edu#include <vector>
422817Sksewell@umich.edu
432817Sksewell@umich.edu#include "base/statistics.hh"
442817Sksewell@umich.edu#include "sim/sim_object.hh"
452817Sksewell@umich.edu
462817Sksewell@umich.educlass CPUExecContext;
473675Sktlim@umich.educlass ExecContext;
482817Sksewell@umich.educlass SyscallDesc;
492817Sksewell@umich.educlass PageTable;
502817Sksewell@umich.educlass TranslatingPort;
512817Sksewell@umich.educlass System;
522817Sksewell@umich.edu
532817Sksewell@umich.educlass Process : public SimObject
542817Sksewell@umich.edu{
553126Sktlim@umich.edu  public:
562817Sksewell@umich.edu
572817Sksewell@umich.edu    /// Pointer to object representing the system this process is
582817Sksewell@umich.edu    /// running on.
592817Sksewell@umich.edu    System *system;
602817Sksewell@umich.edu
612817Sksewell@umich.edu    // have we initialized an execution context from this process?  If
622817Sksewell@umich.edu    // yes, subsequent contexts are assumed to be for dynamically
632817Sksewell@umich.edu    // created threads and are not initialized.
642817Sksewell@umich.edu    bool initialContextLoaded;
652817Sksewell@umich.edu
662817Sksewell@umich.edu    // execution contexts associated with this process
672817Sksewell@umich.edu    std::vector<ExecContext *> execContexts;
682817Sksewell@umich.edu
692817Sksewell@umich.edu    // number of CPUs (esxec contexts, really) assigned to this process.
702817Sksewell@umich.edu    unsigned int numCpus() { return execContexts.size(); }
712817Sksewell@umich.edu
722817Sksewell@umich.edu    // record of blocked context
732817Sksewell@umich.edu    struct WaitRec
742817Sksewell@umich.edu    {
752817Sksewell@umich.edu        Addr waitChan;
762817Sksewell@umich.edu        ExecContext *waitingContext;
772817Sksewell@umich.edu
782817Sksewell@umich.edu        WaitRec(Addr chan, ExecContext *ctx)
792817Sksewell@umich.edu            : waitChan(chan), waitingContext(ctx)
802817Sksewell@umich.edu        {	}
812817Sksewell@umich.edu    };
822817Sksewell@umich.edu
832817Sksewell@umich.edu    // list of all blocked contexts
842817Sksewell@umich.edu    std::list<WaitRec> waitList;
852817Sksewell@umich.edu
862817Sksewell@umich.edu    Addr brk_point;		// top of the data segment
872817Sksewell@umich.edu
882817Sksewell@umich.edu    Addr stack_base;		// stack segment base (highest address)
892817Sksewell@umich.edu    unsigned stack_size;	// initial stack size
902817Sksewell@umich.edu    Addr stack_min;		// lowest address accessed on the stack
912817Sksewell@umich.edu
922817Sksewell@umich.edu    // addr to use for next stack region (for multithreaded apps)
932817Sksewell@umich.edu    Addr next_thread_stack_base;
942817Sksewell@umich.edu
952817Sksewell@umich.edu    // Base of region for mmaps (when user doesn't specify an address).
962817Sksewell@umich.edu    Addr mmap_start;
972817Sksewell@umich.edu    Addr mmap_end;
982817Sksewell@umich.edu
992817Sksewell@umich.edu    // Base of region for nxm data
1002817Sksewell@umich.edu    Addr nxm_start;
1012817Sksewell@umich.edu    Addr nxm_end;
1022817Sksewell@umich.edu
1032817Sksewell@umich.edu    std::string prog_fname;	// file name
1042817Sksewell@umich.edu
1053686Sktlim@umich.edu    Stats::Scalar<> num_syscalls;	// number of syscalls executed
1063686Sktlim@umich.edu
1073686Sktlim@umich.edu
1083686Sktlim@umich.edu  protected:
1092817Sksewell@umich.edu    // constructor
1102817Sksewell@umich.edu    Process(const std::string &nm,
1112817Sksewell@umich.edu            System *_system,
1122817Sksewell@umich.edu            int stdin_fd, 	// initial I/O descriptors
1132817Sksewell@umich.edu            int stdout_fd,
1142817Sksewell@umich.edu            int stderr_fd);
1152817Sksewell@umich.edu
1162875Sksewell@umich.edu    // post initialization startup
1172875Sksewell@umich.edu    virtual void startup();
1182817Sksewell@umich.edu
1192817Sksewell@umich.edu  protected:
1202817Sksewell@umich.edu    /// Memory object for initialization (image loading)
1212817Sksewell@umich.edu    TranslatingPort *initVirtMem;
1222817Sksewell@umich.edu
1232817Sksewell@umich.edu  public:
1242817Sksewell@umich.edu    PageTable *pTable;
1252817Sksewell@umich.edu
1262817Sksewell@umich.edu  private:
1272817Sksewell@umich.edu    // file descriptor remapping support
1282817Sksewell@umich.edu    static const int MAX_FD = 256;	// max legal fd value
1292817Sksewell@umich.edu    int fd_map[MAX_FD+1];
1302817Sksewell@umich.edu
1312817Sksewell@umich.edu  public:
1322817Sksewell@umich.edu    // static helper functions to generate file descriptors for constructor
1332817Sksewell@umich.edu    static int openInputFile(const std::string &filename);
1342817Sksewell@umich.edu    static int openOutputFile(const std::string &filename);
1352817Sksewell@umich.edu
1362817Sksewell@umich.edu    // override of virtual SimObject method: register statistics
1372817Sksewell@umich.edu    virtual void regStats();
1382817Sksewell@umich.edu
1392817Sksewell@umich.edu    // register an execution context for this process.
1402817Sksewell@umich.edu    // returns xc's cpu number (index into execContexts[])
1412875Sksewell@umich.edu    int registerExecContext(ExecContext *xc);
1422875Sksewell@umich.edu
1432817Sksewell@umich.edu
1442817Sksewell@umich.edu    void replaceExecContext(ExecContext *xc, int xcIndex);
1452817Sksewell@umich.edu
1462817Sksewell@umich.edu    // map simulator fd sim_fd to target fd tgt_fd
1472817Sksewell@umich.edu    void dup_fd(int sim_fd, int tgt_fd);
1482817Sksewell@umich.edu
1492817Sksewell@umich.edu    // generate new target fd for sim_fd
1502817Sksewell@umich.edu    int alloc_fd(int sim_fd);
1512817Sksewell@umich.edu
1522817Sksewell@umich.edu    // free target fd (e.g., after close)
1532817Sksewell@umich.edu    void free_fd(int tgt_fd);
1542817Sksewell@umich.edu
1552817Sksewell@umich.edu    // look up simulator fd for given target fd
1562817Sksewell@umich.edu    int sim_fd(int tgt_fd);
1572817Sksewell@umich.edu
1582817Sksewell@umich.edu    virtual void syscall(ExecContext *xc) = 0;
1592817Sksewell@umich.edu};
1602817Sksewell@umich.edu
1612817Sksewell@umich.edu//
1622817Sksewell@umich.edu// "Live" process with system calls redirected to host system
1632817Sksewell@umich.edu//
1642817Sksewell@umich.educlass ObjectFile;
1652817Sksewell@umich.educlass LiveProcess : public Process
1662875Sksewell@umich.edu{
1672817Sksewell@umich.edu  protected:
1683221Sktlim@umich.edu    ObjectFile *objFile;
1693221Sktlim@umich.edu    std::vector<std::string> argv;
1702817Sksewell@umich.edu    std::vector<std::string> envp;
1712817Sksewell@umich.edu
1722817Sksewell@umich.edu    LiveProcess(const std::string &nm, ObjectFile *objFile,
1732817Sksewell@umich.edu                System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
1742817Sksewell@umich.edu                std::vector<std::string> &argv,
1753221Sktlim@umich.edu                std::vector<std::string> &envp);
1762817Sksewell@umich.edu
1772817Sksewell@umich.edu    void argsInit(int intSize, int pageSize);
1782817Sksewell@umich.edu
1792817Sksewell@umich.edu  public:
1802817Sksewell@umich.edu    virtual void syscall(ExecContext *xc);
1812817Sksewell@umich.edu
1822875Sksewell@umich.edu    virtual SyscallDesc* getDesc(int callnum) = 0;
1832875Sksewell@umich.edu};
1842817Sksewell@umich.edu
1852817Sksewell@umich.edu
1862817Sksewell@umich.edu#endif // !FULL_SYSTEM
1872817Sksewell@umich.edu
1882817Sksewell@umich.edu#endif // __PROCESS_HH__
1892817Sksewell@umich.edu