diff options
author | Brandon Potter <Brandon.Potter@amd.com> | 2017-03-01 13:07:43 -0600 |
---|---|---|
committer | Brandon Potter <Brandon.Potter@amd.com> | 2017-03-09 19:19:38 +0000 |
commit | 43418e7f81099072fb7d56dae11110ae1d858162 (patch) | |
tree | 0d624abfdd331b0edffcafc274c08695d0cca97b /src/arch/riscv/process.cc | |
parent | 71dd6c2c17a465b7705f53469cd2c89f16ede4b7 (diff) | |
download | gem5-43418e7f81099072fb7d56dae11110ae1d858162.tar.xz |
syscall-emul: Move memState into its own file
The Process class is full of implementation details and
structures related to SE Mode. This changeset factors out an
internal class from Process and moves it into a separate file.
The purpose behind doing this is to clean up the code and make
it a bit more modular.
Change-Id: Ic6941a1657751e8d51d5b6b1dcc04f1195884280
Reviewed-on: https://gem5-review.googlesource.com/2263
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Diffstat (limited to 'src/arch/riscv/process.cc')
-rw-r--r-- | src/arch/riscv/process.cc | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/arch/riscv/process.cc b/src/arch/riscv/process.cc index 8b168cb35..f50fb3196 100644 --- a/src/arch/riscv/process.cc +++ b/src/arch/riscv/process.cc @@ -56,16 +56,21 @@ RiscvProcess::RiscvProcess(ProcessParams * params, { // Set up stack. On RISC-V, stack starts at the top of kuseg // user address space. RISC-V stack grows down from here - memState->stackBase = (Addr)0x7FFFFFFF; + Addr stack_base = 0x7FFFFFFF; + + Addr max_stack_size = 8 * 1024 * 1024; // Set pointer for next thread stack. Reserve 8M for main stack. - memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); + Addr next_thread_stack_base = stack_base - max_stack_size; // Set up break point (Top of Heap) - memState->brkPoint = objFile->bssBase() + objFile->bssSize(); + Addr brk_point = objFile->bssBase() + objFile->bssSize(); // Set up region for mmaps. Start it 1GB above the top of the heap. - memState->mmapEnd = memState->brkPoint + 0x40000000L; + Addr mmap_end = brk_point + 0x40000000L; + + memState = make_shared<MemState>(brk_point, stack_base, max_stack_size, + next_thread_stack_base, mmap_end); } void @@ -124,19 +129,24 @@ RiscvProcess::argsInit(int pageSize) env_data_size += env.size() + 1; int auxv_array_size = 2 * sizeof(IntType)*auxv.size(); - memState->stackSize = sizeof(IntType) + argv_array_size + 2 * + Addr stack_size = sizeof(IntType) + argv_array_size + 2 * sizeof(Addr) + sizeof(Addr) + arg_data_size + 2 * sizeof(Addr); if (!envp.empty()) { - memState->stackSize += 2 * sizeof(Addr) + envp_array_size + 2 * + stack_size += 2 * sizeof(Addr) + envp_array_size + 2 * sizeof(Addr) + env_data_size; } if (!auxv.empty()) - memState->stackSize += 2 * sizeof(Addr) + auxv_array_size; - memState->stackMin = roundDown(memState->stackBase - memState->stackSize, - pageSize); - allocateMem(memState->stackMin, roundUp(memState->stackSize, pageSize)); + stack_size += 2 * sizeof(Addr) + auxv_array_size; + + memState->setStackSize(stack_size); + + Addr stack_min = roundDown(memState->getStackBase() - + stack_size, pageSize); + allocateMem(stack_min, roundUp(memState->getStackSize(), pageSize)); + + memState->setStackMin(stack_min); - Addr argv_array_base = memState->stackMin + sizeof(IntType); + Addr argv_array_base = memState->getStackMin() + sizeof(IntType); Addr arg_data_base = argv_array_base + argv_array_size + 2 * sizeof(Addr); Addr envp_array_base = arg_data_base + arg_data_size; if (!envp.empty()) @@ -161,7 +171,7 @@ RiscvProcess::argsInit(int pageSize) } } - Addr sp = memState->stackMin; + Addr sp = memState->getStackMin(); initVirtMem.writeBlob(sp, (uint8_t *)&argc, sizeof(IntType)); sp += sizeof(IntType); for (Addr arg_pointer: arg_pointers) { @@ -212,7 +222,7 @@ RiscvProcess::argsInit(int pageSize) } ThreadContext *tc = system->getThreadContext(contextIds[0]); - tc->setIntReg(StackPointerReg, memState->stackMin); + tc->setIntReg(StackPointerReg, memState->getStackMin()); tc->pcState(getStartPC()); } |