process.cc revision 2686
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 302686Sksewell@umich.edu * Korey Sewell 312207SN/A */ 322207SN/A 332474SN/A#include "arch/mips/isa_traits.hh" 342207SN/A#include "arch/mips/process.hh" 352597SN/A#include "arch/mips/linux/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 422447SN/Ausing namespace std; 432474SN/Ausing namespace MipsISA; 442447SN/A 452474SN/A 462474SN/AMipsLiveProcess * 472474SN/AMipsLiveProcess::create(const std::string &nm, System *system, int stdin_fd, 482474SN/A int stdout_fd, int stderr_fd, std::string executable, 492474SN/A std::vector<std::string> &argv, std::vector<std::string> &envp) 502207SN/A{ 512474SN/A MipsLiveProcess *process = NULL; 522207SN/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 592472SN/A if (objFile->getArch() != ObjectFile::Mips) 602686Sksewell@umich.edu fatal("Object file does not match MIPS architecture."); 612686Sksewell@umich.edu 622207SN/A switch (objFile->getOpSys()) { 632207SN/A case ObjectFile::Linux: 642474SN/A process = new MipsLinuxProcess(nm, objFile, system, 652207SN/A stdin_fd, stdout_fd, stderr_fd, 662207SN/A argv, envp); 672207SN/A break; 682207SN/A 692207SN/A default: 702207SN/A fatal("Unknown/unsupported operating system."); 712207SN/A } 722474SN/A 732474SN/A if (process == NULL) 742474SN/A fatal("Unknown error creating process object."); 752207SN/A return process; 762207SN/A} 772207SN/A 782474SN/AMipsLiveProcess::MipsLiveProcess(const std::string &nm, ObjectFile *objFile, 792474SN/A System *_system, int stdin_fd, int stdout_fd, int stderr_fd, 802474SN/A std::vector<std::string> &argv, std::vector<std::string> &envp) 812474SN/A : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, 822474SN/A argv, envp) 832474SN/A{ 842686Sksewell@umich.edu // Set up stack. On MIPS, stack starts at the top of kuseg 852686Sksewell@umich.edu // user address space. MIPS stack grows down from here 862686Sksewell@umich.edu stack_base = 0x7FFFFFFF; 872474SN/A 882474SN/A // Set pointer for next thread stack. Reserve 8M for main stack. 892474SN/A next_thread_stack_base = stack_base - (8 * 1024 * 1024); 902474SN/A 912686Sksewell@umich.edu // Set up break point (Top of Heap) 922686Sksewell@umich.edu brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 932686Sksewell@umich.edu brk_point = roundUp(brk_point, VMPageSize); 942686Sksewell@umich.edu 952686Sksewell@umich.edu // Set up region for mmaps. For now, start at bottom of kuseg space. 962686Sksewell@umich.edu mmap_start = mmap_end = 0x10000; 972474SN/A} 982474SN/A 992474SN/Avoid 1002474SN/AMipsLiveProcess::startup() 1012474SN/A{ 1022474SN/A argsInit(MachineBytes, VMPageSize); 1032474SN/A} 1042474SN/A 1052474SN/A 1062474SN/A 1072474SN/A 1082474SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess) 1092474SN/A 1102474SN/A VectorParam<string> cmd; 1112474SN/A Param<string> executable; 1122474SN/A Param<string> input; 1132474SN/A Param<string> output; 1142474SN/A VectorParam<string> env; 1152474SN/A SimObjectParam<System *> system; 1162474SN/A 1172474SN/AEND_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess) 1182474SN/A 1192474SN/A 1202474SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess) 1212474SN/A 1222474SN/A INIT_PARAM(cmd, "command line (executable plus arguments)"), 1232474SN/A INIT_PARAM(executable, "executable (overrides cmd[0] if set)"), 1242474SN/A INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"), 1252474SN/A INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"), 1262474SN/A INIT_PARAM(env, "environment settings"), 1272474SN/A INIT_PARAM(system, "system") 1282474SN/A 1292474SN/AEND_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess) 1302474SN/A 1312474SN/A 1322474SN/ACREATE_SIM_OBJECT(MipsLiveProcess) 1332474SN/A{ 1342474SN/A string in = input; 1352474SN/A string out = output; 1362474SN/A 1372474SN/A // initialize file descriptors to default: same as simulator 1382474SN/A int stdin_fd, stdout_fd, stderr_fd; 1392474SN/A 1402474SN/A if (in == "stdin" || in == "cin") 1412474SN/A stdin_fd = STDIN_FILENO; 1422474SN/A else 1432474SN/A stdin_fd = Process::openInputFile(input); 1442474SN/A 1452474SN/A if (out == "stdout" || out == "cout") 1462474SN/A stdout_fd = STDOUT_FILENO; 1472474SN/A else if (out == "stderr" || out == "cerr") 1482474SN/A stdout_fd = STDERR_FILENO; 1492474SN/A else 1502474SN/A stdout_fd = Process::openOutputFile(out); 1512474SN/A 1522474SN/A stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; 1532474SN/A 1542474SN/A return MipsLiveProcess::create(getInstanceName(), system, 1552474SN/A stdin_fd, stdout_fd, stderr_fd, 1562474SN/A (string)executable == "" ? cmd[0] : executable, 1572474SN/A cmd, env); 1582474SN/A} 1592474SN/A 1602474SN/A 1612474SN/AREGISTER_SIM_OBJECT("MipsLiveProcess", MipsLiveProcess) 1622474SN/A 1632474SN/A 164