process.cc revision 2561
11689SN/A/* 21689SN/A * Copyright (c) 2003-2004 The Regents of The University of Michigan 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * Redistribution and use in source and binary forms, with or without 61689SN/A * modification, are permitted provided that the following conditions are 71689SN/A * met: redistributions of source code must retain the above copyright 81689SN/A * notice, this list of conditions and the following disclaimer; 91689SN/A * redistributions in binary form must reproduce the above copyright 101689SN/A * notice, this list of conditions and the following disclaimer in the 111689SN/A * documentation and/or other materials provided with the distribution; 121689SN/A * neither the name of the copyright holders nor the names of its 131689SN/A * contributors may be used to endorse or promote products derived from 141689SN/A * this software without specific prior written permission. 151689SN/A * 161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu */ 282665Ssaidi@eecs.umich.edu 291689SN/A#include "arch/alpha/constants.hh" 301689SN/A#include "arch/alpha/process.hh" 312292SN/A#include "arch/alpha/linux/process.hh" 322292SN/A#include "arch/alpha/tru64/process.hh" 331060SN/A#include "base/loader/object_file.hh" 341060SN/A#include "base/misc.hh" 351060SN/A#include "cpu/exec_context.hh" 361060SN/A#include "sim/builder.hh" 376329Sgblack@eecs.umich.edu#include "sim/system.hh" 382669Sktlim@umich.edu 391684SN/A 401684SN/Ausing namespace AlphaISA; 416658Snate@binkert.orgusing namespace std; 421717SN/A 431060SN/AAlphaLiveProcess * 441060SN/AAlphaLiveProcess::create(const std::string &nm, System *system, int stdin_fd, 451060SN/A int stdout_fd, int stderr_fd, std::string executable, 461060SN/A std::vector<std::string> &argv, std::vector<std::string> &envp) 471060SN/A{ 481060SN/A AlphaLiveProcess *process = NULL; 491060SN/A 501060SN/A ObjectFile *objFile = createObjectFile(executable); 511060SN/A if (objFile == NULL) { 522292SN/A fatal("Can't load object file %s", executable); 532292SN/A } 542292SN/A 551060SN/A 561060SN/A if (objFile->getArch() != ObjectFile::Alpha) 571060SN/A fatal("Object file does not match architecture."); 581060SN/A switch (objFile->getOpSys()) { 591060SN/A case ObjectFile::Tru64: 601060SN/A process = new AlphaTru64Process(nm, objFile, system, 611061SN/A stdin_fd, stdout_fd, stderr_fd, 621060SN/A argv, envp); 631060SN/A break; 641061SN/A 651060SN/A case ObjectFile::Linux: 661060SN/A process = new AlphaLinuxProcess(nm, objFile, system, 671060SN/A stdin_fd, stdout_fd, stderr_fd, 681060SN/A argv, envp); 691060SN/A break; 701060SN/A 711060SN/A default: 721060SN/A fatal("Unknown/unsupported operating system."); 731060SN/A } 741060SN/A 751060SN/A if (process == NULL) 761060SN/A fatal("Unknown error creating process object."); 771060SN/A return process; 781060SN/A} 791060SN/A 801060SN/AAlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile, 811060SN/A System *_system, int stdin_fd, int stdout_fd, int stderr_fd, 822292SN/A std::vector<std::string> &argv, std::vector<std::string> &envp) 832292SN/A : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, 842292SN/A argv, envp) 852292SN/A{ 862292SN/A brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 872292SN/A brk_point = roundUp(brk_point, VMPageSize); 882292SN/A 896221Snate@binkert.org // Set up stack. On Alpha, stack goes below text section. This 902292SN/A // code should get moved to some architecture-specific spot. 911060SN/A stack_base = objFile->textBase() - (409600+4096); 921060SN/A 931060SN/A // Set up region for mmaps. Tru64 seems to start just above 0 and 941060SN/A // grow up from there. 952292SN/A mmap_start = mmap_end = 0x10000; 962292SN/A 972292SN/A // Set pointer for next thread stack. Reserve 8M for main stack. 982292SN/A next_thread_stack_base = stack_base - (8 * 1024 * 1024); 991684SN/A 1001060SN/A} 1012292SN/A 1021684SN/Avoid 1031060SN/AAlphaLiveProcess::startup() 1042292SN/A{ 1051684SN/A argsInit(MachineBytes, VMPageSize); 1061060SN/A 1072292SN/A execContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer()); 1081684SN/A} 1091060SN/A 1102292SN/A 1111684SN/A 1121060SN/A 1132292SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess) 1141060SN/A 1151060SN/A VectorParam<string> cmd; 1161060SN/A Param<string> executable; 1172292SN/A Param<string> input; 1181060SN/A Param<string> output; 1191060SN/A VectorParam<string> env; 1201060SN/A SimObjectParam<System *> system; 1212292SN/A 1221060SN/AEND_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess) 1231060SN/A 1241060SN/A 1252292SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess) 1261060SN/A 1271060SN/A INIT_PARAM(cmd, "command line (executable plus arguments)"), 1281060SN/A INIT_PARAM(executable, "executable (overrides cmd[0] if set)"), 1291060SN/A INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"), 1301060SN/A INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"), 1311060SN/A INIT_PARAM(env, "environment settings"), 1321060SN/A INIT_PARAM(system, "system") 1332292SN/A 1342292SN/AEND_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess) 1351060SN/A 1361060SN/A 1371060SN/ACREATE_SIM_OBJECT(AlphaLiveProcess) 1381060SN/A{ 1391060SN/A string in = input; 1401060SN/A string out = output; 1411060SN/A 1421060SN/A // initialize file descriptors to default: same as simulator 1431060SN/A int stdin_fd, stdout_fd, stderr_fd; 1441060SN/A 1451060SN/A if (in == "stdin" || in == "cin") 1461060SN/A stdin_fd = STDIN_FILENO; 1471060SN/A else 1481060SN/A stdin_fd = Process::openInputFile(input); 1492292SN/A 1502292SN/A if (out == "stdout" || out == "cout") 1511060SN/A stdout_fd = STDOUT_FILENO; 1521060SN/A else if (out == "stderr" || out == "cerr") 1531060SN/A stdout_fd = STDERR_FILENO; 1541060SN/A else 1551060SN/A stdout_fd = Process::openOutputFile(out); 1561060SN/A 1571060SN/A stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; 1581060SN/A 1591060SN/A return AlphaLiveProcess::create(getInstanceName(), system, 1601060SN/A stdin_fd, stdout_fd, stderr_fd, 1611060SN/A (string)executable == "" ? cmd[0] : executable, 1621060SN/A cmd, env); 1631060SN/A} 1641060SN/A 1652292SN/A 1661060SN/AREGISTER_SIM_OBJECT("AlphaLiveProcess", AlphaLiveProcess) 1671060SN/A 1681060SN/A