49 #include "debug/Stack.hh"
51 #include "params/Process.hh"
76 Addr stack_base = 0xbf000000
L;
77 Addr max_stack_size = 8 * 1024 * 1024;
78 Addr next_thread_stack_base = stack_base - max_stack_size;
79 Addr mmap_end = 0x40000000
L;
81 memState = make_shared<MemState>(
this, brk_point, stack_base,
82 max_stack_size, next_thread_stack_base,
92 Addr stack_base = 0x7fffff0000
L;
93 Addr max_stack_size = 8 * 1024 * 1024;
94 Addr next_thread_stack_base = stack_base - max_stack_size;
95 Addr mmap_end = 0x4000000000
L;
97 memState = make_shared<MemState>(
this, brk_point, stack_base,
98 max_stack_size, next_thread_stack_base,
153 Arm_FastMult = 1 << 4,
159 Arm_Crunch = 1 << 10,
160 Arm_ThumbEE = 1 << 11,
163 Arm_Vfpv3d16 = 1 << 14
166 return Arm_Swp | Arm_Half | Arm_Thumb | Arm_FastMult |
167 Arm_Vfp | Arm_Edsp | Arm_ThumbEE | Arm_Neon |
168 Arm_Vfpv3 | Arm_Vfpv3d16;
179 Arm_Evtstrm = 1 << 2,
185 Arm_Atomics = 1 << 8,
187 Arm_Asimdhp = 1 << 10,
189 Arm_Asimdrdm = 1 << 12,
197 Arm_Asimddp = 1 << 20,
198 Arm_Sha512 = 1 << 21,
200 Arm_Asimdfhm = 1 << 23,
203 Arm_Ilrcpc = 1 << 26,
213 hwcap |= (pf_r0.fp == 0) ? Arm_Fp : 0;
214 hwcap |= (pf_r0.fp == 1) ? Arm_Fphp | Arm_Fp : 0;
215 hwcap |= (pf_r0.advsimd == 0) ? Arm_Asimd : 0;
216 hwcap |= (pf_r0.advsimd == 1) ? Arm_Asimdhp | Arm_Asimd : 0;
217 hwcap |= (pf_r0.sve >= 1) ? Arm_Sve : 0;
218 hwcap |= (pf_r0.dit >= 1) ? Arm_Dit : 0;
222 hwcap |= (isa_r0.aes >= 1) ? Arm_Aes : 0;
223 hwcap |= (isa_r0.aes >= 2) ? Arm_Pmull : 0;
224 hwcap |= (isa_r0.sha1 >= 1) ? Arm_Sha1 : 0;
225 hwcap |= (isa_r0.sha2 >= 1) ? Arm_Sha2 : 0;
226 hwcap |= (isa_r0.sha2 >= 2) ? Arm_Sha512 : 0;
227 hwcap |= (isa_r0.crc32 >= 1) ? Arm_Crc32 : 0;
228 hwcap |= (isa_r0.atomic >= 1) ? Arm_Atomics : 0;
229 hwcap |= (isa_r0.rdm >= 1) ? Arm_Asimdrdm : 0;
230 hwcap |= (isa_r0.sha3 >= 1) ? Arm_Sha3 : 0;
231 hwcap |= (isa_r0.sm3 >= 1) ? Arm_Sm3 : 0;
232 hwcap |= (isa_r0.sm4 >= 1) ? Arm_Sm4 : 0;
233 hwcap |= (isa_r0.dp >= 1) ? Arm_Asimddp : 0;
234 hwcap |= (isa_r0.fhm >= 1) ? Arm_Asimdfhm : 0;
235 hwcap |= (isa_r0.ts >= 1) ? Arm_Flagm : 0;
239 hwcap |= (isa_r1.dpb >= 1) ? Arm_Dcpop : 0;
240 hwcap |= (isa_r1.jscvt >= 1) ? Arm_Jscvt : 0;
241 hwcap |= (isa_r1.fcma >= 1) ? Arm_Fcma : 0;
242 hwcap |= (isa_r1.lrcpc >= 1) ? Arm_Lrcpc : 0;
243 hwcap |= (isa_r1.lrcpc >= 2) ? Arm_Ilrcpc : 0;
247 hwcap |= (mm_fr2.at >= 1) ? Arm_Uscat : 0;
252 template <
class IntType>
256 int intSize =
sizeof(IntType);
275 IntType features = armHwcap<IntType>();
296 auxv.emplace_back(
M5_AT_PHDR, elfObject->programHeaderTable());
298 auxv.emplace_back(
M5_AT_PHENT, elfObject->programHeaderSize());
300 auxv.emplace_back(
M5_AT_PHNUM, elfObject->programHeaderCount());
319 int sentry_size = intSize;
321 string platform =
"v71";
322 int platform_size = platform.size() + 1;
325 int aux_random_size = 16;
331 int aux_data_size = filename.size() + 1;
333 int env_data_size = 0;
334 for (
int i = 0;
i <
envp.size(); ++
i) {
335 env_data_size +=
envp[
i].size() + 1;
337 int arg_data_size = 0;
338 for (
int i = 0;
i <
argv.size(); ++
i) {
339 arg_data_size +=
argv[
i].size() + 1;
342 int info_block_size =
343 sentry_size + env_data_size + arg_data_size +
344 aux_data_size + platform_size + aux_random_size;
347 int aux_array_size = intSize * 2 * (auxv.size() + 1);
349 int envp_array_size = intSize * (
envp.size() + 1);
350 int argv_array_size = intSize * (
argv.size() + 1);
352 int argc_size = intSize;
364 int partial_size = frame_size;
365 int aligned_partial_size =
roundUp(partial_size,
align);
366 int aux_padding = aligned_partial_size - partial_size;
368 int space_needed = frame_size + aux_padding;
379 IntType sentry_base =
memState->getStackBase() - sentry_size;
380 IntType aux_data_base = sentry_base - aux_data_size;
381 IntType env_data_base = aux_data_base - env_data_size;
382 IntType arg_data_base = env_data_base - arg_data_size;
383 IntType platform_base = arg_data_base - platform_size;
384 IntType aux_random_base = platform_base - aux_random_size;
385 IntType auxv_array_base = aux_random_base - aux_array_size - aux_padding;
386 IntType envp_array_base = auxv_array_base - envp_array_size;
387 IntType argv_array_base = envp_array_base - argv_array_size;
388 IntType argc_base = argv_array_base - argc_size;
390 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
391 DPRINTF(Stack,
"0x%x - aux data\n", aux_data_base);
392 DPRINTF(Stack,
"0x%x - env data\n", env_data_base);
393 DPRINTF(Stack,
"0x%x - arg data\n", arg_data_base);
394 DPRINTF(Stack,
"0x%x - random data\n", aux_random_base);
395 DPRINTF(Stack,
"0x%x - platform base\n", platform_base);
396 DPRINTF(Stack,
"0x%x - auxv array\n", auxv_array_base);
397 DPRINTF(Stack,
"0x%x - envp array\n", envp_array_base);
398 DPRINTF(Stack,
"0x%x - argv array\n", argv_array_base);
399 DPRINTF(Stack,
"0x%x - argc \n", argc_base);
405 IntType argc =
argv.size();
406 IntType guestArgc =
htole(argc);
409 IntType sentry_NULL = 0;
410 initVirtMem->writeBlob(sentry_base, &sentry_NULL, sentry_size);
413 for (
int i = auxv.size() - 1;
i >= 0;
i--) {
415 auxv[
i].val = platform_base;
416 initVirtMem->writeString(platform_base, platform.c_str());
418 auxv[
i].val = aux_data_base;
419 initVirtMem->writeString(aux_data_base, filename.c_str());
421 auxv[
i].val = aux_random_base;
427 Addr auxv_array_end = auxv_array_base;
428 for (
const auto &aux: auxv) {
430 auxv_array_end +=
sizeof(aux);
435 auxv_array_end +=
sizeof(zero);
442 initVirtMem->writeBlob(argc_base, &guestArgc, intSize);
451 if (
argv.size() > 0) {
457 if (
envp.size() > 0) {
466 pc.nextThumb(
pc.thumb());
468 pc.nextAArch64(
pc.aarch64());