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/mips/isa_traits.hh" 332207SN/A#include "arch/mips/process.hh" 342597SN/A#include "arch/mips/linux/process.hh" 352454SN/A#include "base/loader/object_file.hh" 362454SN/A#include "base/misc.hh" 372680Sktlim@umich.edu#include "cpu/thread_context.hh" 382474SN/A#include "sim/builder.hh" 392474SN/A#include "sim/system.hh" 402207SN/A 412447SN/Ausing namespace std; 422474SN/Ausing namespace MipsISA; 432447SN/A 442474SN/A 452474SN/AMipsLiveProcess * 462474SN/AMipsLiveProcess::create(const std::string &nm, System *system, int stdin_fd, 472474SN/A int stdout_fd, int stderr_fd, std::string executable, 482474SN/A std::vector<std::string> &argv, std::vector<std::string> &envp) 492207SN/A{ 502474SN/A MipsLiveProcess *process = NULL; 512207SN/A 522474SN/A ObjectFile *objFile = createObjectFile(executable); 532474SN/A if (objFile == NULL) { 542474SN/A fatal("Can't load object file %s", executable); 552474SN/A } 562474SN/A 572474SN/A 582472SN/A if (objFile->getArch() != ObjectFile::Mips) 592207SN/A fatal("Object file does not match architecture."); 602207SN/A switch (objFile->getOpSys()) { 612207SN/A case ObjectFile::Linux: 622474SN/A process = new MipsLinuxProcess(nm, objFile, system, 632207SN/A stdin_fd, stdout_fd, stderr_fd, 642207SN/A argv, envp); 652207SN/A break; 662207SN/A 672207SN/A default: 682207SN/A fatal("Unknown/unsupported operating system."); 692207SN/A } 702474SN/A 712474SN/A if (process == NULL) 722474SN/A fatal("Unknown error creating process object."); 732207SN/A return process; 742207SN/A} 752207SN/A 762474SN/AMipsLiveProcess::MipsLiveProcess(const std::string &nm, ObjectFile *objFile, 772474SN/A System *_system, int stdin_fd, int stdout_fd, int stderr_fd, 782474SN/A std::vector<std::string> &argv, std::vector<std::string> &envp) 792474SN/A : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, 802474SN/A argv, envp) 812474SN/A{ 822207SN/A 832474SN/A // XXX all the below need to be updated for SPARC - Ali 842474SN/A brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 852474SN/A brk_point = roundUp(brk_point, VMPageSize); 862474SN/A 872474SN/A // Set up stack. On Alpha, stack goes below text section. This 882474SN/A // code should get moved to some architecture-specific spot. 892474SN/A stack_base = objFile->textBase() - (409600+4096); 902474SN/A 912474SN/A // Set up region for mmaps. Tru64 seems to start just above 0 and 922474SN/A // grow up from there. 932474SN/A mmap_start = mmap_end = 0x10000; 942474SN/A 952474SN/A // Set pointer for next thread stack. Reserve 8M for main stack. 962474SN/A next_thread_stack_base = stack_base - (8 * 1024 * 1024); 972474SN/A 982474SN/A} 992474SN/A 1002474SN/Avoid 1012474SN/AMipsLiveProcess::startup() 1022474SN/A{ 1032474SN/A argsInit(MachineBytes, VMPageSize); 1042474SN/A} 1052474SN/A 1062474SN/A 1072474SN/A 1082474SN/A 1092474SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess) 1102474SN/A 1112474SN/A VectorParam<string> cmd; 1122474SN/A Param<string> executable; 1132474SN/A Param<string> input; 1142474SN/A Param<string> output; 1152474SN/A VectorParam<string> env; 1162474SN/A SimObjectParam<System *> system; 1172474SN/A 1182474SN/AEND_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess) 1192474SN/A 1202474SN/A 1212474SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess) 1222474SN/A 1232474SN/A INIT_PARAM(cmd, "command line (executable plus arguments)"), 1242474SN/A INIT_PARAM(executable, "executable (overrides cmd[0] if set)"), 1252474SN/A INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"), 1262474SN/A INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"), 1272474SN/A INIT_PARAM(env, "environment settings"), 1282474SN/A INIT_PARAM(system, "system") 1292474SN/A 1302474SN/AEND_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess) 1312474SN/A 1322474SN/A 1332474SN/ACREATE_SIM_OBJECT(MipsLiveProcess) 1342474SN/A{ 1352474SN/A string in = input; 1362474SN/A string out = output; 1372474SN/A 1382474SN/A // initialize file descriptors to default: same as simulator 1392474SN/A int stdin_fd, stdout_fd, stderr_fd; 1402474SN/A 1412474SN/A if (in == "stdin" || in == "cin") 1422474SN/A stdin_fd = STDIN_FILENO; 1432474SN/A else 1442474SN/A stdin_fd = Process::openInputFile(input); 1452474SN/A 1462474SN/A if (out == "stdout" || out == "cout") 1472474SN/A stdout_fd = STDOUT_FILENO; 1482474SN/A else if (out == "stderr" || out == "cerr") 1492474SN/A stdout_fd = STDERR_FILENO; 1502474SN/A else 1512474SN/A stdout_fd = Process::openOutputFile(out); 1522474SN/A 1532474SN/A stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; 1542474SN/A 1552474SN/A return MipsLiveProcess::create(getInstanceName(), system, 1562474SN/A stdin_fd, stdout_fd, stderr_fd, 1572474SN/A (string)executable == "" ? cmd[0] : executable, 1582474SN/A cmd, env); 1592474SN/A} 1602474SN/A 1612474SN/A 1622474SN/AREGISTER_SIM_OBJECT("MipsLiveProcess", MipsLiveProcess) 1632474SN/A 1642474SN/A 165