51 #include "debug/Stack.hh"
53 #include "params/Process.hh"
63 using namespace ArmISA;
80 Addr stack_base = 0xbf000000
L;
81 Addr max_stack_size = 8 * 1024 * 1024;
82 Addr next_thread_stack_base = stack_base - max_stack_size;
83 Addr mmap_end = 0x40000000
L;
85 memState = std::make_shared<MemState>(
86 this, brk_point, stack_base, max_stack_size,
87 next_thread_stack_base, mmap_end);
96 Addr stack_base = 0x7fffff0000
L;
97 Addr max_stack_size = 8 * 1024 * 1024;
98 Addr next_thread_stack_base = stack_base - max_stack_size;
99 Addr mmap_end = 0x4000000000
L;
101 memState = std::make_shared<MemState>(
102 this, brk_point, stack_base, max_stack_size,
103 next_thread_stack_base, mmap_end);
110 argsInit<uint32_t>(
PageBytes, INTREG_SP);
129 argsInit<uint64_t>(
PageBytes, INTREG_SP0);
158 Arm_FastMult = 1 << 4,
164 Arm_Crunch = 1 << 10,
165 Arm_ThumbEE = 1 << 11,
168 Arm_Vfpv3d16 = 1 << 14
171 return Arm_Swp | Arm_Half | Arm_Thumb | Arm_FastMult |
172 Arm_Vfp | Arm_Edsp | Arm_ThumbEE | Arm_Neon |
173 Arm_Vfpv3 | Arm_Vfpv3d16;
185 Arm_Evtstrm = 1 << 2,
191 Arm_Atomics = 1 << 8,
193 Arm_Asimdhp = 1 << 10,
195 Arm_Asimdrdm = 1 << 12,
203 Arm_Asimddp = 1 << 20,
204 Arm_Sha512 = 1 << 21,
206 Arm_Asimdfhm = 1 << 23,
209 Arm_Ilrcpc = 1 << 26,
219 hwcap |= (pf_r0.fp == 0) ? Arm_Fp : 0;
220 hwcap |= (pf_r0.fp == 1) ? Arm_Fphp | Arm_Fp : 0;
221 hwcap |= (pf_r0.advsimd == 0) ? Arm_Asimd : 0;
222 hwcap |= (pf_r0.advsimd == 1) ? Arm_Asimdhp | Arm_Asimd : 0;
223 hwcap |= (pf_r0.sve >= 1) ? Arm_Sve : 0;
224 hwcap |= (pf_r0.dit >= 1) ? Arm_Dit : 0;
228 hwcap |= (isa_r0.aes >= 1) ? Arm_Aes : 0;
229 hwcap |= (isa_r0.aes >= 2) ? Arm_Pmull : 0;
230 hwcap |= (isa_r0.sha1 >= 1) ? Arm_Sha1 : 0;
231 hwcap |= (isa_r0.sha2 >= 1) ? Arm_Sha2 : 0;
232 hwcap |= (isa_r0.sha2 >= 2) ? Arm_Sha512 : 0;
233 hwcap |= (isa_r0.crc32 >= 1) ? Arm_Crc32 : 0;
234 hwcap |= (isa_r0.atomic >= 1) ? Arm_Atomics : 0;
235 hwcap |= (isa_r0.rdm >= 1) ? Arm_Asimdrdm : 0;
236 hwcap |= (isa_r0.sha3 >= 1) ? Arm_Sha3 : 0;
237 hwcap |= (isa_r0.sm3 >= 1) ? Arm_Sm3 : 0;
238 hwcap |= (isa_r0.sm4 >= 1) ? Arm_Sm4 : 0;
239 hwcap |= (isa_r0.dp >= 1) ? Arm_Asimddp : 0;
240 hwcap |= (isa_r0.fhm >= 1) ? Arm_Asimdfhm : 0;
241 hwcap |= (isa_r0.ts >= 1) ? Arm_Flagm : 0;
245 hwcap |= (isa_r1.dpb >= 1) ? Arm_Dcpop : 0;
246 hwcap |= (isa_r1.jscvt >= 1) ? Arm_Jscvt : 0;
247 hwcap |= (isa_r1.fcma >= 1) ? Arm_Fcma : 0;
248 hwcap |= (isa_r1.lrcpc >= 1) ? Arm_Lrcpc : 0;
249 hwcap |= (isa_r1.lrcpc >= 2) ? Arm_Ilrcpc : 0;
253 hwcap |= (mm_fr2.at >= 1) ? Arm_Uscat : 0;
258 template <
class IntType>
262 int intSize =
sizeof(IntType);
266 std::string filename;
281 IntType features = armHwcap<IntType>();
325 int sentry_size = intSize;
327 std::string platform =
"v71";
328 int platform_size = platform.size() + 1;
331 int aux_random_size = 16;
337 int aux_data_size = filename.size() + 1;
339 int env_data_size = 0;
340 for (
int i = 0;
i <
envp.size(); ++
i) {
341 env_data_size +=
envp[
i].size() + 1;
343 int arg_data_size = 0;
344 for (
int i = 0;
i <
argv.size(); ++
i) {
345 arg_data_size +=
argv[
i].size() + 1;
348 int info_block_size =
349 sentry_size + env_data_size + arg_data_size +
350 aux_data_size + platform_size + aux_random_size;
353 int aux_array_size = intSize * 2 * (auxv.size() + 1);
355 int envp_array_size = intSize * (
envp.size() + 1);
356 int argv_array_size = intSize * (
argv.size() + 1);
358 int argc_size = intSize;
370 int partial_size = frame_size;
371 int aligned_partial_size =
roundUp(partial_size,
align);
372 int aux_padding = aligned_partial_size - partial_size;
374 int space_needed = frame_size + aux_padding;
385 IntType sentry_base =
memState->getStackBase() - sentry_size;
386 IntType aux_data_base = sentry_base - aux_data_size;
387 IntType env_data_base = aux_data_base - env_data_size;
388 IntType arg_data_base = env_data_base - arg_data_size;
389 IntType platform_base = arg_data_base - platform_size;
390 IntType aux_random_base = platform_base - aux_random_size;
391 IntType auxv_array_base = aux_random_base - aux_array_size - aux_padding;
392 IntType envp_array_base = auxv_array_base - envp_array_size;
393 IntType argv_array_base = envp_array_base - argv_array_size;
394 IntType argc_base = argv_array_base - argc_size;
396 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
397 DPRINTF(Stack,
"0x%x - aux data\n", aux_data_base);
398 DPRINTF(Stack,
"0x%x - env data\n", env_data_base);
399 DPRINTF(Stack,
"0x%x - arg data\n", arg_data_base);
400 DPRINTF(Stack,
"0x%x - random data\n", aux_random_base);
401 DPRINTF(Stack,
"0x%x - platform base\n", platform_base);
402 DPRINTF(Stack,
"0x%x - auxv array\n", auxv_array_base);
403 DPRINTF(Stack,
"0x%x - envp array\n", envp_array_base);
404 DPRINTF(Stack,
"0x%x - argv array\n", argv_array_base);
405 DPRINTF(Stack,
"0x%x - argc \n", argc_base);
411 IntType argc =
argv.size();
412 IntType guestArgc =
htole(argc);
415 IntType sentry_NULL = 0;
416 initVirtMem->writeBlob(sentry_base, &sentry_NULL, sentry_size);
419 for (
int i = auxv.size() - 1;
i >= 0;
i--) {
421 auxv[
i].val = platform_base;
422 initVirtMem->writeString(platform_base, platform.c_str());
424 auxv[
i].val = aux_data_base;
425 initVirtMem->writeString(aux_data_base, filename.c_str());
427 auxv[
i].val = aux_random_base;
433 Addr auxv_array_end = auxv_array_base;
434 for (
const auto &aux: auxv) {
435 initVirtMem->write(auxv_array_end, aux, ByteOrder::little);
436 auxv_array_end +=
sizeof(aux);
441 auxv_array_end +=
sizeof(zero);
448 initVirtMem->writeBlob(argc_base, &guestArgc, intSize);
457 if (
argv.size() > 0) {
463 if (
envp.size() > 0) {
472 pc.nextThumb(
pc.thumb());
474 pc.nextAArch64(
pc.aarch64());