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 | |
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')
-rw-r--r-- | src/arch/alpha/process.cc | 34 | ||||
-rw-r--r-- | src/arch/arm/process.cc | 60 | ||||
-rw-r--r-- | src/arch/mips/process.cc | 34 | ||||
-rw-r--r-- | src/arch/power/process.cc | 40 | ||||
-rw-r--r-- | src/arch/riscv/process.cc | 36 | ||||
-rw-r--r-- | src/arch/sparc/process.cc | 31 | ||||
-rw-r--r-- | src/arch/sparc/process.hh | 42 | ||||
-rw-r--r-- | src/arch/x86/process.cc | 78 |
8 files changed, 191 insertions, 164 deletions
diff --git a/src/arch/alpha/process.cc b/src/arch/alpha/process.cc index 64d0b54a9..9be1d6c85 100644 --- a/src/arch/alpha/process.cc +++ b/src/arch/alpha/process.cc @@ -50,21 +50,24 @@ using namespace std; AlphaProcess::AlphaProcess(ProcessParams *params, ObjectFile *objFile) : Process(params, objFile) { - memState->brkPoint = objFile->dataBase() + objFile->dataSize() + - objFile->bssSize(); - memState->brkPoint = roundUp(memState->brkPoint, PageBytes); + Addr brk_point = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + brk_point = roundUp(brk_point, PageBytes); // Set up stack. On Alpha, stack goes below text section. This // code should get moved to some architecture-specific spot. - memState->stackBase = objFile->textBase() - (409600+4096); + Addr stack_base = objFile->textBase() - (409600+4096); - // Set up region for mmaps. Tru64 seems to start just above 0 and - // grow up from there. - memState->mmapEnd = 0x10000; + // Set up region for mmaps. + Addr mmap_end = 0x10000; + + 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; + memState = make_shared<MemState>(brk_point, stack_base, max_stack_size, + next_thread_stack_base, mmap_end); } void @@ -131,15 +134,16 @@ AlphaProcess::argsInit(int intSize, int pageSize) space_needed = 32*1024; // set bottom of stack - memState->stackMin = memState->stackBase - space_needed; + memState->setStackMin(memState->getStackBase() - space_needed); // align it - memState->stackMin = roundDown(memState->stackMin, pageSize); - memState->stackSize = memState->stackBase - memState->stackMin; + memState->setStackMin(roundDown(memState->getStackMin(), pageSize)); + memState->setStackSize(memState->getStackBase() - memState->getStackMin()); // map memory - allocateMem(memState->stackMin, roundUp(memState->stackSize, pageSize)); + allocateMem(memState->getStackMin(), roundUp(memState->getStackSize(), + pageSize)); // map out initial stack contents - Addr argv_array_base = memState->stackMin + intSize; // room for argc + Addr argv_array_base = memState->getStackMin() + intSize; // room for argc Addr envp_array_base = argv_array_base + argv_array_size; Addr auxv_array_base = envp_array_base + envp_array_size; Addr arg_data_base = auxv_array_base + auxv_array_size; @@ -154,7 +158,7 @@ AlphaProcess::argsInit(int intSize, int pageSize) else panic("Unknown int size"); - initVirtMem.writeBlob(memState->stackMin, (uint8_t*)&argc, intSize); + initVirtMem.writeBlob(memState->getStackMin(), (uint8_t*)&argc, intSize); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); @@ -171,7 +175,7 @@ AlphaProcess::argsInit(int intSize, int pageSize) setSyscallArg(tc, 0, argc); setSyscallArg(tc, 1, argv_array_base); - tc->setIntReg(StackPointerReg, memState->stackMin); + tc->setIntReg(StackPointerReg, memState->getStackMin()); tc->pcState(getStartPC()); } diff --git a/src/arch/arm/process.cc b/src/arch/arm/process.cc index fd0243c44..eb8abfb4d 100644 --- a/src/arch/arm/process.cc +++ b/src/arch/arm/process.cc @@ -70,36 +70,30 @@ ArmProcess32::ArmProcess32(ProcessParams *params, ObjectFile *objFile, ObjectFile::Arch _arch) : ArmProcess(params, objFile, _arch) { - memState->stackBase = 0xbf000000L; - - // Set pointer for next thread stack. Reserve 8M for main stack. - memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); - - // Set up break point (Top of Heap) - memState->brkPoint = objFile->dataBase() + objFile->dataSize() + - objFile->bssSize(); - memState->brkPoint = roundUp(memState->brkPoint, PageBytes); - - // Set up region for mmaps. For now, start at bottom of kuseg space. - memState->mmapEnd = 0x40000000L; + Addr brk_point = roundUp(objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(), PageBytes); + Addr stack_base = 0xbf000000L; + Addr max_stack_size = 8 * 1024 * 1024; + Addr next_thread_stack_base = stack_base - max_stack_size; + Addr mmap_end = 0x40000000L; + + memState = make_shared<MemState>(brk_point, stack_base, max_stack_size, + next_thread_stack_base, mmap_end); } ArmProcess64::ArmProcess64(ProcessParams *params, ObjectFile *objFile, ObjectFile::Arch _arch) : ArmProcess(params, objFile, _arch) { - memState->stackBase = 0x7fffff0000L; - - // Set pointer for next thread stack. Reserve 8M for main stack. - memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); - - // Set up break point (Top of Heap) - memState->brkPoint = objFile->dataBase() + objFile->dataSize() + - objFile->bssSize(); - memState->brkPoint = roundUp(memState->brkPoint, PageBytes); - - // Set up region for mmaps. For now, start at bottom of kuseg space. - memState->mmapEnd = 0x4000000000L; + Addr brk_point = roundUp(objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(), PageBytes); + Addr stack_base = 0x7fffff0000L; + Addr max_stack_size = 8 * 1024 * 1024; + Addr next_thread_stack_base = stack_base - max_stack_size; + Addr mmap_end = 0x4000000000L; + + memState = make_shared<MemState>(brk_point, stack_base, max_stack_size, + next_thread_stack_base, mmap_end); } void @@ -302,16 +296,16 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) int space_needed = frame_size + aux_padding; - memState->stackMin = memState->stackBase - space_needed; - memState->stackMin = roundDown(memState->stackMin, align); - memState->stackSize = memState->stackBase - memState->stackMin; + memState->setStackMin(memState->getStackBase() - space_needed); + memState->setStackMin(roundDown(memState->getStackMin(), align)); + memState->setStackSize(memState->getStackBase() - memState->getStackMin()); // map memory - allocateMem(roundDown(memState->stackMin, pageSize), - roundUp(memState->stackSize, pageSize)); + allocateMem(roundDown(memState->getStackMin(), pageSize), + roundUp(memState->getStackSize(), pageSize)); // map out initial stack contents - IntType sentry_base = memState->stackBase - sentry_size; + IntType sentry_base = memState->getStackBase() - sentry_size; IntType aux_data_base = sentry_base - aux_data_size; IntType env_data_base = aux_data_base - env_data_size; IntType arg_data_base = env_data_base - arg_data_size; @@ -332,7 +326,7 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) DPRINTF(Stack, "0x%x - envp array\n", envp_array_base); DPRINTF(Stack, "0x%x - argv array\n", argv_array_base); DPRINTF(Stack, "0x%x - argc \n", argc_base); - DPRINTF(Stack, "0x%x - stack min\n", memState->stackMin); + DPRINTF(Stack, "0x%x - stack min\n", memState->getStackMin()); // write contents to stack @@ -378,7 +372,7 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) ThreadContext *tc = system->getThreadContext(contextIds[0]); //Set the stack pointer register - tc->setIntReg(spIndex, memState->stackMin); + tc->setIntReg(spIndex, memState->getStackMin()); //A pointer to a function to run when the program exits. We'll set this //to zero explicitly to make sure this isn't used. tc->setIntReg(ArgumentReg0, 0); @@ -405,7 +399,7 @@ ArmProcess::argsInit(int pageSize, IntRegIndex spIndex) tc->pcState(pc); //Align the "stackMin" to a page boundary. - memState->stackMin = roundDown(memState->stackMin, pageSize); + memState->setStackMin(roundDown(memState->getStackMin(), pageSize)); } ArmISA::IntReg diff --git a/src/arch/mips/process.cc b/src/arch/mips/process.cc index 4993b3c68..60e343578 100644 --- a/src/arch/mips/process.cc +++ b/src/arch/mips/process.cc @@ -53,18 +53,23 @@ MipsProcess::MipsProcess(ProcessParams * params, ObjectFile *objFile) { // Set up stack. On MIPS, stack starts at the top of kuseg // user address space. MIPS stack grows down from here - memState->stackBase = 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->dataBase() + objFile->dataSize() + - objFile->bssSize(); - memState->brkPoint = roundUp(memState->brkPoint, PageBytes); + Addr brk_point = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + brk_point = roundUp(brk_point, PageBytes); // 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 @@ -141,15 +146,16 @@ MipsProcess::argsInit(int pageSize) env_data_size; // set bottom of stack - memState->stackMin = memState->stackBase - space_needed; + memState->setStackMin(memState->getStackBase() - space_needed); // align it - memState->stackMin = roundDown(memState->stackMin, pageSize); - memState->stackSize = memState->stackBase - memState->stackMin; + memState->setStackMin(roundDown(memState->getStackMin(), pageSize)); + memState->setStackSize(memState->getStackBase() - memState->getStackMin()); // map memory - allocateMem(memState->stackMin, roundUp(memState->stackSize, pageSize)); + allocateMem(memState->getStackMin(), roundUp(memState->getStackSize(), + pageSize)); - // map out initial stack contents - IntType argv_array_base = memState->stackMin + intSize; // room for argc + // map out initial stack contents; leave room for argc + IntType argv_array_base = memState->getStackMin() + intSize; IntType envp_array_base = argv_array_base + argv_array_size; IntType auxv_array_base = envp_array_base + envp_array_size; IntType arg_data_base = auxv_array_base + auxv_array_size; @@ -160,7 +166,7 @@ MipsProcess::argsInit(int pageSize) argc = htog((IntType)argc); - initVirtMem.writeBlob(memState->stackMin, (uint8_t*)&argc, intSize); + initVirtMem.writeBlob(memState->getStackMin(), (uint8_t*)&argc, intSize); copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); @@ -185,7 +191,7 @@ MipsProcess::argsInit(int pageSize) setSyscallArg(tc, 0, argc); setSyscallArg(tc, 1, argv_array_base); - tc->setIntReg(StackPointerReg, memState->stackMin); + tc->setIntReg(StackPointerReg, memState->getStackMin()); tc->pcState(getStartPC()); } diff --git a/src/arch/power/process.cc b/src/arch/power/process.cc index 5a32218ef..4b2efb0a6 100644 --- a/src/arch/power/process.cc +++ b/src/arch/power/process.cc @@ -51,18 +51,23 @@ using namespace PowerISA; PowerProcess::PowerProcess(ProcessParams *params, ObjectFile *objFile) : Process(params, objFile) { - memState->stackBase = 0xbf000000L; + // Set up break point (Top of Heap) + Addr brk_point = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + brk_point = roundUp(brk_point, PageBytes); - // Set pointer for next thread stack. Reserve 8M for main stack. - memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); + Addr stack_base = 0xbf000000L; - // Set up break point (Top of Heap) - memState->brkPoint = objFile->dataBase() + objFile->dataSize() + - objFile->bssSize(); - memState->brkPoint = roundUp(memState->brkPoint, PageBytes); + Addr max_stack_size = 8 * 1024 * 1024; + + // Set pointer for next thread stack. Reserve 8M for main stack. + Addr next_thread_stack_base = stack_base - max_stack_size; // Set up region for mmaps. For now, start at bottom of kuseg space. - memState->mmapEnd = 0x70000000L; + Addr mmap_end = 0x70000000L; + + memState = make_shared<MemState>(brk_point, stack_base, max_stack_size, + next_thread_stack_base, mmap_end); } void @@ -186,16 +191,17 @@ PowerProcess::argsInit(int intSize, int pageSize) int space_needed = frame_size + aux_padding; - memState->stackMin = memState->stackBase - space_needed; - memState->stackMin = roundDown(memState->stackMin, align); - memState->stackSize = memState->stackBase - memState->stackMin; + Addr stack_min = memState->getStackBase() - space_needed; + stack_min = roundDown(stack_min, align); + + memState->setStackSize(memState->getStackBase() - stack_min); // map memory - allocateMem(roundDown(memState->stackMin, pageSize), - roundUp(memState->stackSize, pageSize)); + allocateMem(roundDown(stack_min, pageSize), + roundUp(memState->getStackSize(), pageSize)); // map out initial stack contents - uint32_t sentry_base = memState->stackBase - sentry_size; + uint32_t sentry_base = memState->getStackBase() - sentry_size; uint32_t aux_data_base = sentry_base - aux_data_size; uint32_t env_data_base = aux_data_base - env_data_size; uint32_t arg_data_base = env_data_base - arg_data_size; @@ -214,7 +220,7 @@ PowerProcess::argsInit(int intSize, int pageSize) DPRINTF(Stack, "0x%x - envp array\n", envp_array_base); DPRINTF(Stack, "0x%x - argv array\n", argv_array_base); DPRINTF(Stack, "0x%x - argc \n", argc_base); - DPRINTF(Stack, "0x%x - stack min\n", memState->stackMin); + DPRINTF(Stack, "0x%x - stack min\n", stack_min); // write contents to stack @@ -259,12 +265,12 @@ PowerProcess::argsInit(int intSize, int pageSize) ThreadContext *tc = system->getThreadContext(contextIds[0]); //Set the stack pointer register - tc->setIntReg(StackPointerReg, memState->stackMin); + tc->setIntReg(StackPointerReg, stack_min); tc->pcState(getStartPC()); //Align the "stack_min" to a page boundary. - memState->stackMin = roundDown(memState->stackMin, pageSize); + memState->setStackMin(roundDown(stack_min, pageSize)); } PowerISA::IntReg 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()); } diff --git a/src/arch/sparc/process.cc b/src/arch/sparc/process.cc index a64bc587f..d8384b470 100644 --- a/src/arch/sparc/process.cc +++ b/src/arch/sparc/process.cc @@ -57,15 +57,6 @@ SparcProcess::SparcProcess(ProcessParams * params, ObjectFile *objFile, Addr _StackBias) : Process(params, objFile), StackBias(_StackBias) { - - // XXX all the below need to be updated for SPARC - Ali - memState->brkPoint = objFile->dataBase() + objFile->dataSize() + - objFile->bssSize(); - memState->brkPoint = roundUp(memState->brkPoint, PageBytes); - - // Set pointer for next thread stack. Reserve 8M for main stack. - memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); - // Initialize these to 0s fillStart = 0; spillStart = 0; @@ -325,16 +316,16 @@ SparcProcess::argsInit(int pageSize) aux_padding + frame_size; - memState->stackMin = memState->stackBase - space_needed; - memState->stackMin = roundDown(memState->stackMin, align); - memState->stackSize = memState->stackBase - memState->stackMin; + memState->setStackMin(memState->getStackBase() - space_needed); + memState->setStackMin(roundDown(memState->getStackMin(), align)); + memState->setStackSize(memState->getStackBase() - memState->getStackMin()); // Allocate space for the stack - allocateMem(roundDown(memState->stackMin, pageSize), - roundUp(memState->stackSize, pageSize)); + allocateMem(roundDown(memState->getStackMin(), pageSize), + roundUp(memState->getStackSize(), pageSize)); // map out initial stack contents - IntType sentry_base = memState->stackBase - sentry_size; + IntType sentry_base = memState->getStackBase() - sentry_size; IntType file_name_base = sentry_base - file_name_size; IntType env_data_base = file_name_base - env_data_size; IntType arg_data_base = env_data_base - arg_data_size; @@ -358,9 +349,9 @@ SparcProcess::argsInit(int pageSize) DPRINTF(Stack, "%#x - argv array\n", argv_array_base); DPRINTF(Stack, "%#x - argc \n", argc_base); DPRINTF(Stack, "%#x - window save\n", window_save_base); - DPRINTF(Stack, "%#x - stack min\n", memState->stackMin); + DPRINTF(Stack, "%#x - stack min\n", memState->getStackMin()); - assert(window_save_base == memState->stackMin); + assert(window_save_base == memState->getStackMin()); // write contents to stack @@ -399,7 +390,7 @@ SparcProcess::argsInit(int pageSize) // Set up space for the trap handlers into the processes address space. // Since the stack grows down and there is reserved address space abov // it, we can put stuff above it and stay out of the way. - fillStart = memState->stackBase; + fillStart = memState->getStackBase(); spillStart = fillStart + sizeof(MachInst) * numFillInsts; ThreadContext *tc = system->getThreadContext(contextIds[0]); @@ -407,7 +398,7 @@ SparcProcess::argsInit(int pageSize) // assert(NumArgumentRegs >= 2); // tc->setIntReg(ArgumentReg[0], argc); // tc->setIntReg(ArgumentReg[1], argv_array_base); - tc->setIntReg(StackPointerReg, memState->stackMin - StackBias); + tc->setIntReg(StackPointerReg, memState->getStackMin() - StackBias); // %g1 is a pointer to a function that should be run at exit. Since we // don't have anything like that, it should be set to 0. @@ -416,7 +407,7 @@ SparcProcess::argsInit(int pageSize) tc->pcState(getStartPC()); // Align the "stack_min" to a page boundary. - memState->stackMin = roundDown(memState->stackMin, pageSize); + memState->setStackMin(roundDown(memState->getStackMin(), pageSize)); } void diff --git a/src/arch/sparc/process.hh b/src/arch/sparc/process.hh index 96901fde3..6a203a400 100644 --- a/src/arch/sparc/process.hh +++ b/src/arch/sparc/process.hh @@ -32,15 +32,16 @@ #ifndef __SPARC_PROCESS_HH__ #define __SPARC_PROCESS_HH__ +#include <memory> #include <string> #include <vector> +#include "arch/sparc/isa_traits.hh" +#include "base/loader/object_file.hh" #include "mem/page_table.hh" #include "sim/byteswap.hh" #include "sim/process.hh" -class ObjectFile; - class SparcProcess : public Process { protected: @@ -77,12 +78,27 @@ class Sparc32Process : public SparcProcess Sparc32Process(ProcessParams * params, ObjectFile *objFile) : SparcProcess(params, objFile, 0) { + Addr brk_point = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + brk_point = roundUp(brk_point, SparcISA::PageBytes); + + // Reserve 8M for main stack. + Addr max_stack_size = 8 * 1024 * 1024; + // Set up stack. On SPARC Linux, stack goes from the top of memory // downward, less the hole for the kernel address space. - memState->stackBase = (Addr)0xf0000000ULL; + Addr stack_base = 0xf0000000ULL; + + // Set pointer for next thread stack. + Addr next_thread_stack_base = stack_base - max_stack_size; // Set up region for mmaps. - memState->mmapEnd = 0x70000000; + Addr mmap_end = 0x70000000; + + memState = std::make_shared<MemState>(brk_point, stack_base, + max_stack_size, + next_thread_stack_base, + mmap_end); } void initState(); @@ -107,12 +123,26 @@ class Sparc64Process : public SparcProcess Sparc64Process(ProcessParams * params, ObjectFile *objFile) : SparcProcess(params, objFile, 2047) { + Addr brk_point = objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(); + brk_point = roundUp(brk_point, SparcISA::PageBytes); + + Addr max_stack_size = 8 * 1024 * 1024; + // Set up stack. On SPARC Linux, stack goes from the top of memory // downward, less the hole for the kernel address space. - memState->stackBase = (Addr)0x80000000000ULL; + Addr stack_base = 0x80000000000ULL; + + // Set pointer for next thread stack. Reserve 8M for main stack. + Addr next_thread_stack_base = stack_base - max_stack_size; // Set up region for mmaps. - memState->mmapEnd = 0xfffff80000000000ULL; + Addr mmap_end = 0xfffff80000000000ULL; + + memState = std::make_shared<MemState>(brk_point, stack_base, + max_stack_size, + next_thread_stack_base, + mmap_end); } void initState(); diff --git a/src/arch/x86/process.cc b/src/arch/x86/process.cc index a929897ca..1e6401b10 100644 --- a/src/arch/x86/process.cc +++ b/src/arch/x86/process.cc @@ -100,9 +100,6 @@ X86Process::X86Process(ProcessParams * params, ObjectFile *objFile, : Process(params, objFile), syscallDescs(_syscallDescs), numSyscallDescs(_numSyscallDescs) { - memState->brkPoint = objFile->dataBase() + objFile->dataSize() - + objFile->bssSize(); - memState->brkPoint = roundUp(memState->brkPoint, PageBytes); } void X86Process::clone(ThreadContext *old_tc, ThreadContext *new_tc, @@ -123,23 +120,15 @@ X86_64Process::X86_64Process(ProcessParams *params, ObjectFile *objFile, vsyscallPage.vtimeOffset = 0x400; vsyscallPage.vgettimeofdayOffset = 0x0; - // Set up stack. On X86_64 Linux, stack goes from the top of memory - // downward, less the hole for the kernel address space plus one page - // for undertermined purposes. - memState->stackBase = (Addr)0x7FFFFFFFF000ULL; - - // Set pointer for next thread stack. Reserve 8M for main stack. - memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); - - // "mmap_base" is a function which defines where mmap region starts in - // the process address space. - // mmap_base: PAGE_ALIGN(TASK_SIZE-MIN_GAP-mmap_rnd()) - // TASK_SIZE: (1<<47)-PAGE_SIZE - // MIN_GAP: 128*1024*1024+stack_maxrandom_size() - // We do not use any address space layout randomization in gem5 - // therefore the random fields become zero; the smallest gap space was - // chosen but gap could potentially be much larger. - memState->mmapEnd = (Addr)0x7FFFF7FFF000ULL; + Addr brk_point = roundUp(objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(), PageBytes); + Addr stack_base = 0x7FFFFFFFF000ULL; + Addr max_stack_size = 8 * 1024 * 1024; + Addr next_thread_stack_base = stack_base - max_stack_size; + Addr mmap_end = 0x7FFFF7FFF000ULL; + + memState = make_shared<MemState>(brk_point, stack_base, max_stack_size, + next_thread_stack_base, mmap_end); } void @@ -168,20 +157,15 @@ I386Process::I386Process(ProcessParams *params, ObjectFile *objFile, vsyscallPage.vsyscallOffset = 0x400; vsyscallPage.vsysexitOffset = 0x410; - memState->stackBase = _gdtStart; - - // Set pointer for next thread stack. Reserve 8M for main stack. - memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); + Addr brk_point = roundUp(objFile->dataBase() + objFile->dataSize() + + objFile->bssSize(), PageBytes); + Addr stack_base = _gdtStart; + Addr max_stack_size = 8 * 1024 * 1024; + Addr next_thread_stack_base = stack_base - max_stack_size; + Addr mmap_end = 0xB7FFF000ULL; - // "mmap_base" is a function which defines where mmap region starts in - // the process address space. - // mmap_base: PAGE_ALIGN(TASK_SIZE-MIN_GAP-mmap_rnd()) - // TASK_SIZE: 0xC0000000 - // MIN_GAP: 128*1024*1024+stack_maxrandom_size() - // We do not use any address space layout randomization in gem5 - // therefore the random fields become zero; the smallest gap space was - // chosen but gap could potentially be much larger. - memState->mmapEnd = (Addr)0xB7FFF000ULL; + memState = make_shared<MemState>(brk_point, stack_base, max_stack_size, + next_thread_stack_base, mmap_end); } SyscallDesc* @@ -955,21 +939,23 @@ X86Process::argsInit(int pageSize, aux_padding + frame_size; - memState->stackMin = memState->stackBase - space_needed; - memState->stackMin = roundDown(memState->stackMin, align); - memState->stackSize = roundUp(memState->stackBase - memState->stackMin, - pageSize); + Addr stack_base = memState->getStackBase(); + + Addr stack_min = stack_base - space_needed; + stack_min = roundDown(stack_min, align); + + unsigned stack_size = stack_base - stack_min; + stack_size = roundUp(stack_size, pageSize); + memState->setStackSize(stack_size); // map memory - Addr stack_end = roundDown(memState->stackBase - memState->stackSize, - pageSize); + Addr stack_end = roundDown(stack_base - stack_size, pageSize); - DPRINTF(Stack, "Mapping the stack: 0x%x %dB\n", - stack_end, memState->stackSize); - allocateMem(stack_end, memState->stackSize); + DPRINTF(Stack, "Mapping the stack: 0x%x %dB\n", stack_end, stack_size); + allocateMem(stack_end, stack_size); // map out initial stack contents - IntType sentry_base = memState->stackBase - sentry_size; + IntType sentry_base = stack_base - sentry_size; IntType file_name_base = sentry_base - file_name_size; IntType env_data_base = file_name_base - env_data_size; IntType arg_data_base = env_data_base - arg_data_size; @@ -988,7 +974,7 @@ X86Process::argsInit(int pageSize, DPRINTF(Stack, "0x%x - envp array\n", envp_array_base); DPRINTF(Stack, "0x%x - argv array\n", argv_array_base); DPRINTF(Stack, "0x%x - argc \n", argc_base); - DPRINTF(Stack, "0x%x - stack min\n", memState->stackMin); + DPRINTF(Stack, "0x%x - stack min\n", stack_min); // write contents to stack @@ -1035,14 +1021,14 @@ X86Process::argsInit(int pageSize, ThreadContext *tc = system->getThreadContext(contextIds[0]); //Set the stack pointer register - tc->setIntReg(StackPointerReg, memState->stackMin); + tc->setIntReg(StackPointerReg, stack_min); // There doesn't need to be any segment base added in since we're dealing // with the flat segmentation model. tc->pcState(getStartPC()); //Align the "stack_min" to a page boundary. - memState->stackMin = roundDown(memState->stackMin, pageSize); + memState->setStackMin(roundDown(stack_min, pageSize)); } void |