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