diff options
Diffstat (limited to 'sim/process.cc')
-rw-r--r-- | sim/process.cc | 110 |
1 files changed, 59 insertions, 51 deletions
diff --git a/sim/process.cc b/sim/process.cc index f02ca8bfd..70a92a604 100644 --- a/sim/process.cc +++ b/sim/process.cc @@ -42,12 +42,15 @@ #include "cpu/smt.hh" #include "encumbered/cpu/full/thread.hh" #include "encumbered/eio/eio.hh" -#include "encumbered/mem/functional/main.hh" +#include "mem/page_table.hh" +#include "mem/memory.hh" +#include "mem/translating_port.hh" #include "sim/builder.hh" #include "sim/fake_syscall.hh" #include "sim/process.hh" #include "sim/stats.hh" #include "sim/syscall_emul.hh" +#include "sim/system.hh" #include "arch/process.hh" @@ -67,20 +70,12 @@ using namespace TheISA; int num_processes = 0; Process::Process(const string &nm, + System *_system, int stdin_fd, // initial I/O descriptors int stdout_fd, int stderr_fd) - : SimObject(nm) + : SimObject(nm), system(_system) { - // allocate memory space - memory = new MainMemory(nm + ".MainMem"); - - // allocate initial register file - init_regs = new RegFile; - memset(init_regs, 0, sizeof(RegFile)); - - cpuXC = new CPUExecContext(init_regs); - // initialize first 3 fds (stdin, stdout, stderr) fd_map[STDIN_FILENO] = stdin_fd; fd_map[STDOUT_FILENO] = stdout_fd; @@ -93,9 +88,11 @@ Process::Process(const string &nm, mmap_start = mmap_end = 0; nxm_start = nxm_end = 0; + pTable = new PageTable(system); // other parameters will be initialized when the program is loaded } + void Process::regStats() { @@ -147,12 +144,7 @@ Process::registerExecContext(ExecContext *xc) int myIndex = execContexts.size(); execContexts.push_back(xc); - if (myIndex == 0) { - // copy process's initial regs struct - xc->copyArchRegs(cpuXC->getProxy()); - } - - // return CPU number to caller and increment available CPU count + // return CPU number to caller return myIndex; } @@ -160,7 +152,9 @@ void Process::startup() { if (execContexts.empty()) - return; + fatal("Process %s is not associated with any CPUs!\n", name()); + + initVirtMem = new TranslatingPort((system->physmem->getPort("DCACHE"))->getPeer(), pTable); // first exec context for this process... initialize & enable ExecContext *xc = execContexts[0]; @@ -251,25 +245,28 @@ DEFINE_SIM_OBJECT_CLASS_NAME("Process", Process) static void copyStringArray(vector<string> &strings, Addr array_ptr, Addr data_ptr, - FunctionalMemory *memory) + TranslatingPort* memPort) { Addr data_ptr_swap; for (int i = 0; i < strings.size(); ++i) { data_ptr_swap = htog(data_ptr); - memory->access(Write, array_ptr, &data_ptr_swap, sizeof(Addr)); - memory->writeString(data_ptr, strings[i].c_str()); + memPort->writeBlobFunctional(array_ptr, (uint8_t*)&data_ptr_swap, sizeof(Addr)); + memPort->writeStringFunctional(data_ptr, strings[i].c_str()); array_ptr += sizeof(Addr); data_ptr += strings[i].size() + 1; } // add NULL terminator data_ptr = 0; - memory->access(Write, array_ptr, &data_ptr, sizeof(Addr)); + + memPort->writeBlobFunctional(array_ptr, (uint8_t*)&data_ptr, sizeof(Addr)); } -LiveProcess::LiveProcess(const string &nm, ObjectFile *objFile, +LiveProcess::LiveProcess(const string &nm, ObjectFile *_objFile, + System *_system, int stdin_fd, int stdout_fd, int stderr_fd, - vector<string> &argv, vector<string> &envp) - : Process(nm, stdin_fd, stdout_fd, stderr_fd) + vector<string> &_argv, vector<string> &_envp) + : Process(nm, _system, stdin_fd, stdout_fd, stderr_fd), + objFile(_objFile), argv(_argv), envp(_envp) { prog_fname = argv[0]; @@ -280,8 +277,16 @@ LiveProcess::LiveProcess(const string &nm, ObjectFile *objFile, data_size = objFile->dataSize() + objFile->bssSize(); brk_point = roundUp(data_base + data_size, VMPageSize); - // load object file into target memory - objFile->loadSections(memory); + // Set up stack. On Alpha, stack goes below text section. This + // code should get moved to some architecture-specific spot. + stack_base = text_base - (409600+4096); + + // Set up region for mmaps. Tru64 seems to start just above 0 and + // grow up from there. + mmap_start = mmap_end = 0x10000; + + // Set pointer for next thread stack. Reserve 8M for main stack. + next_thread_stack_base = stack_base - (8 * 1024 * 1024); // load up symbols, if any... these may be used for debugging or // profiling. @@ -294,17 +299,15 @@ LiveProcess::LiveProcess(const string &nm, ObjectFile *objFile, debugSymbolTable = NULL; } } +} - // Set up stack. On Alpha, stack goes below text section. This - // code should get moved to some architecture-specific spot. - stack_base = text_base - (409600+4096); - - // Set up region for mmaps. Tru64 seems to start just above 0 and - // grow up from there. - mmap_start = mmap_end = 0x10000; +void +LiveProcess::startup() +{ + Process::startup(); - // Set pointer for next thread stack. Reserve 8M for main stack. - next_thread_stack_base = stack_base - (8 * 1024 * 1024); + // load object file into target memory + objFile->loadSections(initVirtMem); // Calculate how much space we need for arg & env arrays. int argv_array_size = sizeof(Addr) * (argv.size() + 1); @@ -329,6 +332,9 @@ LiveProcess::LiveProcess(const string &nm, ObjectFile *objFile, // align it stack_min &= ~7; stack_size = stack_base - stack_min; + // map memory + pTable->allocate(roundDown(stack_min, VMPageSize), + roundUp(stack_size, VMPageSize)); // map out initial stack contents Addr argv_array_base = stack_min + sizeof(uint64_t); // room for argc @@ -339,17 +345,19 @@ LiveProcess::LiveProcess(const string &nm, ObjectFile *objFile, // write contents to stack uint64_t argc = argv.size(); argc = htog(argc); - memory->access(Write, stack_min, &argc, sizeof(uint64_t)); + initVirtMem->writeBlobFunctional(stack_min, (uint8_t*)&argc, sizeof(uint64_t)); - copyStringArray(argv, argv_array_base, arg_data_base, memory); - copyStringArray(envp, envp_array_base, env_data_base, memory); + copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); + copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); - init_regs->intRegFile[ArgumentReg0] = argc; - init_regs->intRegFile[ArgumentReg1] = argv_array_base; - init_regs->intRegFile[StackPointerReg] = stack_min; - init_regs->intRegFile[GlobalPointerReg] = objFile->globalPointer(); - init_regs->pc = prog_entry; - init_regs->npc = prog_entry + sizeof(MachInst); + execContexts[0]->setIntReg(ArgumentReg0, argc); + execContexts[0]->setIntReg(ArgumentReg1, argv_array_base); + execContexts[0]->setIntReg(StackPointerReg, stack_min); + execContexts[0]->setIntReg(GlobalPointerReg, objFile->globalPointer()); + execContexts[0]->setPC(prog_entry); + execContexts[0]->setNextPC(prog_entry + sizeof(MachInst)); + + num_processes++; } void @@ -367,7 +375,7 @@ LiveProcess::syscall(ExecContext *xc) } LiveProcess * -LiveProcess::create(const string &nm, +LiveProcess::create(const string &nm, System *system, int stdin_fd, int stdout_fd, int stderr_fd, string executable, vector<string> &argv, vector<string> &envp) @@ -379,12 +387,10 @@ LiveProcess::create(const string &nm, } // set up syscall emulation pointer for the current ISA - process = createProcess(nm, objFile, + process = createProcess(nm, objFile, system, stdin_fd, stdout_fd, stderr_fd, argv, envp); - delete objFile; - if (process == NULL) fatal("Unknown error creating process object."); @@ -400,6 +406,7 @@ BEGIN_DECLARE_SIM_OBJECT_PARAMS(LiveProcess) Param<string> input; Param<string> output; VectorParam<string> env; + SimObjectParam<System *> system; END_DECLARE_SIM_OBJECT_PARAMS(LiveProcess) @@ -410,7 +417,8 @@ BEGIN_INIT_SIM_OBJECT_PARAMS(LiveProcess) INIT_PARAM(executable, "executable (overrides cmd[0] if set)"), INIT_PARAM(input, "filename for stdin (dflt: use sim stdin)"), INIT_PARAM(output, "filename for stdout/stderr (dflt: use sim stdout)"), - INIT_PARAM(env, "environment settings") + INIT_PARAM(env, "environment settings"), + INIT_PARAM(system, "system") END_INIT_SIM_OBJECT_PARAMS(LiveProcess) @@ -437,7 +445,7 @@ CREATE_SIM_OBJECT(LiveProcess) stderr_fd = (stdout_fd != STDOUT_FILENO) ? stdout_fd : STDERR_FILENO; - return LiveProcess::create(getInstanceName(), + return LiveProcess::create(getInstanceName(), system, stdin_fd, stdout_fd, stderr_fd, (string)executable == "" ? cmd[0] : executable, cmd, env); |