48 #include "debug/Stack.hh"
50 #include "params/Process.hh"
58 using namespace RiscvISA;
63 const Addr stack_base = 0x7FFFFFFFFFFFFFFF
L;
65 const Addr next_thread_stack_base = stack_base - max_stack_size;
68 const Addr mmap_end = 0x4000000000000000
L;
69 memState = make_shared<MemState>(brk_point, stack_base, max_stack_size,
70 next_thread_stack_base, mmap_end);
81 template<
class IntType>
void
92 for (
const string& arg:
argv)
93 stack_top -= arg.size() + 1;
94 for (
const string& env:
envp)
95 stack_top -= env.size() + 1;
96 stack_top &= -
sizeof(
Addr);
99 if (elfObject !=
nullptr) {
109 stack_top -= (1 + argv.size()) *
sizeof(
Addr) +
110 (1 + envp.size()) *
sizeof(
Addr) +
111 sizeof(
Addr) + 2 *
sizeof(IntType) * auxv.size();
112 stack_top &= -2*
sizeof(
Addr);
129 for (
const string& arg: argv) {
132 argPointers.push_back(
memState->getStackMin());
136 DPRINTFN(
"Wrote arg \"%s\" to address %p\n",
137 wrote, (
void*)
memState->getStackMin());
140 argPointers.push_back(0);
144 for (
const string& env: envp) {
147 envPointers.push_back(
memState->getStackMin());
148 DPRINTF(Stack,
"Wrote env \"%s\" to address %p\n",
149 env, (
void*)
memState->getStackMin());
151 envPointers.push_back(0);
158 ((1 + argv.size()) *
sizeof(
Addr) +
159 (1 + envp.size()) *
sizeof(
Addr) +
160 sizeof(
Addr) + 2 *
sizeof(IntType) * auxv.size()));
163 const auto pushOntoStack =
164 [
this, &
sp](
const uint8_t*
data,
const size_t size) {
170 IntType argc =
htog((IntType)argv.size());
171 DPRINTF(Stack,
"Wrote argc %d to address %p\n",
172 argv.size(), (
void*)sp);
173 pushOntoStack((uint8_t*)&argc,
sizeof(IntType));
174 for (
const Addr& argPointer: argPointers) {
175 DPRINTF(Stack,
"Wrote argv pointer %p to address %p\n",
176 (
void*)argPointer, (
void*)sp);
177 pushOntoStack((uint8_t*)&argPointer,
sizeof(
Addr));
181 for (
const Addr& envPointer: envPointers) {
182 DPRINTF(Stack,
"Wrote envp pointer %p to address %p\n",
183 (
void*)envPointer, (
void*)sp);
184 pushOntoStack((uint8_t*)&envPointer,
sizeof(
Addr));
188 std::map<IntType, string> aux_keys = {
199 DPRINTF(Stack,
"Wrote aux key %s to address %p\n",
200 aux_keys[aux.a_type], (
void*)sp);
201 pushOntoStack((uint8_t*)&aux.a_type,
sizeof(IntType));
202 DPRINTF(Stack,
"Wrote aux value %x to address %p\n",
203 aux.a_val, (
void*)sp);
204 pushOntoStack((uint8_t*)&aux.a_val,
sizeof(IntType));
void readString(std::string &str, Addr addr) const
Addr programHeaderTable()
std::vector< ContextID > contextIds
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
SETranslatingPortProxy initVirtMem
RiscvProcess(ProcessParams *params, ObjectFile *objFile)
virtual void readBlob(Addr addr, uint8_t *p, int size) const
Read size bytes memory at address and store in p.
virtual void setIntReg(int reg_idx, uint64_t val)=0
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
virtual TheISA::PCState pcState()=0
T roundUp(const T &val, const U &align)
std::shared_ptr< MemState > memState
ThreadContext is the external interface to all thread state for anything outside of the CPU...
void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value) override
virtual uint64_t readIntReg(int reg_idx)=0
int64_t returnValue() const
The return value.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
void setSyscallArg(ThreadContext *tc, int i, RiscvISA::IntReg val) override
int errnoValue() const
The errno value.
const RegIndex StackPointerReg
T roundDown(const T &val, const U &align)
const RegIndex SyscallPseudoReturnReg
std::vector< std::string > envp
ThreadContext * getThreadContext(ContextID tid)
void argsInit(int pageSize)
const int SyscallArgumentRegs[]
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
virtual bool loadSections(PortProxy &mem_proxy, Addr mask=maxAddr, Addr offset=0)
uint16_t programHeaderSize()
void writeString(Addr addr, const char *str) const
Declarations of a non-full system Page Table.
uint16_t programHeaderCount()
RiscvISA::IntReg getSyscallArg(ThreadContext *tc, int &i) override
std::vector< std::string > argv
This class represents the return value from an emulated system call, including any errno setting...
bool successful() const
Was the system call successful?
virtual void writeBlob(Addr addr, const uint8_t *p, int size) const
Write size bytes from p to address.