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;

--- 17 unchanged lines hidden (view full) ---

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/sparc/isa_traits.hh"
33#include "arch/sparc/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;

--- 17 unchanged lines hidden (view full) ---

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/sparc/isa_traits.hh"
33#include "arch/sparc/process.hh"
34#include "arch/sparc/linux/process.hh"
35#include "arch/sparc/solaris/process.hh"
36#include "base/loader/object_file.hh"
37#include "base/misc.hh"
38#include "cpu/thread_context.hh"
39#include "mem/page_table.hh"
40#include "mem/translating_port.hh"
34#include "base/loader/object_file.hh"
35#include "base/misc.hh"
36#include "cpu/thread_context.hh"
37#include "mem/page_table.hh"
38#include "mem/translating_port.hh"
41#include "sim/builder.hh"
42#include "sim/system.hh"
43
44using namespace std;
45using namespace SparcISA;
46
39#include "sim/system.hh"
40
41using namespace std;
42using namespace SparcISA;
43
47SparcLiveProcess *
48SparcLiveProcess::create(const std::string &nm, System *system, int stdin_fd,
49 int stdout_fd, int stderr_fd, std::string executable,
50 std::vector<std::string> &argv, std::vector<std::string> &envp)
51{
52 SparcLiveProcess *process = NULL;
53
44
54 ObjectFile *objFile = createObjectFile(executable);
55 if (objFile == NULL) {
56 fatal("Can't load object file %s", executable);
57 }
58
59
60 if (objFile->getArch() != ObjectFile::SPARC)
61 fatal("Object file with arch %x does not match architecture %x.",
62 objFile->getArch(), ObjectFile::SPARC);
63 switch (objFile->getOpSys()) {
64 case ObjectFile::Linux:
65 process = new SparcLinuxProcess(nm, objFile, system,
66 stdin_fd, stdout_fd, stderr_fd,
67 argv, envp);
68 break;
69
70
71 case ObjectFile::Solaris:
72 process = new SparcSolarisProcess(nm, objFile, system,
73 stdin_fd, stdout_fd, stderr_fd,
74 argv, envp);
75 break;
76 default:
77 fatal("Unknown/unsupported operating system.");
78 }
79
80 if (process == NULL)
81 fatal("Unknown error creating process object.");
82 return process;
83}
84
85SparcLiveProcess::SparcLiveProcess(const std::string &nm, ObjectFile *objFile,
86 System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
87 std::vector<std::string> &argv, std::vector<std::string> &envp)
88 : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd,
89 argv, envp)
90{
91
92 // XXX all the below need to be updated for SPARC - Ali

--- 224 unchanged lines hidden (view full) ---

317
318 Addr prog_entry = objFile->entryPoint();
319 threadContexts[0]->setPC(prog_entry);
320 threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
321 threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
322
323// num_processes++;
324}
45SparcLiveProcess::SparcLiveProcess(const std::string &nm, ObjectFile *objFile,
46 System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
47 std::vector<std::string> &argv, std::vector<std::string> &envp)
48 : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd,
49 argv, envp)
50{
51
52 // XXX all the below need to be updated for SPARC - Ali

--- 224 unchanged lines hidden (view full) ---

277
278 Addr prog_entry = objFile->entryPoint();
279 threadContexts[0]->setPC(prog_entry);
280 threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
281 threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
282
283// num_processes++;
284}
325
326
327BEGIN_DECLARE_SIM_OBJECT_PARAMS(SparcLiveProcess)
328
329 VectorParam<string> cmd;
330 Param<string> executable;
331 Param<string> input;
332 Param<string> output;
333 VectorParam<string> env;
334 SimObjectParam<System *> system;
335
336END_DECLARE_SIM_OBJECT_PARAMS(SparcLiveProcess)
337
338
339BEGIN_INIT_SIM_OBJECT_PARAMS(SparcLiveProcess)
340
341 INIT_PARAM(cmd, "command line (executable plus arguments)"),
342 INIT_PARAM(executable, "executable (overrides cmd[0] if set)"),
343 INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"),
344 INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"),
345 INIT_PARAM(env, "environment settings"),
346 INIT_PARAM(system, "system")
347
348END_INIT_SIM_OBJECT_PARAMS(SparcLiveProcess)
349
350
351CREATE_SIM_OBJECT(SparcLiveProcess)
352{
353 string in = input;
354 string out = output;
355
356 // initialize file descriptors to default: same as simulator
357 int stdin_fd, stdout_fd, stderr_fd;
358
359 if (in == "stdin" || in == "cin")
360 stdin_fd = STDIN_FILENO;
361 else
362 stdin_fd = Process::openInputFile(input);
363
364 if (out == "stdout" || out == "cout")
365 stdout_fd = STDOUT_FILENO;
366 else if (out == "stderr" || out == "cerr")
367 stdout_fd = STDERR_FILENO;
368 else
369 stdout_fd = Process::openOutputFile(out);
370
371 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
372
373 return SparcLiveProcess::create(getInstanceName(), system,
374 stdin_fd, stdout_fd, stderr_fd,
375 (string)executable == "" ? cmd[0] : executable,
376 cmd, env);
377}
378
379
380REGISTER_SIM_OBJECT("SparcLiveProcess", SparcLiveProcess)
381
382