49 #include "debug/Stack.hh"
51 #include "params/Process.hh"
61 using namespace RiscvISA;
76 const Addr stack_base = 0x7FFFFFFFFFFFFFFFL;
77 const Addr max_stack_size = 8 * 1024 * 1024;
78 const Addr next_thread_stack_base = stack_base - max_stack_size;
80 const Addr mmap_end = 0x4000000000000000L;
81 memState = std::make_shared<MemState>(
this, brk_point, stack_base,
82 max_stack_size, next_thread_stack_base, mmap_end);
89 const Addr stack_base = 0x7FFFFFFF;
90 const Addr max_stack_size = 8 * 1024 * 1024;
91 const Addr next_thread_stack_base = stack_base - max_stack_size;
93 const Addr mmap_end = 0x40000000L;
94 memState = std::make_shared<MemState>(
this, brk_point, stack_base,
95 max_stack_size, next_thread_stack_base, mmap_end);
123 template<
class IntType>
void
126 const int RandomBytes = 16;
127 const int addrSize =
sizeof(IntType);
134 stack_top -= RandomBytes;
135 for (
const std::string& arg:
argv)
136 stack_top -= arg.size() + 1;
137 for (
const std::string& env:
envp)
138 stack_top -= env.size() + 1;
139 stack_top &= -addrSize;
142 if (elfObject !=
nullptr) {
152 stack_top -= (1 +
argv.size()) * addrSize +
153 (1 +
envp.size()) * addrSize +
154 addrSize + 2 *
sizeof(IntType) * auxv.size();
155 stack_top &= -2*addrSize;
162 uint8_t at_random[RandomBytes];
163 std::generate(std::begin(at_random), std::end(at_random),
169 for (
const std::string& arg:
argv) {
172 argPointers.push_back(
memState->getStackMin());
175 initVirtMem->readString(wrote, argPointers.back());
176 DPRINTFN(
"Wrote arg \"%s\" to address %p\n",
177 wrote, (
void*)
memState->getStackMin());
180 argPointers.push_back(0);
184 for (
const std::string& env:
envp) {
187 envPointers.push_back(
memState->getStackMin());
188 DPRINTF(Stack,
"Wrote env \"%s\" to address %p\n",
189 env, (
void*)
memState->getStackMin());
191 envPointers.push_back(0);
198 ((1 +
argv.size()) * addrSize +
199 (1 +
envp.size()) * addrSize +
200 addrSize + 2 *
sizeof(IntType) * auxv.size()));
203 const auto pushOntoStack =
204 [
this, &
sp](IntType
data) {
210 IntType argc =
argv.size();
211 DPRINTF(Stack,
"Wrote argc %d to address %#x\n", argc,
sp);
214 for (
const Addr& argPointer: argPointers) {
215 DPRINTF(Stack,
"Wrote argv pointer %#x to address %#x\n",
217 pushOntoStack(argPointer);
221 for (
const Addr& envPointer: envPointers) {
222 DPRINTF(Stack,
"Wrote envp pointer %#x to address %#x\n",
224 pushOntoStack(envPointer);
228 std::map<IntType, std::string> aux_keys = {
238 for (
const auto &aux: auxv) {
239 DPRINTF(Stack,
"Wrote aux key %s to address %#x\n",
240 aux_keys[aux.type],
sp);
241 pushOntoStack(aux.type);
242 DPRINTF(Stack,
"Wrote aux value %x to address %#x\n", aux.val,
sp);
243 pushOntoStack(aux.val);
loader::MemoryImage image
std::unique_ptr< SETranslatingPortProxy > initVirtMem
std::shared_ptr< MemState > memState
std::vector< std::string > argv
std::vector< ContextID > contextIds
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
std::vector< std::string > envp
loader::ObjectFile * objFile
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
RiscvProcess32(const ProcessParams ¶ms, loader::ObjectFile *objFile)
RiscvProcess64(const ProcessParams ¶ms, loader::ObjectFile *objFile)
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
RiscvProcess(const ProcessParams ¶ms, loader::ObjectFile *objFile)
void argsInit(int pageSize)
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual const PCStateBase & pcState() const =0
virtual void setReg(const RegId ®, RegVal val)
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
static constexpr T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
static constexpr T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
const Params & params() const
constexpr auto & StackPointerReg
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
int ContextID
Globally unique thread context ID.
Declarations of a non-full system Page Table.
const std::string & name()