Deleted Added
sdiff udiff text old ( 11813:d0586994a10e ) new ( 11851:824055fe6b30 )
full compact
1/*
2 * Copyright (c) 2014 Advanced Micro Devices, Inc.
3 * Copyright (c) 2012 ARM Limited
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating

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

56#include "base/intmath.hh"
57#include "base/loader/object_file.hh"
58#include "base/loader/symtab.hh"
59#include "base/statistics.hh"
60#include "config/the_isa.hh"
61#include "cpu/thread_context.hh"
62#include "mem/page_table.hh"
63#include "mem/se_translating_port_proxy.hh"
64#include "params/LiveProcess.hh"
65#include "params/Process.hh"
66#include "sim/emul_driver.hh"
67#include "sim/syscall_desc.hh"
68#include "sim/system.hh"
69
70#if THE_ISA == ALPHA_ISA
71#include "arch/alpha/linux/process.hh"
72#elif THE_ISA == SPARC_ISA

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

121}
122
123static int
124openOutputFile(const string &filename)
125{
126 return openFile(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
127}
128
129Process::Process(ProcessParams * params)
130 : SimObject(params), system(params->system),
131 brk_point(0), stack_base(0), stack_size(0), stack_min(0),
132 max_stack_size(params->max_stack_size),
133 next_thread_stack_base(0),
134 useArchPT(params->useArchPT),
135 kvmInSE(params->kvmInSE),
136 pTable(useArchPT ?
137 static_cast<PageTableBase *>(new ArchPageTable(name(), params->pid,

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

143 imap {{"", -1},
144 {"cin", STDIN_FILENO},
145 {"stdin", STDIN_FILENO}},
146 oemap{{"", -1},
147 {"cout", STDOUT_FILENO},
148 {"stdout", STDOUT_FILENO},
149 {"cerr", STDERR_FILENO},
150 {"stderr", STDERR_FILENO}},
151 _uid(params->uid), _euid(params->euid),
152 _gid(params->gid), _egid(params->egid),
153 _pid(params->pid), _ppid(params->ppid)
154{
155 int sim_fd;
156 std::map<string,int>::iterator it;
157
158 // Search through the input options and set fd if match is found;
159 // otherwise, open an input file and seek to location.
160 FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
161 if ((it = imap.find(params->input)) != imap.end())

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

183 else
184 sim_fd = openOutputFile(params->errout);
185 fde_stderr->set(sim_fd, params->errout, O_WRONLY | O_CREAT | O_TRUNC,
186 0664, false);
187
188 mmap_end = 0;
189 nxm_start = nxm_end = 0;
190 // other parameters will be initialized when the program is loaded
191}
192
193
194void
195Process::regStats()
196{
197 SimObject::regStats();
198

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

491Process::map(Addr vaddr, Addr paddr, int size, bool cacheable)
492{
493 pTable->map(vaddr, paddr, size,
494 cacheable ? PageTableBase::Zero : PageTableBase::Uncacheable);
495 return true;
496}
497
498
499////////////////////////////////////////////////////////////////////////
500//
501// LiveProcess member definitions
502//
503////////////////////////////////////////////////////////////////////////
504
505
506LiveProcess::LiveProcess(LiveProcessParams *params, ObjectFile *_objFile)
507 : Process(params), objFile(_objFile),
508 argv(params->cmd), envp(params->env), cwd(params->cwd),
509 executable(params->executable),
510 drivers(params->drivers)
511{
512
513 // load up symbols, if any... these may be used for debugging or
514 // profiling.
515 if (!debugSymbolTable) {
516 debugSymbolTable = new SymbolTable();
517 if (!objFile->loadGlobalSymbols(debugSymbolTable) ||
518 !objFile->loadLocalSymbols(debugSymbolTable) ||
519 !objFile->loadWeakSymbols(debugSymbolTable)) {
520 // didn't load any symbols
521 delete debugSymbolTable;
522 debugSymbolTable = NULL;
523 }
524 }
525}
526
527void
528LiveProcess::syscall(int64_t callnum, ThreadContext *tc)
529{
530 num_syscalls++;
531
532 SyscallDesc *desc = getDesc(callnum);
533 if (desc == NULL)
534 fatal("Syscall %d out of range", callnum);
535
536 desc->doSyscall(callnum, this, tc);
537}
538
539IntReg
540LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width)
541{
542 return getSyscallArg(tc, i);
543}
544
545
546EmulatedDriver *
547LiveProcess::findDriver(std::string filename)
548{
549 for (EmulatedDriver *d : drivers) {
550 if (d->match(filename))
551 return d;
552 }
553
554 return NULL;
555}
556
557void
558LiveProcess::updateBias()
559{
560 ObjectFile *interp = objFile->getInterpreter();
561
562 if (!interp || !interp->relocatable())
563 return;
564
565 // Determine how large the interpreters footprint will be in the process
566 // address space.

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

575 // functions to make these adjustments.
576 mmap_end = mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
577
578 interp->updateBias(ld_bias);
579}
580
581
582ObjectFile *
583LiveProcess::getInterpreter()
584{
585 return objFile->getInterpreter();
586}
587
588
589Addr
590LiveProcess::getBias()
591{
592 ObjectFile *interp = getInterpreter();
593
594 return interp ? interp->bias() : objFile->bias();
595}
596
597
598Addr
599LiveProcess::getStartPC()
600{
601 ObjectFile *interp = getInterpreter();
602
603 return interp ? interp->entryPoint() : objFile->entryPoint();
604}
605
606
607LiveProcess *
608LiveProcess::create(LiveProcessParams * params)
609{
610 LiveProcess *process = NULL;
611
612 // If not specified, set the executable parameter equal to the
613 // simulated system's zeroth command line parameter
614 if (params->executable == "") {
615 params->executable = params->cmd[0];
616 }
617
618 ObjectFile *objFile = createObjectFile(params->executable);
619 if (objFile == NULL) {
620 fatal("Can't load object file %s", params->executable);
621 }
622
623#if THE_ISA == ALPHA_ISA
624 if (objFile->getArch() != ObjectFile::Alpha)
625 fatal("Object file architecture does not match compiled ISA (Alpha).");
626
627 switch (objFile->getOpSys()) {
628 case ObjectFile::UnknownOpSys:
629 warn("Unknown operating system; assuming Linux.");
630 // fall through
631 case ObjectFile::Linux:
632 process = new AlphaLinuxProcess(params, objFile);
633 break;
634
635 default:
636 fatal("Unknown/unsupported operating system.");
637 }
638#elif THE_ISA == SPARC_ISA
639 if (objFile->getArch() != ObjectFile::SPARC64 &&
640 objFile->getArch() != ObjectFile::SPARC32)
641 fatal("Object file architecture does not match compiled ISA (SPARC).");
642 switch (objFile->getOpSys()) {
643 case ObjectFile::UnknownOpSys:
644 warn("Unknown operating system; assuming Linux.");
645 // fall through
646 case ObjectFile::Linux:
647 if (objFile->getArch() == ObjectFile::SPARC64) {
648 process = new Sparc64LinuxProcess(params, objFile);
649 } else {
650 process = new Sparc32LinuxProcess(params, objFile);
651 }
652 break;
653
654
655 case ObjectFile::Solaris:
656 process = new SparcSolarisProcess(params, objFile);
657 break;
658
659 default:
660 fatal("Unknown/unsupported operating system.");
661 }
662#elif THE_ISA == X86_ISA
663 if (objFile->getArch() != ObjectFile::X86_64 &&
664 objFile->getArch() != ObjectFile::I386)
665 fatal("Object file architecture does not match compiled ISA (x86).");
666 switch (objFile->getOpSys()) {
667 case ObjectFile::UnknownOpSys:
668 warn("Unknown operating system; assuming Linux.");
669 // fall through
670 case ObjectFile::Linux:
671 if (objFile->getArch() == ObjectFile::X86_64) {
672 process = new X86_64LinuxProcess(params, objFile);
673 } else {
674 process = new I386LinuxProcess(params, objFile);
675 }
676 break;
677
678 default:
679 fatal("Unknown/unsupported operating system.");
680 }
681#elif THE_ISA == MIPS_ISA
682 if (objFile->getArch() != ObjectFile::Mips)
683 fatal("Object file architecture does not match compiled ISA (MIPS).");
684 switch (objFile->getOpSys()) {
685 case ObjectFile::UnknownOpSys:
686 warn("Unknown operating system; assuming Linux.");
687 // fall through
688 case ObjectFile::Linux:
689 process = new MipsLinuxProcess(params, objFile);
690 break;
691
692 default:
693 fatal("Unknown/unsupported operating system.");
694 }
695#elif THE_ISA == ARM_ISA
696 ObjectFile::Arch arch = objFile->getArch();
697 if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb &&
698 arch != ObjectFile::Arm64)
699 fatal("Object file architecture does not match compiled ISA (ARM).");
700 switch (objFile->getOpSys()) {
701 case ObjectFile::UnknownOpSys:
702 warn("Unknown operating system; assuming Linux.");
703 // fall through
704 case ObjectFile::Linux:
705 if (arch == ObjectFile::Arm64) {
706 process = new ArmLinuxProcess64(params, objFile,
707 objFile->getArch());
708 } else {
709 process = new ArmLinuxProcess32(params, objFile,
710 objFile->getArch());
711 }
712 break;
713 case ObjectFile::FreeBSD:
714 if (arch == ObjectFile::Arm64) {
715 process = new ArmFreebsdProcess64(params, objFile,
716 objFile->getArch());
717 } else {
718 process = new ArmFreebsdProcess32(params, objFile,
719 objFile->getArch());
720 }
721 break;
722 case ObjectFile::LinuxArmOABI:
723 fatal("M5 does not support ARM OABI binaries. Please recompile with an"
724 " EABI compiler.");
725 default:
726 fatal("Unknown/unsupported operating system.");
727 }
728#elif THE_ISA == POWER_ISA
729 if (objFile->getArch() != ObjectFile::Power)
730 fatal("Object file architecture does not match compiled ISA (Power).");
731 switch (objFile->getOpSys()) {
732 case ObjectFile::UnknownOpSys:
733 warn("Unknown operating system; assuming Linux.");
734 // fall through
735 case ObjectFile::Linux:
736 process = new PowerLinuxProcess(params, objFile);
737 break;
738
739 default:
740 fatal("Unknown/unsupported operating system.");
741 }
742#elif THE_ISA == RISCV_ISA
743 if (objFile->getArch() != ObjectFile::Riscv)
744 fatal("Object file architecture does not match compiled ISA (RISCV).");
745 switch (objFile->getOpSys()) {
746 case ObjectFile::UnknownOpSys:
747 warn("Unknown operating system; assuming Linux.");
748 // fall through
749 case ObjectFile::Linux:
750 process = new RiscvLinuxProcess(params, objFile);
751 break;
752 default:
753 fatal("Unknown/unsupported operating system.");
754 }
755#else
756#error "THE_ISA not set"
757#endif
758
759 if (process == NULL)
760 fatal("Unknown error creating process object.");
761 return process;
762}
763
764LiveProcess *
765LiveProcessParams::create()
766{
767 return LiveProcess::create(this);
768}