process.cc revision 7095
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> 35 36#include <cstdio> 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 SERIALIZE_SCALAR(M5_pid); 511 512} 513 514void 515Process::unserialize(Checkpoint *cp, const std::string §ion) 516{ 517 UNSERIALIZE_SCALAR(initialContextLoaded); 518 UNSERIALIZE_SCALAR(brk_point); 519 UNSERIALIZE_SCALAR(stack_base); 520 UNSERIALIZE_SCALAR(stack_size); 521 UNSERIALIZE_SCALAR(stack_min); 522 UNSERIALIZE_SCALAR(next_thread_stack_base); 523 UNSERIALIZE_SCALAR(mmap_start); 524 UNSERIALIZE_SCALAR(mmap_end); 525 UNSERIALIZE_SCALAR(nxm_start); 526 UNSERIALIZE_SCALAR(nxm_end); 527 pTable->unserialize(cp, section); 528 for (int x = 0; x <= MAX_FD; x++) { 529 fd_map[x].unserialize(cp, csprintf("%s.FdMap%d", section, x)); 530 } 531 fix_file_offsets(); 532 UNSERIALIZE_OPT_SCALAR(M5_pid); 533 // The above returns a bool so that you could do something if you don't 534 // find the param in the checkpoint if you wanted to, like set a default 535 // but in this case we'll just stick with the instantianted value if not 536 // found. 537 538 checkpointRestored = true; 539 540} 541 542 543//////////////////////////////////////////////////////////////////////// 544// 545// LiveProcess member definitions 546// 547//////////////////////////////////////////////////////////////////////// 548 549 550LiveProcess::LiveProcess(LiveProcessParams * params, ObjectFile *_objFile) 551 : Process(params), objFile(_objFile), 552 argv(params->cmd), envp(params->env), cwd(params->cwd) 553{ 554 __uid = params->uid; 555 __euid = params->euid; 556 __gid = params->gid; 557 __egid = params->egid; 558 __pid = params->pid; 559 __ppid = params->ppid; 560 561 prog_fname = params->cmd[0]; 562 563 // load up symbols, if any... these may be used for debugging or 564 // profiling. 565 if (!debugSymbolTable) { 566 debugSymbolTable = new SymbolTable(); 567 if (!objFile->loadGlobalSymbols(debugSymbolTable) || 568 !objFile->loadLocalSymbols(debugSymbolTable)) { 569 // didn't load any symbols 570 delete debugSymbolTable; 571 debugSymbolTable = NULL; 572 } 573 } 574} 575 576void 577LiveProcess::argsInit(int intSize, int pageSize) 578{ 579 Process::startup(); 580 581 // load object file into target memory 582 objFile->loadSections(initVirtMem); 583 584 // Calculate how much space we need for arg & env arrays. 585 int argv_array_size = intSize * (argv.size() + 1); 586 int envp_array_size = intSize * (envp.size() + 1); 587 int arg_data_size = 0; 588 for (vector<string>::size_type i = 0; i < argv.size(); ++i) { 589 arg_data_size += argv[i].size() + 1; 590 } 591 int env_data_size = 0; 592 for (vector<string>::size_type i = 0; i < envp.size(); ++i) { 593 env_data_size += envp[i].size() + 1; 594 } 595 596 int space_needed = 597 argv_array_size + envp_array_size + arg_data_size + env_data_size; 598 if (space_needed < 32*1024) 599 space_needed = 32*1024; 600 601 // set bottom of stack 602 stack_min = stack_base - space_needed; 603 // align it 604 stack_min = roundDown(stack_min, pageSize); 605 stack_size = stack_base - stack_min; 606 // map memory 607 pTable->allocate(stack_min, roundUp(stack_size, pageSize)); 608 609 // map out initial stack contents 610 Addr argv_array_base = stack_min + intSize; // room for argc 611 Addr envp_array_base = argv_array_base + argv_array_size; 612 Addr arg_data_base = envp_array_base + envp_array_size; 613 Addr env_data_base = arg_data_base + arg_data_size; 614 615 // write contents to stack 616 uint64_t argc = argv.size(); 617 if (intSize == 8) 618 argc = htog((uint64_t)argc); 619 else if (intSize == 4) 620 argc = htog((uint32_t)argc); 621 else 622 panic("Unknown int size"); 623 624 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize); 625 626 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 627 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 628 629 ThreadContext *tc = system->getThreadContext(contextIds[0]); 630 631 setSyscallArg(tc, 0, argc); 632 setSyscallArg(tc, 1, argv_array_base); 633 tc->setIntReg(StackPointerReg, stack_min); 634 635 Addr prog_entry = objFile->entryPoint(); 636 tc->setPC(prog_entry); 637 tc->setNextPC(prog_entry + sizeof(MachInst)); 638 639#if THE_ISA != ALPHA_ISA && THE_ISA != POWER_ISA //e.g. MIPS or Sparc 640 tc->setNextNPC(prog_entry + (2 * sizeof(MachInst))); 641#endif 642 643 num_processes++; 644} 645 646void 647LiveProcess::syscall(int64_t callnum, ThreadContext *tc) 648{ 649 num_syscalls++; 650 651 SyscallDesc *desc = getDesc(callnum); 652 if (desc == NULL) 653 fatal("Syscall %d out of range", callnum); 654 655 desc->doSyscall(callnum, this, tc); 656} 657 658IntReg 659LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width) 660{ 661 return getSyscallArg(tc, i); 662} 663 664LiveProcess * 665LiveProcess::create(LiveProcessParams * params) 666{ 667 LiveProcess *process = NULL; 668 669 string executable = 670 params->executable == "" ? params->cmd[0] : params->executable; 671 ObjectFile *objFile = createObjectFile(executable); 672 if (objFile == NULL) { 673 fatal("Can't load object file %s", executable); 674 } 675 676 if (objFile->isDynamic()) 677 fatal("Object file is a dynamic executable however only static " 678 "executables are supported!\n Please recompile your " 679 "executable as a static binary and try again.\n"); 680 681#if THE_ISA == ALPHA_ISA 682 if (objFile->getArch() != ObjectFile::Alpha) 683 fatal("Object file architecture does not match compiled ISA (Alpha)."); 684 685 switch (objFile->getOpSys()) { 686 case ObjectFile::Tru64: 687 process = new AlphaTru64Process(params, objFile); 688 break; 689 690 case ObjectFile::UnknownOpSys: 691 warn("Unknown operating system; assuming Linux."); 692 // fall through 693 case ObjectFile::Linux: 694 process = new AlphaLinuxProcess(params, objFile); 695 break; 696 697 default: 698 fatal("Unknown/unsupported operating system."); 699 } 700#elif THE_ISA == SPARC_ISA 701 if (objFile->getArch() != ObjectFile::SPARC64 && 702 objFile->getArch() != ObjectFile::SPARC32) 703 fatal("Object file architecture does not match compiled ISA (SPARC)."); 704 switch (objFile->getOpSys()) { 705 case ObjectFile::UnknownOpSys: 706 warn("Unknown operating system; assuming Linux."); 707 // fall through 708 case ObjectFile::Linux: 709 if (objFile->getArch() == ObjectFile::SPARC64) { 710 process = new Sparc64LinuxProcess(params, objFile); 711 } else { 712 process = new Sparc32LinuxProcess(params, objFile); 713 } 714 break; 715 716 717 case ObjectFile::Solaris: 718 process = new SparcSolarisProcess(params, objFile); 719 break; 720 721 default: 722 fatal("Unknown/unsupported operating system."); 723 } 724#elif THE_ISA == X86_ISA 725 if (objFile->getArch() != ObjectFile::X86_64 && 726 objFile->getArch() != ObjectFile::I386) 727 fatal("Object file architecture does not match compiled ISA (x86)."); 728 switch (objFile->getOpSys()) { 729 case ObjectFile::UnknownOpSys: 730 warn("Unknown operating system; assuming Linux."); 731 // fall through 732 case ObjectFile::Linux: 733 if (objFile->getArch() == ObjectFile::X86_64) { 734 process = new X86_64LinuxProcess(params, objFile); 735 } else { 736 process = new I386LinuxProcess(params, objFile); 737 } 738 break; 739 740 default: 741 fatal("Unknown/unsupported operating system."); 742 } 743#elif THE_ISA == MIPS_ISA 744 if (objFile->getArch() != ObjectFile::Mips) 745 fatal("Object file architecture does not match compiled ISA (MIPS)."); 746 switch (objFile->getOpSys()) { 747 case ObjectFile::UnknownOpSys: 748 warn("Unknown operating system; assuming Linux."); 749 // fall through 750 case ObjectFile::Linux: 751 process = new MipsLinuxProcess(params, objFile); 752 break; 753 754 default: 755 fatal("Unknown/unsupported operating system."); 756 } 757#elif THE_ISA == ARM_ISA 758 if (objFile->getArch() != ObjectFile::Arm && 759 objFile->getArch() != ObjectFile::Thumb) 760 fatal("Object file architecture does not match compiled ISA (ARM)."); 761 switch (objFile->getOpSys()) { 762 case ObjectFile::UnknownOpSys: 763 warn("Unknown operating system; assuming Linux."); 764 // fall through 765 case ObjectFile::Linux: 766 if (objFile->getArch() == ObjectFile::Thumb) 767 panic("Thumb processes not yet supported.\n"); 768 else 769 process = new ArmLinuxProcess(params, objFile); 770 break; 771 case ObjectFile::LinuxArmOABI: 772 fatal("M5 does not support ARM OABI binaries. Please recompile with an" 773 " EABI compiler."); 774 default: 775 fatal("Unknown/unsupported operating system."); 776 } 777#elif THE_ISA == POWER_ISA 778 if (objFile->getArch() != ObjectFile::Power) 779 fatal("Object file architecture does not match compiled ISA (Power)."); 780 switch (objFile->getOpSys()) { 781 case ObjectFile::UnknownOpSys: 782 warn("Unknown operating system; assuming Linux."); 783 // fall through 784 case ObjectFile::Linux: 785 process = new PowerLinuxProcess(params, objFile); 786 break; 787 788 default: 789 fatal("Unknown/unsupported operating system."); 790 } 791#else 792#error "THE_ISA not set" 793#endif 794 795 796 if (process == NULL) 797 fatal("Unknown error creating process object."); 798 return process; 799} 800 801LiveProcess * 802LiveProcessParams::create() 803{ 804 return LiveProcess::create(this); 805} 806