1/*
|
2 * Copyright (c) 2014 Advanced Micro Devices, Inc.
|
2 * Copyright (c) 2014-2016 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 * Brandon Potter |
45 */ 46 47#include "sim/process.hh" 48 49#include <fcntl.h> 50#include <unistd.h> 51 52#include <array> 53#include <map> 54#include <string> 55#include <vector> 56 57#include "base/intmath.hh" 58#include "base/loader/object_file.hh" 59#include "base/loader/symtab.hh" 60#include "base/statistics.hh" 61#include "config/the_isa.hh" 62#include "cpu/thread_context.hh" 63#include "mem/page_table.hh" 64#include "mem/se_translating_port_proxy.hh" 65#include "params/Process.hh" 66#include "sim/emul_driver.hh"
|
67#include "sim/fd_array.hh" 68#include "sim/fd_entry.hh" |
69#include "sim/syscall_desc.hh" 70#include "sim/system.hh" 71 72#if THE_ISA == ALPHA_ISA 73#include "arch/alpha/linux/process.hh" 74#elif THE_ISA == SPARC_ISA 75#include "arch/sparc/linux/process.hh" 76#include "arch/sparc/solaris/process.hh" 77#elif THE_ISA == MIPS_ISA 78#include "arch/mips/linux/process.hh" 79#elif THE_ISA == ARM_ISA 80#include "arch/arm/linux/process.hh" 81#include "arch/arm/freebsd/process.hh" 82#elif THE_ISA == X86_ISA 83#include "arch/x86/linux/process.hh" 84#elif THE_ISA == POWER_ISA 85#include "arch/power/linux/process.hh" 86#elif THE_ISA == RISCV_ISA 87#include "arch/riscv/linux/process.hh" 88#else 89#error "THE_ISA not set" 90#endif 91 92 93using namespace std; 94using namespace TheISA; 95
|
93static int
94openFile(const string& filename, int flags, mode_t mode)
95{
96 int sim_fd = open(filename.c_str(), flags, mode);
97 if (sim_fd != -1)
98 return sim_fd;
99 fatal("Unable to open %s with mode %O", filename, mode);
100}
101
102static int
103openInputFile(const string &filename)
104{
105 return openFile(filename, O_RDONLY, 0);
106}
107
108static int
109openOutputFile(const string &filename)
110{
111 return openFile(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
112}
113
|
96Process::Process(ProcessParams * params, ObjectFile * obj_file) 97 : SimObject(params), system(params->system), 98 brk_point(0), stack_base(0), stack_size(0), stack_min(0), 99 max_stack_size(params->max_stack_size), 100 next_thread_stack_base(0), 101 useArchPT(params->useArchPT), 102 kvmInSE(params->kvmInSE), 103 pTable(useArchPT ? 104 static_cast<PageTableBase *>(new ArchPageTable(name(), params->pid, 105 system)) : 106 static_cast<PageTableBase *>(new FuncPageTable(name(), params->pid))), 107 initVirtMem(system->getSystemPort(), this, 108 SETranslatingPortProxy::Always),
|
127 fd_array(make_shared<array<FDEntry, NUM_FDS>>()),
128 imap {{"", -1},
129 {"cin", STDIN_FILENO},
130 {"stdin", STDIN_FILENO}},
131 oemap{{"", -1},
132 {"cout", STDOUT_FILENO},
133 {"stdout", STDOUT_FILENO},
134 {"cerr", STDERR_FILENO},
135 {"stderr", STDERR_FILENO}},
|
109 objFile(obj_file), 110 argv(params->cmd), envp(params->env), cwd(params->cwd), 111 executable(params->executable), 112 _uid(params->uid), _euid(params->euid), 113 _gid(params->gid), _egid(params->egid), 114 _pid(params->pid), _ppid(params->ppid),
|
142 drivers(params->drivers)
|
115 drivers(params->drivers), 116 fds(make_shared<FDArray>(params->input, params->output, params->errout)) |
117{
|
144 int sim_fd;
145 std::map<string,int>::iterator it;
146
147 // Search through the input options and set fd if match is found;
148 // otherwise, open an input file and seek to location.
149 FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
150 if ((it = imap.find(params->input)) != imap.end())
151 sim_fd = it->second;
152 else
153 sim_fd = openInputFile(params->input);
154 fde_stdin->set(sim_fd, params->input, O_RDONLY, -1, false);
155
156 // Search through the output/error options and set fd if match is found;
157 // otherwise, open an output file and seek to location.
158 FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO);
159 if ((it = oemap.find(params->output)) != oemap.end())
160 sim_fd = it->second;
161 else
162 sim_fd = openOutputFile(params->output);
163 fde_stdout->set(sim_fd, params->output, O_WRONLY | O_CREAT | O_TRUNC,
164 0664, false);
165
166 FDEntry *fde_stderr = getFDEntry(STDERR_FILENO);
167 if (params->output == params->errout)
168 // Reuse the same file descriptor if these match.
169 sim_fd = fde_stdout->fd;
170 else if ((it = oemap.find(params->errout)) != oemap.end())
171 sim_fd = it->second;
172 else
173 sim_fd = openOutputFile(params->errout);
174 fde_stderr->set(sim_fd, params->errout, O_WRONLY | O_CREAT | O_TRUNC,
175 0664, false);
176
|
118 mmap_end = 0;
|
178 // other parameters will be initialized when the program is loaded
|
119 120 // load up symbols, if any... these may be used for debugging or 121 // profiling. 122 if (!debugSymbolTable) { 123 debugSymbolTable = new SymbolTable(); 124 if (!objFile->loadGlobalSymbols(debugSymbolTable) || 125 !objFile->loadLocalSymbols(debugSymbolTable) || 126 !objFile->loadWeakSymbols(debugSymbolTable)) { 127 // didn't load any symbols 128 delete debugSymbolTable; 129 debugSymbolTable = NULL; 130 } 131 } 132} 133 134void 135Process::regStats() 136{ 137 SimObject::regStats(); 138 139 using namespace Stats; 140 141 num_syscalls 142 .name(name() + ".num_syscalls") 143 .desc("Number of system calls") 144 ; 145} 146
|
207void
208Process::inheritFDArray(Process *p)
209{
210 fd_array = p->fd_array;
211}
212
|
147ThreadContext * 148Process::findFreeContext() 149{ 150 for (int id : contextIds) { 151 ThreadContext *tc = system->getThreadContext(id); 152 if (tc->status() == ThreadContext::Halted) 153 return tc; 154 } 155 return NULL; 156} 157 158void 159Process::initState() 160{ 161 if (contextIds.empty()) 162 fatal("Process %s is not associated with any HW contexts!\n", name()); 163 164 // first thread context for this process... initialize & enable 165 ThreadContext *tc = system->getThreadContext(contextIds[0]); 166 167 // mark this context as active so it will start ticking. 168 tc->activate(); 169 170 pTable->initState(tc); 171} 172 173DrainState 174Process::drain() 175{
|
242 findFileOffsets();
|
176 fds->updateFileOffsets(); |
177 return DrainState::Drained; 178} 179
|
246int
247Process::allocFD(int sim_fd, const string& filename, int flags, int mode,
248 bool pipe)
249{
250 for (int free_fd = 0; free_fd < fd_array->size(); free_fd++) {
251 FDEntry *fde = getFDEntry(free_fd);
252 if (fde->isFree()) {
253 fde->set(sim_fd, filename, flags, mode, pipe);
254 return free_fd;
255 }
256 }
257
258 fatal("Out of target file descriptors");
259}
260
|
180void
|
262Process::resetFDEntry(int tgt_fd)
263{
264 FDEntry *fde = getFDEntry(tgt_fd);
265 assert(fde->fd > -1);
266
267 fde->reset();
268}
269
270int
271Process::getSimFD(int tgt_fd)
272{
273 FDEntry *entry = getFDEntry(tgt_fd);
274 return entry ? entry->fd : -1;
275}
276
277FDEntry *
278Process::getFDEntry(int tgt_fd)
279{
280 assert(0 <= tgt_fd && tgt_fd < fd_array->size());
281 return &(*fd_array)[tgt_fd];
282}
283
284int
285Process::getTgtFD(int sim_fd)
286{
287 for (int index = 0; index < fd_array->size(); index++)
288 if ((*fd_array)[index].fd == sim_fd)
289 return index;
290 return -1;
291}
292
293void
|
181Process::allocateMem(Addr vaddr, int64_t size, bool clobber) 182{ 183 int npages = divCeil(size, (int64_t)PageBytes); 184 Addr paddr = system->allocPhysPages(npages); 185 pTable->map(vaddr, paddr, size, 186 clobber ? PageTableBase::Clobber : PageTableBase::Zero); 187} 188 189bool 190Process::fixupStackFault(Addr vaddr) 191{ 192 // Check if this is already on the stack and there's just no page there 193 // yet. 194 if (vaddr >= stack_min && vaddr < stack_base) { 195 allocateMem(roundDown(vaddr, PageBytes), PageBytes); 196 return true; 197 } 198 199 // We've accessed the next page of the stack, so extend it to include 200 // this address. 201 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) { 202 while (vaddr < stack_min) { 203 stack_min -= TheISA::PageBytes; 204 if (stack_base - stack_min > max_stack_size) 205 fatal("Maximum stack size exceeded\n"); 206 allocateMem(stack_min, TheISA::PageBytes); 207 inform("Increasing stack size by one page."); 208 }; 209 return true; 210 } 211 return false; 212} 213 214void
|
328Process::fixFileOffsets()
329{
330 auto seek = [] (FDEntry *fde)
331 {
332 if (lseek(fde->fd, fde->fileOffset, SEEK_SET) < 0)
333 fatal("Unable to see to location in %s", fde->filename);
334 };
335
336 std::map<string,int>::iterator it;
337
338 // Search through the input options and set fd if match is found;
339 // otherwise, open an input file and seek to location.
340 FDEntry *fde_stdin = getFDEntry(STDIN_FILENO);
341
342 // Check if user has specified a different input file, and if so, use it
343 // instead of the file specified in the checkpoint. This also resets the
344 // file offset from the checkpointed value
345 string new_in = ((ProcessParams*)params())->input;
346 if (new_in != fde_stdin->filename) {
347 warn("Using new input file (%s) rather than checkpointed (%s)\n",
348 new_in, fde_stdin->filename);
349 fde_stdin->filename = new_in;
350 fde_stdin->fileOffset = 0;
351 }
352
353 if ((it = imap.find(fde_stdin->filename)) != imap.end()) {
354 fde_stdin->fd = it->second;
355 } else {
356 fde_stdin->fd = openInputFile(fde_stdin->filename);
357 seek(fde_stdin);
358 }
359
360 // Search through the output/error options and set fd if match is found;
361 // otherwise, open an output file and seek to location.
362 FDEntry *fde_stdout = getFDEntry(STDOUT_FILENO);
363
364 // Check if user has specified a different output file, and if so, use it
365 // instead of the file specified in the checkpoint. This also resets the
366 // file offset from the checkpointed value
367 string new_out = ((ProcessParams*)params())->output;
368 if (new_out != fde_stdout->filename) {
369 warn("Using new output file (%s) rather than checkpointed (%s)\n",
370 new_out, fde_stdout->filename);
371 fde_stdout->filename = new_out;
372 fde_stdout->fileOffset = 0;
373 }
374
375 if ((it = oemap.find(fde_stdout->filename)) != oemap.end()) {
376 fde_stdout->fd = it->second;
377 } else {
378 fde_stdout->fd = openOutputFile(fde_stdout->filename);
379 seek(fde_stdout);
380 }
381
382 FDEntry *fde_stderr = getFDEntry(STDERR_FILENO);
383
384 // Check if user has specified a different error file, and if so, use it
385 // instead of the file specified in the checkpoint. This also resets the
386 // file offset from the checkpointed value
387 string new_err = ((ProcessParams*)params())->errout;
388 if (new_err != fde_stderr->filename) {
389 warn("Using new error file (%s) rather than checkpointed (%s)\n",
390 new_err, fde_stderr->filename);
391 fde_stderr->filename = new_err;
392 fde_stderr->fileOffset = 0;
393 }
394
395 if (fde_stdout->filename == fde_stderr->filename) {
396 // Reuse the same file descriptor if these match.
397 fde_stderr->fd = fde_stdout->fd;
398 } else if ((it = oemap.find(fde_stderr->filename)) != oemap.end()) {
399 fde_stderr->fd = it->second;
400 } else {
401 fde_stderr->fd = openOutputFile(fde_stderr->filename);
402 seek(fde_stderr);
403 }
404
405 for (int tgt_fd = 3; tgt_fd < fd_array->size(); tgt_fd++) {
406 FDEntry *fde = getFDEntry(tgt_fd);
407 if (fde->fd == -1)
408 continue;
409
410 if (fde->isPipe) {
411 if (fde->filename == "PIPE-WRITE")
412 continue;
413 assert(fde->filename == "PIPE-READ");
414
415 int fds[2];
416 if (pipe(fds) < 0)
417 fatal("Unable to create new pipe");
418
419 fde->fd = fds[0];
420
421 FDEntry *fde_write = getFDEntry(fde->readPipeSource);
422 assert(fde_write->filename == "PIPE-WRITE");
423 fde_write->fd = fds[1];
424 } else {
425 fde->fd = openFile(fde->filename.c_str(), fde->flags, fde->mode);
426 seek(fde);
427 }
428 }
429}
430
431void
432Process::findFileOffsets()
433{
434 for (auto& fde : *fd_array) {
435 if (fde.fd != -1)
436 fde.fileOffset = lseek(fde.fd, 0, SEEK_CUR);
437 }
438}
439
440void
441Process::setReadPipeSource(int read_pipe_fd, int source_fd)
442{
443 FDEntry *fde = getFDEntry(read_pipe_fd);
444 assert(source_fd >= -1);
445 fde->readPipeSource = source_fd;
446}
447
448void
|
215Process::serialize(CheckpointOut &cp) const 216{ 217 SERIALIZE_SCALAR(brk_point); 218 SERIALIZE_SCALAR(stack_base); 219 SERIALIZE_SCALAR(stack_size); 220 SERIALIZE_SCALAR(stack_min); 221 SERIALIZE_SCALAR(next_thread_stack_base); 222 SERIALIZE_SCALAR(mmap_end); 223 pTable->serialize(cp);
|
458 for (int x = 0; x < fd_array->size(); x++) {
459 (*fd_array)[x].serializeSection(cp, csprintf("FDEntry%d", x));
460 }
|
224 /** 225 * Checkpoints for file descriptors currently do not work. Need to 226 * come back and fix them at a later date. 227 */ |
228
|
229 warn("Checkpoints for file descriptors currently do not work."); 230#if 0 231 for (int x = 0; x < fds->getSize(); x++) 232 (*fds)[x].serializeSection(cp, csprintf("FDEntry%d", x)); 233#endif 234 |
235} 236 237void 238Process::unserialize(CheckpointIn &cp) 239{ 240 UNSERIALIZE_SCALAR(brk_point); 241 UNSERIALIZE_SCALAR(stack_base); 242 UNSERIALIZE_SCALAR(stack_size); 243 UNSERIALIZE_SCALAR(stack_min); 244 UNSERIALIZE_SCALAR(next_thread_stack_base); 245 UNSERIALIZE_SCALAR(mmap_end); 246 pTable->unserialize(cp);
|
474 for (int x = 0; x < fd_array->size(); x++) {
475 FDEntry *fde = getFDEntry(x);
476 fde->unserializeSection(cp, csprintf("FDEntry%d", x));
477 }
478 fixFileOffsets();
|
247 /** 248 * Checkpoints for file descriptors currently do not work. Need to 249 * come back and fix them at a later date. 250 */ 251 warn("Checkpoints for file descriptors currently do not work."); 252#if 0 253 for (int x = 0; x < fds->getSize(); x++) 254 (*fds)[x]->unserializeSection(cp, csprintf("FDEntry%d", x)); 255 fds->restoreFileOffsets(); 256#endif |
257 // The above returns a bool so that you could do something if you don't 258 // find the param in the checkpoint if you wanted to, like set a default 259 // but in this case we'll just stick with the instantiated value if not 260 // found. 261} 262 263bool 264Process::map(Addr vaddr, Addr paddr, int size, bool cacheable) 265{ 266 pTable->map(vaddr, paddr, size, 267 cacheable ? PageTableBase::Zero : PageTableBase::Uncacheable); 268 return true; 269} 270 271void 272Process::syscall(int64_t callnum, ThreadContext *tc) 273{ 274 num_syscalls++; 275 276 SyscallDesc *desc = getDesc(callnum); 277 if (desc == NULL) 278 fatal("Syscall %d out of range", callnum); 279 280 desc->doSyscall(callnum, this, tc); 281} 282 283IntReg 284Process::getSyscallArg(ThreadContext *tc, int &i, int width) 285{ 286 return getSyscallArg(tc, i); 287} 288 289EmulatedDriver * 290Process::findDriver(std::string filename) 291{ 292 for (EmulatedDriver *d : drivers) { 293 if (d->match(filename)) 294 return d; 295 } 296 297 return NULL; 298} 299 300void 301Process::updateBias() 302{ 303 ObjectFile *interp = objFile->getInterpreter(); 304 305 if (!interp || !interp->relocatable()) 306 return; 307 308 // Determine how large the interpreters footprint will be in the process 309 // address space. 310 Addr interp_mapsize = roundUp(interp->mapSize(), TheISA::PageBytes); 311 312 // We are allocating the memory area; set the bias to the lowest address 313 // in the allocated memory region. 314 Addr ld_bias = mmapGrowsDown() ? mmap_end - interp_mapsize : mmap_end; 315 316 // Adjust the process mmap area to give the interpreter room; the real 317 // execve system call would just invoke the kernel's internal mmap 318 // functions to make these adjustments. 319 mmap_end = mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize; 320 321 interp->updateBias(ld_bias); 322} 323 324ObjectFile * 325Process::getInterpreter() 326{ 327 return objFile->getInterpreter(); 328} 329 330Addr 331Process::getBias() 332{ 333 ObjectFile *interp = getInterpreter(); 334 335 return interp ? interp->bias() : objFile->bias(); 336} 337 338Addr 339Process::getStartPC() 340{ 341 ObjectFile *interp = getInterpreter(); 342 343 return interp ? interp->entryPoint() : objFile->entryPoint(); 344} 345 346Process * 347ProcessParams::create() 348{ 349 Process *process = NULL; 350 351 // If not specified, set the executable parameter equal to the 352 // simulated system's zeroth command line parameter 353 if (executable == "") { 354 executable = cmd[0]; 355 } 356 357 ObjectFile *obj_file = createObjectFile(executable); 358 if (obj_file == NULL) { 359 fatal("Can't load object file %s", executable); 360 } 361 362#if THE_ISA == ALPHA_ISA 363 if (obj_file->getArch() != ObjectFile::Alpha) 364 fatal("Object file architecture does not match compiled ISA (Alpha)."); 365 366 switch (obj_file->getOpSys()) { 367 case ObjectFile::UnknownOpSys: 368 warn("Unknown operating system; assuming Linux."); 369 // fall through 370 case ObjectFile::Linux: 371 process = new AlphaLinuxProcess(this, obj_file); 372 break; 373 374 default: 375 fatal("Unknown/unsupported operating system."); 376 } 377#elif THE_ISA == SPARC_ISA 378 if (obj_file->getArch() != ObjectFile::SPARC64 && 379 obj_file->getArch() != ObjectFile::SPARC32) 380 fatal("Object file architecture does not match compiled ISA (SPARC)."); 381 switch (obj_file->getOpSys()) { 382 case ObjectFile::UnknownOpSys: 383 warn("Unknown operating system; assuming Linux."); 384 // fall through 385 case ObjectFile::Linux: 386 if (obj_file->getArch() == ObjectFile::SPARC64) { 387 process = new Sparc64LinuxProcess(this, obj_file); 388 } else { 389 process = new Sparc32LinuxProcess(this, obj_file); 390 } 391 break; 392 393 case ObjectFile::Solaris: 394 process = new SparcSolarisProcess(this, obj_file); 395 break; 396 397 default: 398 fatal("Unknown/unsupported operating system."); 399 } 400#elif THE_ISA == X86_ISA 401 if (obj_file->getArch() != ObjectFile::X86_64 && 402 obj_file->getArch() != ObjectFile::I386) 403 fatal("Object file architecture does not match compiled ISA (x86)."); 404 switch (obj_file->getOpSys()) { 405 case ObjectFile::UnknownOpSys: 406 warn("Unknown operating system; assuming Linux."); 407 // fall through 408 case ObjectFile::Linux: 409 if (obj_file->getArch() == ObjectFile::X86_64) { 410 process = new X86_64LinuxProcess(this, obj_file); 411 } else { 412 process = new I386LinuxProcess(this, obj_file); 413 } 414 break; 415 416 default: 417 fatal("Unknown/unsupported operating system."); 418 } 419#elif THE_ISA == MIPS_ISA 420 if (obj_file->getArch() != ObjectFile::Mips) 421 fatal("Object file architecture does not match compiled ISA (MIPS)."); 422 switch (obj_file->getOpSys()) { 423 case ObjectFile::UnknownOpSys: 424 warn("Unknown operating system; assuming Linux."); 425 // fall through 426 case ObjectFile::Linux: 427 process = new MipsLinuxProcess(this, obj_file); 428 break; 429 430 default: 431 fatal("Unknown/unsupported operating system."); 432 } 433#elif THE_ISA == ARM_ISA 434 ObjectFile::Arch arch = obj_file->getArch(); 435 if (arch != ObjectFile::Arm && arch != ObjectFile::Thumb && 436 arch != ObjectFile::Arm64) 437 fatal("Object file architecture does not match compiled ISA (ARM)."); 438 switch (obj_file->getOpSys()) { 439 case ObjectFile::UnknownOpSys: 440 warn("Unknown operating system; assuming Linux."); 441 // fall through 442 case ObjectFile::Linux: 443 if (arch == ObjectFile::Arm64) { 444 process = new ArmLinuxProcess64(this, obj_file, 445 obj_file->getArch()); 446 } else { 447 process = new ArmLinuxProcess32(this, obj_file, 448 obj_file->getArch()); 449 } 450 break; 451 case ObjectFile::FreeBSD: 452 if (arch == ObjectFile::Arm64) { 453 process = new ArmFreebsdProcess64(this, obj_file, 454 obj_file->getArch()); 455 } else { 456 process = new ArmFreebsdProcess32(this, obj_file, 457 obj_file->getArch()); 458 } 459 break; 460 case ObjectFile::LinuxArmOABI: 461 fatal("M5 does not support ARM OABI binaries. Please recompile with an" 462 " EABI compiler."); 463 default: 464 fatal("Unknown/unsupported operating system."); 465 } 466#elif THE_ISA == POWER_ISA 467 if (obj_file->getArch() != ObjectFile::Power) 468 fatal("Object file architecture does not match compiled ISA (Power)."); 469 switch (obj_file->getOpSys()) { 470 case ObjectFile::UnknownOpSys: 471 warn("Unknown operating system; assuming Linux."); 472 // fall through 473 case ObjectFile::Linux: 474 process = new PowerLinuxProcess(this, obj_file); 475 break; 476 477 default: 478 fatal("Unknown/unsupported operating system."); 479 } 480#elif THE_ISA == RISCV_ISA 481 if (obj_file->getArch() != ObjectFile::Riscv) 482 fatal("Object file architecture does not match compiled ISA (RISCV)."); 483 switch (obj_file->getOpSys()) { 484 case ObjectFile::UnknownOpSys: 485 warn("Unknown operating system; assuming Linux."); 486 // fall through 487 case ObjectFile::Linux: 488 process = new RiscvLinuxProcess(this, obj_file); 489 break; 490 default: 491 fatal("Unknown/unsupported operating system."); 492 } 493#else 494#error "THE_ISA not set" 495#endif 496 497 if (process == NULL) 498 fatal("Unknown error creating process object."); 499 return process; 500} 501 502std::string 503Process::fullPath(const std::string &file_name) 504{ 505 if (file_name[0] == '/' || cwd.empty()) 506 return file_name; 507 508 std::string full = cwd; 509 510 if (cwd[cwd.size() - 1] != '/') 511 full += '/'; 512 513 return full + file_name; 514}
|