process.cc (11854:0e94e16e26ea) process.cc (11886:43b882cada33)
1/*
2 * Copyright (c) 2010, 2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 56 unchanged lines hidden (view full) ---

65 : Process(params, objFile), arch(_arch)
66{
67}
68
69ArmProcess32::ArmProcess32(ProcessParams *params, ObjectFile *objFile,
70 ObjectFile::Arch _arch)
71 : ArmProcess(params, objFile, _arch)
72{
1/*
2 * Copyright (c) 2010, 2012 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 56 unchanged lines hidden (view full) ---

65 : Process(params, objFile), arch(_arch)
66{
67}
68
69ArmProcess32::ArmProcess32(ProcessParams *params, ObjectFile *objFile,
70 ObjectFile::Arch _arch)
71 : ArmProcess(params, objFile, _arch)
72{
73 stack_base = 0xbf000000L;
73 memState->stackBase = 0xbf000000L;
74
75 // Set pointer for next thread stack. Reserve 8M for main stack.
74
75 // Set pointer for next thread stack. Reserve 8M for main stack.
76 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
76 memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024);
77
78 // Set up break point (Top of Heap)
77
78 // Set up break point (Top of Heap)
79 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
80 brk_point = roundUp(brk_point, PageBytes);
79 memState->brkPoint = objFile->dataBase() + objFile->dataSize() +
80 objFile->bssSize();
81 memState->brkPoint = roundUp(memState->brkPoint, PageBytes);
81
82 // Set up region for mmaps. For now, start at bottom of kuseg space.
82
83 // Set up region for mmaps. For now, start at bottom of kuseg space.
83 mmap_end = 0x40000000L;
84 memState->mmapEnd = 0x40000000L;
84}
85
86ArmProcess64::ArmProcess64(ProcessParams *params, ObjectFile *objFile,
87 ObjectFile::Arch _arch)
88 : ArmProcess(params, objFile, _arch)
89{
85}
86
87ArmProcess64::ArmProcess64(ProcessParams *params, ObjectFile *objFile,
88 ObjectFile::Arch _arch)
89 : ArmProcess(params, objFile, _arch)
90{
90 stack_base = 0x7fffff0000L;
91 memState->stackBase = 0x7fffff0000L;
91
92 // Set pointer for next thread stack. Reserve 8M for main stack.
92
93 // Set pointer for next thread stack. Reserve 8M for main stack.
93 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
94 memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024);
94
95 // Set up break point (Top of Heap)
95
96 // Set up break point (Top of Heap)
96 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
97 brk_point = roundUp(brk_point, PageBytes);
97 memState->brkPoint = objFile->dataBase() + objFile->dataSize() +
98 objFile->bssSize();
99 memState->brkPoint = roundUp(memState->brkPoint, PageBytes);
98
99 // Set up region for mmaps. For now, start at bottom of kuseg space.
100
101 // Set up region for mmaps. For now, start at bottom of kuseg space.
100 mmap_end = 0x4000000000L;
102 memState->mmapEnd = 0x4000000000L;
101}
102
103void
104ArmProcess32::initState()
105{
106 Process::initState();
107 argsInit<uint32_t>(PageBytes, INTREG_SP);
108 for (int i = 0; i < contextIds.size(); i++) {

--- 186 unchanged lines hidden (view full) ---

295 //There needs to be padding after the auxiliary vector data so that the
296 //very bottom of the stack is aligned properly.
297 int partial_size = frame_size;
298 int aligned_partial_size = roundUp(partial_size, align);
299 int aux_padding = aligned_partial_size - partial_size;
300
301 int space_needed = frame_size + aux_padding;
302
103}
104
105void
106ArmProcess32::initState()
107{
108 Process::initState();
109 argsInit<uint32_t>(PageBytes, INTREG_SP);
110 for (int i = 0; i < contextIds.size(); i++) {

--- 186 unchanged lines hidden (view full) ---

297 //There needs to be padding after the auxiliary vector data so that the
298 //very bottom of the stack is aligned properly.
299 int partial_size = frame_size;
300 int aligned_partial_size = roundUp(partial_size, align);
301 int aux_padding = aligned_partial_size - partial_size;
302
303 int space_needed = frame_size + aux_padding;
304
303 stack_min = stack_base - space_needed;
304 stack_min = roundDown(stack_min, align);
305 stack_size = stack_base - stack_min;
305 memState->stackMin = memState->stackBase - space_needed;
306 memState->stackMin = roundDown(memState->stackMin, align);
307 memState->stackSize = memState->stackBase - memState->stackMin;
306
307 // map memory
308
309 // map memory
308 allocateMem(roundDown(stack_min, pageSize), roundUp(stack_size, pageSize));
310 allocateMem(roundDown(memState->stackMin, pageSize),
311 roundUp(memState->stackSize, pageSize));
309
310 // map out initial stack contents
312
313 // map out initial stack contents
311 IntType sentry_base = stack_base - sentry_size;
314 IntType sentry_base = memState->stackBase - sentry_size;
312 IntType aux_data_base = sentry_base - aux_data_size;
313 IntType env_data_base = aux_data_base - env_data_size;
314 IntType arg_data_base = env_data_base - arg_data_size;
315 IntType platform_base = arg_data_base - platform_size;
316 IntType aux_random_base = platform_base - aux_random_size;
317 IntType auxv_array_base = aux_random_base - aux_array_size - aux_padding;
318 IntType envp_array_base = auxv_array_base - envp_array_size;
319 IntType argv_array_base = envp_array_base - argv_array_size;

--- 4 unchanged lines hidden (view full) ---

324 DPRINTF(Stack, "0x%x - env data\n", env_data_base);
325 DPRINTF(Stack, "0x%x - arg data\n", arg_data_base);
326 DPRINTF(Stack, "0x%x - random data\n", aux_random_base);
327 DPRINTF(Stack, "0x%x - platform base\n", platform_base);
328 DPRINTF(Stack, "0x%x - auxv array\n", auxv_array_base);
329 DPRINTF(Stack, "0x%x - envp array\n", envp_array_base);
330 DPRINTF(Stack, "0x%x - argv array\n", argv_array_base);
331 DPRINTF(Stack, "0x%x - argc \n", argc_base);
315 IntType aux_data_base = sentry_base - aux_data_size;
316 IntType env_data_base = aux_data_base - env_data_size;
317 IntType arg_data_base = env_data_base - arg_data_size;
318 IntType platform_base = arg_data_base - platform_size;
319 IntType aux_random_base = platform_base - aux_random_size;
320 IntType auxv_array_base = aux_random_base - aux_array_size - aux_padding;
321 IntType envp_array_base = auxv_array_base - envp_array_size;
322 IntType argv_array_base = envp_array_base - argv_array_size;

--- 4 unchanged lines hidden (view full) ---

327 DPRINTF(Stack, "0x%x - env data\n", env_data_base);
328 DPRINTF(Stack, "0x%x - arg data\n", arg_data_base);
329 DPRINTF(Stack, "0x%x - random data\n", aux_random_base);
330 DPRINTF(Stack, "0x%x - platform base\n", platform_base);
331 DPRINTF(Stack, "0x%x - auxv array\n", auxv_array_base);
332 DPRINTF(Stack, "0x%x - envp array\n", envp_array_base);
333 DPRINTF(Stack, "0x%x - argv array\n", argv_array_base);
334 DPRINTF(Stack, "0x%x - argc \n", argc_base);
332 DPRINTF(Stack, "0x%x - stack min\n", stack_min);
335 DPRINTF(Stack, "0x%x - stack min\n", memState->stackMin);
333
334 // write contents to stack
335
336 // figure out argc
337 IntType argc = argv.size();
338 IntType guestArgc = ArmISA::htog(argc);
339
340 //Write out the sentry void *

--- 29 unchanged lines hidden (view full) ---

370
371 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
372 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
373
374 initVirtMem.writeBlob(argc_base, (uint8_t*)&guestArgc, intSize);
375
376 ThreadContext *tc = system->getThreadContext(contextIds[0]);
377 //Set the stack pointer register
336
337 // write contents to stack
338
339 // figure out argc
340 IntType argc = argv.size();
341 IntType guestArgc = ArmISA::htog(argc);
342
343 //Write out the sentry void *

--- 29 unchanged lines hidden (view full) ---

373
374 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
375 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
376
377 initVirtMem.writeBlob(argc_base, (uint8_t*)&guestArgc, intSize);
378
379 ThreadContext *tc = system->getThreadContext(contextIds[0]);
380 //Set the stack pointer register
378 tc->setIntReg(spIndex, stack_min);
381 tc->setIntReg(spIndex, memState->stackMin);
379 //A pointer to a function to run when the program exits. We'll set this
380 //to zero explicitly to make sure this isn't used.
381 tc->setIntReg(ArgumentReg0, 0);
382 //Set argument regs 1 and 2 to argv[0] and envp[0] respectively
383 if (argv.size() > 0) {
384 tc->setIntReg(ArgumentReg1, arg_data_base + arg_data_size -
385 argv[argv.size() - 1].size() - 1);
386 } else {

--- 9 unchanged lines hidden (view full) ---

396 PCState pc;
397 pc.thumb(arch == ObjectFile::Thumb);
398 pc.nextThumb(pc.thumb());
399 pc.aarch64(arch == ObjectFile::Arm64);
400 pc.nextAArch64(pc.aarch64());
401 pc.set(getStartPC() & ~mask(1));
402 tc->pcState(pc);
403
382 //A pointer to a function to run when the program exits. We'll set this
383 //to zero explicitly to make sure this isn't used.
384 tc->setIntReg(ArgumentReg0, 0);
385 //Set argument regs 1 and 2 to argv[0] and envp[0] respectively
386 if (argv.size() > 0) {
387 tc->setIntReg(ArgumentReg1, arg_data_base + arg_data_size -
388 argv[argv.size() - 1].size() - 1);
389 } else {

--- 9 unchanged lines hidden (view full) ---

399 PCState pc;
400 pc.thumb(arch == ObjectFile::Thumb);
401 pc.nextThumb(pc.thumb());
402 pc.aarch64(arch == ObjectFile::Arm64);
403 pc.nextAArch64(pc.aarch64());
404 pc.set(getStartPC() & ~mask(1));
405 tc->pcState(pc);
406
404 //Align the "stack_min" to a page boundary.
405 stack_min = roundDown(stack_min, pageSize);
407 //Align the "stackMin" to a page boundary.
408 memState->stackMin = roundDown(memState->stackMin, pageSize);
406}
407
408ArmISA::IntReg
409ArmProcess32::getSyscallArg(ThreadContext *tc, int &i)
410{
411 assert(i < 6);
412 return tc->readIntReg(ArgumentReg0 + i++);
413}

--- 81 unchanged lines hidden ---
409}
410
411ArmISA::IntReg
412ArmProcess32::getSyscallArg(ThreadContext *tc, int &i)
413{
414 assert(i < 6);
415 return tc->readIntReg(ArgumentReg0 + i++);
416}

--- 81 unchanged lines hidden ---