process.cc revision 10810
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 9 * to a hardware implementation of the functionality of the software 10 * licensed hereunder. You may use the software subject to the license 11 * terms below provided that you ensure that this notice is replicated 12 * unmodified and in its entirety in all distributions of the software, 13 * modified or unmodified, in source code or in binary form. 14 * 15 * Copyright (c) 2001-2005 The Regents of The University of Michigan 16 * All rights reserved. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions are 20 * met: redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer; 22 * redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution; 25 * neither the name of the copyright holders nor the names of its 26 * contributors may be used to endorse or promote products derived from 27 * this software without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Authors: Nathan Binkert 42 * Steve Reinhardt 43 * Ali Saidi 44 */ 45 46#include <fcntl.h> 47#include <unistd.h> 48 49#include <cstdio> 50#include <string> 51 52#include "base/loader/object_file.hh" 53#include "base/loader/symtab.hh" 54#include "base/intmath.hh" 55#include "base/statistics.hh" 56#include "config/the_isa.hh" 57#include "cpu/thread_context.hh" 58#include "mem/page_table.hh" 59#include "mem/multi_level_page_table.hh" 60#include "mem/se_translating_port_proxy.hh" 61#include "params/LiveProcess.hh" 62#include "params/Process.hh" 63#include "sim/debug.hh" 64#include "sim/process.hh" 65#include "sim/process_impl.hh" 66#include "sim/stats.hh" 67#include "sim/syscall_emul.hh" 68#include "sim/system.hh" 69 70#if THE_ISA == ALPHA_ISA 71#include "arch/alpha/linux/process.hh" 72#include "arch/alpha/tru64/process.hh" 73#elif THE_ISA == SPARC_ISA 74#include "arch/sparc/linux/process.hh" 75#include "arch/sparc/solaris/process.hh" 76#elif THE_ISA == MIPS_ISA 77#include "arch/mips/linux/process.hh" 78#elif THE_ISA == ARM_ISA 79#include "arch/arm/linux/process.hh" 80#include "arch/arm/freebsd/process.hh" 81#elif THE_ISA == X86_ISA 82#include "arch/x86/linux/process.hh" 83#elif THE_ISA == POWER_ISA 84#include "arch/power/linux/process.hh" 85#else 86#error "THE_ISA not set" 87#endif 88 89 90using namespace std; 91using namespace TheISA; 92 93// current number of allocated processes 94int num_processes = 0; 95 96template<class IntType> 97AuxVector<IntType>::AuxVector(IntType type, IntType val) 98{ 99 a_type = TheISA::htog(type); 100 a_val = TheISA::htog(val); 101} 102 103template struct AuxVector<uint32_t>; 104template struct AuxVector<uint64_t>; 105 106Process::Process(ProcessParams * params) 107 : SimObject(params), system(params->system), 108 brk_point(0), stack_base(0), stack_size(0), stack_min(0), 109 max_stack_size(params->max_stack_size), 110 next_thread_stack_base(0), 111 M5_pid(system->allocatePID()), 112 useArchPT(params->useArchPT), 113 kvmInSE(params->kvmInSE), 114 pTable(useArchPT ? 115 static_cast<PageTableBase *>(new ArchPageTable(name(), M5_pid, system)) : 116 static_cast<PageTableBase *>(new FuncPageTable(name(), M5_pid)) ), 117 initVirtMem(system->getSystemPort(), this, 118 SETranslatingPortProxy::Always) 119{ 120 string in = params->input; 121 string out = params->output; 122 string err = params->errout; 123 124 // initialize file descriptors to default: same as simulator 125 int stdin_fd, stdout_fd, stderr_fd; 126 127 if (in == "stdin" || in == "cin") 128 stdin_fd = STDIN_FILENO; 129 else if (in == "None") 130 stdin_fd = -1; 131 else 132 stdin_fd = Process::openInputFile(in); 133 134 if (out == "stdout" || out == "cout") 135 stdout_fd = STDOUT_FILENO; 136 else if (out == "stderr" || out == "cerr") 137 stdout_fd = STDERR_FILENO; 138 else if (out == "None") 139 stdout_fd = -1; 140 else 141 stdout_fd = Process::openOutputFile(out); 142 143 if (err == "stdout" || err == "cout") 144 stderr_fd = STDOUT_FILENO; 145 else if (err == "stderr" || err == "cerr") 146 stderr_fd = STDERR_FILENO; 147 else if (err == "None") 148 stderr_fd = -1; 149 else if (err == out) 150 stderr_fd = stdout_fd; 151 else 152 stderr_fd = Process::openOutputFile(err); 153 154 // initialize first 3 fds (stdin, stdout, stderr) 155 Process::FdMap *fdo = &fd_map[STDIN_FILENO]; 156 fdo->fd = stdin_fd; 157 fdo->filename = in; 158 fdo->flags = O_RDONLY; 159 fdo->mode = -1; 160 fdo->fileOffset = 0; 161 162 fdo = &fd_map[STDOUT_FILENO]; 163 fdo->fd = stdout_fd; 164 fdo->filename = out; 165 fdo->flags = O_WRONLY | O_CREAT | O_TRUNC; 166 fdo->mode = 0774; 167 fdo->fileOffset = 0; 168 169 fdo = &fd_map[STDERR_FILENO]; 170 fdo->fd = stderr_fd; 171 fdo->filename = err; 172 fdo->flags = O_WRONLY; 173 fdo->mode = -1; 174 fdo->fileOffset = 0; 175 176 177 // mark remaining fds as free 178 for (int i = 3; i <= MAX_FD; ++i) { 179 fdo = &fd_map[i]; 180 fdo->fd = -1; 181 } 182 183 mmap_start = mmap_end = 0; 184 nxm_start = nxm_end = 0; 185 // other parameters will be initialized when the program is loaded 186} 187 188 189void 190Process::regStats() 191{ 192 using namespace Stats; 193 194 num_syscalls 195 .name(name() + ".num_syscalls") 196 .desc("Number of system calls") 197 ; 198} 199 200// 201// static helper functions 202// 203int 204Process::openInputFile(const string &filename) 205{ 206 int fd = open(filename.c_str(), O_RDONLY); 207 208 if (fd == -1) { 209 perror(NULL); 210 cerr << "unable to open \"" << filename << "\" for reading\n"; 211 fatal("can't open input file"); 212 } 213 214 return fd; 215} 216 217 218int 219Process::openOutputFile(const string &filename) 220{ 221 int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0664); 222 223 if (fd == -1) { 224 perror(NULL); 225 cerr << "unable to open \"" << filename << "\" for writing\n"; 226 fatal("can't open output file"); 227 } 228 229 return fd; 230} 231 232ThreadContext * 233Process::findFreeContext() 234{ 235 int size = contextIds.size(); 236 ThreadContext *tc; 237 for (int i = 0; i < size; ++i) { 238 tc = system->getThreadContext(contextIds[i]); 239 if (tc->status() == ThreadContext::Halted) { 240 // inactive context, free to use 241 return tc; 242 } 243 } 244 return NULL; 245} 246 247void 248Process::initState() 249{ 250 if (contextIds.empty()) 251 fatal("Process %s is not associated with any HW contexts!\n", name()); 252 253 // first thread context for this process... initialize & enable 254 ThreadContext *tc = system->getThreadContext(contextIds[0]); 255 256 // mark this context as active so it will start ticking. 257 tc->activate(); 258 259 pTable->initState(tc); 260} 261 262// map simulator fd sim_fd to target fd tgt_fd 263void 264Process::dup_fd(int sim_fd, int tgt_fd) 265{ 266 if (tgt_fd < 0 || tgt_fd > MAX_FD) 267 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd); 268 269 Process::FdMap *fdo = &fd_map[tgt_fd]; 270 fdo->fd = sim_fd; 271} 272 273 274// generate new target fd for sim_fd 275int 276Process::alloc_fd(int sim_fd, const string& filename, int flags, int mode, 277 bool pipe) 278{ 279 // in case open() returns an error, don't allocate a new fd 280 if (sim_fd == -1) 281 return -1; 282 283 // find first free target fd 284 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { 285 Process::FdMap *fdo = &fd_map[free_fd]; 286 if (fdo->fd == -1 && fdo->driver == NULL) { 287 fdo->fd = sim_fd; 288 fdo->filename = filename; 289 fdo->mode = mode; 290 fdo->fileOffset = 0; 291 fdo->flags = flags; 292 fdo->isPipe = pipe; 293 fdo->readPipeSource = 0; 294 return free_fd; 295 } 296 } 297 298 panic("Process::alloc_fd: out of file descriptors!"); 299} 300 301 302// free target fd (e.g., after close) 303void 304Process::free_fd(int tgt_fd) 305{ 306 Process::FdMap *fdo = &fd_map[tgt_fd]; 307 if (fdo->fd == -1) 308 warn("Process::free_fd: request to free unused fd %d", tgt_fd); 309 310 fdo->fd = -1; 311 fdo->filename = "NULL"; 312 fdo->mode = 0; 313 fdo->fileOffset = 0; 314 fdo->flags = 0; 315 fdo->isPipe = false; 316 fdo->readPipeSource = 0; 317 fdo->driver = NULL; 318} 319 320 321// look up simulator fd for given target fd 322int 323Process::sim_fd(int tgt_fd) 324{ 325 if (tgt_fd < 0 || tgt_fd > MAX_FD) 326 return -1; 327 328 return fd_map[tgt_fd].fd; 329} 330 331Process::FdMap * 332Process::sim_fd_obj(int tgt_fd) 333{ 334 if (tgt_fd < 0 || tgt_fd > MAX_FD) 335 return NULL; 336 337 return &fd_map[tgt_fd]; 338} 339 340void 341Process::allocateMem(Addr vaddr, int64_t size, bool clobber) 342{ 343 int npages = divCeil(size, (int64_t)PageBytes); 344 Addr paddr = system->allocPhysPages(npages); 345 pTable->map(vaddr, paddr, size, clobber ? PageTableBase::Clobber : 0); 346} 347 348bool 349Process::fixupStackFault(Addr vaddr) 350{ 351 // Check if this is already on the stack and there's just no page there 352 // yet. 353 if (vaddr >= stack_min && vaddr < stack_base) { 354 allocateMem(roundDown(vaddr, PageBytes), PageBytes); 355 return true; 356 } 357 358 // We've accessed the next page of the stack, so extend it to include 359 // this address. 360 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) { 361 while (vaddr < stack_min) { 362 stack_min -= TheISA::PageBytes; 363 if (stack_base - stack_min > max_stack_size) 364 fatal("Maximum stack size exceeded\n"); 365 allocateMem(stack_min, TheISA::PageBytes); 366 inform("Increasing stack size by one page."); 367 }; 368 return true; 369 } 370 return false; 371} 372 373// find all offsets for currently open files and save them 374void 375Process::fix_file_offsets() 376{ 377 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO]; 378 Process::FdMap *fdo_stdout = &fd_map[STDOUT_FILENO]; 379 Process::FdMap *fdo_stderr = &fd_map[STDERR_FILENO]; 380 string in = fdo_stdin->filename; 381 string out = fdo_stdout->filename; 382 string err = fdo_stderr->filename; 383 384 // initialize file descriptors to default: same as simulator 385 int stdin_fd, stdout_fd, stderr_fd; 386 387 if (in == "stdin" || in == "cin") 388 stdin_fd = STDIN_FILENO; 389 else if (in == "NULL") 390 stdin_fd = -1; 391 else { 392 // open standard in and seek to the right location 393 stdin_fd = Process::openInputFile(in); 394 if (lseek(stdin_fd, fdo_stdin->fileOffset, SEEK_SET) < 0) 395 panic("Unable to seek to correct location in file: %s", in); 396 } 397 398 if (out == "stdout" || out == "cout") 399 stdout_fd = STDOUT_FILENO; 400 else if (out == "stderr" || out == "cerr") 401 stdout_fd = STDERR_FILENO; 402 else if (out == "NULL") 403 stdout_fd = -1; 404 else { 405 stdout_fd = Process::openOutputFile(out); 406 if (lseek(stdout_fd, fdo_stdout->fileOffset, SEEK_SET) < 0) 407 panic("Unable to seek to correct location in file: %s", out); 408 } 409 410 if (err == "stdout" || err == "cout") 411 stderr_fd = STDOUT_FILENO; 412 else if (err == "stderr" || err == "cerr") 413 stderr_fd = STDERR_FILENO; 414 else if (err == "NULL") 415 stderr_fd = -1; 416 else if (err == out) 417 stderr_fd = stdout_fd; 418 else { 419 stderr_fd = Process::openOutputFile(err); 420 if (lseek(stderr_fd, fdo_stderr->fileOffset, SEEK_SET) < 0) 421 panic("Unable to seek to correct location in file: %s", err); 422 } 423 424 fdo_stdin->fd = stdin_fd; 425 fdo_stdout->fd = stdout_fd; 426 fdo_stderr->fd = stderr_fd; 427 428 429 for (int free_fd = 3; free_fd <= MAX_FD; ++free_fd) { 430 Process::FdMap *fdo = &fd_map[free_fd]; 431 if (fdo->fd != -1) { 432 if (fdo->isPipe){ 433 if (fdo->filename == "PIPE-WRITE") 434 continue; 435 else { 436 assert (fdo->filename == "PIPE-READ"); 437 //create a new pipe 438 int fds[2]; 439 int pipe_retval = pipe(fds); 440 441 if (pipe_retval < 0) { 442 // error 443 panic("Unable to create new pipe."); 444 } 445 fdo->fd = fds[0]; //set read pipe 446 Process::FdMap *fdo_write = &fd_map[fdo->readPipeSource]; 447 if (fdo_write->filename != "PIPE-WRITE") 448 panic ("Couldn't find write end of the pipe"); 449 450 fdo_write->fd = fds[1];//set write pipe 451 } 452 } else { 453 //Open file 454 int fd = open(fdo->filename.c_str(), fdo->flags, fdo->mode); 455 456 if (fd == -1) 457 panic("Unable to open file: %s", fdo->filename); 458 fdo->fd = fd; 459 460 //Seek to correct location before checkpoint 461 if (lseek(fd, fdo->fileOffset, SEEK_SET) < 0) 462 panic("Unable to seek to correct location in file: %s", 463 fdo->filename); 464 } 465 } 466 } 467} 468 469void 470Process::find_file_offsets() 471{ 472 for (int free_fd = 0; free_fd <= MAX_FD; ++free_fd) { 473 Process::FdMap *fdo = &fd_map[free_fd]; 474 if (fdo->fd != -1) { 475 fdo->fileOffset = lseek(fdo->fd, 0, SEEK_CUR); 476 } else { 477 fdo->filename = "NULL"; 478 fdo->fileOffset = 0; 479 } 480 } 481} 482 483void 484Process::setReadPipeSource(int read_pipe_fd, int source_fd) 485{ 486 Process::FdMap *fdo = &fd_map[read_pipe_fd]; 487 fdo->readPipeSource = source_fd; 488} 489 490void 491Process::FdMap::serialize(std::ostream &os) 492{ 493 SERIALIZE_SCALAR(fd); 494 SERIALIZE_SCALAR(isPipe); 495 SERIALIZE_SCALAR(filename); 496 SERIALIZE_SCALAR(flags); 497 SERIALIZE_SCALAR(readPipeSource); 498 SERIALIZE_SCALAR(fileOffset); 499} 500 501void 502Process::FdMap::unserialize(Checkpoint *cp, const std::string §ion) 503{ 504 UNSERIALIZE_SCALAR(fd); 505 UNSERIALIZE_SCALAR(isPipe); 506 UNSERIALIZE_SCALAR(filename); 507 UNSERIALIZE_SCALAR(flags); 508 UNSERIALIZE_SCALAR(readPipeSource); 509 UNSERIALIZE_SCALAR(fileOffset); 510} 511 512void 513Process::serialize(std::ostream &os) 514{ 515 SERIALIZE_SCALAR(brk_point); 516 SERIALIZE_SCALAR(stack_base); 517 SERIALIZE_SCALAR(stack_size); 518 SERIALIZE_SCALAR(stack_min); 519 SERIALIZE_SCALAR(next_thread_stack_base); 520 SERIALIZE_SCALAR(mmap_start); 521 SERIALIZE_SCALAR(mmap_end); 522 SERIALIZE_SCALAR(nxm_start); 523 SERIALIZE_SCALAR(nxm_end); 524 find_file_offsets(); 525 pTable->serialize(os); 526 for (int x = 0; x <= MAX_FD; x++) { 527 nameOut(os, csprintf("%s.FdMap%d", name(), x)); 528 fd_map[x].serialize(os); 529 } 530 SERIALIZE_SCALAR(M5_pid); 531 532} 533 534void 535Process::unserialize(Checkpoint *cp, const std::string §ion) 536{ 537 UNSERIALIZE_SCALAR(brk_point); 538 UNSERIALIZE_SCALAR(stack_base); 539 UNSERIALIZE_SCALAR(stack_size); 540 UNSERIALIZE_SCALAR(stack_min); 541 UNSERIALIZE_SCALAR(next_thread_stack_base); 542 UNSERIALIZE_SCALAR(mmap_start); 543 UNSERIALIZE_SCALAR(mmap_end); 544 UNSERIALIZE_SCALAR(nxm_start); 545 UNSERIALIZE_SCALAR(nxm_end); 546 pTable->unserialize(cp, section); 547 for (int x = 0; x <= MAX_FD; x++) { 548 fd_map[x].unserialize(cp, csprintf("%s.FdMap%d", section, x)); 549 } 550 fix_file_offsets(); 551 UNSERIALIZE_OPT_SCALAR(M5_pid); 552 // The above returns a bool so that you could do something if you don't 553 // find the param in the checkpoint if you wanted to, like set a default 554 // but in this case we'll just stick with the instantianted value if not 555 // found. 556} 557 558 559bool 560Process::map(Addr vaddr, Addr paddr, int size, bool cacheable) 561{ 562 pTable->map(vaddr, paddr, size, 563 cacheable ? 0 : PageTableBase::Uncacheable); 564 return true; 565} 566 567 568//////////////////////////////////////////////////////////////////////// 569// 570// LiveProcess member definitions 571// 572//////////////////////////////////////////////////////////////////////// 573 574 575LiveProcess::LiveProcess(LiveProcessParams *params, ObjectFile *_objFile) 576 : Process(params), objFile(_objFile), 577 argv(params->cmd), envp(params->env), cwd(params->cwd), 578 __uid(params->uid), __euid(params->euid), 579 __gid(params->gid), __egid(params->egid), 580 __pid(params->pid), __ppid(params->ppid), 581 drivers(params->drivers) 582{ 583 584 // load up symbols, if any... these may be used for debugging or 585 // profiling. 586 if (!debugSymbolTable) { 587 debugSymbolTable = new SymbolTable(); 588 if (!objFile->loadGlobalSymbols(debugSymbolTable) || 589 !objFile->loadLocalSymbols(debugSymbolTable) || 590 !objFile->loadWeakSymbols(debugSymbolTable)) { 591 // didn't load any symbols 592 delete debugSymbolTable; 593 debugSymbolTable = NULL; 594 } 595 } 596} 597 598void 599LiveProcess::syscall(int64_t callnum, ThreadContext *tc) 600{ 601 num_syscalls++; 602 603 SyscallDesc *desc = getDesc(callnum); 604 if (desc == NULL) 605 fatal("Syscall %d out of range", callnum); 606 607 desc->doSyscall(callnum, this, tc); 608} 609 610IntReg 611LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width) 612{ 613 return getSyscallArg(tc, i); 614} 615 616 617EmulatedDriver * 618LiveProcess::findDriver(std::string filename) 619{ 620 for (EmulatedDriver *d : drivers) { 621 if (d->match(filename)) 622 return d; 623 } 624 625 return NULL; 626} 627 628 629LiveProcess * 630LiveProcess::create(LiveProcessParams * params) 631{ 632 LiveProcess *process = NULL; 633 634 string executable = 635 params->executable == "" ? params->cmd[0] : params->executable; 636 ObjectFile *objFile = createObjectFile(executable); 637 if (objFile == NULL) { 638 fatal("Can't load object file %s", executable); 639 } 640 641 if (objFile->isDynamic()) 642 fatal("Object file is a dynamic executable however only static " 643 "executables are supported!\n Please recompile your " 644 "executable as a static binary and try again.\n"); 645 646#if THE_ISA == ALPHA_ISA 647 if (objFile->getArch() != ObjectFile::Alpha) 648 fatal("Object file architecture does not match compiled ISA (Alpha)."); 649 650 switch (objFile->getOpSys()) { 651 case ObjectFile::Tru64: 652 process = new AlphaTru64Process(params, objFile); 653 break; 654 655 case ObjectFile::UnknownOpSys: 656 warn("Unknown operating system; assuming Linux."); 657 // fall through 658 case ObjectFile::Linux: 659 process = new AlphaLinuxProcess(params, objFile); 660 break; 661 662 default: 663 fatal("Unknown/unsupported operating system."); 664 } 665#elif THE_ISA == SPARC_ISA 666 if (objFile->getArch() != ObjectFile::SPARC64 && 667 objFile->getArch() != ObjectFile::SPARC32) 668 fatal("Object file architecture does not match compiled ISA (SPARC)."); 669 switch (objFile->getOpSys()) { 670 case ObjectFile::UnknownOpSys: 671 warn("Unknown operating system; assuming Linux."); 672 // fall through 673 case ObjectFile::Linux: 674 if (objFile->getArch() == ObjectFile::SPARC64) { 675 process = new Sparc64LinuxProcess(params, objFile); 676 } else { 677 process = new Sparc32LinuxProcess(params, objFile); 678 } 679 break; 680 681 682 case ObjectFile::Solaris: 683 process = new SparcSolarisProcess(params, objFile); 684 break; 685 686 default: 687 fatal("Unknown/unsupported operating system."); 688 } 689#elif THE_ISA == X86_ISA 690 if (objFile->getArch() != ObjectFile::X86_64 && 691 objFile->getArch() != ObjectFile::I386) 692 fatal("Object file architecture does not match compiled ISA (x86)."); 693 switch (objFile->getOpSys()) { 694 case ObjectFile::UnknownOpSys: 695 warn("Unknown operating system; assuming Linux."); 696 // fall through 697 case ObjectFile::Linux: 698 if (objFile->getArch() == ObjectFile::X86_64) { 699 process = new X86_64LinuxProcess(params, objFile); 700 } else { 701 process = new I386LinuxProcess(params, objFile); 702 } 703 break; 704 705 default: 706 fatal("Unknown/unsupported operating system."); 707 } 708#elif THE_ISA == MIPS_ISA 709 if (objFile->getArch() != ObjectFile::Mips) 710 fatal("Object file architecture does not match compiled ISA (MIPS)."); 711 switch (objFile->getOpSys()) { 712 case ObjectFile::UnknownOpSys: 713 warn("Unknown operating system; assuming Linux."); 714 // fall through 715 case ObjectFile::Linux: 716 process = new MipsLinuxProcess(params, objFile); 717 break; 718 719 default: 720 fatal("Unknown/unsupported operating system."); 721 } 722#elif THE_ISA == ARM_ISA 723 ObjectFile::Arch arch = objFile->getArch(); 724 if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb && 725 arch != ObjectFile::Arm64) 726 fatal("Object file architecture does not match compiled ISA (ARM)."); 727 switch (objFile->getOpSys()) { 728 case ObjectFile::UnknownOpSys: 729 warn("Unknown operating system; assuming Linux."); 730 // fall through 731 case ObjectFile::Linux: 732 if (arch == ObjectFile::Arm64) { 733 process = new ArmLinuxProcess64(params, objFile, 734 objFile->getArch()); 735 } else { 736 process = new ArmLinuxProcess32(params, objFile, 737 objFile->getArch()); 738 } 739 break; 740 case ObjectFile::FreeBSD: 741 if (arch == ObjectFile::Arm64) { 742 process = new ArmFreebsdProcess64(params, objFile, 743 objFile->getArch()); 744 } else { 745 process = new ArmFreebsdProcess32(params, objFile, 746 objFile->getArch()); 747 } 748 break; 749 case ObjectFile::LinuxArmOABI: 750 fatal("M5 does not support ARM OABI binaries. Please recompile with an" 751 " EABI compiler."); 752 default: 753 fatal("Unknown/unsupported operating system."); 754 } 755#elif THE_ISA == POWER_ISA 756 if (objFile->getArch() != ObjectFile::Power) 757 fatal("Object file architecture does not match compiled ISA (Power)."); 758 switch (objFile->getOpSys()) { 759 case ObjectFile::UnknownOpSys: 760 warn("Unknown operating system; assuming Linux."); 761 // fall through 762 case ObjectFile::Linux: 763 process = new PowerLinuxProcess(params, objFile); 764 break; 765 766 default: 767 fatal("Unknown/unsupported operating system."); 768 } 769#else 770#error "THE_ISA not set" 771#endif 772 773 if (process == NULL) 774 fatal("Unknown error creating process object."); 775 return process; 776} 777 778LiveProcess * 779LiveProcessParams::create() 780{ 781 return LiveProcess::create(this); 782} 783