process.cc revision 2474
14120Sgblack@eecs.umich.edu/* 24120Sgblack@eecs.umich.edu * Copyright (c) 2003-2004 The Regents of The University of Michigan 34120Sgblack@eecs.umich.edu * All rights reserved. 44120Sgblack@eecs.umich.edu * 54120Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 64120Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 74120Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 84120Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 94120Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 104120Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 114120Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 124120Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 134120Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 144120Sgblack@eecs.umich.edu * this software without specific prior written permission. 154120Sgblack@eecs.umich.edu * 164120Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174120Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184120Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194120Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204120Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214120Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224120Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234120Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244120Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254120Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264120Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274120Sgblack@eecs.umich.edu */ 284120Sgblack@eecs.umich.edu 294120Sgblack@eecs.umich.edu#include "arch/alpha/constants.hh" 304120Sgblack@eecs.umich.edu#include "arch/alpha/process.hh" 314120Sgblack@eecs.umich.edu#include "arch/alpha/linux/process.hh" 324120Sgblack@eecs.umich.edu#include "arch/alpha/tru64/process.hh" 334120Sgblack@eecs.umich.edu#include "base/loader/object_file.hh" 344151Sgblack@eecs.umich.edu#include "base/misc.hh" 354151Sgblack@eecs.umich.edu#include "cpu/exec_context.hh" 364151Sgblack@eecs.umich.edu#include "sim/builder.hh" 374151Sgblack@eecs.umich.edu#include "sim/system.hh" 384151Sgblack@eecs.umich.edu 394151Sgblack@eecs.umich.edu 404151Sgblack@eecs.umich.eduusing namespace AlphaISA; 414120Sgblack@eecs.umich.eduusing namespace std; 424120Sgblack@eecs.umich.edu 434120Sgblack@eecs.umich.eduAlphaLiveProcess * 444151Sgblack@eecs.umich.eduAlphaLiveProcess::create(const std::string &nm, System *system, int stdin_fd, 454151Sgblack@eecs.umich.edu int stdout_fd, int stderr_fd, std::string executable, 464151Sgblack@eecs.umich.edu std::vector<std::string> &argv, std::vector<std::string> &envp) 474151Sgblack@eecs.umich.edu{ 484151Sgblack@eecs.umich.edu AlphaLiveProcess *process = NULL; 494151Sgblack@eecs.umich.edu 504151Sgblack@eecs.umich.edu ObjectFile *objFile = createObjectFile(executable); 514151Sgblack@eecs.umich.edu if (objFile == NULL) { 524151Sgblack@eecs.umich.edu fatal("Can't load object file %s", executable); 534151Sgblack@eecs.umich.edu } 544151Sgblack@eecs.umich.edu 554151Sgblack@eecs.umich.edu 564120Sgblack@eecs.umich.edu if (objFile->getArch() != ObjectFile::Alpha) 574120Sgblack@eecs.umich.edu fatal("Object file does not match architecture."); 584120Sgblack@eecs.umich.edu switch (objFile->getOpSys()) { 59 case ObjectFile::Tru64: 60 process = new AlphaTru64Process(nm, objFile, system, 61 stdin_fd, stdout_fd, stderr_fd, 62 argv, envp); 63 break; 64 65 case ObjectFile::Linux: 66 process = new AlphaLinuxProcess(nm, objFile, system, 67 stdin_fd, stdout_fd, stderr_fd, 68 argv, envp); 69 break; 70 71 default: 72 fatal("Unknown/unsupported operating system."); 73 } 74 75 if (process == NULL) 76 fatal("Unknown error creating process object."); 77 return process; 78} 79 80AlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile, 81 System *_system, int stdin_fd, int stdout_fd, int stderr_fd, 82 std::vector<std::string> &argv, std::vector<std::string> &envp) 83 : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, 84 argv, envp) 85{ 86 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 87 brk_point = roundUp(brk_point, VMPageSize); 88 89 // Set up stack. On Alpha, stack goes below text section. This 90 // code should get moved to some architecture-specific spot. 91 stack_base = objFile->textBase() - (409600+4096); 92 93 // Set up region for mmaps. Tru64 seems to start just above 0 and 94 // grow up from there. 95 mmap_start = mmap_end = 0x10000; 96 97 // Set pointer for next thread stack. Reserve 8M for main stack. 98 next_thread_stack_base = stack_base - (8 * 1024 * 1024); 99 100} 101 102void 103AlphaLiveProcess::startup() 104{ 105 argsInit(MachineBytes, VMPageSize); 106 107 execContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer()); 108} 109 110 111 112 113BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess) 114 115 VectorParam<string> cmd; 116 Param<string> executable; 117 Param<string> input; 118 Param<string> output; 119 VectorParam<string> env; 120 SimObjectParam<System *> system; 121 122END_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess) 123 124 125BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess) 126 127 INIT_PARAM(cmd, "command line (executable plus arguments)"), 128 INIT_PARAM(executable, "executable (overrides cmd[0] if set)"), 129 INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"), 130 INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"), 131 INIT_PARAM(env, "environment settings"), 132 INIT_PARAM(system, "system") 133 134END_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess) 135 136 137CREATE_SIM_OBJECT(AlphaLiveProcess) 138{ 139 string in = input; 140 string out = output; 141 142 // initialize file descriptors to default: same as simulator 143 int stdin_fd, stdout_fd, stderr_fd; 144 145 if (in == "stdin" || in == "cin") 146 stdin_fd = STDIN_FILENO; 147 else 148 stdin_fd = Process::openInputFile(input); 149 150 if (out == "stdout" || out == "cout") 151 stdout_fd = STDOUT_FILENO; 152 else if (out == "stderr" || out == "cerr") 153 stdout_fd = STDERR_FILENO; 154 else 155 stdout_fd = Process::openOutputFile(out); 156 157 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; 158 159 return AlphaLiveProcess::create(getInstanceName(), system, 160 stdin_fd, stdout_fd, stderr_fd, 161 (string)executable == "" ? cmd[0] : executable, 162 cmd, env); 163} 164 165 166REGISTER_SIM_OBJECT("AlphaLiveProcess", AlphaLiveProcess) 167 168