2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "arch/alpha/constants.hh"
30 #include "arch/alpha/process.hh"
31 #include "arch/alpha/linux/process.hh"
32 #include "arch/alpha/tru64/process.hh"
33 #include "base/loader/object_file.hh"
34 #include "base/misc.hh"
35 #include "cpu/exec_context.hh"
36 #include "sim/builder.hh"
37 #include "sim/system.hh"
40 using namespace AlphaISA
;
44 AlphaLiveProcess::create(const std::string
&nm
, System
*system
, int stdin_fd
,
45 int stdout_fd
, int stderr_fd
, std::string executable
,
46 std::vector
<std::string
> &argv
, std::vector
<std::string
> &envp
)
48 AlphaLiveProcess
*process
= NULL
;
50 ObjectFile
*objFile
= createObjectFile(executable
);
51 if (objFile
== NULL
) {
52 fatal("Can't load object file %s", executable
);
56 if (objFile
->getArch() != ObjectFile::Alpha
)
57 fatal("Object file does not match architecture.");
58 switch (objFile
->getOpSys()) {
59 case ObjectFile::Tru64
:
60 process
= new AlphaTru64Process(nm
, objFile
, system
,
61 stdin_fd
, stdout_fd
, stderr_fd
,
65 case ObjectFile::Linux
:
66 process
= new AlphaLinuxProcess(nm
, objFile
, system
,
67 stdin_fd
, stdout_fd
, stderr_fd
,
72 fatal("Unknown/unsupported operating system.");
76 fatal("Unknown error creating process object.");
80 AlphaLiveProcess::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
,
86 brk_point
= objFile
->dataBase() + objFile
->dataSize() + objFile
->bssSize();
87 brk_point
= roundUp(brk_point
, VMPageSize
);
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);
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;
97 // Set pointer for next thread stack. Reserve 8M for main stack.
98 next_thread_stack_base
= stack_base
- (8 * 1024 * 1024);
103 AlphaLiveProcess::startup()
105 argsInit(MachineBytes
, VMPageSize
);
107 execContexts
[0]->setIntReg(GlobalPointerReg
, objFile
->globalPointer());
113 BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess
)
115 VectorParam
<string
> cmd
;
116 Param
<string
> executable
;
118 Param
<string
> output
;
119 VectorParam
<string
> env
;
120 SimObjectParam
<System
*> system
;
122 END_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess
)
125 BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess
)
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")
134 END_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess
)
137 CREATE_SIM_OBJECT(AlphaLiveProcess
)
142 // initialize file descriptors to default: same as simulator
143 int stdin_fd
, stdout_fd
, stderr_fd
;
145 if (in
== "stdin" || in
== "cin")
146 stdin_fd
= STDIN_FILENO
;
148 stdin_fd
= Process::openInputFile(input
);
150 if (out
== "stdout" || out
== "cout")
151 stdout_fd
= STDOUT_FILENO
;
152 else if (out
== "stderr" || out
== "cerr")
153 stdout_fd
= STDERR_FILENO
;
155 stdout_fd
= Process::openOutputFile(out
);
157 stderr_fd
= (stdout_fd
!= STDOUT_FILENO
) ? stdout_fd
: STDERR_FILENO
;
159 return AlphaLiveProcess::create(getInstanceName(), system
,
160 stdin_fd
, stdout_fd
, stderr_fd
,
161 (string
)executable
== "" ? cmd
[0] : executable
,
166 REGISTER_SIM_OBJECT("AlphaLiveProcess", AlphaLiveProcess
)