process.cc (2680:246e7104f744) process.cc (2715:4032e02b525e)
1/*
2 * Copyright (c) 2001-2005 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;

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

45#include "mem/physical.hh"
46#include "mem/translating_port.hh"
47#include "sim/builder.hh"
48#include "sim/process.hh"
49#include "sim/stats.hh"
50#include "sim/syscall_emul.hh"
51#include "sim/system.hh"
52
1/*
2 * Copyright (c) 2001-2005 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;

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

45#include "mem/physical.hh"
46#include "mem/translating_port.hh"
47#include "sim/builder.hh"
48#include "sim/process.hh"
49#include "sim/stats.hh"
50#include "sim/syscall_emul.hh"
51#include "sim/system.hh"
52
53#include "arch/isa_specific.hh"
54#if THE_ISA == ALPHA_ISA
55#include "arch/alpha/linux/process.hh"
56#include "arch/alpha/tru64/process.hh"
57#elif THE_ISA == SPARC_ISA
58#include "arch/sparc/linux/process.hh"
59#include "arch/sparc/solaris/process.hh"
60#elif THE_ISA == MIPS_ISA
61#include "arch/mips/linux/process.hh"
62#else
63#error "THE_ISA not set"
64#endif
65
66
53using namespace std;
54using namespace TheISA;
55
56//
57// The purpose of this code is to fake the loader & syscall mechanism
58// when there's no OS: thus there's no resone to use it in FULL_SYSTEM
59// mode when we do have an OS
60//

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

357
358 SyscallDesc *desc = getDesc(callnum);
359 if (desc == NULL)
360 fatal("Syscall %d out of range", callnum);
361
362 desc->doSyscall(callnum, this, tc);
363}
364
67using namespace std;
68using namespace TheISA;
69
70//
71// The purpose of this code is to fake the loader & syscall mechanism
72// when there's no OS: thus there's no resone to use it in FULL_SYSTEM
73// mode when we do have an OS
74//

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

371
372 SyscallDesc *desc = getDesc(callnum);
373 if (desc == NULL)
374 fatal("Syscall %d out of range", callnum);
375
376 desc->doSyscall(callnum, this, tc);
377}
378
365DEFINE_SIM_OBJECT_CLASS_NAME("LiveProcess", LiveProcess);
379LiveProcess *
380LiveProcess::create(const std::string &nm, System *system, int stdin_fd,
381 int stdout_fd, int stderr_fd, std::string executable,
382 std::vector<std::string> &argv,
383 std::vector<std::string> &envp)
384{
385 LiveProcess *process = NULL;
386
387 ObjectFile *objFile = createObjectFile(executable);
388 if (objFile == NULL) {
389 fatal("Can't load object file %s", executable);
390 }
391
392#if THE_ISA == ALPHA_ISA
393 if (objFile->getArch() != ObjectFile::Alpha)
394 fatal("Object file architecture does not match compiled ISA (Alpha).");
395 switch (objFile->getOpSys()) {
396 case ObjectFile::Tru64:
397 process = new AlphaTru64Process(nm, objFile, system,
398 stdin_fd, stdout_fd, stderr_fd,
399 argv, envp);
400 break;
401
402 case ObjectFile::Linux:
403 process = new AlphaLinuxProcess(nm, objFile, system,
404 stdin_fd, stdout_fd, stderr_fd,
405 argv, envp);
406 break;
407
408 default:
409 fatal("Unknown/unsupported operating system.");
410 }
411#elif THE_ISA == SPARC_ISA
412 if (objFile->getArch() != ObjectFile::SPARC)
413 fatal("Object file architecture does not match compiled ISA (SPARC).");
414 switch (objFile->getOpSys()) {
415 case ObjectFile::Linux:
416 process = new SparcLinuxProcess(nm, objFile, system,
417 stdin_fd, stdout_fd, stderr_fd,
418 argv, envp);
419 break;
420
421
422 case ObjectFile::Solaris:
423 process = new SparcSolarisProcess(nm, objFile, system,
424 stdin_fd, stdout_fd, stderr_fd,
425 argv, envp);
426 break;
427 default:
428 fatal("Unknown/unsupported operating system.");
429 }
430#elif THE_ISA == MIPS_ISA
431 if (objFile->getArch() != ObjectFile::Mips)
432 fatal("Object file architecture does not match compiled ISA (MIPS).");
433 switch (objFile->getOpSys()) {
434 case ObjectFile::Linux:
435 process = new MipsLinuxProcess(nm, objFile, system,
436 stdin_fd, stdout_fd, stderr_fd,
437 argv, envp);
438 break;
439
440 default:
441 fatal("Unknown/unsupported operating system.");
442 }
443#else
444#error "THE_ISA not set"
445#endif
446
447
448 if (process == NULL)
449 fatal("Unknown error creating process object.");
450 return process;
451}
452
453
454BEGIN_DECLARE_SIM_OBJECT_PARAMS(LiveProcess)
455
456 VectorParam<string> cmd;
457 Param<string> executable;
458 Param<string> input;
459 Param<string> output;
460 VectorParam<string> env;
461 SimObjectParam<System *> system;
462
463END_DECLARE_SIM_OBJECT_PARAMS(LiveProcess)
464
465
466BEGIN_INIT_SIM_OBJECT_PARAMS(LiveProcess)
467
468 INIT_PARAM(cmd, "command line (executable plus arguments)"),
469 INIT_PARAM(executable, "executable (overrides cmd[0] if set)"),
470 INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"),
471 INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"),
472 INIT_PARAM(env, "environment settings"),
473 INIT_PARAM(system, "system")
474
475END_INIT_SIM_OBJECT_PARAMS(LiveProcess)
476
477
478CREATE_SIM_OBJECT(LiveProcess)
479{
480 string in = input;
481 string out = output;
482
483 // initialize file descriptors to default: same as simulator
484 int stdin_fd, stdout_fd, stderr_fd;
485
486 if (in == "stdin" || in == "cin")
487 stdin_fd = STDIN_FILENO;
488 else
489 stdin_fd = Process::openInputFile(input);
490
491 if (out == "stdout" || out == "cout")
492 stdout_fd = STDOUT_FILENO;
493 else if (out == "stderr" || out == "cerr")
494 stdout_fd = STDERR_FILENO;
495 else
496 stdout_fd = Process::openOutputFile(out);
497
498 stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO;
499
500 return LiveProcess::create(getInstanceName(), system,
501 stdin_fd, stdout_fd, stderr_fd,
502 (string)executable == "" ? cmd[0] : executable,
503 cmd, env);
504}
505
506
507REGISTER_SIM_OBJECT("LiveProcess", LiveProcess)