62 #include "config/the_isa.hh"
66 #include "params/Process.hh"
73 #if THE_ISA == ALPHA_ISA
76 #elif THE_ISA == SPARC_ISA
80 #elif THE_ISA == MIPS_ISA
83 #elif THE_ISA == ARM_ISA
87 #elif THE_ISA == X86_ISA
90 #elif THE_ISA == POWER_ISA
93 #elif THE_ISA == RISCV_ISA
97 #error "THE_ISA not set"
102 using namespace TheISA;
106 useArchPT(params->useArchPT),
107 kvmInSE(params->kvmInSE),
112 initVirtMem(
system->getSystemPort(), this,
115 argv(params->cmd), envp(params->env), cwd(params->cwd),
116 executable(params->executable),
117 _uid(params->uid), _euid(params->euid),
118 _gid(params->gid), _egid(params->egid),
119 _pid(params->pid), _ppid(params->ppid),
120 _pgid(params->pgid), drivers(params->drivers),
121 fds(make_shared<
FDArray>(params->input, params->
output, params->errout)),
128 if (!ret_pair.second)
167 #define CLONE_FILES 0
170 #define CLONE_THREAD 0
192 for (
auto map : mappings) {
216 for (
int tgt_fd = 0; tgt_fd <
fds->getSize(); tgt_fd++) {
217 std::shared_ptr<FDArray> nfds = np->
fds;
218 std::shared_ptr<FDEntry> this_fde = (*fds)[tgt_fd];
220 nfds->setFDEntry(tgt_fd,
nullptr);
223 nfds->setFDEntry(tgt_fd, this_fde->clone());
225 auto this_hbfd = std::dynamic_pointer_cast<
HBFDEntry>(this_fde);
229 int this_sim_fd = this_hbfd->
getSimFD();
230 if (this_sim_fd <= 2)
233 int np_sim_fd = dup(this_sim_fd);
234 assert(np_sim_fd != -1);
236 auto nhbfd = std::dynamic_pointer_cast<
HBFDEntry>((*nfds)[tgt_fd]);
256 using namespace Stats;
260 .
desc(
"Number of system calls")
279 if (*it == context_id) {
284 warn(
"Unable to find thread context to revoke");
291 fatal(
"Process %s is not associated with any HW contexts!\n",
name());
305 fds->updateFileOffsets();
346 if (vaddr >= stack_min && vaddr < stack_base) {
353 if (vaddr < stack_min && vaddr >= stack_base - max_stack_size) {
354 while (vaddr < stack_min) {
356 if (stack_base - stack_min > max_stack_size)
357 fatal(
"Maximum stack size exceeded\n");
359 inform(
"Increasing stack size by one page.");
376 warn(
"Checkpoints for file descriptors currently do not work.");
378 for (
int x = 0;
x <
fds->getSize();
x++)
392 warn(
"Checkpoints for file descriptors currently do not work.");
394 for (
int x = 0;
x <
fds->getSize();
x++)
396 fds->restoreFileOffsets();
419 fatal(
"Syscall %d out of range", callnum);
421 desc->
doSyscall(callnum,
this, tc, fault);
434 if (
d->match(filename))
461 mmap_end =
mmapGrowsDown() ? ld_bias : mmap_end + interp_mapsize;
490 ProcessParams::create()
501 if (obj_file ==
nullptr) {
505 #if THE_ISA == ALPHA_ISA
507 fatal(
"Object file architecture does not match compiled ISA (Alpha).");
511 warn(
"Unknown operating system; assuming Linux.");
514 process =
new AlphaLinuxProcess(
this, obj_file);
518 fatal(
"Unknown/unsupported operating system.");
520 #elif THE_ISA == SPARC_ISA
523 fatal(
"Object file architecture does not match compiled ISA (SPARC).");
526 warn(
"Unknown operating system; assuming Linux.");
530 process =
new Sparc64LinuxProcess(
this, obj_file);
532 process =
new Sparc32LinuxProcess(
this, obj_file);
537 process =
new SparcSolarisProcess(
this, obj_file);
541 fatal(
"Unknown/unsupported operating system.");
543 #elif THE_ISA == X86_ISA
546 fatal(
"Object file architecture does not match compiled ISA (x86).");
549 warn(
"Unknown operating system; assuming Linux.");
553 process =
new X86_64LinuxProcess(
this, obj_file);
555 process =
new I386LinuxProcess(
this, obj_file);
560 fatal(
"Unknown/unsupported operating system.");
562 #elif THE_ISA == MIPS_ISA
564 fatal(
"Object file architecture does not match compiled ISA (MIPS).");
567 warn(
"Unknown operating system; assuming Linux.");
574 fatal(
"Unknown/unsupported operating system.");
576 #elif THE_ISA == ARM_ISA
580 fatal(
"Object file architecture does not match compiled ISA (ARM).");
583 warn(
"Unknown operating system; assuming Linux.");
604 fatal(
"M5 does not support ARM OABI binaries. Please recompile with an"
607 fatal(
"Unknown/unsupported operating system.");
609 #elif THE_ISA == POWER_ISA
611 fatal(
"Object file architecture does not match compiled ISA (Power).");
614 warn(
"Unknown operating system; assuming Linux.");
621 fatal(
"Unknown/unsupported operating system.");
623 #elif THE_ISA == RISCV_ISA
625 fatal(
"Object file architecture does not match compiled ISA (RISCV).");
628 warn(
"Unknown operating system; assuming Linux.");
634 fatal(
"Unknown/unsupported operating system.");
637 #error "THE_ISA not set"
640 if (process ==
nullptr)
641 fatal(
"Unknown error creating process object.");
648 if (file_name[0] ==
'/' ||
cwd.empty())
651 std::string full =
cwd;
653 if (
cwd[
cwd.size() - 1] !=
'/')
656 return full + file_name;
virtual SyscallDesc * getDesc(int callnum)=0
Declaration of functional page table.
void revokeThreadContext(int context_id)
After delegating a thread context to a child process no longer should relate to the ThreadContext...
const std::string & name()
static void output(const char *filename)
virtual void getMappings(std::vector< std::pair< Addr, Addr >> *addr_mappings)
DrainState
Object drain/handover states.
virtual bool loadGlobalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=maxAddr)=0
virtual void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags=0)=0
Maps a virtual memory region to a physical memory region.
std::vector< ContextID > contextIds
A process with emulated Arm/Linux syscalls.
A process with emulated Mips/Linux syscalls.
void doSyscall(int callnum, Process *proc, ThreadContext *tc, Fault *fault)
Interface for invoking the system call funcion pointer.
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
virtual bool mmapGrowsDown() const
Does mmap region grow upward or downward from mmapEnd? Most platforms grow downward, but a few (such as Alpha) grow upward instead, so they can override this method to return false.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void regStats() override
Register statistics for this object.
Stats::Scalar numSyscalls
virtual TheISA::IntReg getSyscallArg(ThreadContext *tc, int &i)=0
Addr allocPhysPages(int npages)
Allocate npages contiguous unused physical pages.
A process with emulated Arm/Freebsd syscalls.
void setSimFD(int sim_fd)
virtual void readBlob(Addr addr, uint8_t *p, int size) const
Read size bytes memory at address and store in p.
SymbolTable * debugSymbolTable
Global unified debugging symbol table (for target).
ObjectFile * getInterpreter()
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
virtual bool loadLocalSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=maxAddr)=0
virtual void regStats()
Register statistics for this object.
T roundUp(const T &val, const U &align)
std::shared_ptr< MemState > memState
ThreadContext is the external interface to all thread state for anything outside of the CPU...
virtual ObjectFile * getInterpreter() const
Declaration of Statistics objects.
virtual bool loadWeakSymbols(SymbolTable *symtab, Addr base=0, Addr offset=0, Addr mask=maxAddr)
DrainState drain() override
Notify an object that it needs to drain its state.
void replicatePage(Addr vaddr, Addr new_paddr, ThreadContext *old_tc, ThreadContext *new_tc, bool alloc_page)
virtual void updateBias(Addr bias_addr)
std::string csprintf(const char *format, const Args &...args)
bool map(Addr vaddr, Addr paddr, int size, bool cacheable=true)
Maps a contiguous range of virtual addresses in this process's address space to a contiguous range of...
bool translate(Addr vaddr, Addr &paddr)
Translate function.
std::set< int > PIDs
Process set to track which PIDs have already been allocated.
void setPageTable(PageTableBase *p)
Faux page table class indended to stop the usage of an architectural page table, when there is none d...
std::vector< ThreadContext * > threadContexts
ThreadContext * findFreeContext()
Extends the base class to include a host-backed file descriptor field that records the integer used t...
T roundDown(const T &val, const U &align)
virtual void serialize(CheckpointOut &cp) const =0
Serialize an object.
virtual SETranslatingPortProxy & getMemProxy()=0
std::vector< std::string > envp
ThreadContext * getThreadContext(ContextID tid)
virtual void activate()=0
Set the status to Active.
A process with emulated Arm/Linux syscalls.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Draining buffers pending serialization/handover.
EmulatedDriver * findDriver(std::string filename)
Find an emulated device driver.
virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault)
virtual void initState(ThreadContext *tc)=0
A process with emulated PPC/Linux syscalls.
Declaration of base class for page table.
A process with emulated Riscv/Linux syscalls.
std::string fullPath(const std::string &filename)
This class provides the wrapper interface for the system call implementations which are defined in th...
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
virtual Addr bias() const
bool fixupStackFault(Addr vaddr)
Attempt to fix up a fault at vaddr by allocating a page on the stack.
virtual const std::string name() const
Declarations of a non-full system Page Table.
A process with emulated Arm/Freebsd syscalls.
std::ostream CheckpointOut
Process(ProcessParams *params, ObjectFile *obj_file)
ObjectFile * createObjectFile(const string &fname, bool raw)
T divCeil(const T &a, const U &b)
TranslatingPortProxy Object Declaration for SE.
EmulatedDriver is an abstract base class for fake SE-mode device drivers.
virtual void unserialize(CheckpointIn &cp)=0
Unserialize an object.
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
void serialize(CheckpointOut &cp) const override
Serialize an object.
std::vector< std::string > argv
virtual Addr mapSize() const
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, TheISA::IntReg flags)
virtual bool relocatable() const
std::shared_ptr< FaultBase > Fault
Abstract superclass for simulation objects.
virtual void writeBlob(Addr addr, const uint8_t *p, int size) const
Write size bytes from p to address.
std::shared_ptr< FDArray > fds
std::vector< EmulatedDriver * > drivers