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/Process.hh" 65#include "sim/emul_driver.hh" 66#include "sim/syscall_desc.hh" 67#include "sim/system.hh" 68 69#if THE_ISA == ALPHA_ISA 70#include "arch/alpha/linux/process.hh" 71#elif THE_ISA == SPARC_ISA --- 48 unchanged lines hidden (view full) --- 120} 121 122static int 123openOutputFile(const string &filename) 124{ 125 return openFile(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664); 126} 127 |
128Process::Process(ProcessParams * params, ObjectFile * obj_file) |
129 : SimObject(params), system(params->system), 130 brk_point(0), stack_base(0), stack_size(0), stack_min(0), 131 max_stack_size(params->max_stack_size), 132 next_thread_stack_base(0), 133 useArchPT(params->useArchPT), 134 kvmInSE(params->kvmInSE), 135 pTable(useArchPT ? 136 static_cast<PageTableBase *>(new ArchPageTable(name(), params->pid, --- 5 unchanged lines hidden (view full) --- 142 imap {{"", -1}, 143 {"cin", STDIN_FILENO}, 144 {"stdin", STDIN_FILENO}}, 145 oemap{{"", -1}, 146 {"cout", STDOUT_FILENO}, 147 {"stdout", STDOUT_FILENO}, 148 {"cerr", STDERR_FILENO}, 149 {"stderr", STDERR_FILENO}}, |
150 objFile(obj_file), 151 argv(params->cmd), envp(params->env), cwd(params->cwd), 152 executable(params->executable), |
153 _uid(params->uid), _euid(params->euid), 154 _gid(params->gid), _egid(params->egid), |
155 _pid(params->pid), _ppid(params->ppid), 156 drivers(params->drivers) |
157{ 158 int sim_fd; 159 std::map<string,int>::iterator it; 160 161 // Search through the input options and set fd if match is found; 162 // otherwise, open an input file and seek to location. 163 FDEntry *fde_stdin = getFDEntry(STDIN_FILENO); 164 if ((it = imap.find(params->input)) != imap.end()) --- 21 unchanged lines hidden (view full) --- 186 else 187 sim_fd = openOutputFile(params->errout); 188 fde_stderr->set(sim_fd, params->errout, O_WRONLY | O_CREAT | O_TRUNC, 189 0664, false); 190 191 mmap_end = 0; 192 nxm_start = nxm_end = 0; 193 // other parameters will be initialized when the program is loaded |
194 195 // load up symbols, if any... these may be used for debugging or 196 // profiling. 197 if (!debugSymbolTable) { 198 debugSymbolTable = new SymbolTable(); 199 if (!objFile->loadGlobalSymbols(debugSymbolTable) || 200 !objFile->loadLocalSymbols(debugSymbolTable) || 201 !objFile->loadWeakSymbols(debugSymbolTable)) { 202 // didn't load any symbols 203 delete debugSymbolTable; 204 debugSymbolTable = NULL; 205 } 206 } |
207} 208 209 210void 211Process::regStats() 212{ 213 SimObject::regStats(); 214 --- 292 unchanged lines hidden (view full) --- 507Process::map(Addr vaddr, Addr paddr, int size, bool cacheable) 508{ 509 pTable->map(vaddr, paddr, size, 510 cacheable ? PageTableBase::Zero : PageTableBase::Uncacheable); 511 return true; 512} 513 514 |
515void |
516Process::syscall(int64_t callnum, ThreadContext *tc) |
517{ 518 num_syscalls++; 519 520 SyscallDesc *desc = getDesc(callnum); 521 if (desc == NULL) 522 fatal("Syscall %d out of range", callnum); 523 524 desc->doSyscall(callnum, this, tc); 525} 526 527IntReg |
528Process::getSyscallArg(ThreadContext *tc, int &i, int width) |
529{ 530 return getSyscallArg(tc, i); 531} 532 533 534EmulatedDriver * |
535Process::findDriver(std::string filename) |
536{ 537 for (EmulatedDriver *d : drivers) { 538 if (d->match(filename)) 539 return d; 540 } 541 542 return NULL; 543} 544 545void |
546Process::updateBias() |
547{ 548 ObjectFile *interp = objFile->getInterpreter(); 549 550 if (!interp || !interp->relocatable()) 551 return; 552 553 // Determine how large the interpreters footprint will be in the process 554 // address space. --- 8 unchanged lines hidden (view full) --- 563 // functions to make these adjustments. 564 mmap_end = mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize; 565 566 interp->updateBias(ld_bias); 567} 568 569 570ObjectFile * |
571Process::getInterpreter() |
572{ 573 return objFile->getInterpreter(); 574} 575 576 577Addr |
578Process::getBias() |
579{ 580 ObjectFile *interp = getInterpreter(); 581 582 return interp ? interp->bias() : objFile->bias(); 583} 584 585 586Addr |
587Process::getStartPC() |
588{ 589 ObjectFile *interp = getInterpreter(); 590 591 return interp ? interp->entryPoint() : objFile->entryPoint(); 592} 593 594 |
595Process * 596ProcessParams::create() |
597{ |
598 Process *process = NULL; |
599 600 // If not specified, set the executable parameter equal to the 601 // simulated system's zeroth command line parameter |
602 if (executable == "") { 603 executable = cmd[0]; |
604 } 605 |
606 ObjectFile *obj_file = createObjectFile(executable); 607 if (obj_file == NULL) { 608 fatal("Can't load object file %s", executable); |
609 } 610 611#if THE_ISA == ALPHA_ISA |
612 if (obj_file->getArch() != ObjectFile::Alpha) |
613 fatal("Object file architecture does not match compiled ISA (Alpha)."); 614 |
615 switch (obj_file->getOpSys()) { |
616 case ObjectFile::UnknownOpSys: 617 warn("Unknown operating system; assuming Linux."); 618 // fall through 619 case ObjectFile::Linux: |
620 process = new AlphaLinuxProcess(this, obj_file); |
621 break; 622 623 default: 624 fatal("Unknown/unsupported operating system."); 625 } 626#elif THE_ISA == SPARC_ISA |
627 if (obj_file->getArch() != ObjectFile::SPARC64 && 628 obj_file->getArch() != ObjectFile::SPARC32) |
629 fatal("Object file architecture does not match compiled ISA (SPARC)."); |
630 switch (obj_file->getOpSys()) { |
631 case ObjectFile::UnknownOpSys: 632 warn("Unknown operating system; assuming Linux."); 633 // fall through 634 case ObjectFile::Linux: |
635 if (obj_file->getArch() == ObjectFile::SPARC64) { 636 process = new Sparc64LinuxProcess(this, obj_file); |
637 } else { |
638 process = new Sparc32LinuxProcess(this, obj_file); |
639 } 640 break; 641 642 643 case ObjectFile::Solaris: |
644 process = new SparcSolarisProcess(this, obj_file); |
645 break; 646 647 default: 648 fatal("Unknown/unsupported operating system."); 649 } 650#elif THE_ISA == X86_ISA |
651 if (obj_file->getArch() != ObjectFile::X86_64 && 652 obj_file->getArch() != ObjectFile::I386) |
653 fatal("Object file architecture does not match compiled ISA (x86)."); |
654 switch (obj_file->getOpSys()) { |
655 case ObjectFile::UnknownOpSys: 656 warn("Unknown operating system; assuming Linux."); 657 // fall through 658 case ObjectFile::Linux: |
659 if (obj_file->getArch() == ObjectFile::X86_64) { 660 process = new X86_64LinuxProcess(this, obj_file); |
661 } else { |
662 process = new I386LinuxProcess(this, obj_file); |
663 } 664 break; 665 666 default: 667 fatal("Unknown/unsupported operating system."); 668 } 669#elif THE_ISA == MIPS_ISA |
670 if (obj_file->getArch() != ObjectFile::Mips) |
671 fatal("Object file architecture does not match compiled ISA (MIPS)."); |
672 switch (obj_file->getOpSys()) { |
673 case ObjectFile::UnknownOpSys: 674 warn("Unknown operating system; assuming Linux."); 675 // fall through 676 case ObjectFile::Linux: |
677 process = new MipsLinuxProcess(this, obj_file); |
678 break; 679 680 default: 681 fatal("Unknown/unsupported operating system."); 682 } 683#elif THE_ISA == ARM_ISA |
684 ObjectFile::Arch arch = obj_file->getArch(); |
685 if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb && 686 arch != ObjectFile::Arm64) 687 fatal("Object file architecture does not match compiled ISA (ARM)."); |
688 switch (obj_file->getOpSys()) { |
689 case ObjectFile::UnknownOpSys: 690 warn("Unknown operating system; assuming Linux."); 691 // fall through 692 case ObjectFile::Linux: 693 if (arch == ObjectFile::Arm64) { |
694 process = new ArmLinuxProcess64(this, obj_file, 695 obj_file->getArch()); |
696 } else { |
697 process = new ArmLinuxProcess32(this, obj_file, 698 obj_file->getArch()); |
699 } 700 break; 701 case ObjectFile::FreeBSD: 702 if (arch == ObjectFile::Arm64) { |
703 process = new ArmFreebsdProcess64(this, obj_file, 704 obj_file->getArch()); |
705 } else { |
706 process = new ArmFreebsdProcess32(this, obj_file, 707 obj_file->getArch()); |
708 } 709 break; 710 case ObjectFile::LinuxArmOABI: 711 fatal("M5 does not support ARM OABI binaries. Please recompile with an" 712 " EABI compiler."); 713 default: 714 fatal("Unknown/unsupported operating system."); 715 } 716#elif THE_ISA == POWER_ISA |
717 if (obj_file->getArch() != ObjectFile::Power) |
718 fatal("Object file architecture does not match compiled ISA (Power)."); |
719 switch (obj_file->getOpSys()) { |
720 case ObjectFile::UnknownOpSys: 721 warn("Unknown operating system; assuming Linux."); 722 // fall through 723 case ObjectFile::Linux: |
724 process = new PowerLinuxProcess(this, obj_file); |
725 break; 726 727 default: 728 fatal("Unknown/unsupported operating system."); 729 } 730#elif THE_ISA == RISCV_ISA |
731 if (obj_file->getArch() != ObjectFile::Riscv) |
732 fatal("Object file architecture does not match compiled ISA (RISCV)."); |
733 switch (obj_file->getOpSys()) { |
734 case ObjectFile::UnknownOpSys: 735 warn("Unknown operating system; assuming Linux."); 736 // fall through 737 case ObjectFile::Linux: |
738 process = new RiscvLinuxProcess(this, obj_file); |
739 break; 740 default: 741 fatal("Unknown/unsupported operating system."); 742 } 743#else 744#error "THE_ISA not set" 745#endif 746 747 if (process == NULL) 748 fatal("Unknown error creating process object."); 749 return process; 750} |