process.cc (8737:770ccf3af571) | process.cc (8766:b0773af78423) |
---|---|
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; --- 31 unchanged lines hidden (view full) --- 40#include "base/loader/symtab.hh" 41#include "base/intmath.hh" 42#include "base/statistics.hh" 43#include "config/full_system.hh" 44#include "config/the_isa.hh" 45#include "cpu/thread_context.hh" 46#include "mem/page_table.hh" 47#include "mem/physical.hh" | 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; --- 31 unchanged lines hidden (view full) --- 40#include "base/loader/symtab.hh" 41#include "base/intmath.hh" 42#include "base/statistics.hh" 43#include "config/full_system.hh" 44#include "config/the_isa.hh" 45#include "cpu/thread_context.hh" 46#include "mem/page_table.hh" 47#include "mem/physical.hh" |
48#include "mem/se_translating_port_proxy.hh" | 48#include "mem/translating_port.hh" |
49#include "params/LiveProcess.hh" 50#include "params/Process.hh" 51#include "sim/debug.hh" 52#include "sim/process.hh" 53#include "sim/process_impl.hh" 54#include "sim/stats.hh" 55#include "sim/syscall_emul.hh" 56#include "sim/system.hh" --- 15 unchanged lines hidden (view full) --- 72#else 73#error "THE_ISA not set" 74#endif 75 76 77using namespace std; 78using namespace TheISA; 79 | 49#include "params/LiveProcess.hh" 50#include "params/Process.hh" 51#include "sim/debug.hh" 52#include "sim/process.hh" 53#include "sim/process_impl.hh" 54#include "sim/stats.hh" 55#include "sim/syscall_emul.hh" 56#include "sim/system.hh" --- 15 unchanged lines hidden (view full) --- 72#else 73#error "THE_ISA not set" 74#endif 75 76 77using namespace std; 78using namespace TheISA; 79 |
80// 81// The purpose of this code is to fake the loader & syscall mechanism 82// when there's no OS: thus there's no resone to use it in FULL_SYSTEM 83// mode when we do have an OS 84// 85#if FULL_SYSTEM 86#error "process.cc not compatible with FULL_SYSTEM" 87#endif 88 | |
89// current number of allocated processes 90int num_processes = 0; 91 92template<class IntType> 93AuxVector<IntType>::AuxVector(IntType type, IntType val) 94{ 95 a_type = TheISA::htog(type); 96 a_val = TheISA::htog(val); 97} 98 | 80// current number of allocated processes 81int num_processes = 0; 82 83template<class IntType> 84AuxVector<IntType>::AuxVector(IntType type, IntType val) 85{ 86 a_type = TheISA::htog(type); 87 a_val = TheISA::htog(val); 88} 89 |
99template struct AuxVector<uint32_t>; 100template struct AuxVector<uint64_t>; | 90template class AuxVector<uint32_t>; 91template class AuxVector<uint64_t>; |
101 102Process::Process(ProcessParams * params) 103 : SimObject(params), system(params->system), 104 max_stack_size(params->max_stack_size) 105{ 106 string in = params->input; 107 string out = params->output; 108 string err = params->errout; --- 55 unchanged lines hidden (view full) --- 164 // mark remaining fds as free 165 for (int i = 3; i <= MAX_FD; ++i) { 166 Process::FdMap *fdo = &fd_map[i]; 167 fdo->fd = -1; 168 } 169 170 mmap_start = mmap_end = 0; 171 nxm_start = nxm_end = 0; | 92 93Process::Process(ProcessParams * params) 94 : SimObject(params), system(params->system), 95 max_stack_size(params->max_stack_size) 96{ 97 string in = params->input; 98 string out = params->output; 99 string err = params->errout; --- 55 unchanged lines hidden (view full) --- 155 // mark remaining fds as free 156 for (int i = 3; i <= MAX_FD; ++i) { 157 Process::FdMap *fdo = &fd_map[i]; 158 fdo->fd = -1; 159 } 160 161 mmap_start = mmap_end = 0; 162 nxm_start = nxm_end = 0; |
172 pTable = new PageTable(name(), M5_pid); | 163 pTable = new PageTable(this); |
173 // other parameters will be initialized when the program is loaded 174} 175 176 177void 178Process::regStats() 179{ 180 using namespace Stats; --- 58 unchanged lines hidden (view full) --- 239 fatal("Process %s is not associated with any HW contexts!\n", name()); 240 241 // first thread context for this process... initialize & enable 242 ThreadContext *tc = system->getThreadContext(contextIds[0]); 243 244 // mark this context as active so it will start ticking. 245 tc->activate(0); 246 | 164 // other parameters will be initialized when the program is loaded 165} 166 167 168void 169Process::regStats() 170{ 171 using namespace Stats; --- 58 unchanged lines hidden (view full) --- 230 fatal("Process %s is not associated with any HW contexts!\n", name()); 231 232 // first thread context for this process... initialize & enable 233 ThreadContext *tc = system->getThreadContext(contextIds[0]); 234 235 // mark this context as active so it will start ticking. 236 tc->activate(0); 237 |
247 initVirtMem = new SETranslatingPortProxy(*system->getSystemPort(), this, 248 SETranslatingPortProxy::Always); | 238 Port *mem_port; 239 mem_port = system->physmem->getPort("functional"); 240 initVirtMem = new TranslatingPort("process init port", this, 241 TranslatingPort::Always); 242 mem_port->setPeer(initVirtMem); 243 initVirtMem->setPeer(mem_port); |
249} 250 251// map simulator fd sim_fd to target fd tgt_fd 252void 253Process::dup_fd(int sim_fd, int tgt_fd) 254{ 255 if (tgt_fd < 0 || tgt_fd > MAX_FD) 256 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd); --- 62 unchanged lines hidden (view full) --- 319Process::sim_fd_obj(int tgt_fd) 320{ 321 if (tgt_fd < 0 || tgt_fd > MAX_FD) 322 return NULL; 323 324 return &fd_map[tgt_fd]; 325} 326 | 244} 245 246// map simulator fd sim_fd to target fd tgt_fd 247void 248Process::dup_fd(int sim_fd, int tgt_fd) 249{ 250 if (tgt_fd < 0 || tgt_fd > MAX_FD) 251 panic("Process::dup_fd tried to dup past MAX_FD (%d)", tgt_fd); --- 62 unchanged lines hidden (view full) --- 314Process::sim_fd_obj(int tgt_fd) 315{ 316 if (tgt_fd < 0 || tgt_fd > MAX_FD) 317 return NULL; 318 319 return &fd_map[tgt_fd]; 320} 321 |
327void 328Process::allocateMem(Addr vaddr, int64_t size, bool clobber) 329{ 330 int npages = divCeil(size, (int64_t)VMPageSize); 331 Addr paddr = system->allocPhysPages(npages); 332 pTable->map(vaddr, paddr, size, clobber); 333} 334 | |
335bool 336Process::fixupStackFault(Addr vaddr) 337{ 338 // Check if this is already on the stack and there's just no page there 339 // yet. 340 if (vaddr >= stack_min && vaddr < stack_base) { | 322bool 323Process::fixupStackFault(Addr vaddr) 324{ 325 // Check if this is already on the stack and there's just no page there 326 // yet. 327 if (vaddr >= stack_min && vaddr < stack_base) { |
341 allocateMem(roundDown(vaddr, VMPageSize), VMPageSize); | 328 pTable->allocate(roundDown(vaddr, VMPageSize), VMPageSize); |
342 return true; 343 } 344 345 // We've accessed the next page of the stack, so extend it to include 346 // this address. 347 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) { 348 while (vaddr < stack_min) { 349 stack_min -= TheISA::PageBytes; 350 if (stack_base - stack_min > max_stack_size) 351 fatal("Maximum stack size exceeded\n"); 352 if (stack_base - stack_min > 8 * 1024 * 1024) 353 fatal("Over max stack size for one thread\n"); | 329 return true; 330 } 331 332 // We've accessed the next page of the stack, so extend it to include 333 // this address. 334 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) { 335 while (vaddr < stack_min) { 336 stack_min -= TheISA::PageBytes; 337 if (stack_base - stack_min > max_stack_size) 338 fatal("Maximum stack size exceeded\n"); 339 if (stack_base - stack_min > 8 * 1024 * 1024) 340 fatal("Over max stack size for one thread\n"); |
354 allocateMem(stack_min, TheISA::PageBytes); | 341 pTable->allocate(stack_min, TheISA::PageBytes); |
355 inform("Increasing stack size by one page."); 356 }; 357 return true; 358 } | 342 inform("Increasing stack size by one page."); 343 }; 344 return true; 345 } |
346 warn("Not extending stack: address %#x isn't at the end of the stack.", 347 vaddr); |
|
359 return false; 360} 361 362// find all offsets for currently open files and save them 363void 364Process::fix_file_offsets() 365{ 366 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO]; --- 209 unchanged lines hidden (view full) --- 576 debugSymbolTable = NULL; 577 } 578 } 579} 580 581void 582LiveProcess::syscall(int64_t callnum, ThreadContext *tc) 583{ | 348 return false; 349} 350 351// find all offsets for currently open files and save them 352void 353Process::fix_file_offsets() 354{ 355 Process::FdMap *fdo_stdin = &fd_map[STDIN_FILENO]; --- 209 unchanged lines hidden (view full) --- 565 debugSymbolTable = NULL; 566 } 567 } 568} 569 570void 571LiveProcess::syscall(int64_t callnum, ThreadContext *tc) 572{ |
573#if !FULL_SYSTEM |
|
584 num_syscalls++; 585 586 SyscallDesc *desc = getDesc(callnum); 587 if (desc == NULL) 588 fatal("Syscall %d out of range", callnum); 589 590 desc->doSyscall(callnum, this, tc); | 574 num_syscalls++; 575 576 SyscallDesc *desc = getDesc(callnum); 577 if (desc == NULL) 578 fatal("Syscall %d out of range", callnum); 579 580 desc->doSyscall(callnum, this, tc); |
581#endif |
|
591} 592 593IntReg 594LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width) 595{ 596 return getSyscallArg(tc, i); 597} 598 --- 9 unchanged lines hidden (view full) --- 608 fatal("Can't load object file %s", executable); 609 } 610 611 if (objFile->isDynamic()) 612 fatal("Object file is a dynamic executable however only static " 613 "executables are supported!\n Please recompile your " 614 "executable as a static binary and try again.\n"); 615 | 582} 583 584IntReg 585LiveProcess::getSyscallArg(ThreadContext *tc, int &i, int width) 586{ 587 return getSyscallArg(tc, i); 588} 589 --- 9 unchanged lines hidden (view full) --- 599 fatal("Can't load object file %s", executable); 600 } 601 602 if (objFile->isDynamic()) 603 fatal("Object file is a dynamic executable however only static " 604 "executables are supported!\n Please recompile your " 605 "executable as a static binary and try again.\n"); 606 |
607#if !FULL_SYSTEM |
|
616#if THE_ISA == ALPHA_ISA 617 if (objFile->getArch() != ObjectFile::Alpha) 618 fatal("Object file architecture does not match compiled ISA (Alpha)."); 619 620 switch (objFile->getOpSys()) { 621 case ObjectFile::Tru64: 622 process = new AlphaTru64Process(params, objFile); 623 break; --- 94 unchanged lines hidden (view full) --- 718 break; 719 720 default: 721 fatal("Unknown/unsupported operating system."); 722 } 723#else 724#error "THE_ISA not set" 725#endif | 608#if THE_ISA == ALPHA_ISA 609 if (objFile->getArch() != ObjectFile::Alpha) 610 fatal("Object file architecture does not match compiled ISA (Alpha)."); 611 612 switch (objFile->getOpSys()) { 613 case ObjectFile::Tru64: 614 process = new AlphaTru64Process(params, objFile); 615 break; --- 94 unchanged lines hidden (view full) --- 710 break; 711 712 default: 713 fatal("Unknown/unsupported operating system."); 714 } 715#else 716#error "THE_ISA not set" 717#endif |
718#endif |
|
726 | 719 |
727 | |
728 if (process == NULL) 729 fatal("Unknown error creating process object."); 730 return process; 731} 732 733LiveProcess * 734LiveProcessParams::create() 735{ 736 return LiveProcess::create(this); 737} | 720 if (process == NULL) 721 fatal("Unknown error creating process object."); 722 return process; 723} 724 725LiveProcess * 726LiveProcessParams::create() 727{ 728 return LiveProcess::create(this); 729} |