summaryrefslogtreecommitdiff
path: root/src/arch/riscv/process.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/riscv/process.cc')
-rw-r--r--src/arch/riscv/process.cc78
1 files changed, 56 insertions, 22 deletions
diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc
index 7548c65b2..ed6de1546 100644
--- a/src/arch/riscv/process.cc
+++ b/src/arch/riscv/process.cc
@@ -67,6 +67,11 @@ RiscvProcess::RiscvProcess(ProcessParams *params, ObjectFile *objFile) :
objFile)
{
fatal_if(params->useArchPT, "Arch page tables not implemented.");
+}
+
+RiscvProcess64::RiscvProcess64(ProcessParams *params, ObjectFile *objFile) :
+ RiscvProcess(params, objFile)
+{
const Addr stack_base = 0x7FFFFFFFFFFFFFFFL;
const Addr max_stack_size = 8 * 1024 * 1024;
const Addr next_thread_stack_base = stack_base - max_stack_size;
@@ -77,8 +82,21 @@ RiscvProcess::RiscvProcess(ProcessParams *params, ObjectFile *objFile) :
next_thread_stack_base, mmap_end);
}
+RiscvProcess32::RiscvProcess32(ProcessParams *params, ObjectFile *objFile) :
+ RiscvProcess(params, objFile)
+{
+ const Addr stack_base = 0x7FFFFFFF;
+ const Addr max_stack_size = 8 * 1024 * 1024;
+ const Addr next_thread_stack_base = stack_base - max_stack_size;
+ const Addr brk_point = roundUp(objFile->bssBase() + objFile->bssSize(),
+ PageBytes);
+ const Addr mmap_end = 0x40000000L;
+ memState = make_shared<MemState>(brk_point, stack_base, max_stack_size,
+ next_thread_stack_base, mmap_end);
+}
+
void
-RiscvProcess::initState()
+RiscvProcess64::initState()
{
Process::initState();
@@ -87,10 +105,25 @@ RiscvProcess::initState()
system->getThreadContext(ctx)->setMiscRegNoEffect(MISCREG_PRV, PRV_U);
}
+void
+RiscvProcess32::initState()
+{
+ Process::initState();
+
+ argsInit<uint32_t>(PageBytes);
+ for (ContextID ctx: contextIds) {
+ system->getThreadContext(ctx)->setMiscRegNoEffect(MISCREG_PRV, PRV_U);
+ PCState pc = system->getThreadContext(ctx)->pcState();
+ pc.rv32(true);
+ system->getThreadContext(ctx)->pcState(pc);
+ }
+}
+
template<class IntType> void
RiscvProcess::argsInit(int pageSize)
{
const int RandomBytes = 16;
+ const int addrSize = sizeof(IntType);
updateBias();
objFile->loadSections(initVirtMem);
@@ -104,23 +137,24 @@ RiscvProcess::argsInit(int pageSize)
stack_top -= arg.size() + 1;
for (const string& env: envp)
stack_top -= env.size() + 1;
- stack_top &= -sizeof(Addr);
+ stack_top &= -addrSize;
- vector<AuxVector<IntType>> auxv;
+ typedef AuxVector<IntType> auxv_t;
+ vector<auxv_t> auxv;
if (elfObject != nullptr) {
- auxv.push_back({M5_AT_ENTRY, objFile->entryPoint()});
- auxv.push_back({M5_AT_PHNUM, elfObject->programHeaderCount()});
- auxv.push_back({M5_AT_PHENT, elfObject->programHeaderSize()});
- auxv.push_back({M5_AT_PHDR, elfObject->programHeaderTable()});
- auxv.push_back({M5_AT_PAGESZ, PageBytes});
- auxv.push_back({M5_AT_SECURE, 0});
- auxv.push_back({M5_AT_RANDOM, stack_top});
- auxv.push_back({M5_AT_NULL, 0});
+ auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint()));
+ auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount()));
+ auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize()));
+ auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable()));
+ auxv.push_back(auxv_t(M5_AT_PAGESZ, PageBytes));
+ auxv.push_back(auxv_t(M5_AT_SECURE, 0));
+ auxv.push_back(auxv_t(M5_AT_RANDOM, stack_top));
+ auxv.push_back(auxv_t(M5_AT_NULL, 0));
}
- stack_top -= (1 + argv.size()) * sizeof(Addr) +
- (1 + envp.size()) * sizeof(Addr) +
- sizeof(Addr) + 2 * sizeof(IntType) * auxv.size();
- stack_top &= -2*sizeof(Addr);
+ stack_top -= (1 + argv.size()) * addrSize +
+ (1 + envp.size()) * addrSize +
+ addrSize + 2 * sizeof(IntType) * auxv.size();
+ stack_top &= -2*addrSize;
memState->setStackSize(memState->getStackBase() - stack_top);
allocateMem(roundDown(stack_top, pageSize),
roundUp(memState->getStackSize(), pageSize));
@@ -159,14 +193,14 @@ RiscvProcess::argsInit(int pageSize)
envPointers.push_back(0);
// Align stack
- memState->setStackMin(memState->getStackMin() & -sizeof(Addr));
+ memState->setStackMin(memState->getStackMin() & -addrSize);
// Calculate bottom of stack
memState->setStackMin(memState->getStackMin() -
- ((1 + argv.size()) * sizeof(Addr) +
- (1 + envp.size()) * sizeof(Addr) +
- sizeof(Addr) + 2 * sizeof(IntType) * auxv.size()));
- memState->setStackMin(memState->getStackMin() & -2*sizeof(Addr));
+ ((1 + argv.size()) * addrSize +
+ (1 + envp.size()) * addrSize +
+ addrSize + 2 * sizeof(IntType) * auxv.size()));
+ memState->setStackMin(memState->getStackMin() & -2*addrSize);
Addr sp = memState->getStackMin();
const auto pushOntoStack =
[this, &sp](const uint8_t* data, const size_t size) {
@@ -182,14 +216,14 @@ RiscvProcess::argsInit(int pageSize)
for (const Addr& argPointer: argPointers) {
DPRINTF(Stack, "Wrote argv pointer %p to address %p\n",
(void*)argPointer, (void*)sp);
- pushOntoStack((uint8_t*)&argPointer, sizeof(Addr));
+ pushOntoStack((uint8_t*)&argPointer, addrSize);
}
// Push env pointers onto stack
for (const Addr& envPointer: envPointers) {
DPRINTF(Stack, "Wrote envp pointer %p to address %p\n",
(void*)envPointer, (void*)sp);
- pushOntoStack((uint8_t*)&envPointer, sizeof(Addr));
+ pushOntoStack((uint8_t*)&envPointer, addrSize);
}
// Push aux vector onto stack