process.hh revision 180
1298SN/A/* 22188SN/A * Copyright (c) 2003 The Regents of The University of Michigan 3298SN/A * All rights reserved. 4298SN/A * 5298SN/A * Redistribution and use in source and binary forms, with or without 6298SN/A * modification, are permitted provided that the following conditions are 7298SN/A * met: redistributions of source code must retain the above copyright 8298SN/A * notice, this list of conditions and the following disclaimer; 9298SN/A * redistributions in binary form must reproduce the above copyright 10298SN/A * notice, this list of conditions and the following disclaimer in the 11298SN/A * documentation and/or other materials provided with the distribution; 12298SN/A * neither the name of the copyright holders nor the names of its 13298SN/A * contributors may be used to endorse or promote products derived from 14298SN/A * this software without specific prior written permission. 15298SN/A * 16298SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17298SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18298SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19298SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20298SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21298SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22298SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23298SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24298SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25298SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26298SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 29298SN/A#ifndef __PROG_HH__ 30298SN/A#define __PROG_HH__ 311642SN/A 32954SN/A// 33956SN/A// The purpose of this code is to fake the loader & syscall mechanism 34956SN/A// when there's no OS: thus there's no reason to use it in FULL_SYSTEM 35299SN/A// mode when we do have an OS. 36299SN/A// 372170SN/A#ifndef FULL_SYSTEM 383089Ssaidi@eecs.umich.edu 391717SN/A#include <vector> 402680Sktlim@umich.edu 412313SN/A#include "targetarch/isa_traits.hh" 423565Sgblack@eecs.umich.edu#include "sim/sim_object.hh" 433565Sgblack@eecs.umich.edu#include "sim/sim_stats.hh" 44298SN/A#include "base/statistics.hh" 45298SN/A 46695SN/Aclass ExecContext; 47695SN/Aclass FunctionalMemory; 48954SN/Aclass Process : public SimObject 491052SN/A{ 502080SN/A public: 51298SN/A 52299SN/A // have we initialized an execution context from this process? If 531052SN/A // yes, subsequent contexts are assumed to be for dynamically 54729SN/A // created threads and are not initialized. 552107SN/A bool initialContextLoaded; 56298SN/A 57298SN/A // execution contexts associated with this process 58298SN/A std::vector<ExecContext *> execContexts; 59310SN/A 602680Sktlim@umich.edu // number of CPUs (esxec contexts, really) assigned to this process. 61711SN/A unsigned int numCpus() { return execContexts.size(); } 622680Sktlim@umich.edu 632680Sktlim@umich.edu // record of blocked context 64711SN/A struct WaitRec 65711SN/A { 66711SN/A Addr waitChan; 672680Sktlim@umich.edu ExecContext *waitingContext; 68310SN/A 693617Sbinkertn@umich.edu WaitRec(Addr chan, ExecContext *ctx) 70310SN/A : waitChan(chan), waitingContext(ctx) 71310SN/A { 723373Sstever@eecs.umich.edu } 733373Sstever@eecs.umich.edu }; 742680Sktlim@umich.edu 752680Sktlim@umich.edu // list of all blocked contexts 762680Sktlim@umich.edu std::list<WaitRec> waitList; 77310SN/A 78299SN/A RegFile *init_regs; // initial register contents 79298SN/A 802680Sktlim@umich.edu Addr text_base; // text (code) segment base 812188SN/A unsigned text_size; // text (code) size in bytes 823617Sbinkertn@umich.edu 832188SN/A Addr data_base; // initialized data segment base 842188SN/A unsigned data_size; // initialized data + bss size in bytes 852680Sktlim@umich.edu 862235SN/A Addr brk_point; // top of the data segment 873368Sstever@eecs.umich.edu 883368Sstever@eecs.umich.edu Addr stack_base; // stack segment base (highest address) 892235SN/A unsigned stack_size; // initial stack size 903368Sstever@eecs.umich.edu Addr stack_min; // lowest address accessed on the stack 912188SN/A 923368Sstever@eecs.umich.edu 933368Sstever@eecs.umich.edu // addr to use for next stack region (for multithreaded apps) 943368Sstever@eecs.umich.edu Addr next_thread_stack_base; 953368Sstever@eecs.umich.edu 962188SN/A std::string prog_fname; // file name 972680Sktlim@umich.edu Addr prog_entry; // entry point (initial PC) 982680Sktlim@umich.edu 992680Sktlim@umich.edu Statistics::Scalar<> num_syscalls; // number of syscalls executed 1002188SN/A 1012188SN/A 1022188SN/A protected: 1032680Sktlim@umich.edu // constructor 1042188SN/A Process(const std::string &name, 1053617Sbinkertn@umich.edu int stdin_fd, // initial I/O descriptors 1062188SN/A int stdout_fd, 1072188SN/A int stderr_fd); 1082680Sktlim@umich.edu 1092235SN/A 1103368Sstever@eecs.umich.edu protected: 1113368Sstever@eecs.umich.edu FunctionalMemory *memory; 1122235SN/A 1133368Sstever@eecs.umich.edu private: 1142188SN/A // file descriptor remapping support 1153368Sstever@eecs.umich.edu static const int MAX_FD = 100; // max legal fd value 1163368Sstever@eecs.umich.edu int fd_map[MAX_FD+1]; 1173368Sstever@eecs.umich.edu 1183368Sstever@eecs.umich.edu public: 1192188SN/A // static helper functions to generate file descriptors for constructor 1202680Sktlim@umich.edu static int openInputFile(const std::string &filename); 1212680Sktlim@umich.edu static int openOutputFile(const std::string &filename); 1222680Sktlim@umich.edu 1232188SN/A // override of virtual SimObject method: register statistics 1242188SN/A virtual void regStats(); 1252188SN/A 1262680Sktlim@umich.edu // register an execution context for this process. 1272188SN/A // returns xc's cpu number (index into execContexts[]) 1282680Sktlim@umich.edu int registerExecContext(ExecContext *xc); 1292188SN/A 1302188SN/A 1312188SN/A void replaceExecContext(int xcIndex, ExecContext *xc); 1322680Sktlim@umich.edu 133298SN/A // map simulator fd sim_fd to target fd tgt_fd 1343144Shsul@eecs.umich.edu void dup_fd(int sim_fd, int tgt_fd); 135298SN/A 136298SN/A // generate new target fd for sim_fd 137298SN/A int open_fd(int sim_fd); 1382680Sktlim@umich.edu 139298SN/A // look up simulator fd for given target fd 1401609SN/A int sim_fd(int tgt_fd); 1413144Shsul@eecs.umich.edu 142298SN/A // is this a valid instruction fetch address? 143298SN/A bool validInstAddr(Addr addr) 144298SN/A { 1453126Sktlim@umich.edu return (text_base <= addr && 1462358SN/A addr < text_base + text_size && 1473126Sktlim@umich.edu !(addr & (sizeof(MachInst)-1))); 1482358SN/A } 1492358SN/A 1502358SN/A // is this a valid address? (used to filter data fetches) 1512358SN/A // note that we just assume stack size <= 16MB 1522358SN/A // this may be alpha-specific 1532358SN/A bool validDataAddr(Addr addr) 1542358SN/A { 1552358SN/A return ((data_base <= addr && addr < brk_point) || 1562358SN/A ((stack_base - 16*1024*1024) <= addr && addr < stack_base) || 1572358SN/A (text_base <= addr && addr < (text_base + text_size))); 1582358SN/A } 1592358SN/A 1602358SN/A virtual void syscall(ExecContext *xc) = 0; 1612358SN/A 1622358SN/A virtual FunctionalMemory *getMemory() { return memory; } 1632358SN/A}; 1642358SN/A 1652358SN/A// 1662358SN/A// "Live" process with system calls redirected to host system 1672358SN/A// 1682358SN/Aclass MainMemory; 1692358SN/Aclass LiveProcess : public Process 1702358SN/A{ 1712358SN/A public: 1722358SN/A LiveProcess(const std::string &name, 1732358SN/A int stdin_fd, int stdout_fd, int stderr_fd, 1742358SN/A std::vector<std::string> &argv, 1752358SN/A std::vector<std::string> &envp); 1762358SN/A 1772358SN/A virtual void syscall(ExecContext *xc); 1782358SN/A}; 1792358SN/A 1802358SN/A#endif // !FULL_SYSTEM 1812358SN/A 1822358SN/A#endif // __PROG_HH__ 1833126Sktlim@umich.edu