process.cc revision 4997
12207SN/A/*
22207SN/A * Copyright (c) 2003-2004 The Regents of The University of Michigan
32207SN/A * All rights reserved.
42207SN/A *
52207SN/A * Redistribution and use in source and binary forms, with or without
62207SN/A * modification, are permitted provided that the following conditions are
72207SN/A * met: redistributions of source code must retain the above copyright
82207SN/A * notice, this list of conditions and the following disclaimer;
92207SN/A * redistributions in binary form must reproduce the above copyright
102207SN/A * notice, this list of conditions and the following disclaimer in the
112207SN/A * documentation and/or other materials provided with the distribution;
122207SN/A * neither the name of the copyright holders nor the names of its
132207SN/A * contributors may be used to endorse or promote products derived from
142207SN/A * this software without specific prior written permission.
152207SN/A *
162207SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172207SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182207SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192207SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202207SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212207SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222207SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232207SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242207SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252207SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262207SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Gabe Black
292665Ssaidi@eecs.umich.edu *          Ali Saidi
302207SN/A */
312207SN/A
323589Sgblack@eecs.umich.edu#include "arch/sparc/asi.hh"
334111Sgblack@eecs.umich.edu#include "arch/sparc/handlers.hh"
342474SN/A#include "arch/sparc/isa_traits.hh"
352207SN/A#include "arch/sparc/process.hh"
363760Sgblack@eecs.umich.edu#include "arch/sparc/types.hh"
372454SN/A#include "base/loader/object_file.hh"
382976Sgblack@eecs.umich.edu#include "base/loader/elf_object.hh"
392454SN/A#include "base/misc.hh"
402680Sktlim@umich.edu#include "cpu/thread_context.hh"
412561SN/A#include "mem/page_table.hh"
424434Ssaidi@eecs.umich.edu#include "sim/process_impl.hh"
432561SN/A#include "mem/translating_port.hh"
442474SN/A#include "sim/system.hh"
452207SN/A
462458SN/Ausing namespace std;
472474SN/Ausing namespace SparcISA;
482458SN/A
492207SN/A
502474SN/ASparcLiveProcess::SparcLiveProcess(const std::string &nm, ObjectFile *objFile,
512474SN/A        System *_system, int stdin_fd, int stdout_fd, int stderr_fd,
523114Sgblack@eecs.umich.edu        std::vector<std::string> &argv, std::vector<std::string> &envp,
533669Sbinkertn@umich.edu        const std::string &cwd,
543114Sgblack@eecs.umich.edu        uint64_t _uid, uint64_t _euid, uint64_t _gid, uint64_t _egid,
553114Sgblack@eecs.umich.edu        uint64_t _pid, uint64_t _ppid)
562474SN/A    : LiveProcess(nm, objFile, _system, stdin_fd, stdout_fd, stderr_fd,
573669Sbinkertn@umich.edu        argv, envp, cwd, _uid, _euid, _gid, _egid, _pid, _ppid)
582474SN/A{
592474SN/A
602474SN/A    // XXX all the below need to be updated for SPARC - Ali
612474SN/A    brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
622474SN/A    brk_point = roundUp(brk_point, VMPageSize);
632474SN/A
642474SN/A    // Set pointer for next thread stack.  Reserve 8M for main stack.
652474SN/A    next_thread_stack_base = stack_base - (8 * 1024 * 1024);
663415Sgblack@eecs.umich.edu
673415Sgblack@eecs.umich.edu    //Initialize these to 0s
683415Sgblack@eecs.umich.edu    fillStart = 0;
693415Sgblack@eecs.umich.edu    spillStart = 0;
702474SN/A}
712474SN/A
724111Sgblack@eecs.umich.eduvoid SparcLiveProcess::handleTrap(int trapNum, ThreadContext *tc)
734111Sgblack@eecs.umich.edu{
744111Sgblack@eecs.umich.edu    switch(trapNum)
754111Sgblack@eecs.umich.edu    {
764111Sgblack@eecs.umich.edu      case 0x03: //Flush window trap
774111Sgblack@eecs.umich.edu        warn("Ignoring request to flush register windows.\n");
784111Sgblack@eecs.umich.edu        break;
794111Sgblack@eecs.umich.edu      default:
804111Sgblack@eecs.umich.edu        panic("Unimplemented trap to operating system: trap number %#x.\n", trapNum);
814111Sgblack@eecs.umich.edu    }
824111Sgblack@eecs.umich.edu}
834111Sgblack@eecs.umich.edu
842474SN/Avoid
854111Sgblack@eecs.umich.eduSparc32LiveProcess::startup()
864111Sgblack@eecs.umich.edu{
874111Sgblack@eecs.umich.edu    argsInit(32 / 8, VMPageSize);
884111Sgblack@eecs.umich.edu
894111Sgblack@eecs.umich.edu    //From the SPARC ABI
904111Sgblack@eecs.umich.edu
914648Sgblack@eecs.umich.edu    //The process runs in user mode with 32 bit addresses
924648Sgblack@eecs.umich.edu    threadContexts[0]->setMiscReg(MISCREG_PSTATE, 0x0a);
934111Sgblack@eecs.umich.edu
944111Sgblack@eecs.umich.edu    //Setup default FP state
954172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_FSR, 0);
964111Sgblack@eecs.umich.edu
974172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_TICK, 0);
984111Sgblack@eecs.umich.edu    //
994111Sgblack@eecs.umich.edu    /*
1004111Sgblack@eecs.umich.edu     * Register window management registers
1014111Sgblack@eecs.umich.edu     */
1024111Sgblack@eecs.umich.edu
1034111Sgblack@eecs.umich.edu    //No windows contain info from other programs
1044172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_OTHERWIN, 0);
1054111Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 6, 0);
1064111Sgblack@eecs.umich.edu    //There are no windows to pop
1074172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_CANRESTORE, 0);
1084111Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 4, 0);
1094111Sgblack@eecs.umich.edu    //All windows are available to save into
1104172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_CANSAVE, NWindows - 2);
1114111Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 3, NWindows - 2);
1124111Sgblack@eecs.umich.edu    //All windows are "clean"
1134172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_CLEANWIN, NWindows);
1144111Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 5, NWindows);
1154111Sgblack@eecs.umich.edu    //Start with register window 0
1164172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_CWP, 0);
1174111Sgblack@eecs.umich.edu    //Always use spill and fill traps 0
1184172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_WSTATE, 0);
1194111Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 7, 0);
1204111Sgblack@eecs.umich.edu    //Set the trap level to 0
1214172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_TL, 0);
1224111Sgblack@eecs.umich.edu    //Set the ASI register to something fixed
1234172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY);
1244997Sgblack@eecs.umich.edu
1254997Sgblack@eecs.umich.edu    /*
1264997Sgblack@eecs.umich.edu     * T1 specific registers
1274997Sgblack@eecs.umich.edu     */
1284997Sgblack@eecs.umich.edu    //Turn on the icache, dcache, dtb translation, and itb translation.
1294997Sgblack@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_MMU_LSU_CTRL, 15);
1304111Sgblack@eecs.umich.edu}
1314111Sgblack@eecs.umich.edu
1324111Sgblack@eecs.umich.eduvoid
1334111Sgblack@eecs.umich.eduSparc64LiveProcess::startup()
1342474SN/A{
1353760Sgblack@eecs.umich.edu    argsInit(sizeof(IntReg), VMPageSize);
1362561SN/A
1372561SN/A    //From the SPARC ABI
1382561SN/A
1392561SN/A    //The process runs in user mode
1404172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscReg(MISCREG_PSTATE, 0x02);
1412561SN/A
1422646Ssaidi@eecs.umich.edu    //Setup default FP state
1434172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_FSR, 0);
1442646Ssaidi@eecs.umich.edu
1454172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_TICK, 0);
1464997Sgblack@eecs.umich.edu
1472561SN/A    /*
1482561SN/A     * Register window management registers
1492561SN/A     */
1502561SN/A
1512561SN/A    //No windows contain info from other programs
1524172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_OTHERWIN, 0);
1533761Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 6, 0);
1542561SN/A    //There are no windows to pop
1554172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_CANRESTORE, 0);
1563761Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 4, 0);
1572561SN/A    //All windows are available to save into
1584172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_CANSAVE, NWindows - 2);
1593761Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 3, NWindows - 2);
1602561SN/A    //All windows are "clean"
1614172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_CLEANWIN, NWindows);
1623761Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 5, NWindows);
1632561SN/A    //Start with register window 0
1644172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_CWP, 0);
1653415Sgblack@eecs.umich.edu    //Always use spill and fill traps 0
1664172Ssaidi@eecs.umich.edu    //threadContexts[0]->setMiscRegNoEffect(MISCREG_WSTATE, 0);
1673761Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(NumIntArchRegs + 7, 0);
1683415Sgblack@eecs.umich.edu    //Set the trap level to 0
1694172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_TL, 0);
1703589Sgblack@eecs.umich.edu    //Set the ASI register to something fixed
1714172Ssaidi@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY);
1724997Sgblack@eecs.umich.edu
1734997Sgblack@eecs.umich.edu    /*
1744997Sgblack@eecs.umich.edu     * T1 specific registers
1754997Sgblack@eecs.umich.edu     */
1764997Sgblack@eecs.umich.edu    //Turn on the icache, dcache, dtb translation, and itb translation.
1774997Sgblack@eecs.umich.edu    threadContexts[0]->setMiscRegNoEffect(MISCREG_MMU_LSU_CTRL, 15);
1782474SN/A}
1792474SN/A
1804111Sgblack@eecs.umich.eduM5_32_auxv_t::M5_32_auxv_t(int32_t type, int32_t val)
1812585SN/A{
1824111Sgblack@eecs.umich.edu    a_type = TheISA::htog(type);
1834111Sgblack@eecs.umich.edu    a_val = TheISA::htog(val);
1842585SN/A}
1852585SN/A
1864111Sgblack@eecs.umich.eduM5_64_auxv_t::M5_64_auxv_t(int64_t type, int64_t val)
1873415Sgblack@eecs.umich.edu{
1884111Sgblack@eecs.umich.edu    a_type = TheISA::htog(type);
1894111Sgblack@eecs.umich.edu    a_val = TheISA::htog(val);
1904111Sgblack@eecs.umich.edu}
1913415Sgblack@eecs.umich.edu
1922561SN/Avoid
1934111Sgblack@eecs.umich.eduSparc64LiveProcess::argsInit(int intSize, int pageSize)
1942561SN/A{
1954111Sgblack@eecs.umich.edu    typedef M5_64_auxv_t auxv_t;
1962561SN/A    Process::startup();
1972474SN/A
1983044Sgblack@eecs.umich.edu    string filename;
1993044Sgblack@eecs.umich.edu    if(argv.size() < 1)
2003044Sgblack@eecs.umich.edu        filename = "";
2013044Sgblack@eecs.umich.edu    else
2023044Sgblack@eecs.umich.edu        filename = argv[0];
2033044Sgblack@eecs.umich.edu
2042561SN/A    Addr alignmentMask = ~(intSize - 1);
2052561SN/A
2062561SN/A    // load object file into target memory
2072561SN/A    objFile->loadSections(initVirtMem);
2082561SN/A
2092585SN/A    enum hardwareCaps
2102585SN/A    {
2112585SN/A        M5_HWCAP_SPARC_FLUSH = 1,
2122585SN/A        M5_HWCAP_SPARC_STBAR = 2,
2132585SN/A        M5_HWCAP_SPARC_SWAP = 4,
2142585SN/A        M5_HWCAP_SPARC_MULDIV = 8,
2152585SN/A        M5_HWCAP_SPARC_V9 = 16,
2162585SN/A        //This one should technically only be set
2172585SN/A        //if there is a cheetah or cheetah_plus tlb,
2182585SN/A        //but we'll use it all the time
2192585SN/A        M5_HWCAP_SPARC_ULTRA3 = 32
2202585SN/A    };
2212585SN/A
2222585SN/A    const int64_t hwcap =
2232585SN/A        M5_HWCAP_SPARC_FLUSH |
2242585SN/A        M5_HWCAP_SPARC_STBAR |
2252585SN/A        M5_HWCAP_SPARC_SWAP |
2262585SN/A        M5_HWCAP_SPARC_MULDIV |
2272585SN/A        M5_HWCAP_SPARC_V9 |
2282585SN/A        M5_HWCAP_SPARC_ULTRA3;
2292585SN/A
2302976Sgblack@eecs.umich.edu
2312976Sgblack@eecs.umich.edu    //Setup the auxilliary vectors. These will already have endian conversion.
2322976Sgblack@eecs.umich.edu    //Auxilliary vectors are loaded only for elf formatted executables.
2332976Sgblack@eecs.umich.edu    ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile);
2342976Sgblack@eecs.umich.edu    if(elfObject)
2352976Sgblack@eecs.umich.edu    {
2362976Sgblack@eecs.umich.edu        //Bits which describe the system hardware capabilities
2374793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_HWCAP, hwcap));
2382976Sgblack@eecs.umich.edu        //The system page size
2394793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_PAGESZ, SparcISA::VMPageSize));
2402976Sgblack@eecs.umich.edu        //Defined to be 100 in the kernel source.
2412976Sgblack@eecs.umich.edu        //Frequency at which times() increments
2424793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_CLKTCK, 100));
2432976Sgblack@eecs.umich.edu        // For statically linked executables, this is the virtual address of the
2442976Sgblack@eecs.umich.edu        // program header tables if they appear in the executable image
2454793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable()));
2462976Sgblack@eecs.umich.edu        // This is the size of a program header entry from the elf file.
2474793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize()));
2482976Sgblack@eecs.umich.edu        // This is the number of program headers from the original elf file.
2494793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount()));
2502976Sgblack@eecs.umich.edu        //This is the address of the elf "interpreter", It should be set
2512976Sgblack@eecs.umich.edu        //to 0 for regular executables. It should be something else
2522976Sgblack@eecs.umich.edu        //(not sure what) for dynamic libraries.
2534793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_BASE, 0));
2542976Sgblack@eecs.umich.edu        //This is hardwired to 0 in the elf loading code in the kernel
2554793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_FLAGS, 0));
2562976Sgblack@eecs.umich.edu        //The entry point to the program
2574793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint()));
2582976Sgblack@eecs.umich.edu        //Different user and group IDs
2594793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_UID, uid()));
2604793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_EUID, euid()));
2614793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_GID, gid()));
2624793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_EGID, egid()));
2632976Sgblack@eecs.umich.edu        //Whether to enable "secure mode" in the executable
2644793Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(M5_AT_SECURE, 0));
2652976Sgblack@eecs.umich.edu    }
2662585SN/A
2672561SN/A    //Figure out how big the initial stack needs to be
2682561SN/A
2693044Sgblack@eecs.umich.edu    // The unaccounted for 0 at the top of the stack
2703044Sgblack@eecs.umich.edu    int mysterious_size = intSize;
2713044Sgblack@eecs.umich.edu
2723044Sgblack@eecs.umich.edu    //This is the name of the file which is present on the initial stack
2733044Sgblack@eecs.umich.edu    //It's purpose is to let the user space linker examine the original file.
2743044Sgblack@eecs.umich.edu    int file_name_size = filename.size() + 1;
2753044Sgblack@eecs.umich.edu
2762561SN/A    int env_data_size = 0;
2772561SN/A    for (int i = 0; i < envp.size(); ++i) {
2782561SN/A        env_data_size += envp[i].size() + 1;
2792561SN/A    }
2802561SN/A    int arg_data_size = 0;
2812561SN/A    for (int i = 0; i < argv.size(); ++i) {
2822561SN/A        arg_data_size += argv[i].size() + 1;
2832561SN/A    }
2842561SN/A
2853044Sgblack@eecs.umich.edu    //The info_block needs to be padded so it's size is a multiple of the
2863044Sgblack@eecs.umich.edu    //alignment mask. Also, it appears that there needs to be at least some
2873044Sgblack@eecs.umich.edu    //padding, so if the size is already a multiple, we need to increase it
2883044Sgblack@eecs.umich.edu    //anyway.
2893044Sgblack@eecs.umich.edu    int info_block_size =
2903044Sgblack@eecs.umich.edu        (file_name_size +
2913044Sgblack@eecs.umich.edu        env_data_size +
2923044Sgblack@eecs.umich.edu        arg_data_size +
2933044Sgblack@eecs.umich.edu        intSize) & alignmentMask;
2943044Sgblack@eecs.umich.edu
2953044Sgblack@eecs.umich.edu    int info_block_padding =
2963044Sgblack@eecs.umich.edu        info_block_size -
2973044Sgblack@eecs.umich.edu        file_name_size -
2983044Sgblack@eecs.umich.edu        env_data_size -
2993044Sgblack@eecs.umich.edu        arg_data_size;
3003044Sgblack@eecs.umich.edu
3013044Sgblack@eecs.umich.edu    //Each auxilliary vector is two 8 byte words
3022561SN/A    int aux_array_size = intSize * 2 * (auxv.size() + 1);
3032561SN/A
3043044Sgblack@eecs.umich.edu    int envp_array_size = intSize * (envp.size() + 1);
3052561SN/A    int argv_array_size = intSize * (argv.size() + 1);
3062561SN/A
3072561SN/A    int argc_size = intSize;
3082561SN/A    int window_save_size = intSize * 16;
3092561SN/A
3102561SN/A    int space_needed =
3113044Sgblack@eecs.umich.edu        mysterious_size +
3122561SN/A        info_block_size +
3132561SN/A        aux_array_size +
3142561SN/A        envp_array_size +
3152561SN/A        argv_array_size +
3162561SN/A        argc_size +
3172561SN/A        window_save_size;
3182561SN/A
3192561SN/A    stack_min = stack_base - space_needed;
3202561SN/A    stack_min &= alignmentMask;
3212561SN/A    stack_size = stack_base - stack_min;
3222561SN/A
3232561SN/A    // map memory
3242561SN/A    pTable->allocate(roundDown(stack_min, pageSize),
3252561SN/A                     roundUp(stack_size, pageSize));
3262561SN/A
3272561SN/A    // map out initial stack contents
3283044Sgblack@eecs.umich.edu    Addr mysterious_base = stack_base - mysterious_size;
3293044Sgblack@eecs.umich.edu    Addr file_name_base = mysterious_base - file_name_size;
3303044Sgblack@eecs.umich.edu    Addr env_data_base = file_name_base - env_data_size;
3312561SN/A    Addr arg_data_base = env_data_base - arg_data_size;
3323044Sgblack@eecs.umich.edu    Addr auxv_array_base = arg_data_base - aux_array_size - info_block_padding;
3332585SN/A    Addr envp_array_base = auxv_array_base - envp_array_size;
3342561SN/A    Addr argv_array_base = envp_array_base - argv_array_size;
3352561SN/A    Addr argc_base = argv_array_base - argc_size;
3363039Sstever@eecs.umich.edu#ifndef NDEBUG
3373039Sstever@eecs.umich.edu    // only used in DPRINTF
3382561SN/A    Addr window_save_base = argc_base - window_save_size;
3393039Sstever@eecs.umich.edu#endif
3402561SN/A
3412561SN/A    DPRINTF(Sparc, "The addresses of items on the initial stack:\n");
3423044Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - file name\n", file_name_base);
3432561SN/A    DPRINTF(Sparc, "0x%x - env data\n", env_data_base);
3442561SN/A    DPRINTF(Sparc, "0x%x - arg data\n", arg_data_base);
3452585SN/A    DPRINTF(Sparc, "0x%x - auxv array\n", auxv_array_base);
3462585SN/A    DPRINTF(Sparc, "0x%x - envp array\n", envp_array_base);
3472585SN/A    DPRINTF(Sparc, "0x%x - argv array\n", argv_array_base);
3482561SN/A    DPRINTF(Sparc, "0x%x - argc \n", argc_base);
3492561SN/A    DPRINTF(Sparc, "0x%x - window save\n", window_save_base);
3502561SN/A    DPRINTF(Sparc, "0x%x - stack min\n", stack_min);
3512561SN/A
3522561SN/A    // write contents to stack
3533044Sgblack@eecs.umich.edu
3543044Sgblack@eecs.umich.edu    // figure out argc
3552561SN/A    uint64_t argc = argv.size();
3562585SN/A    uint64_t guestArgc = TheISA::htog(argc);
3572561SN/A
3583044Sgblack@eecs.umich.edu    //Write out the mysterious 0
3593044Sgblack@eecs.umich.edu    uint64_t mysterious_zero = 0;
3603044Sgblack@eecs.umich.edu    initVirtMem->writeBlob(mysterious_base,
3613044Sgblack@eecs.umich.edu            (uint8_t*)&mysterious_zero, mysterious_size);
3623044Sgblack@eecs.umich.edu
3633044Sgblack@eecs.umich.edu    //Write the file name
3643044Sgblack@eecs.umich.edu    initVirtMem->writeString(file_name_base, filename.c_str());
3653044Sgblack@eecs.umich.edu
3662585SN/A    //Copy the aux stuff
3672585SN/A    for(int x = 0; x < auxv.size(); x++)
3682585SN/A    {
3692585SN/A        initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize,
3702585SN/A                (uint8_t*)&(auxv[x].a_type), intSize);
3712585SN/A        initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize,
3722585SN/A                (uint8_t*)&(auxv[x].a_val), intSize);
3732585SN/A    }
3742585SN/A    //Write out the terminating zeroed auxilliary vector
3752561SN/A    const uint64_t zero = 0;
3762585SN/A    initVirtMem->writeBlob(auxv_array_base + 2 * intSize * auxv.size(),
3772585SN/A            (uint8_t*)&zero, 2 * intSize);
3782561SN/A
3792561SN/A    copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
3802561SN/A    copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
3812561SN/A
3822585SN/A    initVirtMem->writeBlob(argc_base, (uint8_t*)&guestArgc, intSize);
3832561SN/A
3843415Sgblack@eecs.umich.edu    //Stuff the trap handlers into the processes address space.
3853415Sgblack@eecs.umich.edu    //Since the stack grows down and is the highest area in the processes
3863415Sgblack@eecs.umich.edu    //address space, we can put stuff above it and stay out of the way.
3873415Sgblack@eecs.umich.edu    int fillSize = sizeof(MachInst) * numFillInsts;
3883415Sgblack@eecs.umich.edu    int spillSize = sizeof(MachInst) * numSpillInsts;
3893415Sgblack@eecs.umich.edu    fillStart = stack_base;
3903415Sgblack@eecs.umich.edu    spillStart = fillStart + fillSize;
3914111Sgblack@eecs.umich.edu    initVirtMem->writeBlob(fillStart, (uint8_t*)fillHandler64, fillSize);
3924111Sgblack@eecs.umich.edu    initVirtMem->writeBlob(spillStart, (uint8_t*)spillHandler64, spillSize);
3933415Sgblack@eecs.umich.edu
3943415Sgblack@eecs.umich.edu    //Set up the thread context to start running the process
3954772Sgblack@eecs.umich.edu    assert(NumArgumentRegs >= 2);
3964772Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(ArgumentReg[0], argc);
3974772Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(ArgumentReg[1], argv_array_base);
3982680Sktlim@umich.edu    threadContexts[0]->setIntReg(StackPointerReg, stack_min - StackBias);
3992561SN/A
4002561SN/A    Addr prog_entry = objFile->entryPoint();
4012680Sktlim@umich.edu    threadContexts[0]->setPC(prog_entry);
4022680Sktlim@umich.edu    threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
4032680Sktlim@umich.edu    threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
4042561SN/A
4053959Sgblack@eecs.umich.edu    //Align the "stack_min" to a page boundary.
4063959Sgblack@eecs.umich.edu    stack_min = roundDown(stack_min, pageSize);
4073959Sgblack@eecs.umich.edu
4082561SN/A//    num_processes++;
4092561SN/A}
4104111Sgblack@eecs.umich.edu
4114111Sgblack@eecs.umich.eduvoid
4124111Sgblack@eecs.umich.eduSparc32LiveProcess::argsInit(int intSize, int pageSize)
4134111Sgblack@eecs.umich.edu{
4144111Sgblack@eecs.umich.edu    typedef M5_32_auxv_t auxv_t;
4154111Sgblack@eecs.umich.edu    Process::startup();
4164111Sgblack@eecs.umich.edu
4174111Sgblack@eecs.umich.edu    string filename;
4184111Sgblack@eecs.umich.edu    if(argv.size() < 1)
4194111Sgblack@eecs.umich.edu        filename = "";
4204111Sgblack@eecs.umich.edu    else
4214111Sgblack@eecs.umich.edu        filename = argv[0];
4224111Sgblack@eecs.umich.edu
4234117Sgblack@eecs.umich.edu    //Even though this is a 32 bit process, the ABI says we still need to
4244117Sgblack@eecs.umich.edu    //maintain double word alignment of the stack pointer.
4254117Sgblack@eecs.umich.edu    Addr alignmentMask = ~(8 - 1);
4264111Sgblack@eecs.umich.edu
4274111Sgblack@eecs.umich.edu    // load object file into target memory
4284111Sgblack@eecs.umich.edu    objFile->loadSections(initVirtMem);
4294111Sgblack@eecs.umich.edu
4304111Sgblack@eecs.umich.edu    //These are the auxilliary vector types
4314111Sgblack@eecs.umich.edu    enum auxTypes
4324111Sgblack@eecs.umich.edu    {
4334111Sgblack@eecs.umich.edu        SPARC_AT_HWCAP = 16,
4344111Sgblack@eecs.umich.edu        SPARC_AT_PAGESZ = 6,
4354111Sgblack@eecs.umich.edu        SPARC_AT_CLKTCK = 17,
4364111Sgblack@eecs.umich.edu        SPARC_AT_PHDR = 3,
4374111Sgblack@eecs.umich.edu        SPARC_AT_PHENT = 4,
4384111Sgblack@eecs.umich.edu        SPARC_AT_PHNUM = 5,
4394111Sgblack@eecs.umich.edu        SPARC_AT_BASE = 7,
4404111Sgblack@eecs.umich.edu        SPARC_AT_FLAGS = 8,
4414111Sgblack@eecs.umich.edu        SPARC_AT_ENTRY = 9,
4424111Sgblack@eecs.umich.edu        SPARC_AT_UID = 11,
4434111Sgblack@eecs.umich.edu        SPARC_AT_EUID = 12,
4444111Sgblack@eecs.umich.edu        SPARC_AT_GID = 13,
4454111Sgblack@eecs.umich.edu        SPARC_AT_EGID = 14,
4464111Sgblack@eecs.umich.edu        SPARC_AT_SECURE = 23
4474111Sgblack@eecs.umich.edu    };
4484111Sgblack@eecs.umich.edu
4494111Sgblack@eecs.umich.edu    enum hardwareCaps
4504111Sgblack@eecs.umich.edu    {
4514111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_FLUSH = 1,
4524111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_STBAR = 2,
4534111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_SWAP = 4,
4544111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_MULDIV = 8,
4554111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_V9 = 16,
4564111Sgblack@eecs.umich.edu        //This one should technically only be set
4574111Sgblack@eecs.umich.edu        //if there is a cheetah or cheetah_plus tlb,
4584111Sgblack@eecs.umich.edu        //but we'll use it all the time
4594111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_ULTRA3 = 32
4604111Sgblack@eecs.umich.edu    };
4614111Sgblack@eecs.umich.edu
4624111Sgblack@eecs.umich.edu    const int64_t hwcap =
4634111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_FLUSH |
4644111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_STBAR |
4654111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_SWAP |
4664111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_MULDIV |
4674111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_V9 |
4684111Sgblack@eecs.umich.edu        M5_HWCAP_SPARC_ULTRA3;
4694111Sgblack@eecs.umich.edu
4704111Sgblack@eecs.umich.edu
4714111Sgblack@eecs.umich.edu    //Setup the auxilliary vectors. These will already have endian conversion.
4724111Sgblack@eecs.umich.edu    //Auxilliary vectors are loaded only for elf formatted executables.
4734111Sgblack@eecs.umich.edu    ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile);
4744111Sgblack@eecs.umich.edu    if(elfObject)
4754111Sgblack@eecs.umich.edu    {
4764111Sgblack@eecs.umich.edu        //Bits which describe the system hardware capabilities
4774111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_HWCAP, hwcap));
4784111Sgblack@eecs.umich.edu        //The system page size
4794111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_PAGESZ, SparcISA::VMPageSize));
4804111Sgblack@eecs.umich.edu        //Defined to be 100 in the kernel source.
4814111Sgblack@eecs.umich.edu        //Frequency at which times() increments
4824111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_CLKTCK, 100));
4834111Sgblack@eecs.umich.edu        // For statically linked executables, this is the virtual address of the
4844111Sgblack@eecs.umich.edu        // program header tables if they appear in the executable image
4854111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_PHDR, elfObject->programHeaderTable()));
4864111Sgblack@eecs.umich.edu        // This is the size of a program header entry from the elf file.
4874111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_PHENT, elfObject->programHeaderSize()));
4884111Sgblack@eecs.umich.edu        // This is the number of program headers from the original elf file.
4894111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_PHNUM, elfObject->programHeaderCount()));
4904111Sgblack@eecs.umich.edu        //This is the address of the elf "interpreter", It should be set
4914111Sgblack@eecs.umich.edu        //to 0 for regular executables. It should be something else
4924111Sgblack@eecs.umich.edu        //(not sure what) for dynamic libraries.
4934111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_BASE, 0));
4944111Sgblack@eecs.umich.edu        //This is hardwired to 0 in the elf loading code in the kernel
4954111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_FLAGS, 0));
4964111Sgblack@eecs.umich.edu        //The entry point to the program
4974111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_ENTRY, objFile->entryPoint()));
4984111Sgblack@eecs.umich.edu        //Different user and group IDs
4994111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_UID, uid()));
5004111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_EUID, euid()));
5014111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_GID, gid()));
5024111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_EGID, egid()));
5034111Sgblack@eecs.umich.edu        //Whether to enable "secure mode" in the executable
5044111Sgblack@eecs.umich.edu        auxv.push_back(auxv_t(SPARC_AT_SECURE, 0));
5054111Sgblack@eecs.umich.edu    }
5064111Sgblack@eecs.umich.edu
5074111Sgblack@eecs.umich.edu    //Figure out how big the initial stack needs to be
5084111Sgblack@eecs.umich.edu
5094164Sgblack@eecs.umich.edu    // The unaccounted for 8 byte 0 at the top of the stack
5104164Sgblack@eecs.umich.edu    int mysterious_size = 8;
5114111Sgblack@eecs.umich.edu
5124111Sgblack@eecs.umich.edu    //This is the name of the file which is present on the initial stack
5134111Sgblack@eecs.umich.edu    //It's purpose is to let the user space linker examine the original file.
5144111Sgblack@eecs.umich.edu    int file_name_size = filename.size() + 1;
5154111Sgblack@eecs.umich.edu
5164111Sgblack@eecs.umich.edu    int env_data_size = 0;
5174111Sgblack@eecs.umich.edu    for (int i = 0; i < envp.size(); ++i) {
5184111Sgblack@eecs.umich.edu        env_data_size += envp[i].size() + 1;
5194111Sgblack@eecs.umich.edu    }
5204111Sgblack@eecs.umich.edu    int arg_data_size = 0;
5214111Sgblack@eecs.umich.edu    for (int i = 0; i < argv.size(); ++i) {
5224111Sgblack@eecs.umich.edu        arg_data_size += argv[i].size() + 1;
5234111Sgblack@eecs.umich.edu    }
5244111Sgblack@eecs.umich.edu
5254164Sgblack@eecs.umich.edu    //The info_block - This seems to need an pad for some reason.
5264111Sgblack@eecs.umich.edu    int info_block_size =
5274164Sgblack@eecs.umich.edu        (mysterious_size +
5284164Sgblack@eecs.umich.edu        file_name_size +
5294111Sgblack@eecs.umich.edu        env_data_size +
5304164Sgblack@eecs.umich.edu        arg_data_size + intSize);
5314111Sgblack@eecs.umich.edu
5324164Sgblack@eecs.umich.edu    //Each auxilliary vector is two 4 byte words
5334111Sgblack@eecs.umich.edu    int aux_array_size = intSize * 2 * (auxv.size() + 1);
5344111Sgblack@eecs.umich.edu
5354111Sgblack@eecs.umich.edu    int envp_array_size = intSize * (envp.size() + 1);
5364111Sgblack@eecs.umich.edu    int argv_array_size = intSize * (argv.size() + 1);
5374111Sgblack@eecs.umich.edu
5384111Sgblack@eecs.umich.edu    int argc_size = intSize;
5394111Sgblack@eecs.umich.edu    int window_save_size = intSize * 16;
5404111Sgblack@eecs.umich.edu
5414111Sgblack@eecs.umich.edu    int space_needed =
5424164Sgblack@eecs.umich.edu        info_block_size +
5434111Sgblack@eecs.umich.edu        aux_array_size +
5444111Sgblack@eecs.umich.edu        envp_array_size +
5454111Sgblack@eecs.umich.edu        argv_array_size +
5464111Sgblack@eecs.umich.edu        argc_size +
5474111Sgblack@eecs.umich.edu        window_save_size;
5484111Sgblack@eecs.umich.edu
5494111Sgblack@eecs.umich.edu    stack_min = stack_base - space_needed;
5504111Sgblack@eecs.umich.edu    stack_min &= alignmentMask;
5514111Sgblack@eecs.umich.edu    stack_size = stack_base - stack_min;
5524111Sgblack@eecs.umich.edu
5534111Sgblack@eecs.umich.edu    // map memory
5544111Sgblack@eecs.umich.edu    pTable->allocate(roundDown(stack_min, pageSize),
5554111Sgblack@eecs.umich.edu                     roundUp(stack_size, pageSize));
5564111Sgblack@eecs.umich.edu
5574111Sgblack@eecs.umich.edu    // map out initial stack contents
5584117Sgblack@eecs.umich.edu    uint32_t window_save_base = stack_min;
5594117Sgblack@eecs.umich.edu    uint32_t argc_base = window_save_base + window_save_size;
5604117Sgblack@eecs.umich.edu    uint32_t argv_array_base = argc_base + argc_size;
5614117Sgblack@eecs.umich.edu    uint32_t envp_array_base = argv_array_base + argv_array_size;
5624117Sgblack@eecs.umich.edu    uint32_t auxv_array_base = envp_array_base + envp_array_size;
5634117Sgblack@eecs.umich.edu    //The info block is pushed up against the top of the stack, while
5644117Sgblack@eecs.umich.edu    //the rest of the initial stack frame is aligned to an 8 byte boudary.
5654164Sgblack@eecs.umich.edu    uint32_t arg_data_base = stack_base - info_block_size + intSize;
5664117Sgblack@eecs.umich.edu    uint32_t env_data_base = arg_data_base + arg_data_size;
5674117Sgblack@eecs.umich.edu    uint32_t file_name_base = env_data_base + env_data_size;
5684117Sgblack@eecs.umich.edu    uint32_t mysterious_base = file_name_base + file_name_size;
5694111Sgblack@eecs.umich.edu
5704111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "The addresses of items on the initial stack:\n");
5714111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - file name\n", file_name_base);
5724111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - env data\n", env_data_base);
5734111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - arg data\n", arg_data_base);
5744111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - auxv array\n", auxv_array_base);
5754111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - envp array\n", envp_array_base);
5764111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - argv array\n", argv_array_base);
5774111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - argc \n", argc_base);
5784111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - window save\n", window_save_base);
5794111Sgblack@eecs.umich.edu    DPRINTF(Sparc, "0x%x - stack min\n", stack_min);
5804111Sgblack@eecs.umich.edu
5814111Sgblack@eecs.umich.edu    // write contents to stack
5824111Sgblack@eecs.umich.edu
5834111Sgblack@eecs.umich.edu    // figure out argc
5844111Sgblack@eecs.umich.edu    uint32_t argc = argv.size();
5854111Sgblack@eecs.umich.edu    uint32_t guestArgc = TheISA::htog(argc);
5864111Sgblack@eecs.umich.edu
5874111Sgblack@eecs.umich.edu    //Write out the mysterious 0
5884111Sgblack@eecs.umich.edu    uint64_t mysterious_zero = 0;
5894111Sgblack@eecs.umich.edu    initVirtMem->writeBlob(mysterious_base,
5904111Sgblack@eecs.umich.edu            (uint8_t*)&mysterious_zero, mysterious_size);
5914111Sgblack@eecs.umich.edu
5924111Sgblack@eecs.umich.edu    //Write the file name
5934111Sgblack@eecs.umich.edu    initVirtMem->writeString(file_name_base, filename.c_str());
5944111Sgblack@eecs.umich.edu
5954111Sgblack@eecs.umich.edu    //Copy the aux stuff
5964111Sgblack@eecs.umich.edu    for(int x = 0; x < auxv.size(); x++)
5974111Sgblack@eecs.umich.edu    {
5984111Sgblack@eecs.umich.edu        initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize,
5994111Sgblack@eecs.umich.edu                (uint8_t*)&(auxv[x].a_type), intSize);
6004111Sgblack@eecs.umich.edu        initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize,
6014111Sgblack@eecs.umich.edu                (uint8_t*)&(auxv[x].a_val), intSize);
6024111Sgblack@eecs.umich.edu    }
6034111Sgblack@eecs.umich.edu    //Write out the terminating zeroed auxilliary vector
6044111Sgblack@eecs.umich.edu    const uint64_t zero = 0;
6054111Sgblack@eecs.umich.edu    initVirtMem->writeBlob(auxv_array_base + 2 * intSize * auxv.size(),
6064111Sgblack@eecs.umich.edu            (uint8_t*)&zero, 2 * intSize);
6074111Sgblack@eecs.umich.edu
6084117Sgblack@eecs.umich.edu    copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
6094117Sgblack@eecs.umich.edu    copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
6104111Sgblack@eecs.umich.edu
6114111Sgblack@eecs.umich.edu    initVirtMem->writeBlob(argc_base, (uint8_t*)&guestArgc, intSize);
6124111Sgblack@eecs.umich.edu
6134111Sgblack@eecs.umich.edu    //Stuff the trap handlers into the processes address space.
6144111Sgblack@eecs.umich.edu    //Since the stack grows down and is the highest area in the processes
6154111Sgblack@eecs.umich.edu    //address space, we can put stuff above it and stay out of the way.
6164111Sgblack@eecs.umich.edu    int fillSize = sizeof(MachInst) * numFillInsts;
6174111Sgblack@eecs.umich.edu    int spillSize = sizeof(MachInst) * numSpillInsts;
6184111Sgblack@eecs.umich.edu    fillStart = stack_base;
6194111Sgblack@eecs.umich.edu    spillStart = fillStart + fillSize;
6204111Sgblack@eecs.umich.edu    initVirtMem->writeBlob(fillStart, (uint8_t*)fillHandler32, fillSize);
6214111Sgblack@eecs.umich.edu    initVirtMem->writeBlob(spillStart, (uint8_t*)spillHandler32, spillSize);
6224111Sgblack@eecs.umich.edu
6234111Sgblack@eecs.umich.edu    //Set up the thread context to start running the process
6244772Sgblack@eecs.umich.edu    //assert(NumArgumentRegs >= 2);
6254772Sgblack@eecs.umich.edu    //threadContexts[0]->setIntReg(ArgumentReg[0], argc);
6264772Sgblack@eecs.umich.edu    //threadContexts[0]->setIntReg(ArgumentReg[1], argv_array_base);
6274111Sgblack@eecs.umich.edu    threadContexts[0]->setIntReg(StackPointerReg, stack_min);
6284111Sgblack@eecs.umich.edu
6294117Sgblack@eecs.umich.edu    uint32_t prog_entry = objFile->entryPoint();
6304111Sgblack@eecs.umich.edu    threadContexts[0]->setPC(prog_entry);
6314111Sgblack@eecs.umich.edu    threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst));
6324111Sgblack@eecs.umich.edu    threadContexts[0]->setNextNPC(prog_entry + (2 * sizeof(MachInst)));
6334111Sgblack@eecs.umich.edu
6344111Sgblack@eecs.umich.edu    //Align the "stack_min" to a page boundary.
6354111Sgblack@eecs.umich.edu    stack_min = roundDown(stack_min, pageSize);
6364111Sgblack@eecs.umich.edu
6374111Sgblack@eecs.umich.edu//    num_processes++;
6384111Sgblack@eecs.umich.edu}
639