48 #include "debug/Stack.hh" 50 #include "params/Process.hh" 66 fatal_if(params->useArchPT,
"Arch page tables not implemented.");
73 const Addr stack_base = 0x7FFFFFFFFFFFFFFF
L;
74 const Addr max_stack_size = 8 * 1024 * 1024;
75 const Addr next_thread_stack_base = stack_base - max_stack_size;
77 const Addr mmap_end = 0x4000000000000000
L;
78 memState = make_shared<MemState>(
this, brk_point, stack_base,
79 max_stack_size, next_thread_stack_base, mmap_end);
86 const Addr stack_base = 0x7FFFFFFF;
87 const Addr max_stack_size = 8 * 1024 * 1024;
88 const Addr next_thread_stack_base = stack_base - max_stack_size;
90 const Addr mmap_end = 0x40000000
L;
91 memState = make_shared<MemState>(
this, brk_point, stack_base,
92 max_stack_size, next_thread_stack_base, mmap_end);
119 template<
class IntType>
void 122 const int RandomBytes = 16;
123 const int addrSize =
sizeof(IntType);
130 stack_top -= RandomBytes;
131 for (
const string& arg:
argv)
132 stack_top -= arg.size() + 1;
133 for (
const string& env:
envp)
134 stack_top -= env.size() + 1;
135 stack_top &= -addrSize;
138 if (elfObject !=
nullptr) {
140 auxv.emplace_back(
M5_AT_PHNUM, elfObject->programHeaderCount());
141 auxv.emplace_back(
M5_AT_PHENT, elfObject->programHeaderSize());
142 auxv.emplace_back(
M5_AT_PHDR, elfObject->programHeaderTable());
148 stack_top -= (1 + argv.size()) * addrSize +
149 (1 + envp.size()) * addrSize +
150 addrSize + 2 *
sizeof(IntType) * auxv.size();
151 stack_top &= -2*addrSize;
158 uint8_t at_random[RandomBytes];
159 generate(begin(at_random), end(at_random),
165 for (
const string& arg: argv) {
168 argPointers.push_back(
memState->getStackMin());
171 initVirtMem->readString(wrote, argPointers.back());
172 DPRINTFN(
"Wrote arg \"%s\" to address %p\n",
173 wrote, (
void*)
memState->getStackMin());
176 argPointers.push_back(0);
180 for (
const string& env: envp) {
183 envPointers.push_back(
memState->getStackMin());
184 DPRINTF(Stack,
"Wrote env \"%s\" to address %p\n",
185 env, (
void*)
memState->getStackMin());
187 envPointers.push_back(0);
194 ((1 + argv.size()) * addrSize +
195 (1 + envp.size()) * addrSize +
196 addrSize + 2 *
sizeof(IntType) * auxv.size()));
199 const auto pushOntoStack =
200 [
this, &
sp](IntType
data) {
206 IntType argc = argv.size();
207 DPRINTF(Stack,
"Wrote argc %d to address %#x\n", argc, sp);
210 for (
const Addr& argPointer: argPointers) {
211 DPRINTF(Stack,
"Wrote argv pointer %#x to address %#x\n",
213 pushOntoStack(argPointer);
217 for (
const Addr& envPointer: envPointers) {
218 DPRINTF(Stack,
"Wrote envp pointer %#x to address %#x\n",
220 pushOntoStack(envPointer);
224 std::map<IntType, string> aux_keys = {
234 for (
const auto &aux: auxv) {
235 DPRINTF(Stack,
"Wrote aux key %s to address %#x\n",
236 aux_keys[aux.type], sp);
237 pushOntoStack(aux.type);
238 DPRINTF(Stack,
"Wrote aux value %x to address %#x\n", aux.val, sp);
239 pushOntoStack(aux.val);
250 10, 11, 12, 13, 14, 15, 16
static const std::vector< int > ArgumentRegs
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
const std::string & name()
virtual TheISA::PCState pcState() const =0
std::unique_ptr< SETranslatingPortProxy > initVirtMem
std::vector< ContextID > contextIds
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
Overload hash function for BasicBlockRange type.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
std::shared_ptr< MemState > memState
ThreadContext is the external interface to all thread state for anything outside of the CPU...
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
ThreadContext * getThreadContext(ContextID tid) const
const int StackPointerReg
RiscvProcess(ProcessParams *params, ::Loader::ObjectFile *objFile)
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
std::vector< std::string > envp
void argsInit(int pageSize)
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
const Params * params() const
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Declarations of a non-full system Page Table.
::Loader::MemoryImage image
RiscvProcess32(ProcessParams *params, ::Loader::ObjectFile *objFile)
const ByteOrder GuestByteOrder
std::vector< std::string > argv
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
::Loader::ObjectFile * objFile
int ContextID
Globally unique thread context ID.
RiscvProcess64(ProcessParams *params, ::Loader::ObjectFile *objFile)