process.cc revision 2561
12SN/A/*
29952Sdam.sunwoo@arm.com * Copyright (c) 2003-2004 The Regents of The University of Michigan
39952Sdam.sunwoo@arm.com * All rights reserved.
49952Sdam.sunwoo@arm.com *
59952Sdam.sunwoo@arm.com * Redistribution and use in source and binary forms, with or without
69952Sdam.sunwoo@arm.com * modification, are permitted provided that the following conditions are
79952Sdam.sunwoo@arm.com * met: redistributions of source code must retain the above copyright
89952Sdam.sunwoo@arm.com * notice, this list of conditions and the following disclaimer;
99952Sdam.sunwoo@arm.com * redistributions in binary form must reproduce the above copyright
109952Sdam.sunwoo@arm.com * notice, this list of conditions and the following disclaimer in the
119952Sdam.sunwoo@arm.com * documentation and/or other materials provided with the distribution;
129952Sdam.sunwoo@arm.com * neither the name of the copyright holders nor the names of its
139952Sdam.sunwoo@arm.com * contributors may be used to endorse or promote products derived from
141762SN/A * this software without specific prior written permission.
159983Sstever@gmail.com *
169983Sstever@gmail.com * 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.
272SN/A */
282SN/A
292SN/A#include "arch/alpha/constants.hh"
302SN/A#include "arch/alpha/process.hh"
312SN/A#include "arch/alpha/linux/process.hh"
322SN/A#include "arch/alpha/tru64/process.hh"
332SN/A#include "base/loader/object_file.hh"
342SN/A#include "base/misc.hh"
352SN/A#include "cpu/exec_context.hh"
362SN/A#include "sim/builder.hh"
372SN/A#include "sim/system.hh"
382SN/A
392SN/A
402SN/Ausing namespace AlphaISA;
412665Ssaidi@eecs.umich.eduusing namespace std;
422665Ssaidi@eecs.umich.edu
432SN/AAlphaLiveProcess *
442SN/AAlphaLiveProcess::create(const std::string &nm, System *system, int stdin_fd,
451798SN/A        int stdout_fd, int stderr_fd, std::string executable,
461798SN/A        std::vector<std::string> &argv, std::vector<std::string> &envp)
472SN/A{
489983Sstever@gmail.com    AlphaLiveProcess *process = NULL;
499952Sdam.sunwoo@arm.com
502SN/A    ObjectFile *objFile = createObjectFile(executable);
512SN/A    if (objFile == NULL) {
522SN/A        fatal("Can't load object file %s", executable);
532SN/A    }
549983Sstever@gmail.com
552SN/A
565606Snate@binkert.org    if (objFile->getArch() != ObjectFile::Alpha)
572SN/A        fatal("Object file does not match architecture.");
582SN/A    switch (objFile->getOpSys()) {
592SN/A      case ObjectFile::Tru64:
603144Shsul@eecs.umich.edu        process = new AlphaTru64Process(nm, objFile, system,
612SN/A                                        stdin_fd, stdout_fd, stderr_fd,
622SN/A                                        argv, envp);
639983Sstever@gmail.com        break;
6411070Sandreas.sandberg@arm.com
6513694Sgabeblack@google.com      case ObjectFile::Linux:
662SN/A        process = new AlphaLinuxProcess(nm, objFile, system,
679983Sstever@gmail.com                                        stdin_fd, stdout_fd, stderr_fd,
6811294Sandreas.hansson@arm.com                                        argv, envp);
699983Sstever@gmail.com        break;
709983Sstever@gmail.com
719983Sstever@gmail.com      default:
729983Sstever@gmail.com        fatal("Unknown/unsupported operating system.");
739983Sstever@gmail.com    }
749983Sstever@gmail.com
759983Sstever@gmail.com    if (process == NULL)
769983Sstever@gmail.com        fatal("Unknown error creating process object.");
779983Sstever@gmail.com    return process;
789983Sstever@gmail.com}
799983Sstever@gmail.com
809983Sstever@gmail.comAlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile,
819983Sstever@gmail.com        System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
829983Sstever@gmail.com        std::vector<std::string> &argv, std::vector<std::string> &envp)
839983Sstever@gmail.com    : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd,
849983Sstever@gmail.com        argv, envp)
8511070Sandreas.sandberg@arm.com{
869983Sstever@gmail.com    brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
879983Sstever@gmail.com    brk_point = roundUp(brk_point, VMPageSize);
8811294Sandreas.hansson@arm.com
892SN/A    // Set up stack.  On Alpha, stack goes below text section.  This
9011169Sandreas.hansson@arm.com    // code should get moved to some architecture-specific spot.
912SN/A    stack_base = objFile->textBase() - (409600+4096);
9211169Sandreas.hansson@arm.com
939952Sdam.sunwoo@arm.com    // Set up region for mmaps.  Tru64 seems to start just above 0 and
9411168Sandreas.hansson@arm.com    // grow up from there.
9511168Sandreas.hansson@arm.com    mmap_start = mmap_end = 0x10000;
962SN/A
972SN/A    // Set pointer for next thread stack.  Reserve 8M for main stack.
982SN/A    next_thread_stack_base = stack_base - (8 * 1024 * 1024);
992SN/A
1002SN/A}
1012SN/A
1022SN/Avoid
1032SN/AAlphaLiveProcess::startup()
1042SN/A{
1052SN/A    argsInit(MachineBytes, VMPageSize);
1065543Ssaidi@eecs.umich.edu
1075543Ssaidi@eecs.umich.edu    execContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer());
1082SN/A}
1092SN/A
1105606Snate@binkert.org
1112SN/A
11211169Sandreas.hansson@arm.com
1132SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess)
11411169Sandreas.hansson@arm.com
1152SN/A    VectorParam<string> cmd;
1162SN/A    Param<string> executable;
1172SN/A    Param<string> input;
1181798SN/A    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