⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alpha_linux_process.cc

📁 linux下基于c++的处理器仿真平台。具有处理器流水线
💻 CC
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 2003, 2004, 2005 * The Regents of The University of Michigan * All Rights Reserved * * This code is part of the M5 simulator, developed by Nathan Binkert, * Erik Hallnor, Steve Raasch, and Steve Reinhardt, with contributions * from Ron Dreslinski, Dave Greene, Lisa Hsu, Kevin Lim, Ali Saidi, * and Andrew Schultz. * * Permission is granted to use, copy, create derivative works and * redistribute this software and such derivative works for any * purpose, so long as the copyright notice above, this grant of * permission, and the disclaimer below appear in all copies made; and * so long as the name of The University of Michigan is not used in * any advertising or publicity pertaining to the use or distribution * of this software without specific, written prior authorization. * * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT, * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH * DAMAGES. */#include <dirent.h>#include <errno.h>#include <fcntl.h>	// for host open() flags#include <string.h>	// for memset()#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include "cpu/base.hh"#include "cpu/exec_context.hh"#include "mem/functional/functional.hh"#include "sim/fake_syscall.hh"#include "sim/host.hh"#include "sim/process.hh"#include "sim/sim_events.hh"#include "arch/alpha/alpha_common_syscall_emul.hh"#include "sim/syscall_emul.hh"#include "sim/root.hh"	// for curTick & ticksPerSecond#include "arch/alpha/alpha_linux_process.hh"#include "base/trace.hh"using namespace std;////// This class encapsulates the types, structures, constants,/// functions, and syscall-number mappings specific to the Alpha Linux/// syscall interface.///class Linux {  public:    //@{    /// Basic Linux types.    typedef uint64_t size_t;    typedef uint64_t off_t;    typedef int64_t time_t;    typedef uint32_t uid_t;    typedef uint32_t gid_t;    //@}    //@{    /// open(2) flag values.    static const int TGT_O_RDONLY	= 00000000;	//!< O_RDONLY    static const int TGT_O_WRONLY	= 00000001;	//!< O_WRONLY    static const int TGT_O_RDWR	 	= 00000002;	//!< O_RDWR    static const int TGT_O_NONBLOCK  	= 00000004;	//!< O_NONBLOCK    static const int TGT_O_APPEND	= 00000010;	//!< O_APPEND    static const int TGT_O_CREAT	= 00001000;	//!< O_CREAT    static const int TGT_O_TRUNC	= 00002000;	//!< O_TRUNC    static const int TGT_O_EXCL	 	= 00004000;	//!< O_EXCL    static const int TGT_O_NOCTTY	= 00010000;	//!< O_NOCTTY    static const int TGT_O_SYNC	 	= 00040000;	//!< O_SYNC    static const int TGT_O_DRD	 	= 00100000;	//!< O_DRD    static const int TGT_O_DIRECTIO  	= 00200000;	//!< O_DIRECTIO    static const int TGT_O_CACHE	= 00400000;	//!< O_CACHE    static const int TGT_O_DSYNC	= 02000000;	//!< O_DSYNC    static const int TGT_O_RSYNC	= 04000000;	//!< O_RSYNC    //@}    /// This table maps the target open() flags to the corresponding    /// host open() flags.    static OpenFlagTransTable openFlagTable[];    /// Number of entries in openFlagTable[].    static const int NUM_OPEN_FLAGS;    /// Stat buffer.  Note that we can't call it 'stat' since that    /// gets #defined to something else on some systems.    struct tgt_stat {	uint32_t	st_dev;		//!< device	uint32_t	st_ino;		//!< inode	uint32_t	st_mode;	//!< mode	uint32_t	st_nlink;	//!< link count	uint32_t	st_uid;		//!< owner's user ID	uint32_t	st_gid;		//!< owner's group ID	uint32_t	st_rdev;	//!< device number	int32_t		_pad1;		//!< for alignment	int64_t		st_size;	//!< file size in bytes	uint64_t	st_atimeX;	//!< time of last access	uint64_t	st_mtimeX;	//!< time of last modification	uint64_t	st_ctimeX;	//!< time of last status change	uint32_t	st_blksize;	//!< optimal I/O block size	int32_t		st_blocks;	//!< number of blocks allocated	uint32_t	st_flags;	//!< flags	uint32_t	st_gen;		//!< unknown    };    /// Length of strings in struct utsname (plus 1 for null char).    static const int _SYS_NMLN = 65;    /// Interface struct for uname().    struct utsname {	char sysname[_SYS_NMLN];	//!< System name.	char nodename[_SYS_NMLN];	//!< Node name.	char release[_SYS_NMLN];	//!< OS release.	char version[_SYS_NMLN];	//!< OS version.	char machine[_SYS_NMLN];	//!< Machine type.    };    //@{    /// ioctl() command codes.    static const unsigned TIOCGETP   = 0x40067408;    static const unsigned TIOCSETP   = 0x80067409;    static const unsigned TIOCSETN   = 0x8006740a;    static const unsigned TIOCSETC   = 0x80067411;    static const unsigned TIOCGETC   = 0x40067412;    static const unsigned FIONREAD   = 0x4004667f;    static const unsigned TIOCISATTY = 0x2000745e;    static const unsigned TIOCGETS   = 0x402c7413;    static const unsigned TIOCGETA   = 0x40127417;    //@}    /// Resource enumeration for getrlimit().    enum rlimit_resources {	RLIMIT_CPU = 0,	RLIMIT_FSIZE = 1,	RLIMIT_DATA = 2,	RLIMIT_STACK = 3,	RLIMIT_CORE = 4,	RLIMIT_RSS = 5,	RLIMIT_NOFILE = 6,	RLIMIT_AS = 7,	RLIMIT_VMEM = 7,	RLIMIT_NPROC = 8,	RLIMIT_MEMLOCK = 9,	RLIMIT_LOCKS = 10    };    /// Limit struct for getrlimit/setrlimit.    struct rlimit {	uint64_t  rlim_cur;	//!< soft limit	uint64_t  rlim_max;	//!< hard limit    };    /// For mmap().    static const unsigned TGT_MAP_ANONYMOUS = 0x10;        /// For gettimeofday().    struct timeval {	int64_t tv_sec;		//!< seconds	int64_t tv_usec;	//!< microseconds    };    //@{    /// For getrusage().    static const int RUSAGE_SELF = 0;    static const int RUSAGE_CHILDREN = -1;    static const int RUSAGE_BOTH = -2;    //@}    /// For getrusage().    struct rusage { 	struct timeval ru_utime;	//!< user time used	struct timeval ru_stime;	//!< system time used	int64_t ru_maxrss;		//!< max rss	int64_t ru_ixrss;		//!< integral shared memory size	int64_t ru_idrss;		//!< integral unshared data "	int64_t ru_isrss;		//!< integral unshared stack "	int64_t ru_minflt;		//!< page reclaims - total vmfaults	int64_t ru_majflt;		//!< page faults	int64_t ru_nswap;		//!< swaps	int64_t ru_inblock;		//!< block input operations	int64_t ru_oublock;		//!< block output operations	int64_t ru_msgsnd;		//!< messages sent	int64_t ru_msgrcv;		//!< messages received	int64_t ru_nsignals;		//!< signals received	int64_t ru_nvcsw;		//!< voluntary context switches	int64_t ru_nivcsw;		//!< involuntary "    };    /// Helper function to convert a host stat buffer to a target stat    /// buffer.  Also copies the target buffer out to the simulated    /// memorty space.  Used by stat(), fstat(), and lstat().    static void    copyOutStatBuf(FunctionalMemory *mem, Addr addr, struct stat *host)    {	TypedBufferArg<Linux::tgt_stat> tgt(addr);	tgt->st_dev = host->st_dev;	tgt->st_ino = host->st_ino;	tgt->st_mode = host->st_mode;	tgt->st_nlink = host->st_nlink;	tgt->st_uid = host->st_uid;	tgt->st_gid = host->st_gid;	tgt->st_rdev = host->st_rdev;	tgt->st_size = host->st_size;	tgt->st_atimeX = host->st_atime;	tgt->st_mtimeX = host->st_mtime;	tgt->st_ctimeX = host->st_ctime;	tgt->st_blksize = host->st_blksize;	tgt->st_blocks = host->st_blocks;	tgt.copyOut(mem);    }    /// The target system's hostname.    static const char *hostname;    /// Target uname() handler.    static SyscallReturn    unameFunc(SyscallDesc *desc, int callnum, Process *process,	      ExecContext *xc)    {	TypedBufferArg<Linux::utsname> name(xc->getSyscallArg(0));	strcpy(name->sysname, "Linux");	strcpy(name->nodename, hostname);	strcpy(name->release, "2.4.20");	strcpy(name->version, "#1 Mon Aug 18 11:32:15 EDT 2003");	strcpy(name->machine, "alpha");	name.copyOut(xc->mem);	return 0;    }    /// Target osf_getsysyinfo() handler.  Even though this call is    /// borrowed from Tru64, the subcases that get used appear to be    /// different in practice from those used by Tru64 processes.    static SyscallReturn    osf_getsysinfoFunc(SyscallDesc *desc, int callnum, Process *process,		       ExecContext *xc)    {	unsigned op = xc->getSyscallArg(0);	// unsigned nbytes = xc->getSyscallArg(2);	switch (op) {	  case 45: { // GSI_IEEE_FP_CONTROL	      TypedBufferArg<uint64_t> fpcr(xc->getSyscallArg(1));	      // I don't think this exactly matches the HW FPCR	      *fpcr = 0;	      fpcr.copyOut(xc->mem);	      return 0;	  }	  default:	    cerr << "osf_getsysinfo: unknown op " << op << endl;	    abort();	    break;	}	return 1;    }    /// Target osf_setsysinfo() handler.    static SyscallReturn    osf_setsysinfoFunc(SyscallDesc *desc, int callnum, Process *process,		       ExecContext *xc)    {	unsigned op = xc->getSyscallArg(0);	// unsigned nbytes = xc->getSyscallArg(2);	switch (op) {	  case 14: { // SSI_IEEE_FP_CONTROL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -