process.cc (2680:246e7104f744) process.cc (2715:4032e02b525e)
1/*
2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Gabe Black
29 * Ali Saidi
30 */
31
32#include "arch/alpha/constants.hh"
33#include "arch/alpha/process.hh"
1/*
2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Gabe Black
29 * Ali Saidi
30 */
31
32#include "arch/alpha/constants.hh"
33#include "arch/alpha/process.hh"
34#include "arch/alpha/linux/process.hh"
35#include "arch/alpha/tru64/process.hh"
36#include "base/loader/object_file.hh"
37#include "base/misc.hh"
38#include "cpu/thread_context.hh"
34#include "base/loader/object_file.hh"
35#include "base/misc.hh"
36#include "cpu/thread_context.hh"
39#include "sim/builder.hh"
40#include "sim/system.hh"
41
42
43using namespace AlphaISA;
44using namespace std;
45
37#include "sim/system.hh"
38
39
40using namespace AlphaISA;
41using namespace std;
42
46AlphaLiveProcess *
47AlphaLiveProcess::create(const std::string &nm, System *system, int stdin_fd,
48 int stdout_fd, int stderr_fd, std::string executable,
49 std::vector<std::string> &argv, std::vector<std::string> &envp)
50{
51 AlphaLiveProcess *process = NULL;
52
53 ObjectFile *objFile = createObjectFile(executable);
54 if (objFile == NULL) {
55 fatal("Can't load object file %s", executable);
56 }
57
58
59 if (objFile->getArch() != ObjectFile::Alpha)
60 fatal("Object file does not match architecture.");
61 switch (objFile->getOpSys()) {
62 case ObjectFile::Tru64:
63 process = new AlphaTru64Process(nm, objFile, system,
64 stdin_fd, stdout_fd, stderr_fd,
65 argv, envp);
66 break;
67
68 case ObjectFile::Linux:
69 process = new AlphaLinuxProcess(nm, objFile, system,
70 stdin_fd, stdout_fd, stderr_fd,
71 argv, envp);
72 break;
73
74 default:
75 fatal("Unknown/unsupported operating system.");
76 }
77
78 if (process == NULL)
79 fatal("Unknown error creating process object.");
80 return process;
81}
82
83AlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile,
84 System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
85 std::vector<std::string> &argv, std::vector<std::string> &envp)
86 : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd,
87 argv, envp)
88{
89 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
90 brk_point = roundUp(brk_point, VMPageSize);
91
92 // Set up stack. On Alpha, stack goes below text section. This
93 // code should get moved to some architecture-specific spot.
94 stack_base = objFile->textBase() - (409600+4096);
95
96 // Set up region for mmaps. Tru64 seems to start just above 0 and
97 // grow up from there.
98 mmap_start = mmap_end = 0x10000;
99
100 // Set pointer for next thread stack. Reserve 8M for main stack.
101 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
102
103}
104
105void
106AlphaLiveProcess::startup()
107{
108 argsInit(MachineBytes, VMPageSize);
109
110 threadContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer());
111}
112
113
43AlphaLiveProcess::AlphaLiveProcess(const std::string &nm, ObjectFile *objFile,
44 System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
45 std::vector<std::string> &argv, std::vector<std::string> &envp)
46 : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd,
47 argv, envp)
48{
49 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
50 brk_point = roundUp(brk_point, VMPageSize);
51
52 // Set up stack. On Alpha, stack goes below text section. This
53 // code should get moved to some architecture-specific spot.
54 stack_base = objFile->textBase() - (409600+4096);
55
56 // Set up region for mmaps. Tru64 seems to start just above 0 and
57 // grow up from there.
58 mmap_start = mmap_end = 0x10000;
59
60 // Set pointer for next thread stack. Reserve 8M for main stack.
61 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
62
63}
64
65void
66AlphaLiveProcess::startup()
67{
68 argsInit(MachineBytes, VMPageSize);
69
70 threadContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer());
71}
72
73
114
115
116BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess)
117
118 VectorParam<string> cmd;
119 Param<string> executable;
120 Param<string> input;
121 Param<string> output;
122 VectorParam<string> env;
123 SimObjectParam<System *> system;
124
125END_DECLARE_SIM_OBJECT_PARAMS(AlphaLiveProcess)
126
127
128BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess)
129
130 INIT_PARAM(cmd, "command line (executable plus arguments)"),
131 INIT_PARAM(executable, "executable (overrides cmd[0] if set)"),
132 INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"),
133 INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"),
134 INIT_PARAM(env, "environment settings"),
135 INIT_PARAM(system, "system")
136
137END_INIT_SIM_OBJECT_PARAMS(AlphaLiveProcess)
138
139
140CREATE_SIM_OBJECT(AlphaLiveProcess)
141{
142 string in = input;
143 string out = output;
144
145 // initialize file descriptors to default: same as simulator
146 int stdin_fd, stdout_fd, stderr_fd;
147
148 if (in == "stdin" || in == "cin")
149 stdin_fd = STDIN_FILENO;
150 else
151 stdin_fd = Process::openInputFile(input);
152
153 if (out == "stdout" || out == "cout")
154 stdout_fd = STDOUT_FILENO;
155 else if (out == "stderr" || out == "cerr")
156 stdout_fd = STDERR_FILENO;
157 else
158 stdout_fd = Process::openOutputFile(out);
159
160 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
161
162 return AlphaLiveProcess::create(getInstanceName(), system,
163 stdin_fd, stdout_fd, stderr_fd,
164 (string)executable == "" ? cmd[0] : executable,
165 cmd, env);
166}
167
168
169REGISTER_SIM_OBJECT("AlphaLiveProcess", AlphaLiveProcess)
170