process.cc (4111:65fffcb4fae9) process.cc (4117:2807cee7b892)
1/*
2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

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

420 Process::startup();
421
422 string filename;
423 if(argv.size() < 1)
424 filename = "";
425 else
426 filename = argv[0];
427
1/*
2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

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

420 Process::startup();
421
422 string filename;
423 if(argv.size() < 1)
424 filename = "";
425 else
426 filename = argv[0];
427
428 Addr alignmentMask = ~(intSize - 1);
428 //Even though this is a 32 bit process, the ABI says we still need to
429 //maintain double word alignment of the stack pointer.
430 Addr alignmentMask = ~(8 - 1);
429
430 // load object file into target memory
431 objFile->loadSections(initVirtMem);
432
433 //These are the auxilliary vector types
434 enum auxTypes
435 {
436 SPARC_AT_HWCAP = 16,

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

520 for (int i = 0; i < envp.size(); ++i) {
521 env_data_size += envp[i].size() + 1;
522 }
523 int arg_data_size = 0;
524 for (int i = 0; i < argv.size(); ++i) {
525 arg_data_size += argv[i].size() + 1;
526 }
527
431
432 // load object file into target memory
433 objFile->loadSections(initVirtMem);
434
435 //These are the auxilliary vector types
436 enum auxTypes
437 {
438 SPARC_AT_HWCAP = 16,

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

522 for (int i = 0; i < envp.size(); ++i) {
523 env_data_size += envp[i].size() + 1;
524 }
525 int arg_data_size = 0;
526 for (int i = 0; i < argv.size(); ++i) {
527 arg_data_size += argv[i].size() + 1;
528 }
529
528 //The info_block needs to be padded so it's size is a multiple of the
529 //alignment mask. Also, it appears that there needs to be at least some
530 //padding, so if the size is already a multiple, we need to increase it
531 //anyway.
530 //The info_block
532 int info_block_size =
533 (file_name_size +
534 env_data_size +
531 int info_block_size =
532 (file_name_size +
533 env_data_size +
535 arg_data_size +
536 intSize) & alignmentMask;
534 arg_data_size);
537
535
538 int info_block_padding =
539 info_block_size -
540 file_name_size -
541 env_data_size -
542 arg_data_size;
543
544 //Each auxilliary vector is two 8 byte words
545 int aux_array_size = intSize * 2 * (auxv.size() + 1);
546
547 int envp_array_size = intSize * (envp.size() + 1);
548 int argv_array_size = intSize * (argv.size() + 1);
549
550 int argc_size = intSize;
551 int window_save_size = intSize * 16;
552
553 int space_needed =
554 mysterious_size +
536 //Each auxilliary vector is two 8 byte words
537 int aux_array_size = intSize * 2 * (auxv.size() + 1);
538
539 int envp_array_size = intSize * (envp.size() + 1);
540 int argv_array_size = intSize * (argv.size() + 1);
541
542 int argc_size = intSize;
543 int window_save_size = intSize * 16;
544
545 int space_needed =
546 mysterious_size +
555 info_block_size +
556 aux_array_size +
557 envp_array_size +
558 argv_array_size +
559 argc_size +
560 window_save_size;
561
562 stack_min = stack_base - space_needed;
563 stack_min &= alignmentMask;
564 stack_size = stack_base - stack_min;
565
566 // map memory
567 pTable->allocate(roundDown(stack_min, pageSize),
568 roundUp(stack_size, pageSize));
569
570 // map out initial stack contents
547 aux_array_size +
548 envp_array_size +
549 argv_array_size +
550 argc_size +
551 window_save_size;
552
553 stack_min = stack_base - space_needed;
554 stack_min &= alignmentMask;
555 stack_size = stack_base - stack_min;
556
557 // map memory
558 pTable->allocate(roundDown(stack_min, pageSize),
559 roundUp(stack_size, pageSize));
560
561 // map out initial stack contents
571 Addr mysterious_base = stack_base - mysterious_size;
572 Addr file_name_base = mysterious_base - file_name_size;
573 Addr env_data_base = file_name_base - env_data_size;
574 Addr arg_data_base = env_data_base - arg_data_size;
575 Addr auxv_array_base = arg_data_base - aux_array_size - info_block_padding;
576 Addr envp_array_base = auxv_array_base - envp_array_size;
577 Addr argv_array_base = envp_array_base - argv_array_size;
578 Addr argc_base = argv_array_base - argc_size;
579#ifndef NDEBUG
580 // only used in DPRINTF
581 Addr window_save_base = argc_base - window_save_size;
582#endif
562 uint32_t window_save_base = stack_min;
563 uint32_t argc_base = window_save_base + window_save_size;
564 uint32_t argv_array_base = argc_base + argc_size;
565 uint32_t envp_array_base = argv_array_base + argv_array_size;
566 uint32_t auxv_array_base = envp_array_base + envp_array_size;
567 //The info block is pushed up against the top of the stack, while
568 //the rest of the initial stack frame is aligned to an 8 byte boudary.
569 uint32_t arg_data_base = stack_base - info_block_size;
570 uint32_t env_data_base = arg_data_base + arg_data_size;
571 uint32_t file_name_base = env_data_base + env_data_size;
572 uint32_t mysterious_base = file_name_base + file_name_size;
583
584 DPRINTF(Sparc, "The addresses of items on the initial stack:\n");
585 DPRINTF(Sparc, "0x%x - file name\n", file_name_base);
586 DPRINTF(Sparc, "0x%x - env data\n", env_data_base);
587 DPRINTF(Sparc, "0x%x - arg data\n", arg_data_base);
588 DPRINTF(Sparc, "0x%x - auxv array\n", auxv_array_base);
589 DPRINTF(Sparc, "0x%x - envp array\n", envp_array_base);
590 DPRINTF(Sparc, "0x%x - argv array\n", argv_array_base);

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

614 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize,
615 (uint8_t*)&(auxv[x].a_val), intSize);
616 }
617 //Write out the terminating zeroed auxilliary vector
618 const uint64_t zero = 0;
619 initVirtMem->writeBlob(auxv_array_base + 2 * intSize * auxv.size(),
620 (uint8_t*)&zero, 2 * intSize);
621
573
574 DPRINTF(Sparc, "The addresses of items on the initial stack:\n");
575 DPRINTF(Sparc, "0x%x - file name\n", file_name_base);
576 DPRINTF(Sparc, "0x%x - env data\n", env_data_base);
577 DPRINTF(Sparc, "0x%x - arg data\n", arg_data_base);
578 DPRINTF(Sparc, "0x%x - auxv array\n", auxv_array_base);
579 DPRINTF(Sparc, "0x%x - envp array\n", envp_array_base);
580 DPRINTF(Sparc, "0x%x - argv array\n", argv_array_base);

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

604 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize,
605 (uint8_t*)&(auxv[x].a_val), intSize);
606 }
607 //Write out the terminating zeroed auxilliary vector
608 const uint64_t zero = 0;
609 initVirtMem->writeBlob(auxv_array_base + 2 * intSize * auxv.size(),
610 (uint8_t*)&zero, 2 * intSize);
611
622 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem, intSize);
623 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem, intSize);
612 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
613 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
624
625 initVirtMem->writeBlob(argc_base, (uint8_t*)&guestArgc, intSize);
626
627 //Stuff the trap handlers into the processes address space.
628 //Since the stack grows down and is the highest area in the processes
629 //address space, we can put stuff above it and stay out of the way.
630 int fillSize = sizeof(MachInst) * numFillInsts;
631 int spillSize = sizeof(MachInst) * numSpillInsts;
632 fillStart = stack_base;
633 spillStart = fillStart + fillSize;
634 initVirtMem->writeBlob(fillStart, (uint8_t*)fillHandler32, fillSize);
635 initVirtMem->writeBlob(spillStart, (uint8_t*)spillHandler32, spillSize);
636
637 //Set up the thread context to start running the process
638 threadContexts[0]->setIntReg(ArgumentReg0, argc);
639 threadContexts[0]->setIntReg(ArgumentReg1, argv_array_base);
640 threadContexts[0]->setIntReg(StackPointerReg, stack_min);
641
614
615 initVirtMem->writeBlob(argc_base, (uint8_t*)&guestArgc, intSize);
616
617 //Stuff the trap handlers into the processes address space.
618 //Since the stack grows down and is the highest area in the processes
619 //address space, we can put stuff above it and stay out of the way.
620 int fillSize = sizeof(MachInst) * numFillInsts;
621 int spillSize = sizeof(MachInst) * numSpillInsts;
622 fillStart = stack_base;
623 spillStart = fillStart + fillSize;
624 initVirtMem->writeBlob(fillStart, (uint8_t*)fillHandler32, fillSize);
625 initVirtMem->writeBlob(spillStart, (uint8_t*)spillHandler32, spillSize);
626
627 //Set up the thread context to start running the process
628 threadContexts[0]->setIntReg(ArgumentReg0, argc);
629 threadContexts[0]->setIntReg(ArgumentReg1, argv_array_base);
630 threadContexts[0]->setIntReg(StackPointerReg, stack_min);
631
642 Addr prog_entry = objFile->entryPoint();
632 uint32_t prog_entry = objFile->entryPoint();
643 threadContexts[0]->setPC(prog_entry);
644 threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
645 threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
646
647 //Align the "stack_min" to a page boundary.
648 stack_min = roundDown(stack_min, pageSize);
649
650// num_processes++;
651}
633 threadContexts[0]->setPC(prog_entry);
634 threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
635 threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
636
637 //Align the "stack_min" to a page boundary.
638 stack_min = roundDown(stack_min, pageSize);
639
640// num_processes++;
641}