41 #include "debug/Stack.hh"
49 using namespace PowerISA;
59 Addr stack_base = 0xbf000000
L;
61 Addr max_stack_size = 8 * 1024 * 1024;
64 Addr next_thread_stack_base = stack_base - max_stack_size;
67 Addr mmap_end = 0x70000000
L;
69 memState = make_shared<MemState>(brk_point, stack_base, max_stack_size,
70 next_thread_stack_base, mmap_end);
106 uint32_t features = 0;
146 int sentry_size = intSize;
148 string platform =
"v51";
149 int platform_size = platform.size() + 1;
155 int aux_data_size = filename.size() + 1;
157 int env_data_size = 0;
158 for (
int i = 0;
i <
envp.size(); ++
i) {
159 env_data_size +=
envp[
i].size() + 1;
161 int arg_data_size = 0;
162 for (
int i = 0;
i <
argv.size(); ++
i) {
163 arg_data_size +=
argv[
i].size() + 1;
166 int info_block_size =
167 sentry_size + env_data_size + arg_data_size +
168 aux_data_size + platform_size;
171 int aux_array_size = intSize * 2 * (auxv.size() + 1);
173 int envp_array_size = intSize * (
envp.size() + 1);
174 int argv_array_size = intSize * (
argv.size() + 1);
176 int argc_size = intSize;
188 int partial_size = frame_size;
189 int aligned_partial_size =
roundUp(partial_size, align);
190 int aux_padding = aligned_partial_size - partial_size;
192 int space_needed = frame_size + aux_padding;
194 Addr stack_min =
memState->getStackBase() - space_needed;
204 uint32_t sentry_base =
memState->getStackBase() - sentry_size;
205 uint32_t aux_data_base = sentry_base - aux_data_size;
206 uint32_t env_data_base = aux_data_base - env_data_size;
207 uint32_t arg_data_base = env_data_base - arg_data_size;
208 uint32_t platform_base = arg_data_base - platform_size;
209 uint32_t auxv_array_base = platform_base - aux_array_size - aux_padding;
210 uint32_t envp_array_base = auxv_array_base - envp_array_size;
211 uint32_t argv_array_base = envp_array_base - argv_array_size;
212 uint32_t argc_base = argv_array_base - argc_size;
214 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
215 DPRINTF(Stack,
"0x%x - aux data\n", aux_data_base);
216 DPRINTF(Stack,
"0x%x - env data\n", env_data_base);
217 DPRINTF(Stack,
"0x%x - arg data\n", arg_data_base);
218 DPRINTF(Stack,
"0x%x - platform base\n", platform_base);
219 DPRINTF(Stack,
"0x%x - auxv array\n", auxv_array_base);
220 DPRINTF(Stack,
"0x%x - envp array\n", envp_array_base);
221 DPRINTF(Stack,
"0x%x - argv array\n", argv_array_base);
222 DPRINTF(Stack,
"0x%x - argc \n", argc_base);
223 DPRINTF(Stack,
"0x%x - stack min\n", stack_min);
228 uint32_t argc =
argv.size();
232 uint32_t sentry_NULL = 0;
234 (uint8_t*)&sentry_NULL, sentry_size);
237 for (
int i = auxv.size() - 1;
i >= 0;
i--) {
239 auxv[
i].a_val = platform_base;
242 auxv[
i].a_val = aux_data_base;
248 for (
int x = 0;
x < auxv.size();
x++)
251 (uint8_t*)&(auxv[
x].a_type), intSize);
253 (uint8_t*)&(auxv[
x].a_val), intSize);
256 const uint64_t zero = 0;
258 (uint8_t*)&zero, 2 * intSize);
PowerISA::IntReg getSyscallArg(ThreadContext *tc, int &i)
Addr programHeaderTable()
std::vector< ContextID > contextIds
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
SETranslatingPortProxy initVirtMem
void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value)
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...
PowerProcess(ProcessParams *params, ObjectFile *objFile)
virtual uint64_t readIntReg(int reg_idx)=0
void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
void argsInit(int intSize, int pageSize)
const RegIndex StackPointerReg
T roundDown(const T &val, const U &align)
std::vector< std::string > envp
ThreadContext * getThreadContext(ContextID tid)
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 copyStringArray(std::vector< std::string > &strings, AddrType array_ptr, AddrType data_ptr, SETranslatingPortProxy &memProxy)
void setSyscallArg(ThreadContext *tc, int i, PowerISA::IntReg val)
void writeString(Addr addr, const char *str) const
Declarations of a non-full system Page Table.
uint16_t programHeaderCount()
int64_t encodedValue() const
The encoded value (as described above)
const RegIndex ReturnValueReg
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.