38 #include "debug/Stack.hh" 40 #include "params/Process.hh" 55 fatal_if(params->useArchPT,
"Arch page tables not implemented.");
60 Addr stack_base = 0xbf000000
L;
62 Addr max_stack_size = 8 * 1024 * 1024;
65 Addr next_thread_stack_base = stack_base - max_stack_size;
68 Addr mmap_end = 0x70000000
L;
70 memState = make_shared<MemState>(
this, brk_point, stack_base,
71 max_stack_size, next_thread_stack_base,
105 uint32_t features = 0;
116 auxv.emplace_back(
M5_AT_PHDR, elfObject->programHeaderTable());
118 auxv.emplace_back(
M5_AT_PHENT, elfObject->programHeaderSize());
120 auxv.emplace_back(
M5_AT_PHNUM, elfObject->programHeaderCount());
147 int sentry_size = intSize;
149 string platform =
"v51";
150 int platform_size = platform.size() + 1;
156 int aux_data_size = filename.size() + 1;
158 const int numRandomBytes = 16;
159 aux_data_size += numRandomBytes;
161 int env_data_size = 0;
162 for (
int i = 0;
i <
envp.size(); ++
i) {
163 env_data_size +=
envp[
i].size() + 1;
165 int arg_data_size = 0;
166 for (
int i = 0;
i <
argv.size(); ++
i) {
167 arg_data_size +=
argv[
i].size() + 1;
170 int info_block_size =
171 sentry_size + env_data_size + arg_data_size +
172 aux_data_size + platform_size;
175 int aux_array_size = intSize * 2 * (auxv.size() + 1);
177 int envp_array_size = intSize * (
envp.size() + 1);
178 int argv_array_size = intSize * (
argv.size() + 1);
180 int argc_size = intSize;
192 int partial_size = frame_size;
193 int aligned_partial_size =
roundUp(partial_size, align);
194 int aux_padding = aligned_partial_size - partial_size;
196 int space_needed = frame_size + aux_padding;
198 Addr stack_min =
memState->getStackBase() - space_needed;
208 uint32_t sentry_base =
memState->getStackBase() - sentry_size;
209 uint32_t aux_data_base = sentry_base - aux_data_size;
210 uint32_t env_data_base = aux_data_base - env_data_size;
211 uint32_t arg_data_base = env_data_base - arg_data_size;
212 uint32_t platform_base = arg_data_base - platform_size;
213 uint32_t auxv_array_base = platform_base - aux_array_size - aux_padding;
214 uint32_t envp_array_base = auxv_array_base - envp_array_size;
215 uint32_t argv_array_base = envp_array_base - argv_array_size;
216 uint32_t argc_base = argv_array_base - argc_size;
218 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
219 DPRINTF(Stack,
"0x%x - aux data\n", aux_data_base);
220 DPRINTF(Stack,
"0x%x - env data\n", env_data_base);
221 DPRINTF(Stack,
"0x%x - arg data\n", arg_data_base);
222 DPRINTF(Stack,
"0x%x - platform base\n", platform_base);
223 DPRINTF(Stack,
"0x%x - auxv array\n", auxv_array_base);
224 DPRINTF(Stack,
"0x%x - envp array\n", envp_array_base);
225 DPRINTF(Stack,
"0x%x - argv array\n", argv_array_base);
226 DPRINTF(Stack,
"0x%x - argc \n", argc_base);
227 DPRINTF(Stack,
"0x%x - stack min\n", stack_min);
232 uint32_t argc =
argv.size();
233 uint32_t guestArgc =
htobe(argc);
236 uint32_t sentry_NULL = 0;
237 initVirtMem->writeBlob(sentry_base, &sentry_NULL, sentry_size);
240 for (
int i = auxv.size() - 1;
i >= 0;
i--) {
242 auxv[
i].val = platform_base;
243 initVirtMem->writeString(platform_base, platform.c_str());
245 auxv[
i].val = aux_data_base + numRandomBytes;
246 initVirtMem->writeString(aux_data_base, filename.c_str());
248 auxv[
i].val = aux_data_base;
253 Addr auxv_array_end = auxv_array_base;
254 for (
const auto &aux: auxv) {
256 auxv_array_end +=
sizeof(aux);
261 auxv_array_end +=
sizeof(zero);
268 initVirtMem->writeBlob(argc_base, &guestArgc, intSize);
const std::string & name()
virtual TheISA::PCState pcState() const =0
std::unique_ptr< SETranslatingPortProxy > initVirtMem
std::vector< ContextID > contextIds
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
PowerProcess(ProcessParams *params, ::Loader::ObjectFile *objFile)
ThreadContext is the external interface to all thread state for anything outside of the CPU...
ThreadContext * getThreadContext(ContextID tid) const
bool write(const PortProxy &proxy) const
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
void align(const scfx_rep &lhs, const scfx_rep &rhs, int &new_wp, int &len_mant, scfx_mant_ref &lhs_mant, scfx_mant_ref &rhs_mant)
const int StackPointerReg
void copyStringArray(std::vector< std::string > &strings, AddrType array_ptr, AddrType data_ptr, const ByteOrder bo, PortProxy &memProxy)
void argsInit(int intSize, int pageSize)
static const std::vector< int > ArgumentRegs
#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
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
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
::Loader::MemoryImage interpImage
const ByteOrder GuestByteOrder
std::vector< std::string > argv
::Loader::ObjectFile * objFile