process.cc revision 2561
17199Sgblack@eecs.umich.edu/* 27199Sgblack@eecs.umich.edu * Copyright (c) 2003-2004 The Regents of The University of Michigan 310037SARM gem5 Developers * All rights reserved. 47199Sgblack@eecs.umich.edu * 57199Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 67199Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 77199Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 87199Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 97199Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 107199Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 117199Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 127199Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 137199Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 147199Sgblack@eecs.umich.edu * this software without specific prior written permission. 157199Sgblack@eecs.umich.edu * 167199Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177199Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187199Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197199Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207199Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217199Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227199Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237199Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247199Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257199Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267199Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277199Sgblack@eecs.umich.edu */ 287199Sgblack@eecs.umich.edu 297199Sgblack@eecs.umich.edu#include "arch/alpha/constants.hh" 307199Sgblack@eecs.umich.edu#include "arch/alpha/process.hh" 317199Sgblack@eecs.umich.edu#include "arch/alpha/linux/process.hh" 327199Sgblack@eecs.umich.edu#include "arch/alpha/tru64/process.hh" 337199Sgblack@eecs.umich.edu#include "base/loader/object_file.hh" 347199Sgblack@eecs.umich.edu#include "base/misc.hh" 357199Sgblack@eecs.umich.edu#include "cpu/exec_context.hh" 367199Sgblack@eecs.umich.edu#include "sim/builder.hh" 377199Sgblack@eecs.umich.edu#include "sim/system.hh" 387199Sgblack@eecs.umich.edu 397199Sgblack@eecs.umich.edu 407199Sgblack@eecs.umich.eduusing namespace AlphaISA; 417199Sgblack@eecs.umich.eduusing namespace std; 427199Sgblack@eecs.umich.edu 4310474Sandreas.hansson@arm.comAlphaLiveProcess * 4410037SARM gem5 DevelopersAlphaLiveProcess::create(const std::string &nm, System *system, int stdin_fd, 4510037SARM gem5 Developers int stdout_fd, int stderr_fd, std::string executable, 4610037SARM gem5 Developers std::vector<std::string> &argv, std::vector<std::string> &envp) 4710037SARM gem5 Developers{ 4810037SARM gem5 Developers AlphaLiveProcess *process = NULL; 4910037SARM gem5 Developers 5010037SARM gem5 Developers ObjectFile *objFile = createObjectFile(executable); 5110037SARM gem5 Developers if (objFile == NULL) { 5210037SARM gem5 Developers fatal("Can't load object file %s", executable); 5310037SARM gem5 Developers } 5410037SARM gem5 Developers 5510037SARM gem5 Developers 5610037SARM gem5 Developers if (objFile->getArch() != ObjectFile::Alpha) 5710037SARM gem5 Developers fatal("Object file does not match architecture."); 5810037SARM gem5 Developers switch (objFile->getOpSys()) { 5910037SARM gem5 Developers case ObjectFile::Tru64: 6010037SARM gem5 Developers process = new AlphaTru64Process(nm, objFile, system, 6110037SARM gem5 Developers stdin_fd, stdout_fd, stderr_fd, 6210474Sandreas.hansson@arm.com argv, envp); 6310474Sandreas.hansson@arm.com break; 6410037SARM gem5 Developers 6510037SARM gem5 Developers case ObjectFile::Linux: 6610037SARM gem5 Developers process = new AlphaLinuxProcess(nm, objFile, system, 6710037SARM gem5 Developers stdin_fd, stdout_fd, stderr_fd, 6810474Sandreas.hansson@arm.com argv, envp); 6910037SARM gem5 Developers break; 7010037SARM gem5 Developers 718782Sgblack@eecs.umich.edu default: 7210037SARM gem5 Developers fatal("Unknown/unsupported operating system."); 738782Sgblack@eecs.umich.edu } 747199Sgblack@eecs.umich.edu 757199Sgblack@eecs.umich.edu if (process == NULL) 7610037SARM gem5 Developers fatal("Unknown error creating process object."); 7710037SARM gem5 Developers return process; 788628SAli.Saidi@ARM.com} 7910037SARM gem5 Developers 8010037SARM gem5 DevelopersAlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile, 8110037SARM gem5 Developers System *_system, int stdin_fd, int stdout_fd, int stderr_fd, 8210037SARM gem5 Developers std::vector<std::string> &argv, std::vector<std::string> &envp) 8310037SARM gem5 Developers : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd, 8410037SARM gem5 Developers argv, envp) 8510037SARM gem5 Developers{ 8610037SARM gem5 Developers brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 8710037SARM gem5 Developers brk_point = roundUp(brk_point, VMPageSize); 8810037SARM gem5 Developers 8910037SARM gem5 Developers // Set up stack. On Alpha, stack goes below text section. This 9010037SARM gem5 Developers // code should get moved to some architecture-specific spot. 9110037SARM gem5 Developers stack_base = objFile->textBase() - (409600+4096); 9210037SARM gem5 Developers 9310037SARM gem5 Developers // Set up region for mmaps. Tru64 seems to start just above 0 and 9410474Sandreas.hansson@arm.com // grow up from there. 9510037SARM gem5 Developers mmap_start = mmap_end = 0x10000; 9610037SARM gem5 Developers 9710037SARM gem5 Developers // Set pointer for next thread stack. Reserve 8M for main stack. 9810037SARM gem5 Developers next_thread_stack_base = stack_base - (8 * 1024 * 1024); 9910037SARM gem5 Developers 10010037SARM gem5 Developers} 10110037SARM gem5 Developers 10210037SARM gem5 Developersvoid 10310037SARM gem5 DevelopersAlphaLiveProcess::startup() 10410037SARM gem5 Developers{ 10510037SARM gem5 Developers argsInit(MachineBytes, VMPageSize); 10610037SARM gem5 Developers 10710037SARM gem5 Developers execContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer()); 10810037SARM gem5 Developers} 10910037SARM gem5 Developers 11010037SARM gem5 Developers 11110037SARM gem5 Developers 11210037SARM gem5 Developers 11310037SARM gem5 DevelopersBEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess) 11410037SARM gem5 Developers 11510037SARM gem5 Developers VectorParam<string> cmd; 11610037SARM gem5 Developers Param<string> executable; 11710037SARM gem5 Developers Param<string> input; 11810037SARM gem5 Developers Param<string> output; 11910037SARM gem5 Developers VectorParam<string> env; 12010037SARM gem5 Developers SimObjectParam<System *> system; 12110037SARM gem5 Developers 12210037SARM gem5 DevelopersEND_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess) 12310037SARM gem5 Developers 12410037SARM gem5 Developers 12510037SARM gem5 DevelopersBEGIN_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess) 12610037SARM gem5 Developers 12710037SARM gem5 Developers INIT_PARAM(cmd, "command line (executable plus arguments)"), 12810037SARM gem5 Developers INIT_PARAM(executable, "executable (overrides cmd[0] if set)"), 12910037SARM gem5 Developers INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"), 13010037SARM gem5 Developers INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"), 13110037SARM gem5 Developers INIT_PARAM(env, "environment settings"), 13210037SARM gem5 Developers INIT_PARAM(system, "system") 13310037SARM gem5 Developers 13410037SARM gem5 DevelopersEND_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess) 13510037SARM gem5 Developers 13610037SARM gem5 Developers 13710037SARM gem5 DevelopersCREATE_SIM_OBJECT(AlphaLiveProcess) 13810037SARM gem5 Developers{ 1397199Sgblack@eecs.umich.edu string in = input; 1407199Sgblack@eecs.umich.edu string out = output; 1417202Sgblack@eecs.umich.edu 1427202Sgblack@eecs.umich.edu // initialize file descriptors to default: same as simulator 1437202Sgblack@eecs.umich.edu int stdin_fd, stdout_fd, stderr_fd; 1447202Sgblack@eecs.umich.edu 1457202Sgblack@eecs.umich.edu if (in == "stdin" || in == "cin") 1468301SAli.Saidi@ARM.com stdin_fd = STDIN_FILENO; 1478303SAli.Saidi@ARM.com else 1488303SAli.Saidi@ARM.com stdin_fd = Process::openInputFile(input); 1498303SAli.Saidi@ARM.com 1508303SAli.Saidi@ARM.com if (out == "stdout" || out == "cout") 1518303SAli.Saidi@ARM.com stdout_fd = STDOUT_FILENO; 1528303SAli.Saidi@ARM.com else if (out == "stderr" || out == "cerr") 1538301SAli.Saidi@ARM.com stdout_fd = STDERR_FILENO; 1548301SAli.Saidi@ARM.com else 1557202Sgblack@eecs.umich.edu stdout_fd = Process::openOutputFile(out); 1567202Sgblack@eecs.umich.edu 1577599Sminkyu.jeong@arm.com stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; 1587783SGiacomo.Gabrielli@arm.com 1597202Sgblack@eecs.umich.edu return AlphaLiveProcess::create(getInstanceName(), system, 1607202Sgblack@eecs.umich.edu stdin_fd, stdout_fd, stderr_fd, 1617202Sgblack@eecs.umich.edu (string)executable == "" ? cmd[0] : executable, 1627202Sgblack@eecs.umich.edu cmd, env); 1637202Sgblack@eecs.umich.edu} 1647202Sgblack@eecs.umich.edu 1657202Sgblack@eecs.umich.edu 1667599Sminkyu.jeong@arm.comREGISTER_SIM_OBJECT("AlphaLiveProcess", AlphaLiveProcess) 1677783SGiacomo.Gabrielli@arm.com 1687202Sgblack@eecs.umich.edu