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.
33 #include "arch/mips/isa_traits.hh"
34 #include "arch/mips/process.hh"
35 #include "arch/mips/linux/process.hh"
36 #include "base/loader/object_file.hh"
37 #include "base/misc.hh"
38 #include "cpu/thread_context.hh"
39 #include "sim/builder.hh"
40 #include "sim/system.hh"
43 using namespace MipsISA
;
47 MipsLiveProcess::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
)
51 MipsLiveProcess
*process
= NULL
;
53 ObjectFile
*objFile
= createObjectFile(executable
);
54 if (objFile
== NULL
) {
55 fatal("Can't load object file %s", executable
);
59 if (objFile
->getArch() != ObjectFile::Mips
)
60 fatal("Object file does not match MIPS architecture.");
62 switch (objFile
->getOpSys()) {
63 case ObjectFile::Linux
:
64 process
= new MipsLinuxProcess(nm
, objFile
, system
,
65 stdin_fd
, stdout_fd
, stderr_fd
,
70 fatal("Unknown/unsupported operating system.");
74 fatal("Unknown error creating process object.");
78 MipsLiveProcess::MipsLiveProcess(const std::string
&nm
, ObjectFile
*objFile
,
79 System
*_system
, int stdin_fd
, int stdout_fd
, int stderr_fd
,
80 std::vector
<std::string
> &argv
, std::vector
<std::string
> &envp
)
81 : LiveProcess(nm
, objFile
, _system
, stdin_fd
, stdout_fd
, stderr_fd
,
84 // Set up stack. On MIPS, stack starts at the top of kuseg
85 // user address space. MIPS stack grows down from here
86 stack_base
= 0x7FFFFFFF;
88 // Set pointer for next thread stack. Reserve 8M for main stack.
89 next_thread_stack_base
= stack_base
- (8 * 1024 * 1024);
91 // Set up break point (Top of Heap)
92 brk_point
= objFile
->dataBase() + objFile
->dataSize() + objFile
->bssSize();
93 brk_point
= roundUp(brk_point
, VMPageSize
);
95 // Set up region for mmaps. For now, start at bottom of kuseg space.
96 mmap_start
= mmap_end
= 0x10000;
100 MipsLiveProcess::startup()
102 argsInit(MachineBytes
, VMPageSize
);
108 BEGIN_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess
)
110 VectorParam
<string
> cmd
;
111 Param
<string
> executable
;
113 Param
<string
> output
;
114 VectorParam
<string
> env
;
115 SimObjectParam
<System
*> system
;
117 END_DECLARE_SIM_OBJECT_PARAMS(MipsLiveProcess
)
120 BEGIN_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess
)
122 INIT_PARAM(cmd
, "command line (executable plus arguments)"),
123 INIT_PARAM(executable
, "executable (overrides cmd[0] if set)"),
124 INIT_PARAM(input
, "filename for stdin (dflt: use sim stdin)"),
125 INIT_PARAM(output
, "filename for stdout/stderr (dflt: use sim stdout)"),
126 INIT_PARAM(env
, "environment settings"),
127 INIT_PARAM(system
, "system")
129 END_INIT_SIM_OBJECT_PARAMS(MipsLiveProcess
)
132 CREATE_SIM_OBJECT(MipsLiveProcess
)
137 // initialize file descriptors to default: same as simulator
138 int stdin_fd
, stdout_fd
, stderr_fd
;
140 if (in
== "stdin" || in
== "cin")
141 stdin_fd
= STDIN_FILENO
;
143 stdin_fd
= Process::openInputFile(input
);
145 if (out
== "stdout" || out
== "cout")
146 stdout_fd
= STDOUT_FILENO
;
147 else if (out
== "stderr" || out
== "cerr")
148 stdout_fd
= STDERR_FILENO
;
150 stdout_fd
= Process::openOutputFile(out
);
152 stderr_fd
= (stdout_fd
!= STDOUT_FILENO
) ? stdout_fd
: STDERR_FILENO
;
154 return MipsLiveProcess::create(getInstanceName(), system
,
155 stdin_fd
, stdout_fd
, stderr_fd
,
156 (string
)executable
== "" ? cmd
[0] : executable
,
161 REGISTER_SIM_OBJECT("MipsLiveProcess", MipsLiveProcess
)