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

📄 traps.cc

📁 ml-rsim 多处理器模拟器 支持类bsd操作系统
💻 CC
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (c) 2002 The Board of Trustees of the University of Illinois and *                    William Marsh Rice University * Copyright (c) 2002 The University of Utah * Copyright (c) 2002 The University of Notre Dame du Lac * * All rights reserved. * * Based on RSIM 1.0, developed by: *   Professor Sarita Adve's RSIM research group *   University of Illinois at Urbana-Champaign and     William Marsh Rice University *   http://www.cs.uiuc.edu/rsim and http://www.ece.rice.edu/~rsim/dist.html * ML-RSIM/URSIM extensions by: *   The Impulse Research Group, University of Utah *   http://www.cs.utah.edu/impulse *   Lambert Schaelicke, University of Utah and University of Notre Dame du Lac *   http://www.cse.nd.edu/~lambert *   Mike Parker, University of Utah *   http://www.cs.utah.edu/~map * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal with the Software without restriction, including without * limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to * whom the Software is furnished to do so, subject to the following * conditions: * * 1. Redistributions of source code must retain the above copyright notice, *    this list of conditions and the following disclaimers.  * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimers in the *    documentation and/or other materials provided with the distribution. * 3. Neither the names of Professor Sarita Adve's RSIM research group, *    the University of Illinois at Urbana-Champaign, William Marsh Rice *    University, nor the names of its contributors may be used to endorse *    or promote products derived from this Software without specific prior *    written permission.  * 4. Neither the names of the ML-RSIM project, the URSIM project, the *    Impulse research group, the University of Utah, the University of *    Notre Dame du Lac, nor the names of its contributors may be used to *    endorse or promote products derived from this software without specific *    prior written permission.  * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS WITH THE SOFTWARE.  */// make sure this won't cause problems w/ linux!#define _FILE_OFFSET_BITS 64#ifdef linux#  define _GNU_SOURCE#endif#include <stdio.h>#include <string.h>#include <sys/time.h>#include <unistd.h>#include <utime.h>#include <fcntl.h>#include <errno.h>#include <signal.h>#include <sys/types.h>#include <sys/uio.h>#include <sys/stat.h>#include <sys/statvfs.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#ifndef linux#include <sys/ioccom.h>#include <sys/systeminfo.h>#include <sys/dirent.h>#else#include <sys/ioctl.h>#include <linux/types.h>#include <linux/dirent.h>#include <sys/syscall.h>#include <unistd.h>#include <sys/utsname.h>typedef struct timespec timespec_t;_syscall3(int, getdents, uint, fd, struct dirent *, buf, uint, size);#endif#include <sys/param.h>extern "C"{#include "sim_main/simsys.h"#include "Caches/system.h"#include "sim_main/util.h"#include "sim_main/invoke_debugger.h"}#include "Processor/procstate.h"#include "Processor/pagetable.h"#include "Processor/userstat.h"#include "Processor/exec.h"#include "Processor/memunit.h"#include "Processor/mainsim.h"#include "Processor/simio.h"#include "Processor/branchpred.h"#include "Processor/fastnews.h"#include "Processor/filedesc.h"#include "Processor/tagcvt.hh"#include "Processor/procstate.hh"#include "Processor/active.hh"#include "Processor/endian_swap.h"#include "../lamix/interrupts/traps.h"#include "../lamix/sys/userstat.h"#include "../lamix/lib_src/hostent.h"#ifndef _ST_FSTYPSZ#  define _ST_FSTYPSZ 16#endif#ifndef _SOCKLEN_T#define _SOCKLEN_Ttypedef unsigned int socklen_t;#endifstatic void UserStatAllocHandler  (instance *, ProcState *);static void UserStatSampleHandler (instance *, ProcState *);static void WritelogHandler       (instance *, ProcState *);static void DCreatHandler         (instance *, ProcState *);static void DOpenHandler          (instance *, ProcState *);static void PRead64Handler        (instance *, ProcState *);static void PWrite64Handler       (instance *, ProcState *);static void Lseek64Handler        (instance *, ProcState *);static void ReadlinkHandler       (instance *, ProcState *);static void CloseHandler          (instance *, ProcState *);static void DUnlinkHandler        (instance *, ProcState *);static void DAccessHandler        (instance *, ProcState *);static void IoctlHandler          (instance *, ProcState *);static void FcntlHandler          (instance *, ProcState *);static void Fstat64Handler        (instance *, ProcState *);static void DFStat64Handler       (instance *, ProcState *);static void Lstat64Handler        (instance *, ProcState *);static void Fstatvfs64Handler     (instance *, ProcState *);static void ChmodHandler          (instance *, ProcState *);static void FchmodHandler         (instance *, ProcState *);static void ChownHandler          (instance *, ProcState *);static void FchownHandler         (instance *, ProcState *);static void LchownHandler         (instance *, ProcState *);static void RenameHandler         (instance *, ProcState *);static void UtimeHandler          (instance *, ProcState *);static void DMkdirHandler         (instance *, ProcState *);static void DRmdirHandler         (instance *, ProcState *);static void Getdents64Handler     (instance *, ProcState *);static void LinkHandler           (instance *, ProcState *);static void SymlinkHandler        (instance *, ProcState *);static void SocketHandler         (instance *, ProcState *);static void BindHandler           (instance *, ProcState *);static void ListenHandler         (instance *, ProcState *);static void AcceptHandler         (instance *, ProcState *);static void ConnectHandler        (instance *, ProcState *);static void GetSockOptHandler     (instance *, ProcState *);static void SetSockOptHandler     (instance *, ProcState *);static void ShutdownHandler       (instance *, ProcState *);static void CloseSocketHandler    (instance *, ProcState *);static void GetSockNameHandler    (instance *, ProcState *);static void GetPeerNameHandler    (instance *, ProcState *);static void SendMsgHandler        (instance *, ProcState *);static void RecvMsgHandler        (instance *, ProcState *);static void GetHostByNameHandler  (instance *, ProcState *);static void GetHostByAddrHandler  (instance *, ProcState *);static void SysInfoHandler        (instance *, ProcState *);static void PathConfHandler       (instance *, ProcState *);static void GetUIDHandler         (instance *, ProcState *);static void GetGIDHandler         (instance *, ProcState *);static void GetgroupsHandler      (instance *, ProcState *);static void GetStdioHandler       (instance *, ProcState *);static void GetSegmentInfoHandler (instance *, ProcState *);   extern char fnstdin[MAXPATHLEN], fnstdout[MAXPATHLEN], fnstderr[MAXPATHLEN];extern char fnsimmount[MAXPATHLEN], fncwd[MAXPATHLEN];#define NET_MSG_DELAY 30       // wait N seconds before printing message                               // that simulation is blocked on INET socket/**************************************************************************//* SimTrapHandle : Handle special operating system and RSIM traps         *//**************************************************************************/int SimTrapHandle(instance *inst, ProcState *proc){  int type, pr;  char *phys_mem;  ProcState *np;  unsigned addr;    // trap type is in %g1 - register 1  // all other arguments are in %o0 - %o5  type = proc->phy_int_reg_file[proc->intmapper[arch_to_log(proc,							   proc->cwp,								   1)]];#ifdef COREFILE  if (YS__Simtime > DEBUG_TIME)    fprintf(corefile,            "traps.cc: In SysTrapHandler with code %d\n",            type);#endif  if (type >= SIM_TRAP_GET_SEGMENT_INFO)    {      if (!PSTATE_GET_PRIV(proc->pstate))        {          inst->exception_code = PRIVILEGED;          return(0);        }    }   //=========================================================================  switch (type)    {    case SIM_TRAP_EXIT:                                // exit      pr = proc->intmapper[arch_to_log(proc, proc->cwp, 8)];       YS__logmsg(proc->proc_id / ARCH_cpus,		 "Processor %d exiting with code %d\n",		 proc->proc_id,		 proc->phy_int_reg_file[pr]);      proc->exit = proc->phy_int_reg_file[pr] ?        (proc->phy_int_reg_file[pr] - 128) :          1;      break;      //---------------------------------------------------------------------    case SIM_TRAP_NEWPHASE:               // newphase      proc->newphase(inst->rs1vali);      break;             //---------------------------------------------------------------------    case SIM_TRAP_ENDPHASE:               // endphase      proc->endphase(proc->proc_id / ARCH_cpus);      break;             //---------------------------------------------------------------------    case SIM_TRAP_HALT:                  // fullstop -- force everyone to exit!      pr = proc->intmapper[arch_to_log(proc, proc->cwp, 8)];       YS__logmsg(proc->proc_id / ARCH_cpus,		 "Processor %d forcing halt with code %d\n",		 proc->proc_id,		 proc->phy_int_reg_file[pr]);      exit(1);     // abort all processors immediately, without graceful exit       break;             //---------------------------------------------------------------------    case SIM_TRAP_RSIM_OFF:              // RSIM OFF      proc->decode_rate = 1;      proc->graduate_rate = 1;      proc->max_active_list = 2;      break;             //---------------------------------------------------------------------    case SIM_TRAP_RSIM_ON:               // RSIM ON      proc->decode_rate = DECODES_PER_CYCLE;      proc->graduate_rate = GRADUATES_PER_CYCLE;      proc->max_active_list = MAX_ACTIVE_NUMBER;      break;             //=====================================================================    case SIM_TRAP_CLEAR_STAT:            // clear stats      StatClear(proc->proc_id / ARCH_cpus);      break;             //---------------------------------------------------------------------    case SIM_TRAP_REPORT_STAT:           // report stats      StatReport(proc->proc_id / ARCH_cpus);      break;      //---------------------------------------------------------------------    case SIM_TRAP_USERSTAT_ALLOC:      UserStatAllocHandler(inst, proc);      break;      //---------------------------------------------------------------------    case SIM_TRAP_USERSTAT_SAMPLE:      UserStatSampleHandler(inst, proc);      break;          case SIM_TRAP_LOG_SIMTIME:      YS__logmsg(proc->proc_id / ARCH_cpus, "Current simtime: %.0f\n",		 YS__Simtime);      break;    case SIM_TRAP_INVOKE_DEBUGGER:      fprintf(stderr, "Hit INVOKE_DEBUGGER trap at simtime: %.0f\n",	      YS__Simtime);       YS__logmsg(proc->proc_id / ARCH_cpus,		 "Hit INVOKE_DEBUGGER trap at simtime: %.0f\n",		 YS__Simtime); #ifdef DEBUG_PROC      invoke_debugger(realsimpath);#else      fprintf(stderr, "This trap can only be used with the debugging version"	      " of mlrsim\n");      YS__logmsg(proc->proc_id / ARCH_cpus,		 "This trap can only be used with the debugging version"		 "of mlrsim\n");#endif      break;      //=====================================================================            //---------------------------------------------------------------------    case SIM_TRAP_GET_SEGMENT_INFO:         // get segment start/end address      GetSegmentInfoHandler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_ALLOC_PAGE:               // allocate physical memory      pr = proc->intmapper[arch_to_log(proc, proc->cwp, 8)];      addr = (unsigned)proc->phy_int_reg_file[pr];      phys_mem = proc->PageTable->lookup(addr);      if (!phys_mem)	{#ifdef TRACE	  if (YS__Simtime > TRACE)	    YS__logmsg(proc->proc_id / ARCH_cpus,		       "%.0f: Installing Mapping: %08X\n",		       YS__Simtime, addr);#endif          phys_mem = (char*)malloc(PAGE_SIZE);	  if (phys_mem == NULL)	    YS__errmsg(proc->proc_id / ARCH_cpus,		       "SimAllocPage: Malloc failed: %s\n",		       YS__strerror(errno));	  memset(phys_mem, 0, PAGE_SIZE);	  proc->PageTable->insert(addr, phys_mem);        }#ifdef TRACE      else	if (YS__Simtime > TRACE)	  YS__logmsg(proc->proc_id / ARCH_cpus,		     "Installing Mapping: %08X - exists!\n",		     addr);#endif      break;             //=====================================================================             //---------------------------------------------------------------------    case SIM_TRAP_WRITELOG:              // write simulator log      WritelogHandler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_DCREAT:                // creat system call      DCreatHandler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_DOPEN:                 // open system call      DOpenHandler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_PREAD64:               // pread system call      PRead64Handler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_PWRITE64:              // pwrite system call      PWrite64Handler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_LSEEK64:               // lseek system call      Lseek64Handler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_READLINK:              // readlink system call      ReadlinkHandler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_CLOSE:                 // close system call      CloseHandler(inst, proc);      break;       //---------------------------------------------------------------------    case SIM_TRAP_DUNLINK:               // unlink system call      DUnlinkHandler(inst, proc);      break;       //---------------------------------------------------------------------    case SIM_TRAP_DACCESS:               // access system call      DAccessHandler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_IOCTL:                 // ioctl system call      IoctlHandler(inst, proc);      break;             //---------------------------------------------------------------------    case SIM_TRAP_FCNTL:                 // fcntl system call      FcntlHandler(inst, proc);      break;       

⌨️ 快捷键说明

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