process.cc revision 2680
12SN/A/* 21458SN/A * Copyright (c) 2003-2004 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/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 302SN/A */ 312SN/A 321147SN/A#include "arch/mips/isa_traits.hh" 331147SN/A#include "arch/mips/process.hh" 342SN/A#include "arch/mips/linux/process.hh" 352037SN/A#include "base/loader/object_file.hh" 362037SN/A#include "base/misc.hh" 372428SN/A#include "cpu/thread_context.hh" 386216Snate@binkert.org#include "sim/builder.hh" 398542Sgblack@eecs.umich.edu#include "sim/system.hh" 402SN/A 415569Snate@binkert.orgusing namespace std; 422238SN/Ausing namespace MipsISA; 435569Snate@binkert.org 442107SN/A 455569Snate@binkert.orgMipsLiveProcess * 465569Snate@binkert.orgMipsLiveProcess::create(const std::string &nm, System *system, int stdin_fd, 475569Snate@binkert.org int stdout_fd, int stderr_fd, std::string executable, 485569Snate@binkert.org std::vector<std::string> &argv, std::vector<std::string> &envp) 495569Snate@binkert.org{ 505569Snate@binkert.org MipsLiveProcess *process = NULL; 515569Snate@binkert.org 525569Snate@binkert.org ObjectFile *objFile = createObjectFile(executable); 535569Snate@binkert.org if (objFile == NULL) { 545569Snate@binkert.org fatal("Can't load object file %s", executable); 555569Snate@binkert.org } 565569Snate@binkert.org 575569Snate@binkert.org 585569Snate@binkert.org if (objFile->getArch() != ObjectFile::Mips) 595569Snate@binkert.org fatal("Object file does not match architecture."); 605569Snate@binkert.org switch (objFile->getOpSys()) { 615569Snate@binkert.org case ObjectFile::Linux: 625569Snate@binkert.org process = new MipsLinuxProcess(nm, objFile, system, 635569Snate@binkert.org stdin_fd, stdout_fd, stderr_fd, 645569Snate@binkert.org argv, envp); 655569Snate@binkert.org break; 665569Snate@binkert.org 675569Snate@binkert.org default: 685569Snate@binkert.org fatal("Unknown/unsupported operating system."); 695569Snate@binkert.org } 705569Snate@binkert.org 715569Snate@binkert.org if (process == NULL) 725569Snate@binkert.org fatal("Unknown error creating process object."); 735569Snate@binkert.org return process; 745569Snate@binkert.org} 755569Snate@binkert.org 765569Snate@binkert.orgMipsLiveProcess::MipsLiveProcess(const std::string &nm, ObjectFile *objFile, 775569Snate@binkert.org System *_system, int stdin_fd, int stdout_fd, int stderr_fd, 785569Snate@binkert.org std::vector<std::string> &argv, std::vector<std::string> &envp) 795569Snate@binkert.org : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, 805569Snate@binkert.org argv, envp) 815569Snate@binkert.org{ 825569Snate@binkert.org 835569Snate@binkert.org // XXX all the below need to be updated for SPARC - Ali 845569Snate@binkert.org brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 855569Snate@binkert.org brk_point = roundUp(brk_point, VMPageSize); 865569Snate@binkert.org 875569Snate@binkert.org // Set up stack. On Alpha, stack goes below text section. This 885569Snate@binkert.org // code should get moved to some architecture-specific spot. 895569Snate@binkert.org stack_base = objFile->textBase() - (409600+4096); 905569Snate@binkert.org 915569Snate@binkert.org // Set up region for mmaps. Tru64 seems to start just above 0 and 925569Snate@binkert.org // grow up from there. 935569Snate@binkert.org mmap_start = mmap_end = 0x10000; 945569Snate@binkert.org 955569Snate@binkert.org // Set pointer for next thread stack. Reserve 8M for main stack. 965569Snate@binkert.org next_thread_stack_base = stack_base - (8 * 1024 * 1024); 975569Snate@binkert.org 985569Snate@binkert.org} 995569Snate@binkert.org 1005569Snate@binkert.orgvoid 1015569Snate@binkert.orgMipsLiveProcess::startup() 1025569Snate@binkert.org{ 1035569Snate@binkert.org argsInit(MachineBytes, VMPageSize); 1045569Snate@binkert.org} 1055569Snate@binkert.org 1065569Snate@binkert.org 1075569Snate@binkert.org 1085569Snate@binkert.org 1095569Snate@binkert.orgBEGIN_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess) 1105569Snate@binkert.org 1115569Snate@binkert.org VectorParam<string> cmd; 1125569Snate@binkert.org Param<string> executable; 1136227Snate@binkert.org Param<string> input; 1146227Snate@binkert.org Param<string> output; 1156227Snate@binkert.org VectorParam<string> env; 1165569Snate@binkert.org SimObjectParam<System *> system; 1176227Snate@binkert.org 1185569Snate@binkert.orgEND_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess) 1196227Snate@binkert.org 1206227Snate@binkert.org 1216227Snate@binkert.orgBEGIN_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess) 1228902Sandreas.hansson@arm.com 1236227Snate@binkert.org INIT_PARAM(cmd, "command line (executable plus arguments)"), 1245569Snate@binkert.org INIT_PARAM(executable, "executable (overrides cmd[0] if set)"), 1255569Snate@binkert.org INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"), 1265569Snate@binkert.org INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"), 1275569Snate@binkert.org INIT_PARAM(env, "environment settings"), 1285569Snate@binkert.org INIT_PARAM(system, "system") 1296974Stjones1@inf.ed.ac.uk 1306974Stjones1@inf.ed.ac.ukEND_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess) 1316974Stjones1@inf.ed.ac.uk 1325569Snate@binkert.org 1335569Snate@binkert.orgCREATE_SIM_OBJECT(MipsLiveProcess) 1341147SN/A{ 135 string in = input; 136 string out = output; 137 138 // initialize file descriptors to default: same as simulator 139 int stdin_fd, stdout_fd, stderr_fd; 140 141 if (in == "stdin" || in == "cin") 142 stdin_fd = STDIN_FILENO; 143 else 144 stdin_fd = Process::openInputFile(input); 145 146 if (out == "stdout" || out == "cout") 147 stdout_fd = STDOUT_FILENO; 148 else if (out == "stderr" || out == "cerr") 149 stdout_fd = STDERR_FILENO; 150 else 151 stdout_fd = Process::openOutputFile(out); 152 153 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; 154 155 return MipsLiveProcess::create(getInstanceName(), system, 156 stdin_fd, stdout_fd, stderr_fd, 157 (string)executable == "" ? cmd[0] : executable, 158 cmd, env); 159} 160 161 162REGISTER_SIM_OBJECT("MipsLiveProcess", MipsLiveProcess) 163 164 165