process.cc

来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· CC 代码 · 共 583 行 · 第 1/2 页

CC
583
字号
/* * Copyright (c) 2001, 2002, 2003, 2004, 2005 * The Regents of The University of Michigan * All Rights Reserved * * This code is part of the M5 simulator. * * 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. * * Authors: Steven K. Reinhardt *          Ali G. Saidi */#include "arch/alpha/tru64/tru64.hh"#include "arch/alpha/isa_traits.hh"#include "arch/alpha/tru64/process.hh"#include "cpu/thread_context.hh"#include "kern/tru64/tru64.hh"#include "sim/process.hh"#include "sim/syscall_emul.hh"using namespace std;using namespace AlphaISA;/// Target uname() handler.static SyscallReturnunameFunc(SyscallDesc *desc, int callnum, LiveProcess *process,          ThreadContext *tc){    TypedBufferArg<AlphaTru64::utsname> name(tc->getSyscallArg(0));    strcpy(name->sysname, "OSF1");    strcpy(name->nodename, "m5.eecs.umich.edu");    strcpy(name->release, "V5.1");    strcpy(name->version, "732");    strcpy(name->machine, "alpha");    name.copyOut(tc->getMemPort());    return 0;}/// Target getsysyinfo() handler.static SyscallReturngetsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,               ThreadContext *tc){    unsigned op = tc->getSyscallArg(0);    unsigned nbytes = tc->getSyscallArg(2);    switch (op) {      case AlphaTru64::GSI_MAX_CPU: {          TypedBufferArg<uint32_t> max_cpu(tc->getSyscallArg(1));          *max_cpu = htog((uint32_t)process->numCpus());          max_cpu.copyOut(tc->getMemPort());          return 1;      }      case AlphaTru64::GSI_CPUS_IN_BOX: {          TypedBufferArg<uint32_t> cpus_in_box(tc->getSyscallArg(1));          *cpus_in_box = htog((uint32_t)process->numCpus());          cpus_in_box.copyOut(tc->getMemPort());          return 1;      }      case AlphaTru64::GSI_PHYSMEM: {          TypedBufferArg<uint64_t> physmem(tc->getSyscallArg(1));          *physmem = htog((uint64_t)1024 * 1024);	// physical memory in KB          physmem.copyOut(tc->getMemPort());          return 1;      }      case AlphaTru64::GSI_CPU_INFO: {          TypedBufferArg<AlphaTru64::cpu_info> infop(tc->getSyscallArg(1));          infop->current_cpu = htog(0);          infop->cpus_in_box = htog(process->numCpus());          infop->cpu_type = htog(57);          infop->ncpus = htog(process->numCpus());          uint64_t cpumask = (1 << process->numCpus()) - 1;          infop->cpus_present = infop->cpus_running = htog(cpumask);          infop->cpu_binding = htog(0);          infop->cpu_ex_binding = htog(0);          infop->mhz = htog(667);          infop.copyOut(tc->getMemPort());          return 1;      }      case AlphaTru64::GSI_PROC_TYPE: {          TypedBufferArg<uint64_t> proc_type(tc->getSyscallArg(1));          *proc_type = htog((uint64_t)11);          proc_type.copyOut(tc->getMemPort());          return 1;      }      case AlphaTru64::GSI_PLATFORM_NAME: {          BufferArg bufArg(tc->getSyscallArg(1), nbytes);          strncpy((char *)bufArg.bufferPtr(),                  "COMPAQ Professional Workstation XP1000",                  nbytes);          bufArg.copyOut(tc->getMemPort());          return 1;      }      case AlphaTru64::GSI_CLK_TCK: {          TypedBufferArg<uint64_t> clk_hz(tc->getSyscallArg(1));          *clk_hz = htog((uint64_t)1024);          clk_hz.copyOut(tc->getMemPort());          return 1;      }      default:        warn("getsysinfo: unknown op %d\n", op);        break;    }    return 0;}/// Target setsysyinfo() handler.static SyscallReturnsetsysinfoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,               ThreadContext *tc){    unsigned op = tc->getSyscallArg(0);    switch (op) {      case AlphaTru64::SSI_IEEE_FP_CONTROL:        warn("setsysinfo: ignoring ieee_set_fp_control() arg 0x%x\n",             tc->getSyscallArg(1));        break;      default:        warn("setsysinfo: unknown op %d\n", op);        break;    }    return 0;}/// Target table() handler.staticSyscallReturn tableFunc(SyscallDesc *desc, int callnum, LiveProcess *process,                        ThreadContext *tc){    using namespace std;    using namespace TheISA;    int id = tc->getSyscallArg(0);		// table ID    int index = tc->getSyscallArg(1);	// index into table    // arg 2 is buffer pointer; type depends on table ID    int nel = tc->getSyscallArg(3);		// number of elements    int lel = tc->getSyscallArg(4);		// expected element size    switch (id) {      case AlphaTru64::TBL_SYSINFO: {          if (index != 0 || nel != 1 || lel != sizeof(Tru64::tbl_sysinfo))              return -EINVAL;          TypedBufferArg<Tru64::tbl_sysinfo> elp(tc->getSyscallArg(2));          const int clk_hz = one_million;          elp->si_user = htog(curTick / (Clock::Frequency / clk_hz));          elp->si_nice = htog(0);          elp->si_sys = htog(0);          elp->si_idle = htog(0);          elp->wait = htog(0);          elp->si_hz = htog(clk_hz);          elp->si_phz = htog(clk_hz);          elp->si_boottime = htog(seconds_since_epoch); // seconds since epoch?          elp->si_max_procs = htog(process->numCpus());          elp.copyOut(tc->getMemPort());          return 0;      }      default:        cerr << "table(): id " << id << " unknown." << endl;        return -EINVAL;    }}SyscallDesc AlphaTru64Process::syscallDescs[] = {    /* 0 */ SyscallDesc("syscall (#0)", AlphaTru64::indirectSyscallFunc,                        SyscallDesc::SuppressReturnValue),    /* 1 */ SyscallDesc("exit", exitFunc),    /* 2 */ SyscallDesc("fork", unimplementedFunc),    /* 3 */ SyscallDesc("read", readFunc),    /* 4 */ SyscallDesc("write", writeFunc),    /* 5 */ SyscallDesc("old_open", unimplementedFunc),    /* 6 */ SyscallDesc("close", closeFunc),    /* 7 */ SyscallDesc("wait4", unimplementedFunc),    /* 8 */ SyscallDesc("old_creat", unimplementedFunc),    /* 9 */ SyscallDesc("link", unimplementedFunc),    /* 10 */ SyscallDesc("unlink", unlinkFunc),    /* 11 */ SyscallDesc("execv", unimplementedFunc),    /* 12 */ SyscallDesc("chdir", unimplementedFunc),    /* 13 */ SyscallDesc("fchdir", unimplementedFunc),    /* 14 */ SyscallDesc("mknod", unimplementedFunc),    /* 15 */ SyscallDesc("chmod", unimplementedFunc),    /* 16 */ SyscallDesc("chown", unimplementedFunc),    /* 17 */ SyscallDesc("obreak", obreakFunc),    /* 18 */ SyscallDesc("pre_F64_getfsstat", unimplementedFunc),    /* 19 */ SyscallDesc("lseek", lseekFunc),    /* 20 */ SyscallDesc("getpid", getpidPseudoFunc),    /* 21 */ SyscallDesc("mount", unimplementedFunc),    /* 22 */ SyscallDesc("unmount", unimplementedFunc),    /* 23 */ SyscallDesc("setuid", setuidFunc),    /* 24 */ SyscallDesc("getuid", getuidPseudoFunc),    /* 25 */ SyscallDesc("exec_with_loader", unimplementedFunc),    /* 26 */ SyscallDesc("ptrace", unimplementedFunc),    /* 27 */ SyscallDesc("recvmsg", unimplementedFunc),    /* 28 */ SyscallDesc("sendmsg", unimplementedFunc),    /* 29 */ SyscallDesc("recvfrom", unimplementedFunc),    /* 30 */ SyscallDesc("accept", unimplementedFunc),    /* 31 */ SyscallDesc("getpeername", unimplementedFunc),    /* 32 */ SyscallDesc("getsockname", unimplementedFunc),    /* 33 */ SyscallDesc("access", unimplementedFunc),    /* 34 */ SyscallDesc("chflags", unimplementedFunc),    /* 35 */ SyscallDesc("fchflags", unimplementedFunc),    /* 36 */ SyscallDesc("sync", unimplementedFunc),    /* 37 */ SyscallDesc("kill", unimplementedFunc),    /* 38 */ SyscallDesc("old_stat", unimplementedFunc),    /* 39 */ SyscallDesc("setpgid", unimplementedFunc),    /* 40 */ SyscallDesc("old_lstat", unimplementedFunc),    /* 41 */ SyscallDesc("dup", unimplementedFunc),    /* 42 */ SyscallDesc("pipe", unimplementedFunc),    /* 43 */ SyscallDesc("set_program_attributes", unimplementedFunc),    /* 44 */ SyscallDesc("profil", unimplementedFunc),    /* 45 */ SyscallDesc("open", openFunc<AlphaTru64>),    /* 46 */ SyscallDesc("obsolete osigaction", unimplementedFunc),    /* 47 */ SyscallDesc("getgid", getgidPseudoFunc),    /* 48 */ SyscallDesc("sigprocmask", ignoreFunc),    /* 49 */ SyscallDesc("getlogin", unimplementedFunc),    /* 50 */ SyscallDesc("setlogin", unimplementedFunc),    /* 51 */ SyscallDesc("acct", unimplementedFunc),    /* 52 */ SyscallDesc("sigpending", unimplementedFunc),    /* 53 */ SyscallDesc("classcntl", unimplementedFunc),    /* 54 */ SyscallDesc("ioctl", ioctlFunc<AlphaTru64>),    /* 55 */ SyscallDesc("reboot", unimplementedFunc),    /* 56 */ SyscallDesc("revoke", unimplementedFunc),    /* 57 */ SyscallDesc("symlink", unimplementedFunc),    /* 58 */ SyscallDesc("readlink", unimplementedFunc),    /* 59 */ SyscallDesc("execve", unimplementedFunc),    /* 60 */ SyscallDesc("umask", unimplementedFunc),    /* 61 */ SyscallDesc("chroot", unimplementedFunc),    /* 62 */ SyscallDesc("old_fstat", unimplementedFunc),    /* 63 */ SyscallDesc("getpgrp", unimplementedFunc),    /* 64 */ SyscallDesc("getpagesize", getpagesizeFunc),    /* 65 */ SyscallDesc("mremap", unimplementedFunc),    /* 66 */ SyscallDesc("vfork", unimplementedFunc),    /* 67 */ SyscallDesc("pre_F64_stat", statFunc<Tru64_PreF64>),    /* 68 */ SyscallDesc("pre_F64_lstat", lstatFunc<Tru64_PreF64>),    /* 69 */ SyscallDesc("sbrk", unimplementedFunc),    /* 70 */ SyscallDesc("sstk", unimplementedFunc),    /* 71 */ SyscallDesc("mmap", mmapFunc<AlphaTru64>),    /* 72 */ SyscallDesc("ovadvise", unimplementedFunc),    /* 73 */ SyscallDesc("munmap", munmapFunc),    /* 74 */ SyscallDesc("mprotect", ignoreFunc),    /* 75 */ SyscallDesc("madvise", unimplementedFunc),    /* 76 */ SyscallDesc("old_vhangup", unimplementedFunc),    /* 77 */ SyscallDesc("kmodcall", unimplementedFunc),    /* 78 */ SyscallDesc("mincore", unimplementedFunc),    /* 79 */ SyscallDesc("getgroups", unimplementedFunc),    /* 80 */ SyscallDesc("setgroups", unimplementedFunc),    /* 81 */ SyscallDesc("old_getpgrp", unimplementedFunc),    /* 82 */ SyscallDesc("setpgrp", unimplementedFunc),    /* 83 */ SyscallDesc("setitimer", unimplementedFunc),    /* 84 */ SyscallDesc("old_wait", unimplementedFunc),    /* 85 */ SyscallDesc("table", tableFunc),    /* 86 */ SyscallDesc("getitimer", unimplementedFunc),    /* 87 */ SyscallDesc("gethostname", gethostnameFunc),

⌨️ 快捷键说明

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