process.cc revision 5183
12SN/A/* 21762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu * Steve Reinhardt 302665Ssaidi@eecs.umich.edu * Ali Saidi 312SN/A */ 322SN/A 332SN/A#include <unistd.h> 342SN/A#include <fcntl.h> 352SN/A 362SN/A#include <string> 372SN/A 383971Sgblack@eecs.umich.edu#include "arch/remote_gdb.hh" 3956SN/A#include "base/intmath.hh" 4056SN/A#include "base/loader/object_file.hh" 411158SN/A#include "base/loader/symtab.hh" 42146SN/A#include "base/statistics.hh" 431858SN/A#include "config/full_system.hh" 442680Sktlim@umich.edu#include "cpu/thread_context.hh" 452378SN/A#include "mem/page_table.hh" 462522SN/A#include "mem/physical.hh" 472401SN/A#include "mem/translating_port.hh" 485154Sgblack@eecs.umich.edu#include "params/Process.hh" 494762Snate@binkert.org#include "params/LiveProcess.hh" 50360SN/A#include "sim/process.hh" 514434Ssaidi@eecs.umich.edu#include "sim/process_impl.hh" 52695SN/A#include "sim/stats.hh" 532093SN/A#include "sim/syscall_emul.hh" 542378SN/A#include "sim/system.hh" 552SN/A 562715Sstever@eecs.umich.edu#include "arch/isa_specific.hh" 572715Sstever@eecs.umich.edu#if THE_ISA == ALPHA_ISA 582715Sstever@eecs.umich.edu#include "arch/alpha/linux/process.hh" 592715Sstever@eecs.umich.edu#include "arch/alpha/tru64/process.hh" 602715Sstever@eecs.umich.edu#elif THE_ISA == SPARC_ISA 612715Sstever@eecs.umich.edu#include "arch/sparc/linux/process.hh" 622715Sstever@eecs.umich.edu#include "arch/sparc/solaris/process.hh" 632715Sstever@eecs.umich.edu#elif THE_ISA == MIPS_ISA 642715Sstever@eecs.umich.edu#include "arch/mips/linux/process.hh" 654157Sgblack@eecs.umich.edu#elif THE_ISA == X86_ISA 664166Sgblack@eecs.umich.edu#include "arch/x86/linux/process.hh" 672715Sstever@eecs.umich.edu#else 682715Sstever@eecs.umich.edu#error "THE_ISA not set" 692715Sstever@eecs.umich.edu#endif 702715Sstever@eecs.umich.edu 712715Sstever@eecs.umich.edu 722SN/Ausing namespace std; 732107SN/Ausing namespace TheISA; 742SN/A 752SN/A// 762SN/A// The purpose of this code is to fake the loader & syscall mechanism 772SN/A// when there's no OS: thus there's no resone to use it in FULL_SYSTEM 782SN/A// mode when we do have an OS 792SN/A// 801858SN/A#if FULL_SYSTEM 81360SN/A#error "process.cc not compatible with FULL_SYSTEM" 822SN/A#endif 832SN/A 842SN/A// current number of allocated processes 852SN/Aint num_processes = 0; 862SN/A 875154Sgblack@eecs.umich.eduProcess::Process(ProcessParams * params) 885183Ssaidi@eecs.umich.edu : SimObject(params), system(params->system), checkpointRestored(false), 895154Sgblack@eecs.umich.edu max_stack_size(params->max_stack_size) 902SN/A{ 915154Sgblack@eecs.umich.edu string in = params->input; 925154Sgblack@eecs.umich.edu string out = params->output; 935154Sgblack@eecs.umich.edu 945154Sgblack@eecs.umich.edu // initialize file descriptors to default: same as simulator 955154Sgblack@eecs.umich.edu int stdin_fd, stdout_fd, stderr_fd; 965154Sgblack@eecs.umich.edu 975154Sgblack@eecs.umich.edu if (in == "stdin" || in == "cin") 985154Sgblack@eecs.umich.edu stdin_fd = STDIN_FILENO; 995154Sgblack@eecs.umich.edu else if (in == "None") 1005154Sgblack@eecs.umich.edu stdin_fd = -1; 1015154Sgblack@eecs.umich.edu else 1025154Sgblack@eecs.umich.edu stdin_fd = Process::openInputFile(in); 1035154Sgblack@eecs.umich.edu 1045154Sgblack@eecs.umich.edu if (out == "stdout" || out == "cout") 1055154Sgblack@eecs.umich.edu stdout_fd = STDOUT_FILENO; 1065154Sgblack@eecs.umich.edu else if (out == "stderr" || out == "cerr") 1075154Sgblack@eecs.umich.edu stdout_fd = STDERR_FILENO; 1085154Sgblack@eecs.umich.edu else if (out == "None") 1095154Sgblack@eecs.umich.edu stdout_fd = -1; 1105154Sgblack@eecs.umich.edu else 1115154Sgblack@eecs.umich.edu stdout_fd = Process::openOutputFile(out); 1125154Sgblack@eecs.umich.edu 1135154Sgblack@eecs.umich.edu stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; 1145154Sgblack@eecs.umich.edu 1154997Sgblack@eecs.umich.edu M5_pid = system->allocatePID(); 1162SN/A // initialize first 3 fds (stdin, stdout, stderr) 1172SN/A fd_map[STDIN_FILENO] = stdin_fd; 1182SN/A fd_map[STDOUT_FILENO] = stdout_fd; 1192SN/A fd_map[STDERR_FILENO] = stderr_fd; 1202SN/A 1212SN/A // mark remaining fds as free 1222SN/A for (int i = 3; i <= MAX_FD; ++i) { 1232SN/A fd_map[i] = -1; 1242SN/A } 1252SN/A 1261450SN/A mmap_start = mmap_end = 0; 1271514SN/A nxm_start = nxm_end = 0; 1282378SN/A pTable = new PageTable(system); 1292SN/A // other parameters will be initialized when the program is loaded 1302SN/A} 1312SN/A 1322378SN/A 1332SN/Avoid 1342SN/AProcess::regStats() 1352SN/A{ 136729SN/A using namespace Stats; 1372SN/A 1382SN/A num_syscalls 1392SN/A .name(name() + ".PROG:num_syscalls") 1402SN/A .desc("Number of system calls") 1412SN/A ; 1422SN/A} 1432SN/A 1442SN/A// 1452SN/A// static helper functions 1462SN/A// 1472SN/Aint 1482SN/AProcess::openInputFile(const string &filename) 1492SN/A{ 1502SN/A int fd = open(filename.c_str(), O_RDONLY); 1512SN/A 1522SN/A if (fd == -1) { 1532SN/A perror(NULL); 1542SN/A cerr << "unable to open \"" << filename << "\" for reading\n"; 1552SN/A fatal("can't open input file"); 1562SN/A } 1572SN/A 1582SN/A return fd; 1592SN/A} 1602SN/A 1612SN/A 1622SN/Aint 1632SN/AProcess::openOutputFile(const string &filename) 1642SN/A{ 1652SN/A int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0774); 1662SN/A 1672SN/A if (fd == -1) { 1682SN/A perror(NULL); 1692SN/A cerr << "unable to open \"" << filename << "\" for writing\n"; 1702SN/A fatal("can't open output file"); 1712SN/A } 1722SN/A 1732SN/A return fd; 1742SN/A} 1752SN/A 1762SN/A 177180SN/Aint 1782680Sktlim@umich.eduProcess::registerThreadContext(ThreadContext *tc) 1792SN/A{ 180180SN/A // add to list 1812680Sktlim@umich.edu int myIndex = threadContexts.size(); 1822680Sktlim@umich.edu threadContexts.push_back(tc); 183180SN/A 1845109Sgblack@eecs.umich.edu RemoteGDB *rgdb = new RemoteGDB(system, tc); 1855109Sgblack@eecs.umich.edu GDBListener *gdbl = new GDBListener(rgdb, 7000 + myIndex); 1865109Sgblack@eecs.umich.edu gdbl->listen(); 1873971Sgblack@eecs.umich.edu //gdbl->accept(); 1883971Sgblack@eecs.umich.edu 1895109Sgblack@eecs.umich.edu remoteGDB.push_back(rgdb); 1903971Sgblack@eecs.umich.edu 1912378SN/A // return CPU number to caller 192180SN/A return myIndex; 1932SN/A} 1942SN/A 1951395SN/Avoid 1961395SN/AProcess::startup() 1971395SN/A{ 1982680Sktlim@umich.edu if (threadContexts.empty()) 1992378SN/A fatal("Process %s is not associated with any CPUs!\n", name()); 2002378SN/A 2012680Sktlim@umich.edu // first thread context for this process... initialize & enable 2022680Sktlim@umich.edu ThreadContext *tc = threadContexts[0]; 2031395SN/A 2041634SN/A // mark this context as active so it will start ticking. 2052680Sktlim@umich.edu tc->activate(0); 2062462SN/A 2072519SN/A Port *mem_port; 2082519SN/A mem_port = system->physmem->getPort("functional"); 2094434Ssaidi@eecs.umich.edu initVirtMem = new TranslatingPort("process init port", this, 2104434Ssaidi@eecs.umich.edu TranslatingPort::Always); 2112519SN/A mem_port->setPeer(initVirtMem); 2122519SN/A initVirtMem->setPeer(mem_port); 2131395SN/A} 2142SN/A 215180SN/Avoid 2162680Sktlim@umich.eduProcess::replaceThreadContext(ThreadContext *tc, int tcIndex) 217180SN/A{ 2182680Sktlim@umich.edu if (tcIndex >= threadContexts.size()) { 2192680Sktlim@umich.edu panic("replaceThreadContext: bad tcIndex, %d >= %d\n", 2202680Sktlim@umich.edu tcIndex, threadContexts.size()); 221180SN/A } 222180SN/A 2232680Sktlim@umich.edu threadContexts[tcIndex] = tc; 224180SN/A} 225180SN/A 2262SN/A// map simulator fd sim_fd to target fd tgt_fd 2272SN/Avoid 2282SN/AProcess::dup_fd(int sim_fd, int tgt_fd) 2292SN/A{ 2302SN/A if (tgt_fd < 0 || tgt_fd > MAX_FD) 2312SN/A panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd); 2322SN/A 2332SN/A fd_map[tgt_fd] = sim_fd; 2342SN/A} 2352SN/A 2362SN/A 2372SN/A// generate new target fd for sim_fd 2382SN/Aint 2391970SN/AProcess::alloc_fd(int sim_fd) 2402SN/A{ 2412SN/A // in case open() returns an error, don't allocate a new fd 2422SN/A if (sim_fd == -1) 2432SN/A return -1; 2442SN/A 2452SN/A // find first free target fd 2461970SN/A for (int free_fd = 0; free_fd < MAX_FD; ++free_fd) { 2471970SN/A if (fd_map[free_fd] == -1) { 2481970SN/A fd_map[free_fd] = sim_fd; 2491970SN/A return free_fd; 2501970SN/A } 2512SN/A } 2522SN/A 2531970SN/A panic("Process::alloc_fd: out of file descriptors!"); 2541970SN/A} 2552SN/A 2561970SN/A 2571970SN/A// free target fd (e.g., after close) 2581970SN/Avoid 2591970SN/AProcess::free_fd(int tgt_fd) 2601970SN/A{ 2611970SN/A if (fd_map[tgt_fd] == -1) 2621970SN/A warn("Process::free_fd: request to free unused fd %d", tgt_fd); 2631970SN/A 2641970SN/A fd_map[tgt_fd] = -1; 2652SN/A} 2662SN/A 2672SN/A 2682SN/A// look up simulator fd for given target fd 2692SN/Aint 2702SN/AProcess::sim_fd(int tgt_fd) 2712SN/A{ 2722SN/A if (tgt_fd > MAX_FD) 2732SN/A return -1; 2742SN/A 2752SN/A return fd_map[tgt_fd]; 2762SN/A} 2772SN/A 2784434Ssaidi@eecs.umich.edubool 2794434Ssaidi@eecs.umich.eduProcess::checkAndAllocNextPage(Addr vaddr) 2804434Ssaidi@eecs.umich.edu{ 2814434Ssaidi@eecs.umich.edu // if this is an initial write we might not have 2824434Ssaidi@eecs.umich.edu if (vaddr >= stack_min && vaddr < stack_base) { 2834434Ssaidi@eecs.umich.edu pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize); 2844434Ssaidi@eecs.umich.edu return true; 2854434Ssaidi@eecs.umich.edu } 2864434Ssaidi@eecs.umich.edu 2874434Ssaidi@eecs.umich.edu // We've accessed the next page of the stack, so extend the stack 2884434Ssaidi@eecs.umich.edu // to cover it. 2895154Sgblack@eecs.umich.edu if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) { 2905154Sgblack@eecs.umich.edu while (vaddr < stack_min) { 2915154Sgblack@eecs.umich.edu stack_min -= TheISA::PageBytes; 2925154Sgblack@eecs.umich.edu if(stack_base - stack_min > max_stack_size) 2935154Sgblack@eecs.umich.edu fatal("Maximum stack size exceeded\n"); 2945154Sgblack@eecs.umich.edu if(stack_base - stack_min > 8*1024*1024) 2955154Sgblack@eecs.umich.edu fatal("Over max stack size for one thread\n"); 2965154Sgblack@eecs.umich.edu pTable->allocate(stack_min, TheISA::PageBytes); 2975154Sgblack@eecs.umich.edu warn("Increasing stack size by one page."); 2985154Sgblack@eecs.umich.edu }; 2994434Ssaidi@eecs.umich.edu return true; 3004434Ssaidi@eecs.umich.edu } 3014434Ssaidi@eecs.umich.edu return false; 3024434Ssaidi@eecs.umich.edu} 3034434Ssaidi@eecs.umich.edu 3043311Ssaidi@eecs.umich.eduvoid 3053311Ssaidi@eecs.umich.eduProcess::serialize(std::ostream &os) 3063311Ssaidi@eecs.umich.edu{ 3073311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(initialContextLoaded); 3083311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(brk_point); 3093311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(stack_base); 3103311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(stack_size); 3113311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(stack_min); 3123311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(next_thread_stack_base); 3133311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(mmap_start); 3143311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(mmap_end); 3153311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(nxm_start); 3163311Ssaidi@eecs.umich.edu SERIALIZE_SCALAR(nxm_end); 3173311Ssaidi@eecs.umich.edu SERIALIZE_ARRAY(fd_map, MAX_FD); 3183311Ssaidi@eecs.umich.edu 3193311Ssaidi@eecs.umich.edu pTable->serialize(os); 3203311Ssaidi@eecs.umich.edu} 3213311Ssaidi@eecs.umich.edu 3223311Ssaidi@eecs.umich.eduvoid 3233311Ssaidi@eecs.umich.eduProcess::unserialize(Checkpoint *cp, const std::string §ion) 3243311Ssaidi@eecs.umich.edu{ 3253311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(initialContextLoaded); 3263311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(brk_point); 3273311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(stack_base); 3283311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(stack_size); 3293311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(stack_min); 3303311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(next_thread_stack_base); 3313311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(mmap_start); 3323311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(mmap_end); 3333311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(nxm_start); 3343311Ssaidi@eecs.umich.edu UNSERIALIZE_SCALAR(nxm_end); 3353311Ssaidi@eecs.umich.edu UNSERIALIZE_ARRAY(fd_map, MAX_FD); 3363311Ssaidi@eecs.umich.edu 3373311Ssaidi@eecs.umich.edu pTable->unserialize(cp, section); 3385183Ssaidi@eecs.umich.edu 3395183Ssaidi@eecs.umich.edu 3405183Ssaidi@eecs.umich.edu checkpointRestored = true; 3415183Ssaidi@eecs.umich.edu 3423311Ssaidi@eecs.umich.edu} 3432SN/A 3442SN/A 3452SN/A//////////////////////////////////////////////////////////////////////// 3462SN/A// 3472SN/A// LiveProcess member definitions 3482SN/A// 3492SN/A//////////////////////////////////////////////////////////////////////// 3502SN/A 35112SN/A 3525154Sgblack@eecs.umich.eduLiveProcess::LiveProcess(LiveProcessParams * params, ObjectFile *_objFile) 3535154Sgblack@eecs.umich.edu : Process(params), objFile(_objFile), 3545154Sgblack@eecs.umich.edu argv(params->cmd), envp(params->env), cwd(params->cwd) 3552SN/A{ 3565154Sgblack@eecs.umich.edu __uid = params->uid; 3575154Sgblack@eecs.umich.edu __euid = params->euid; 3585154Sgblack@eecs.umich.edu __gid = params->gid; 3595154Sgblack@eecs.umich.edu __egid = params->egid; 3605154Sgblack@eecs.umich.edu __pid = params->pid; 3615154Sgblack@eecs.umich.edu __ppid = params->ppid; 3623114Sgblack@eecs.umich.edu 3635154Sgblack@eecs.umich.edu prog_fname = params->cmd[0]; 36412SN/A 3651158SN/A // load up symbols, if any... these may be used for debugging or 3661158SN/A // profiling. 3671158SN/A if (!debugSymbolTable) { 3681158SN/A debugSymbolTable = new SymbolTable(); 3691158SN/A if (!objFile->loadGlobalSymbols(debugSymbolTable) || 3701158SN/A !objFile->loadLocalSymbols(debugSymbolTable)) { 3711158SN/A // didn't load any symbols 3721158SN/A delete debugSymbolTable; 3731158SN/A debugSymbolTable = NULL; 3741158SN/A } 3751158SN/A } 3762378SN/A} 3771158SN/A 3782378SN/Avoid 3792474SN/ALiveProcess::argsInit(int intSize, int pageSize) 3802378SN/A{ 3812378SN/A Process::startup(); 38212SN/A 3832378SN/A // load object file into target memory 3842378SN/A objFile->loadSections(initVirtMem); 38512SN/A 38612SN/A // Calculate how much space we need for arg & env arrays. 3872474SN/A int argv_array_size = intSize * (argv.size() + 1); 3882474SN/A int envp_array_size = intSize * (envp.size() + 1); 38912SN/A int arg_data_size = 0; 39012SN/A for (int i = 0; i < argv.size(); ++i) { 39112SN/A arg_data_size += argv[i].size() + 1; 39212SN/A } 39312SN/A int env_data_size = 0; 39412SN/A for (int i = 0; i < envp.size(); ++i) { 39512SN/A env_data_size += envp[i].size() + 1; 39612SN/A } 39712SN/A 39812SN/A int space_needed = 39912SN/A argv_array_size + envp_array_size + arg_data_size + env_data_size; 4003005Sstever@eecs.umich.edu if (space_needed < 32*1024) 4013005Sstever@eecs.umich.edu space_needed = 32*1024; 40212SN/A 40312SN/A // set bottom of stack 40412SN/A stack_min = stack_base - space_needed; 40512SN/A // align it 4062800Ssaidi@eecs.umich.edu stack_min = roundDown(stack_min, pageSize); 40712SN/A stack_size = stack_base - stack_min; 4082378SN/A // map memory 4092800Ssaidi@eecs.umich.edu pTable->allocate(stack_min, roundUp(stack_size, pageSize)); 41012SN/A 41112SN/A // map out initial stack contents 4122523SN/A Addr argv_array_base = stack_min + intSize; // room for argc 41312SN/A Addr envp_array_base = argv_array_base + argv_array_size; 41412SN/A Addr arg_data_base = envp_array_base + envp_array_size; 41512SN/A Addr env_data_base = arg_data_base + arg_data_size; 41612SN/A 41712SN/A // write contents to stack 41812SN/A uint64_t argc = argv.size(); 4192474SN/A if (intSize == 8) 4202474SN/A argc = htog((uint64_t)argc); 4212474SN/A else if (intSize == 4) 4222474SN/A argc = htog((uint32_t)argc); 4232474SN/A else 4242474SN/A panic("Unknown int size"); 4252474SN/A 4262474SN/A initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize); 42712SN/A 4282378SN/A copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 4292378SN/A copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 43012SN/A 4314772Sgblack@eecs.umich.edu assert(NumArgumentRegs >= 2); 4324772Sgblack@eecs.umich.edu threadContexts[0]->setIntReg(ArgumentReg[0], argc); 4334772Sgblack@eecs.umich.edu threadContexts[0]->setIntReg(ArgumentReg[1], argv_array_base); 4342680Sktlim@umich.edu threadContexts[0]->setIntReg(StackPointerReg, stack_min); 4352451SN/A 4362451SN/A Addr prog_entry = objFile->entryPoint(); 4372680Sktlim@umich.edu threadContexts[0]->setPC(prog_entry); 4382680Sktlim@umich.edu threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst)); 4392817Sksewell@umich.edu 4402817Sksewell@umich.edu#if THE_ISA != ALPHA_ISA //e.g. MIPS or Sparc 4412680Sktlim@umich.edu threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst))); 4422817Sksewell@umich.edu#endif 4432378SN/A 4442378SN/A num_processes++; 4452SN/A} 4462SN/A 4472093SN/Avoid 4482680Sktlim@umich.eduLiveProcess::syscall(int64_t callnum, ThreadContext *tc) 4492093SN/A{ 4502093SN/A num_syscalls++; 4512093SN/A 4522093SN/A SyscallDesc *desc = getDesc(callnum); 4532093SN/A if (desc == NULL) 4542093SN/A fatal("Syscall %d out of range", callnum); 4552093SN/A 4562680Sktlim@umich.edu desc->doSyscall(callnum, this, tc); 4572093SN/A} 4582SN/A 4592715Sstever@eecs.umich.eduLiveProcess * 4605154Sgblack@eecs.umich.eduLiveProcess::create(LiveProcessParams * params) 4612715Sstever@eecs.umich.edu{ 4622715Sstever@eecs.umich.edu LiveProcess *process = NULL; 4632715Sstever@eecs.umich.edu 4645154Sgblack@eecs.umich.edu string executable = 4655154Sgblack@eecs.umich.edu params->executable == "" ? params->cmd[0] : params->executable; 4662715Sstever@eecs.umich.edu ObjectFile *objFile = createObjectFile(executable); 4672715Sstever@eecs.umich.edu if (objFile == NULL) { 4682715Sstever@eecs.umich.edu fatal("Can't load object file %s", executable); 4692715Sstever@eecs.umich.edu } 4702715Sstever@eecs.umich.edu 4713917Ssaidi@eecs.umich.edu if (objFile->isDynamic()) 4723917Ssaidi@eecs.umich.edu fatal("Object file is a dynamic executable however only static " 4735070Ssaidi@eecs.umich.edu "executables are supported!\n Please recompile your " 4743917Ssaidi@eecs.umich.edu "executable as a static binary and try again.\n"); 4753917Ssaidi@eecs.umich.edu 4765089Sgblack@eecs.umich.edu#if THE_ISA == ALPHA_ISA 4775070Ssaidi@eecs.umich.edu if (objFile->hasTLS()) 4785089Sgblack@eecs.umich.edu fatal("Object file has a TLS section and single threaded TLS is not\n" 4795089Sgblack@eecs.umich.edu " currently supported for Alpha! Please recompile your " 4805089Sgblack@eecs.umich.edu "executable with \n a non-TLS toolchain.\n"); 4815070Ssaidi@eecs.umich.edu 4822715Sstever@eecs.umich.edu if (objFile->getArch() != ObjectFile::Alpha) 4832715Sstever@eecs.umich.edu fatal("Object file architecture does not match compiled ISA (Alpha)."); 4842715Sstever@eecs.umich.edu switch (objFile->getOpSys()) { 4852715Sstever@eecs.umich.edu case ObjectFile::Tru64: 4865154Sgblack@eecs.umich.edu process = new AlphaTru64Process(params, objFile); 4872715Sstever@eecs.umich.edu break; 4882715Sstever@eecs.umich.edu 4892715Sstever@eecs.umich.edu case ObjectFile::Linux: 4905154Sgblack@eecs.umich.edu process = new AlphaLinuxProcess(params, objFile); 4912715Sstever@eecs.umich.edu break; 4922715Sstever@eecs.umich.edu 4932715Sstever@eecs.umich.edu default: 4942715Sstever@eecs.umich.edu fatal("Unknown/unsupported operating system."); 4952715Sstever@eecs.umich.edu } 4962715Sstever@eecs.umich.edu#elif THE_ISA == SPARC_ISA 4974111Sgblack@eecs.umich.edu if (objFile->getArch() != ObjectFile::SPARC64 && objFile->getArch() != ObjectFile::SPARC32) 4982715Sstever@eecs.umich.edu fatal("Object file architecture does not match compiled ISA (SPARC)."); 4992715Sstever@eecs.umich.edu switch (objFile->getOpSys()) { 5002715Sstever@eecs.umich.edu case ObjectFile::Linux: 5014111Sgblack@eecs.umich.edu if (objFile->getArch() == ObjectFile::SPARC64) { 5025154Sgblack@eecs.umich.edu process = new Sparc64LinuxProcess(params, objFile); 5034111Sgblack@eecs.umich.edu } else { 5045154Sgblack@eecs.umich.edu process = new Sparc32LinuxProcess(params, objFile); 5054111Sgblack@eecs.umich.edu } 5062715Sstever@eecs.umich.edu break; 5072715Sstever@eecs.umich.edu 5082715Sstever@eecs.umich.edu 5092715Sstever@eecs.umich.edu case ObjectFile::Solaris: 5105154Sgblack@eecs.umich.edu process = new SparcSolarisProcess(params, objFile); 5112715Sstever@eecs.umich.edu break; 5122715Sstever@eecs.umich.edu default: 5132715Sstever@eecs.umich.edu fatal("Unknown/unsupported operating system."); 5142715Sstever@eecs.umich.edu } 5154157Sgblack@eecs.umich.edu#elif THE_ISA == X86_ISA 5164157Sgblack@eecs.umich.edu if (objFile->getArch() != ObjectFile::X86) 5174166Sgblack@eecs.umich.edu fatal("Object file architecture does not match compiled ISA (x86)."); 5184157Sgblack@eecs.umich.edu switch (objFile->getOpSys()) { 5194166Sgblack@eecs.umich.edu case ObjectFile::Linux: 5205154Sgblack@eecs.umich.edu process = new X86LinuxProcess(params, objFile); 5214166Sgblack@eecs.umich.edu break; 5224157Sgblack@eecs.umich.edu default: 5234157Sgblack@eecs.umich.edu fatal("Unknown/unsupported operating system."); 5244157Sgblack@eecs.umich.edu } 5252715Sstever@eecs.umich.edu#elif THE_ISA == MIPS_ISA 5262715Sstever@eecs.umich.edu if (objFile->getArch() != ObjectFile::Mips) 5272715Sstever@eecs.umich.edu fatal("Object file architecture does not match compiled ISA (MIPS)."); 5282715Sstever@eecs.umich.edu switch (objFile->getOpSys()) { 5292715Sstever@eecs.umich.edu case ObjectFile::Linux: 5305154Sgblack@eecs.umich.edu process = new MipsLinuxProcess(params, objFile); 5312715Sstever@eecs.umich.edu break; 5322715Sstever@eecs.umich.edu 5332715Sstever@eecs.umich.edu default: 5342715Sstever@eecs.umich.edu fatal("Unknown/unsupported operating system."); 5352715Sstever@eecs.umich.edu } 5362715Sstever@eecs.umich.edu#else 5372715Sstever@eecs.umich.edu#error "THE_ISA not set" 5382715Sstever@eecs.umich.edu#endif 5392715Sstever@eecs.umich.edu 5402715Sstever@eecs.umich.edu 5412715Sstever@eecs.umich.edu if (process == NULL) 5422715Sstever@eecs.umich.edu fatal("Unknown error creating process object."); 5432715Sstever@eecs.umich.edu return process; 5442715Sstever@eecs.umich.edu} 5452715Sstever@eecs.umich.edu 5464762Snate@binkert.orgLiveProcess * 5474762Snate@binkert.orgLiveProcessParams::create() 5482715Sstever@eecs.umich.edu{ 5495154Sgblack@eecs.umich.edu return LiveProcess::create(this); 5502715Sstever@eecs.umich.edu} 551