process.cc revision 2680
12207SN/A/* 22207SN/A * Copyright (c) 2003-2004 The Regents of The University of Michigan 32207SN/A * All rights reserved. 42207SN/A * 52207SN/A * Redistribution and use in source and binary forms, with or without 62207SN/A * modification, are permitted provided that the following conditions are 72207SN/A * met: redistributions of source code must retain the above copyright 82207SN/A * notice, this list of conditions and the following disclaimer; 92207SN/A * redistributions in binary form must reproduce the above copyright 102207SN/A * notice, this list of conditions and the following disclaimer in the 112207SN/A * documentation and/or other materials provided with the distribution; 122207SN/A * neither the name of the copyright holders nor the names of its 132207SN/A * contributors may be used to endorse or promote products derived from 142207SN/A * this software without specific prior written permission. 152207SN/A * 162207SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172207SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182207SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192207SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202207SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212207SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222207SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232207SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242207SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252207SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262207SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Gabe Black 292665Ssaidi@eecs.umich.edu * Ali Saidi 302207SN/A */ 312207SN/A 322474SN/A#include "arch/alpha/constants.hh" 332207SN/A#include "arch/alpha/process.hh" 342454SN/A#include "arch/alpha/linux/process.hh" 352454SN/A#include "arch/alpha/tru64/process.hh" 362454SN/A#include "base/loader/object_file.hh" 372454SN/A#include "base/misc.hh" 382680Sktlim@umich.edu#include "cpu/thread_context.hh" 392474SN/A#include "sim/builder.hh" 402474SN/A#include "sim/system.hh" 412207SN/A 422207SN/A 432474SN/Ausing namespace AlphaISA; 442474SN/Ausing namespace std; 452474SN/A 462474SN/AAlphaLiveProcess * 472474SN/AAlphaLiveProcess::create(const std::string &nm, System *system, int stdin_fd, 482474SN/A int stdout_fd, int stderr_fd, std::string executable, 492207SN/A std::vector<std::string> &argv, std::vector<std::string> &envp) 502207SN/A{ 512474SN/A AlphaLiveProcess *process = NULL; 522474SN/A 532474SN/A ObjectFile *objFile = createObjectFile(executable); 542474SN/A if (objFile == NULL) { 552474SN/A fatal("Can't load object file %s", executable); 562474SN/A } 572474SN/A 582474SN/A 592207SN/A if (objFile->getArch() != ObjectFile::Alpha) 602207SN/A fatal("Object file does not match architecture."); 612207SN/A switch (objFile->getOpSys()) { 622207SN/A case ObjectFile::Tru64: 632423SN/A process = new AlphaTru64Process(nm, objFile, system, 642207SN/A stdin_fd, stdout_fd, stderr_fd, 652207SN/A argv, envp); 662207SN/A break; 672207SN/A 682207SN/A case ObjectFile::Linux: 692423SN/A process = new AlphaLinuxProcess(nm, objFile, system, 702207SN/A stdin_fd, stdout_fd, stderr_fd, 712207SN/A argv, envp); 722207SN/A break; 732207SN/A 742207SN/A default: 752207SN/A fatal("Unknown/unsupported operating system."); 762207SN/A } 772474SN/A 782474SN/A if (process == NULL) 792474SN/A fatal("Unknown error creating process object."); 802207SN/A return process; 812207SN/A} 822207SN/A 832474SN/AAlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile, 842474SN/A System *_system, int stdin_fd, int stdout_fd, int stderr_fd, 852474SN/A std::vector<std::string> &argv, std::vector<std::string> &envp) 862474SN/A : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, 872474SN/A argv, envp) 882474SN/A{ 892474SN/A brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 902474SN/A brk_point = roundUp(brk_point, VMPageSize); 912474SN/A 922474SN/A // Set up stack. On Alpha, stack goes below text section. This 932474SN/A // code should get moved to some architecture-specific spot. 942474SN/A stack_base = objFile->textBase() - (409600+4096); 952474SN/A 962474SN/A // Set up region for mmaps. Tru64 seems to start just above 0 and 972474SN/A // grow up from there. 982474SN/A mmap_start = mmap_end = 0x10000; 992474SN/A 1002474SN/A // Set pointer for next thread stack. Reserve 8M for main stack. 1012474SN/A next_thread_stack_base = stack_base - (8 * 1024 * 1024); 1022474SN/A 1032474SN/A} 1042474SN/A 1052474SN/Avoid 1062474SN/AAlphaLiveProcess::startup() 1072474SN/A{ 1082474SN/A argsInit(MachineBytes, VMPageSize); 1092474SN/A 1102680Sktlim@umich.edu threadContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer()); 1112474SN/A} 1122474SN/A 1132474SN/A 1142474SN/A 1152474SN/A 1162474SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess) 1172474SN/A 1182474SN/A VectorParam<string> cmd; 1192474SN/A Param<string> executable; 1202474SN/A Param<string> input; 1212474SN/A Param<string> output; 1222474SN/A VectorParam<string> env; 1232474SN/A SimObjectParam<System *> system; 1242474SN/A 1252474SN/AEND_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess) 1262474SN/A 1272474SN/A 1282474SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess) 1292474SN/A 1302474SN/A INIT_PARAM(cmd, "command line (executable plus arguments)"), 1312474SN/A INIT_PARAM(executable, "executable (overrides cmd[0] if set)"), 1322474SN/A INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"), 1332474SN/A INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"), 1342474SN/A INIT_PARAM(env, "environment settings"), 1352474SN/A INIT_PARAM(system, "system") 1362474SN/A 1372474SN/AEND_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess) 1382474SN/A 1392474SN/A 1402474SN/ACREATE_SIM_OBJECT(AlphaLiveProcess) 1412474SN/A{ 1422474SN/A string in = input; 1432474SN/A string out = output; 1442474SN/A 1452474SN/A // initialize file descriptors to default: same as simulator 1462474SN/A int stdin_fd, stdout_fd, stderr_fd; 1472474SN/A 1482474SN/A if (in == "stdin" || in == "cin") 1492474SN/A stdin_fd = STDIN_FILENO; 1502474SN/A else 1512474SN/A stdin_fd = Process::openInputFile(input); 1522474SN/A 1532474SN/A if (out == "stdout" || out == "cout") 1542474SN/A stdout_fd = STDOUT_FILENO; 1552474SN/A else if (out == "stderr" || out == "cerr") 1562474SN/A stdout_fd = STDERR_FILENO; 1572474SN/A else 1582474SN/A stdout_fd = Process::openOutputFile(out); 1592474SN/A 1602474SN/A stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; 1612474SN/A 1622474SN/A return AlphaLiveProcess::create(getInstanceName(), system, 1632474SN/A stdin_fd, stdout_fd, stderr_fd, 1642474SN/A (string)executable == "" ? cmd[0] : executable, 1652474SN/A cmd, env); 1662474SN/A} 1672474SN/A 1682474SN/A 1692474SN/AREGISTER_SIM_OBJECT("AlphaLiveProcess", AlphaLiveProcess) 1702474SN/A 171