41 #include "debug/Stack.hh"
43 #include "params/Process.hh"
53 using namespace SparcISA;
141 template<
class IntType>
145 int intSize =
sizeof(IntType);
149 std::string filename;
164 HwcapSparcMuldiv = 8,
169 HwcapSparcUltra3 = 32
172 const int64_t hwcap =
224 int file_name_size = filename.size() + 1;
226 const int numRandomBytes = 16;
227 int aux_data_size = numRandomBytes;
229 int env_data_size = 0;
230 for (
int i = 0;
i <
envp.size(); ++
i) {
231 env_data_size +=
envp[
i].size() + 1;
233 int arg_data_size = 0;
234 for (
int i = 0;
i <
argv.size(); ++
i) {
235 arg_data_size +=
argv[
i].size() + 1;
239 int base_info_block_size =
240 sentry_size + file_name_size + env_data_size + arg_data_size;
242 int info_block_size =
roundUp(base_info_block_size,
align);
244 int info_block_padding = info_block_size - base_info_block_size;
247 int aux_array_size = intSize * 2 * (auxv.size() + 1);
249 int envp_array_size = intSize * (
envp.size() + 1);
250 int argv_array_size = intSize * (
argv.size() + 1);
252 int argc_size = intSize;
253 int window_save_size = intSize * 16;
266 int aux_padding = aligned_partial_size - frame_size;
283 IntType sentry_base =
memState->getStackBase() - sentry_size;
284 IntType file_name_base = sentry_base - file_name_size;
285 IntType env_data_base = file_name_base - env_data_size;
286 IntType arg_data_base = env_data_base - arg_data_size;
287 IntType aux_data_base = arg_data_base - info_block_padding - aux_data_size;
288 IntType auxv_array_base = aux_data_base - aux_array_size - aux_padding;
289 IntType envp_array_base = auxv_array_base - envp_array_size;
290 IntType argv_array_base = envp_array_base - argv_array_size;
291 IntType argc_base = argv_array_base - argc_size;
292 IntType window_save_base = argc_base - window_save_size;
294 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
295 DPRINTF(Stack,
"%#x - sentry NULL\n", sentry_base);
296 DPRINTF(Stack,
"filename = %s\n", filename);
297 DPRINTF(Stack,
"%#x - file name\n", file_name_base);
298 DPRINTF(Stack,
"%#x - env data\n", env_data_base);
299 DPRINTF(Stack,
"%#x - arg data\n", arg_data_base);
300 DPRINTF(Stack,
"%#x - auxv array\n", auxv_array_base);
301 DPRINTF(Stack,
"%#x - envp array\n", envp_array_base);
302 DPRINTF(Stack,
"%#x - argv array\n", argv_array_base);
303 DPRINTF(Stack,
"%#x - argc \n", argc_base);
304 DPRINTF(Stack,
"%#x - window save\n", window_save_base);
307 assert(window_save_base ==
memState->getStackMin());
312 IntType argc =
argv.size();
313 IntType guestArgc =
htobe(argc);
316 uint64_t sentry_NULL = 0;
317 initVirtMem->writeBlob(sentry_base, &sentry_NULL, sentry_size);
320 initVirtMem->writeString(file_name_base, filename.c_str());
323 for (
auto &aux: auxv) {
325 aux.val = aux_data_base;
329 Addr auxv_array_end = auxv_array_base;
330 for (
const auto &aux: auxv) {
331 initVirtMem->write(auxv_array_end, aux, ByteOrder::big);
332 auxv_array_end +=
sizeof(aux);
338 auxv_array_end +=
sizeof(zero);
345 initVirtMem->writeBlob(argc_base, &guestArgc, intSize);
373 SparcProcess::argsInit<uint64_t>(pageSize);
385 SparcProcess::argsInit<uint32_t>(pageSize);